10.25午夜修改
This commit is contained in:
parent
6a45185641
commit
a62eed8a22
@ -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';// 正式环境(由于本地测试后台没有启动,暂时通用正式服)
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -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();
|
||||
//访问接口
|
||||
const data={
|
||||
username:params.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)
|
||||
if(!avatarUrl.value) {
|
||||
uni.showToast({
|
||||
title:"请选择头像!",
|
||||
icon:"error",
|
||||
duration:1500
|
||||
})
|
||||
return
|
||||
}
|
||||
if(!nickname.value) {
|
||||
uni.showToast({
|
||||
title:"请填写昵称!",
|
||||
icon:"error",
|
||||
duration:1500
|
||||
})
|
||||
return
|
||||
}
|
||||
//访问接口
|
||||
// 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)
|
||||
// }
|
||||
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"
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<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" />
|
||||
</view>
|
||||
<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>
|
||||
</template>
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user