123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import {
- api_config
- } from "../config.js"
- class ReqestConfig {
- constructor() {
- this.params = {
- 'content-type': "application/json",
- timeout: 16000,
- header: {
- appId: uni.getStorageSync('storage_users').uid,
- authorization: uni.getStorageSync('storage_token')
- }
- }
- }
- }
- class RequestFun extends ReqestConfig {
- constructor(arg) {
- super(arg)
- }
- fetch(url, method, data, complete = null, responseType = 'text') {
- return new Promise((resolve, reject) => {
- uni.request({
- url: api_config + url, //
- ...this.params,
- responseType: responseType,
- method: method,
- data: data,
- success: (res) => {
- try {
- if (res.data.code == 0) {
- resolve(res.data.data)
- } else if (res.data.code == 205) {
- reject(res)
- } else {
- // let value =
- // `参数:${JSON.stringify(data)}\n\n接口:${method}=>${api_config+url}\n\n接口报错信息:${res.data.msg}`
- // uni.showModal({
- // title: '开发错误提示(仅供测试使用)',
- // showCancel: true,
- // content: value,
- // confirmText: '复制内容',
- // success(resp) {
- // if (resp.confirm) {
- // uni.setClipboardData({
- // data: value,
- // success: () => {
- // uni.showToast({
- // title: '复制成功'
- // })
- // }
- // });
- // } else if (resp.cancel) {
- // console.log('用户点击取消');
- // }
- // }
- // });
- plus.nativeUI.toast(res.data.msg); //可定制化
- reject(res)
- }
- } catch (e) {
- console.log(e)
- plus.nativeUI.toast(res.data.message);
- reject(res)
- }
- },
- fail: (error) => {
- plus.nativeUI.toast('连接超时,请检查您的网络~');
- reject(error)
- },
- complete: complete
- });
- })
- }
- }
- export default RequestFun
|