12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- class HTTP {
- constructor() {
- this.ENV = wx.getAccountInfoSync().miniProgram.envVersion;
- this.urls = [{
- name: "生产环境",
- url: "https://oms.idcgroup.com.cn:8079"
- }, {
- name: "开发环境",
- url: "http://61.164.207.46:8000"
- }]
- if (this.ENV === 'release') { // 正式版
- this.baseUrl = "https://oms.idcgroup.com.cn:8079";
- } else {
- this.baseUrl = "http://61.164.207.46:8000";
- // this.baseUrl = "https://oms.idcgroup.com.cn:8079";
- }
- this.init = (content, init = false) => {
- return new Promise((resolve, reject) => {
- if (init.detail != undefined) init = init.detail;
- if (init) content.pageNumber = 1;
- content.pageNumber > content.pageTotal ? reject() : resolve(content)
- })
- }
- this.paging = (data, res) => {
- let content = JSON.parse(JSON.stringify(data))
- content.pageNumber = res.pageNumber + 1;
- content.pageTotal = res.pageTotal;
- content.total = res.total;
- content.sort = res.sort;
- if (this.isShowEmpty) this.empty = res.total == 0;
- return content;
- }
- }
- request({
- url,
- data = {},
- method = "POST",
- header = {
- 'content-type': 'application/json'
- },
- loading = true
- }) {
- return new Promise((resolve, reject) => {
- this._request(url, resolve, reject, data, method, header, loading);
- })
- }
- _request(url, resolve, reject, data, method, header, loading) {
- /* if (loading) wx.showLoading({
- title: getApp().globalData.Language.getMapText('加载中...'),
- mask: true
- }) */
- if (data.method && data.method != "query_userauth") data.languagecode = wx.getStorageSync('languagecode') || 'ZH'
- wx.request({
- url: this.baseUrl + '/yos/rest/index' + url,
- data: data,
- method: method,
- header: header,
- timeout: 60000,
- success: res => resolve(res.data),
- fial: err => reject(err),
- complete: (res) => {
- // if (loading) wx.hideLoading()
- if (res.data.code != 1) {
- console.error("错误的请求", {
- request: data,
- result: res.data
- })
- }
- if (res.errMsg != 'request:ok') {
- wx.showToast({
- title: getApp().globalData.Language.getMapText('网络异常,请重新进入'),
- icon: "none"
- })
- } else if (res.data.msg == '登陆状态已过期,请重新登陆!' || res.data.msg == getApp().globalData.Language.getMapText('登陆状态已过期,请重新登陆!')) {
- wx.showToast({
- title: getApp().globalData.Language.getMapText(res.data.msg),
- icon: "none",
- mask: true
- })
- getApp().globalData.LaunchOptions = wx.getLaunchOptionsSync();
- count = setTimeout(() => {
- wx.reLaunch({
- url: '/pages/login/phone',
- });
- }, 1000)
- }
- }
- })
- }
- }
- export {
- HTTP
- }
|