Commit dd5ecdbd5e268552664a7c954b64abe7b889148c

Authored by chenbiao
1 parent e133a83d

add 接口文档更新

common/common.js
... ... @@ -33,6 +33,7 @@ const requestSign = function(inputData) {
33 33 jsonList.app_id = "0eca8f5373ca4866aec2f8e9d9367104";
34 34 jsonList.deviceInfo = "BC0703A4-AFB0-4B51-9089-9B7487C0CC6E";
35 35 jsonList.salt = getSalt();
  36 + jsonList.terminalSource = "11";
36 37 jsonList.token = getGlobalUser("globalUser").token;
37 38 // jsonList.token = '84b5a8edb5974f7989e7888b9f48a765';
38 39  
... ...
common/requestServer.js
... ... @@ -8,7 +8,7 @@ export const myRequest = (options) => {
8 8 });
9 9 return new Promise((resolve, reject) => {
10 10 uni.request({
11   - url: common,
  11 + url: options.url,
12 12 //默认参数
13 13 data: options.data || {},
14 14 // 配置请求头参数-例如token
... ... @@ -27,54 +27,28 @@ export const myRequest = (options) => {
27 27 success: (res) => {
28 28 // 关闭加载
29 29 uni.hideLoading();
30   - console.log('接口所有参数', res);
31   - if (res.statusCode !== 200) {
32   - // 不同报错信息的提示和配置
33   - if (res.statusCode == 500) {
34   - return uni.showToast({
35   - title: '服务器重启中...',
36   - icon: "none",
37   - mask: true,
38   - })
39   - } else {
40   - return uni.showToast({
41   - title: '获取数据失败',
42   - icon: "none",
43   - mask: true,
44   - })
45   - }
46   - }
  30 +
  31 +
47 32 // 调用成功且有数据 返回数据 组件内通过 .then() 或者async await 接受异步返回数据
48 33 //resolve(res.data)
49 34 //在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示
50   - const { statusCode, data } = res
51   - let return_code = res.data.return_code
52   - let return_message = res.data.return_message
  35 + let result=res.data
  36 + console.log( result);
  37 + let return_code = result.data.code
  38 + let return_message = result.data.message
  39 + console.log(typeof return_code)
  40 + console.log(return_code)
53 41 switch (return_code) {
54 42 case '0':
55 43 // 成功的数据data状态码 则直接返回数据
56 44 resolve(res.data)
57 45 break
58   - case '4011':
59   - uni.clearStorage()
60   - if (hasUserInfo && !isExisited && !checkToken) {
61   - isExisited = true
62   - uni.showModal({
63   - title: '提示',
64   - content: '身份失效,请重新登录!',
65   - complete: () => {
66   - uni.reLaunch({ url: '/pages/index/index' })
67   - },
68   - })
69   - } else {
70   - reject(res.data)
71   - }
72   - break
  46 +
73 47 default:
74 48 // 其他的如无特定要求 则做提示
75 49 // reject(res.data)
76 50 return uni.showToast({
77   - title: return_message || '请求失败',
  51 + title: return_message,
78 52 duration: 2000,
79 53 icon: 'none',
80 54 })
... ...
1 1 import App from './App'
2 2 import store from './store'
  3 +import common from "./common/common.js";
3 4 // 引入封装的接口api
4 5 import { myRequest } from './common/requestServer.js'
5 6 // 挂在Vue属性 全局通过this.$myRequest()可以访问到
  7 +Vue.prototype.$common = common
6 8 Vue.prototype.$myRequest = myRequest
7 9  
8 10 // #ifndef VUE3
... ...
pages/index/index.vue
... ... @@ -91,7 +91,6 @@
91 91 </template>
92 92  
93 93 <script>
94   - import common from "../../common/common.js";
95 94  
96 95 export default {
97 96 data() {
... ... @@ -109,6 +108,10 @@
109 108 methods: {
110 109 login() {
111 110 let that = this;
  111 + let data = {
  112 + userCode: that.username,
  113 + userPwd: that.password
  114 + };
112 115 if (that.username.trim() === "" || that.password.trim() === "") {
113 116 uni.showToast({
114 117 title: '用户名密码必填',
... ... @@ -117,15 +120,16 @@
117 120 })
118 121 return;
119 122 } else {
  123 +
120 124 that.$myRequest({
121   - url: common.userLogin,
  125 + url:that.$common.userLogin,
122 126 method: 'POST',
123   - data: {
124   - userCode: that.username,
125   - userPwd: that.password
126   - }
  127 + data: that.$common.requestSign(data)
127 128 }).then(res => {
128   - console.log('使用.then()获取返回的参数', res);
  129 + var userInfo = res.data.data;
  130 + // 保存用户信息到全局的缓存中
  131 + uni.setStorageSync("globalUser", userInfo);
  132 + that.userIsLogin = true;
129 133  
130 134 })
131 135  
... ...