Commit dd5ecdbd5e268552664a7c954b64abe7b889148c

Authored by chenbiao
1 parent e133a83d

add 接口文档更新

common/common.js
@@ -33,6 +33,7 @@ const requestSign = function(inputData) { @@ -33,6 +33,7 @@ const requestSign = function(inputData) {
33 jsonList.app_id = "0eca8f5373ca4866aec2f8e9d9367104"; 33 jsonList.app_id = "0eca8f5373ca4866aec2f8e9d9367104";
34 jsonList.deviceInfo = "BC0703A4-AFB0-4B51-9089-9B7487C0CC6E"; 34 jsonList.deviceInfo = "BC0703A4-AFB0-4B51-9089-9B7487C0CC6E";
35 jsonList.salt = getSalt(); 35 jsonList.salt = getSalt();
  36 + jsonList.terminalSource = "11";
36 jsonList.token = getGlobalUser("globalUser").token; 37 jsonList.token = getGlobalUser("globalUser").token;
37 // jsonList.token = '84b5a8edb5974f7989e7888b9f48a765'; 38 // jsonList.token = '84b5a8edb5974f7989e7888b9f48a765';
38 39
common/requestServer.js
@@ -8,7 +8,7 @@ export const myRequest = (options) => { @@ -8,7 +8,7 @@ export const myRequest = (options) => {
8 }); 8 });
9 return new Promise((resolve, reject) => { 9 return new Promise((resolve, reject) => {
10 uni.request({ 10 uni.request({
11 - url: common, 11 + url: options.url,
12 //默认参数 12 //默认参数
13 data: options.data || {}, 13 data: options.data || {},
14 // 配置请求头参数-例如token 14 // 配置请求头参数-例如token
@@ -27,54 +27,28 @@ export const myRequest = (options) => { @@ -27,54 +27,28 @@ export const myRequest = (options) => {
27 success: (res) => { 27 success: (res) => {
28 // 关闭加载 28 // 关闭加载
29 uni.hideLoading(); 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 // 调用成功且有数据 返回数据 组件内通过 .then() 或者async await 接受异步返回数据 32 // 调用成功且有数据 返回数据 组件内通过 .then() 或者async await 接受异步返回数据
48 //resolve(res.data) 33 //resolve(res.data)
49 //在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示 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 switch (return_code) { 41 switch (return_code) {
54 case '0': 42 case '0':
55 // 成功的数据data状态码 则直接返回数据 43 // 成功的数据data状态码 则直接返回数据
56 resolve(res.data) 44 resolve(res.data)
57 break 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 default: 47 default:
74 // 其他的如无特定要求 则做提示 48 // 其他的如无特定要求 则做提示
75 // reject(res.data) 49 // reject(res.data)
76 return uni.showToast({ 50 return uni.showToast({
77 - title: return_message || '请求失败', 51 + title: return_message,
78 duration: 2000, 52 duration: 2000,
79 icon: 'none', 53 icon: 'none',
80 }) 54 })
1 import App from './App' 1 import App from './App'
2 import store from './store' 2 import store from './store'
  3 +import common from "./common/common.js";
3 // 引入封装的接口api 4 // 引入封装的接口api
4 import { myRequest } from './common/requestServer.js' 5 import { myRequest } from './common/requestServer.js'
5 // 挂在Vue属性 全局通过this.$myRequest()可以访问到 6 // 挂在Vue属性 全局通过this.$myRequest()可以访问到
  7 +Vue.prototype.$common = common
6 Vue.prototype.$myRequest = myRequest 8 Vue.prototype.$myRequest = myRequest
7 9
8 // #ifndef VUE3 10 // #ifndef VUE3
pages/index/index.vue
@@ -91,7 +91,6 @@ @@ -91,7 +91,6 @@
91 </template> 91 </template>
92 92
93 <script> 93 <script>
94 - import common from "../../common/common.js";  
95 94
96 export default { 95 export default {
97 data() { 96 data() {
@@ -109,6 +108,10 @@ @@ -109,6 +108,10 @@
109 methods: { 108 methods: {
110 login() { 109 login() {
111 let that = this; 110 let that = this;
  111 + let data = {
  112 + userCode: that.username,
  113 + userPwd: that.password
  114 + };
112 if (that.username.trim() === "" || that.password.trim() === "") { 115 if (that.username.trim() === "" || that.password.trim() === "") {
113 uni.showToast({ 116 uni.showToast({
114 title: '用户名密码必填', 117 title: '用户名密码必填',
@@ -117,15 +120,16 @@ @@ -117,15 +120,16 @@
117 }) 120 })
118 return; 121 return;
119 } else { 122 } else {
  123 +
120 that.$myRequest({ 124 that.$myRequest({
121 - url: common.userLogin, 125 + url:that.$common.userLogin,
122 method: 'POST', 126 method: 'POST',
123 - data: {  
124 - userCode: that.username,  
125 - userPwd: that.password  
126 - } 127 + data: that.$common.requestSign(data)
127 }).then(res => { 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