10.25午夜修改

This commit is contained in:
阿怪 2023-10-25 23:45:00 +08:00
parent 6a45185641
commit a62eed8a22
4 changed files with 103 additions and 28 deletions

View File

@ -1,6 +1,6 @@
// isdev 为 true 表示开发环境 false 表示发布环境 // isdev 为 true 表示开发环境 false 表示发布环境
const isdev = true; 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 = isdev ? 'http://192.168.1.133:8899' : 'https://api.gwkjxb.com';// 办公室接口 & 正式环境
// const baseUrl = 'https://api.gwkjxb.com';// 正式环境(由于本地测试后台没有启动,暂时通用正式服) // const baseUrl = 'https://api.gwkjxb.com';// 正式环境(由于本地测试后台没有启动,暂时通用正式服)

View File

@ -121,11 +121,11 @@
isSurgery:isSurgery.value, isSurgery:isSurgery.value,
surgery_time:surgery_time.value, surgery_time:surgery_time.value,
userId:user_info.userId, userId:user_info.userId,
hospitalId:choosed_h.value.ID hospitalId:choosed_h.value?.ID
}) })
console.log(res) console.log(res)
if(res.code == 0) { if(res.code == 0) {
toClose()
} }
} }
</script> </script>

View File

@ -7,12 +7,14 @@
const store = useStore() const store = useStore()
import api from "@/api/index" import api from "@/api/index"
import custom from "@/utils/index.js" import custom from "@/utils/index.js"
onLoad(() => { onLoad((e) => {
token_info.value = JSON.parse(decodeURIComponent(e.token_info))
// is_login.value = custom.checkLogin() // is_login.value = custom.checkLogin()
// console.log(is_login.value) // console.log(is_login.value)
}) })
// //
const token_info = ref(null)
const avatarUrl = ref(null) const avatarUrl = ref(null)
const nickname = ref('') const nickname = ref('')
const res_form = ref(null) const res_form = ref(null)
@ -34,29 +36,48 @@
// console.log(e.detail.errMsg) // // console.log(e.detail.errMsg) //
// console.log(e.detail.errno) // // console.log(e.detail.errno) //
} }
async function getAccess_token(params={}){//token async function getAccess_token(code){//
//token //token
// wx.clearStorageSync(); // 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={ // console.log(code.value);return
username:params.code,//code // const data={
type:'wechat_mini_app', // username:code,//code
identity:'user', // type:'wechat_mini_app',
password:'111', // identity:'user',
avatarUrl:avatarUrl.value, // password:'111',
nickName:nickname.value // avatarUrl:avatarUrl.value,
} // nickName:nickname.value
// }
// console.log(':',data);return; // console.log(':',data);return;
const res = await api.getToken(data) // const res = await api.getToken(data)
if(res.code === 200) { // 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 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) wx_login(userId)
} }
}
async function wx_login(userId){ async function wx_login(userId){
let res=await new Promise(resolve=>{ let res=await new Promise(resolve=>{
uni.login({ uni.login({
@ -99,6 +120,39 @@
// console.log('',e) // console.log('',e)
// console.log('nickname:',nickname.value) // 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"
})
})
}
</script> </script>
<template> <template>
<view class="loginBox page-box img-part card-part" style="text-align:center"> <view class="loginBox page-box img-part card-part" style="text-align:center">
@ -110,7 +164,8 @@
<input type="nickname" @blur="nameInput" class="weui-input" placeholder="请输入昵称" v-model="nickname" /> <input type="nickname" @blur="nameInput" class="weui-input" placeholder="请输入昵称" v-model="nickname" />
</view> </view>
<view class="btn-part"> <view class="btn-part">
<button class="buy-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即登录</button> <!-- <button class="buy-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即登录</button> -->
<button class="buy-btn" @tap="updateInfoFunc">立即登录</button>
</view> </view>
</view> </view>
</template> </template>

View File

@ -15,6 +15,7 @@
const res_form = ref(null) const res_form = ref(null)
const is_login = ref(null) const is_login = ref(null)
const userinfo = ref(null) const userinfo = ref(null)
const newUser = ref(null)
// const avatarUrl = ref(null) // const avatarUrl = ref(null)
const nickname = ref('') const nickname = ref('')
// //
@ -26,9 +27,9 @@
userinfo.value = JSON.parse(uni.getStorageSync('userInfo')) userinfo.value = JSON.parse(uni.getStorageSync('userInfo'))
} }
} }
function toLogin() { function toLogin(token_info) {
uni.navigateTo({ uni.navigateTo({
url:"/pages/login/login" url:"/pages/login/login?token_info="+token_info
}) })
} }
function toDetail(type) { function toDetail(type) {
@ -83,8 +84,24 @@
// console.log(':',data);return; // console.log(':',data);return;
const res = await api.getToken(data) const res = await api.getToken(data)
if(res.code === 200) { if(res.code === 200) {
if(res.data.newUser) { // // newUser.value = res.data.newUser
toLogin() 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{ else{
uni.setStorageSync('avatarUrl', res.data.avatar);//avatarUrl uni.setStorageSync('avatarUrl', res.data.avatar);//avatarUrl
@ -111,6 +128,9 @@
uni.setStorageSync('userInfo',JSON.stringify(res_form.value)) uni.setStorageSync('userInfo',JSON.stringify(res_form.value))
// is_login.value = custom.checkLogin() // is_login.value = custom.checkLogin()
getInfo() getInfo()
// if(newUser.value) {
// toLogin()
// }
} }
else{ else{
uni.clearStorage(); uni.clearStorage();