This commit is contained in:
aihe 2024-08-01 03:36:54 +08:00
parent 598a3c1b0e
commit 0055c72918
4 changed files with 43 additions and 27 deletions

View File

@ -28,6 +28,10 @@ const pageEventNames = {
addressSaveSuccess: "addressSaveSuccess", // 地址保存成功 addressSaveSuccess: "addressSaveSuccess", // 地址保存成功
} }
const sysEventNames = {
login: "login", // 触发登录
}
const addressNameCodeMap = [ const addressNameCodeMap = [
{ nameKey: 'countryName', codeKey: 'country' }, { nameKey: 'countryName', codeKey: 'country' },
{ nameKey: 'provinceName', codeKey: 'province' }, { nameKey: 'provinceName', codeKey: 'province' },
@ -52,6 +56,7 @@ export {
addressNameCodeMap, addressNameCodeMap,
dateRangeList, dateRangeList,
pageEventNames, pageEventNames,
sysEventNames,
authCodeEnum, authCodeEnum,
dealBtnMap, dealBtnMap,
dateTypeEnum, dateTypeEnum,

View File

@ -1,14 +1,11 @@
import { goto } from "./untool" import { goto } from "./untool"
import { getCurrentInstance } from "vue"
import { sysEventNames } from "@/common/enum"
export const goLogin = ()=> { export const goLogin = ()=> {
// #ifdef MP // #ifdef MP
setTimeout(()=> { uni.$emit(sysEventNames.login, { })
console.log("===uni===", uni)
debugger
}, 500)
debugger
// #endif // #endif
// #ifndef MP // #ifndef MP

View File

@ -9,6 +9,8 @@
import { getSessionLoginInfo, setSessionLoginInfo, setSessionXToken } from "@/session" import { getSessionLoginInfo, setSessionLoginInfo, setSessionXToken } from "@/session"
import { encrypt } from "@/common/libs/jsencrypt_utils" import { encrypt } from "@/common/libs/jsencrypt_utils"
import { promiseTimeout, showToast } from "@/common/untool" import { promiseTimeout, showToast } from "@/common/untool"
import { getCurrentInstance } from "vue"
import { sysEventNames } from "@/common/enum"
// #ifdef MP // #ifdef MP
import LoginComponent from "@/components/buns-api/login/mp-login" import LoginComponent from "@/components/buns-api/login/mp-login"
@ -29,11 +31,13 @@
}, },
created() { created() {
uni.$on(sysEventNames.login, this.triggerLogin)
// setSessionXToken() // 登录前先清除xtoke
}, },
mounted(){ mounted(){
}, },
unmounted(){
uni.$off(sysEventNames.login, this.triggerLogin)
},
methods: { methods: {
async handleLoginedBack() { async handleLoginedBack() {
await promiseTimeout(300) await promiseTimeout(300)

View File

@ -50,7 +50,7 @@
export default { export default {
data() { data() {
return { return {
pageLoading: true, pageLoading: false,
submitLogin: { submitLogin: {
code: '', code: '',
nickName: '', nickName: '',
@ -70,11 +70,11 @@
}, },
created() { created() {
try{ try{
this.initData() // this.initData()
}catch(e){ }catch(e){
console.error("created -- initData ==========", e) console.error("created -- initData ==========", e)
} }
this.pageLoading = false
}, },
methods: { methods: {
commodHeaders(){ commodHeaders(){
@ -84,27 +84,37 @@
} }
}, },
async initData(){ async initData(){
// 防止多次触发
if(this.pageLoading) {
return
}
this.pageLoading = true
let isLogined = !!getSessionXToken() let isLogined = !!getSessionXToken()
if(!isLogined) { if(!isLogined) {
await this.autoLogin() try{
if(this.token) { await this.autoLogin()
// 如果用户信息已绑定,直接触发登录成功 if(this.token) {
const res = await apiService.getInfoByApp({ _loading: true }, this.commodHeaders()) // 如果用户信息已绑定,直接触发登录成功
let userInfo = res?.user || {} const res = await apiService.getInfoByApp({ _loading: true }, this.commodHeaders())
Object.assign(this.submitLogin , { let userInfo = res?.user || {}
nickName: userInfo.nickName, Object.assign(this.submitLogin , {
avatarUrl: userInfo.avatar, nickName: userInfo.nickName,
phoneNumber: userInfo.phonenumber, avatarUrl: userInfo.avatar,
}) phoneNumber: userInfo.phonenumber,
try{ })
await checkParams(this.submitLogin, this.submitValidConfig, false) try{
this.loginSucceed() await checkParams(this.submitLogin, this.submitValidConfig, false)
}catch(err){ this.loginSucceed()
this.$emit("needLoginInput") }catch(err){
console.error("auto login checkParams err=====", err) this.$emit("needLoginInput")
console.error("auto login checkParams err=====", err)
}
} }
}catch(err){
console.error("isLogined ==== err", err)
} }
} }
this.pageLoading = false
}, },
async onChooseAvatar(res) { async onChooseAvatar(res) {
let tmpFilePath = res.detail.avatarUrl let tmpFilePath = res.detail.avatarUrl