From a62eed8a22fa515bd4279d0955eb605d3cc2bfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=80=AA?= <690927457@qq.com> Date: Wed, 25 Oct 2023 23:45:00 +0800 Subject: [PATCH] =?UTF-8?q?10.25=E5=8D=88=E5=A4=9C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/index.js | 2 +- pages/index/index.vue | 4 +- pages/login/login.vue | 95 ++++++++++++++++++++++++++++++++++--------- pages/user/index.vue | 28 +++++++++++-- 4 files changed, 102 insertions(+), 27 deletions(-) diff --git a/config/index.js b/config/index.js index 9f90e1f..a5c4fa1 100644 --- a/config/index.js +++ b/config/index.js @@ -1,6 +1,6 @@ // isdev 为 true 表示开发环境 false 表示发布环境 const isdev = true; -const baseUrl = isdev ? 'http://eb467b6.r19.cpolar.top' : 'http://eb467b6.r19.cpolar.top';// 办公室接口 & 测试环境 +const baseUrl = isdev ? 'http://3fc7c93a.r7.cpolar.top' : 'http://eb467b6.r19.cpolar.top';// 办公室接口 & 测试环境 // const baseUrl = isdev ? 'http://192.168.1.133:8899' : 'https://api.gwkjxb.com';// 办公室接口 & 正式环境 // const baseUrl = 'https://api.gwkjxb.com';// 正式环境(由于本地测试后台没有启动,暂时通用正式服) diff --git a/pages/index/index.vue b/pages/index/index.vue index d76a73b..1755bab 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -121,11 +121,11 @@ isSurgery:isSurgery.value, surgery_time:surgery_time.value, userId:user_info.userId, - hospitalId:choosed_h.value.ID + hospitalId:choosed_h.value?.ID }) console.log(res) if(res.code == 0) { - + toClose() } } diff --git a/pages/login/login.vue b/pages/login/login.vue index 191a00b..547cc6b 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -7,12 +7,14 @@ const store = useStore() import api from "@/api/index" import custom from "@/utils/index.js" - onLoad(() => { + onLoad((e) => { + token_info.value = JSON.parse(decodeURIComponent(e.token_info)) // is_login.value = custom.checkLogin() // console.log(is_login.value) }) // 变量 + const token_info = ref(null) const avatarUrl = ref(null) const nickname = ref('') const res_form = ref(null) @@ -34,28 +36,47 @@ // console.log(e.detail.errMsg) // 回调信息(成功失败都会返回) // console.log(e.detail.errno) // 错误码(失败时返回) } - async function getAccess_token(params={}){//获取token 获取手机号 + async function getAccess_token(code){// //清除token缓存 // wx.clearStorageSync(); + if(!avatarUrl.value) { + uni.showToast({ + title:"请选择头像!", + icon:"error", + duration:1500 + }) + return + } + if(!nickname.value) { + uni.showToast({ + title:"请填写昵称!", + icon:"error", + duration:1500 + }) + return + } //访问接口 - const data={ - username:params.code,//手机号按钮获取的code - type:'wechat_mini_app', - identity:'user', - password:'111', - avatarUrl:avatarUrl.value, - nickName:nickname.value - } + // console.log(code.value);return + // const data={ + // username:code,//手机号按钮获取的code + // type:'wechat_mini_app', + // identity:'user', + // password:'111', + // avatarUrl:avatarUrl.value, + // nickName:nickname.value + // } // console.log('登录参数:',data);return; - const res = await api.getToken(data) - if(res.code === 200) { - uni.setStorageSync('avatarUrl', avatarUrl.value);//avatarUrl - res_form.value = res.data - res_form.value.access_token = 'Bearer '+res.data.access_token - let userId = res.data.userId - uni.setStorageSync('access_token',res_form.value.access_token);// token单独缓存一次 - wx_login(userId) - } + // const res = await api.getToken(data) + // if(res.code === 200) { + // uni.setStorageSync('avatarUrl', avatarUrl.value);//avatarUrl + // res_form.value = res.data + // res_form.value.access_token = 'Bearer '+res.data.access_token + // let userId = res.data.userId + // uni.setStorageSync('access_token',res_form.value.access_token);// token单独缓存一次 + // wx_login(userId) + // } + uni.setStorageSync('avatarUrl', avatarUrl.value);//avatarUrl + wx_login(userId) } async function wx_login(userId){ let res=await new Promise(resolve=>{ @@ -99,6 +120,39 @@ // console.log('拿到的值:',e) // console.log('nickname:',nickname.value) } + async function updateInfoFunc() { + if(!avatarUrl.value) { + uni.showToast({ + title:"请选择头像!", + icon:"error", + duration:1500 + }) + return + } + if(!nickname.value) { + uni.showToast({ + title:"请填写昵称!", + icon:"error", + duration:1500 + }) + return + } + // let user_info = JSON.parse(uni.getStorageSync('userInfo')) + await custom.uploadImage(avatarUrl.value,async (file)=>{ + avatarUrl.value = file.data.file.url + uni.setStorageSync('avatarUrl', file.data.file.url);//头像链接 + token_info.value.nickname = nickname.value + token_info.value.avatar = avatarUrl.value + uni.setStorageSync('userInfo',JSON.stringify(token_info.value)) + const up_res = await updateFunc() // 更新用户信息 + + uni.setStorageSync('access_token','Bearer '+token_info.value.access_token);// token单独缓存一次 + uni.switchTab({ + url:"/pages/user/index" + }) + }) + + } diff --git a/pages/user/index.vue b/pages/user/index.vue index 7ff3004..96ae389 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -15,6 +15,7 @@ const res_form = ref(null) const is_login = ref(null) const userinfo = ref(null) + const newUser = ref(null) // const avatarUrl = ref(null) const nickname = ref('') // 函数 @@ -26,9 +27,9 @@ userinfo.value = JSON.parse(uni.getStorageSync('userInfo')) } } - function toLogin() { + function toLogin(token_info) { uni.navigateTo({ - url:"/pages/login/login" + url:"/pages/login/login?token_info="+token_info }) } function toDetail(type) { @@ -83,8 +84,24 @@ // console.log('登录参数:',data);return; const res = await api.getToken(data) if(res.code === 200) { - if(res.data.newUser) { // 新用户,跳转登录页 - toLogin() + // newUser.value = res.data.newUser + if(res.data.newUser) { // 新用户,不做任何缓存动作,跳转登录页 + let userId = res.data.userId + let res_p=await new Promise(resolve=>{ + uni.login({ + provider: 'weixin', //使用微信登录 + success: function (loginRes) { + resolve(loginRes); + console.log(loginRes,'微信登录返回信息'); + } + }); + }); + uni.setStorageSync('access_token','Bearer '+res.data.access_token);// token单独缓存一次 + let res2=await api.wx_login({code:res_p.code},userId); + if(res2.code === 0) { + + toLogin(encodeURIComponent(JSON.stringify(res.data))) + } } else{ uni.setStorageSync('avatarUrl', res.data.avatar);//avatarUrl @@ -111,6 +128,9 @@ uni.setStorageSync('userInfo',JSON.stringify(res_form.value)) // is_login.value = custom.checkLogin() getInfo() + // if(newUser.value) { + // toLogin() + // } } else{ uni.clearStorage();