From f7e9351ebeba76645114c42d82fd502ecdd2161e Mon Sep 17 00:00:00 2001 From: chenbiao Date: Thu, 12 May 2022 16:25:29 +0800 Subject: [PATCH] add 接口文档更新 --- common/common.js | 4 ++++ common/requestServer.js | 20 ++++++++------------ pages/index/index.vue | 33 +++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/common/common.js b/common/common.js index c95baf7..0c46f8e 100644 --- a/common/common.js +++ b/common/common.js @@ -19,6 +19,9 @@ const SetToken = uni.getStorageSync("globalUser").token; // 商户登录 const userLogin = serverUrl + "/business/h5/index/login"; +// 获取已登录商户用户信息 +const indexInfo = serverUrl + "/business/h5/index/info"; + // 商户退出登录 const userLoginout = serverUrl + "/business/h5/index/logout"; @@ -116,6 +119,7 @@ export default { // 接口 userLogin, + indexInfo, userLoginout, useraboutUs, } diff --git a/common/requestServer.js b/common/requestServer.js index 7ca0fbd..c556bd9 100644 --- a/common/requestServer.js +++ b/common/requestServer.js @@ -13,7 +13,6 @@ export const myRequest = (options) => { // 配置请求头参数-例如token header: { 'content-type': 'application/json', - Token: common.SetToken, // Accept: 'application/json', // 'Content-Type': 'application/json', // 'X-Requested-With': 'XMLHttpRequest' @@ -30,31 +29,28 @@ export const myRequest = (options) => { //在接口200 调用成功后 才能进行判断接口内的状态码 return_code 以此判定作何操作和提示 let result = res.data console.log(result); - console.log(result.code) + if (result.code == 0) { resolve(res.data) } else { uni.hideLoading(); uni.showToast({ - title: res.data.message, - icon: 'none', + title: result.message, + icon: 'error', duration: 2000 }); } - // let return_code = result.data.code - // let return_message = result.data.message - // console.log(typeof return_code) - // console.log(return_code) + }, // 接口接口失败 fail: (error) => { // 关闭加载 uni.hideLoading(); - console.log(2, error); + console.log("请求失败", error); uni.showToast({ - title: '请求接口失败', - icon: "none", - mask: true, + title: error.message, + icon: 'error', + duration: 2000 }) // 失败数据 reject(error) diff --git a/pages/index/index.vue b/pages/index/index.vue index 3f88e15..9187036 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -10,7 +10,7 @@ - + @@ -30,7 +30,7 @@ - 张三 + {{userName}} @@ -98,8 +98,9 @@ userIsLogin: true, appName: '江阴慧停车', apptitle: '江阴慧停车·智慧便捷', - username: '', + userCode: '', password: '', + userName:'', } }, onLoad() { @@ -109,10 +110,10 @@ login() { let that = this; let data = { - userCode: that.username, + userCode: that.userCode, userPwd: that.password }; - if (that.username.trim() === "" || that.password.trim() === "") { + if (that.userCode.trim() === "" || that.password.trim() === "") { uni.showToast({ title: '用户名密码必填', icon: 'error', @@ -127,11 +128,31 @@ data: that.$common.requestSign(data) }).then(res => { console.log(res) - var userInfo = res.data; + let userInfo = res.data; console.log(res.data) + // 保存用户信息到全局的缓存中 uni.setStorageSync("globalUser", userInfo); + + // 登陆成功 展示首页 that.userIsLogin = false; + + // 首页信息获取 接口 + that.$myRequest({ + url:that.$common.indexInfo, + method: 'POST', + data: that.$common.requestSign() + }).then(res => { + console.log(res) + var indexInfo = res.data; + console.log(indexInfo) + that.userName=indexInfo.indexInfo; + + + + + }) + }) -- libgit2 0.21.4