diff --git a/common/common.js b/common/common.js index a79a52c..c95baf7 100644 --- a/common/common.js +++ b/common/common.js @@ -33,6 +33,7 @@ const requestSign = function(inputData) { jsonList.app_id = "0eca8f5373ca4866aec2f8e9d9367104"; jsonList.deviceInfo = "BC0703A4-AFB0-4B51-9089-9B7487C0CC6E"; jsonList.salt = getSalt(); + jsonList.terminalSource = "11"; jsonList.token = getGlobalUser("globalUser").token; // jsonList.token = '84b5a8edb5974f7989e7888b9f48a765'; diff --git a/common/requestServer.js b/common/requestServer.js index 8c02805..ec0ccf0 100644 --- a/common/requestServer.js +++ b/common/requestServer.js @@ -8,7 +8,7 @@ export const myRequest = (options) => { }); return new Promise((resolve, reject) => { uni.request({ - url: common, + url: options.url, //默认参数 data: options.data || {}, // 配置请求头参数-例如token @@ -27,54 +27,28 @@ export const myRequest = (options) => { success: (res) => { // 关闭加载 uni.hideLoading(); - console.log('接口所有参数', res); - if (res.statusCode !== 200) { - // 不同报错信息的提示和配置 - if (res.statusCode == 500) { - return uni.showToast({ - title: '服务器重启中...', - icon: "none", - mask: true, - }) - } else { - return uni.showToast({ - title: '获取数据失败', - icon: "none", - mask: true, - }) - } - } + + // 调用成功且有数据 返回数据 组件内通过 .then() 或者async await 接受异步返回数据 //resolve(res.data) //在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示 - const { statusCode, data } = res - let return_code = res.data.return_code - let return_message = res.data.return_message + let result=res.data + console.log( result); + let return_code = result.data.code + let return_message = result.data.message + console.log(typeof return_code) + console.log(return_code) switch (return_code) { case '0': // 成功的数据data状态码 则直接返回数据 resolve(res.data) break - case '4011': - uni.clearStorage() - if (hasUserInfo && !isExisited && !checkToken) { - isExisited = true - uni.showModal({ - title: '提示', - content: '身份失效,请重新登录!', - complete: () => { - uni.reLaunch({ url: '/pages/index/index' }) - }, - }) - } else { - reject(res.data) - } - break + default: // 其他的如无特定要求 则做提示 // reject(res.data) return uni.showToast({ - title: return_message || '请求失败', + title: return_message, duration: 2000, icon: 'none', }) diff --git a/main.js b/main.js index a600a6c..e4eba40 100644 --- a/main.js +++ b/main.js @@ -1,8 +1,10 @@ import App from './App' import store from './store' +import common from "./common/common.js"; // 引入封装的接口api import { myRequest } from './common/requestServer.js' // 挂在Vue属性 全局通过this.$myRequest()可以访问到 +Vue.prototype.$common = common Vue.prototype.$myRequest = myRequest // #ifndef VUE3 diff --git a/pages/index/index.vue b/pages/index/index.vue index 5f150f6..7e27c1c 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -91,7 +91,6 @@