| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- class HTTP {
- constructor() {
- this.urls = [{
- name: '测试',
- url: "http://61.164.207.46:8300"
- }, {
- name: '正式',
- url: "https://crm.meida.com:16691"
- }, {
- name: "楚楚",
- url: "https://cucu.cnyunl.com:8079"
- }]
- if (process.env.NODE_ENV === 'development') {
- this.baseUrl = this.urls[0].url;
- } else {
- this.baseUrl = this.urls[1].url;
- }
- console.log("接口地址", this.baseUrl)
- }
- request({
- url,
- data = {},
- method = "POST",
- header = {
- 'content-type': 'application/json'
- },
- showLoading = ''
- }) {
- return new Promise((resolve, reject) => {
- this._request(url, resolve, reject, data, method, header, showLoading);
- })
- }
- _request(url, resolve, reject, data, method, header, showLoading) {
- if (showLoading) uni.showLoading({
- title: showLoading,
- mask: true
- })
- uni.request({
- url: this.baseUrl + '/yos/rest' + url,
- data: data,
- method: method,
- header: header,
- timeout: 60000,
- success: res => resolve(res.data),
- fial: err => reject(err),
- complete: (res) => {
- if (showLoading) uni.hideLoading()
- if (res.errMsg != 'request:ok') {
- uni.showToast({
- title: '网络异常,请稍后再试',
- icon: "none"
- })
- } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
- uni.redirectTo({
- url: '/pages/login/login',
- success() {
- uni.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- });
- }
- }
- })
- }
- }
- export {
- HTTP
- }
|