|
|
@ -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,28 +36,47 @@
|
|
|
|
// 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
|
|
|
|
// uni.setStorageSync('avatarUrl', avatarUrl.value);//avatarUrl
|
|
|
|
res_form.value = res.data
|
|
|
|
// res_form.value = res.data
|
|
|
|
res_form.value.access_token = 'Bearer '+res.data.access_token
|
|
|
|
// res_form.value.access_token = 'Bearer '+res.data.access_token
|
|
|
|
let userId = res.data.userId
|
|
|
|
// let userId = res.data.userId
|
|
|
|
uni.setStorageSync('access_token',res_form.value.access_token);// token单独缓存一次
|
|
|
|
// uni.setStorageSync('access_token',res_form.value.access_token);// token单独缓存一次
|
|
|
|
wx_login(userId)
|
|
|
|
// wx_login(userId)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
uni.setStorageSync('avatarUrl', avatarUrl.value);//avatarUrl
|
|
|
|
|
|
|
|
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=>{
|
|
|
@ -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>
|
|
|
|