emis-sapp/components/buns-api/login/index.vue

91 lines
2.5 KiB
Vue
Raw Normal View History

2024-07-31 16:54:49 +00:00
<template>
2025-04-15 15:51:42 +00:00
<tpx-dialog v-model:show="lgDialog.show" :renderDefaultSlot="true" title="登录" :rootStyle="'min-height:auto;'">
<LoginComponent ref="lcRef" @succeedBack="handleLoginedBack"
@userinfoUpdateBack="handleUpdateUserInfoBanck"/>
2024-07-31 16:54:49 +00:00
</tpx-dialog>
</template>
<script>
import { USERKEY } from "@/store/actionKey"
import { getSessionLoginInfo, setSessionLoginInfo, setSessionXToken } from "@/session"
import { encrypt } from "@/common/libs/jsencrypt_utils"
import { promiseTimeout, showToast } from "@/common/untool"
2024-07-31 19:36:54 +00:00
import { getCurrentInstance } from "vue"
import { sysEventNames } from "@/common/enum"
2025-04-15 17:34:06 +00:00
import { checkParams } from "@/common/validate"
2024-07-31 16:54:49 +00:00
// #ifdef MP
import LoginComponent from "@/components/buns-api/login/mp-login"
// #endif
// #ifndef MP
import LoginComponent from "@/components/buns-api/login/com-login"
// #endif
export default {
components: { LoginComponent },
data() {
return {
lgDialog: { show: false },
2025-04-15 17:34:06 +00:00
submitValidConfig: {
nickName: { required: true, requiredMsg: '昵称不能为空' },
// avatarUrl: { required: true, requiredMsg: '头像不能为空' },
phoneNumber: { required: true, requiredMsg: '手机号不能为空' },
},
2024-07-31 16:54:49 +00:00
}
},
computed: {
},
created() {
2024-07-31 19:36:54 +00:00
uni.$on(sysEventNames.login, this.triggerLogin)
2024-07-31 16:54:49 +00:00
},
2024-07-31 18:59:34 +00:00
mounted(){
2025-04-15 16:40:23 +00:00
2024-07-31 18:59:34 +00:00
},
2024-07-31 19:36:54 +00:00
unmounted(){
uni.$off(sysEventNames.login, this.triggerLogin)
},
2024-07-31 16:54:49 +00:00
methods: {
async handleLoginedBack() {
await promiseTimeout(300)
await this.$store.dispatch(USERKEY.GETUSERINFO)
2025-04-15 15:51:42 +00:00
this.reloadCurrentPage(this) // 刷新当前页面
},
async handleUpdateUserInfoBanck(){
2024-08-09 12:50:36 +00:00
this.lgDialog.show = false
2025-04-15 15:51:42 +00:00
await this.$store.dispatch(USERKEY.GETUSERINFO)
2024-07-31 16:54:49 +00:00
this.reloadCurrentPage(this) // 刷新当前页面
},
2025-04-15 15:51:42 +00:00
async handleCheckUserInfo() {
2025-04-15 17:34:06 +00:00
let bl = false
const userInfo = this.$store.getters.userInfo
let data = {
nickName: userInfo.nickName,
avatarUrl: userInfo.avatar,
phoneNumber: userInfo.phonenumber,
}
try{
await checkParams(data, this.submitValidConfig, false)
bl = true
}catch(err){
console.error("auto login checkParams err=====", err)
}
2025-04-15 15:51:42 +00:00
this.lgDialog.show = !bl
2025-04-16 15:54:10 +00:00
if(this.lgDialog.show) { // 更新用户信息到组件中
this.$refs.lcRef?.updateSubmitLoginInfo?.(data)
}
2025-04-15 15:51:42 +00:00
return bl
2024-07-31 18:59:34 +00:00
},
2025-04-15 15:51:42 +00:00
async triggerLogin(){
setSessionXToken() // 登录前先清除xtoke
await this.$refs.lcRef.initData()
2024-07-31 16:54:49 +00:00
}
}
}
</script>
<style scoped lang="scss">
2024-07-31 17:47:31 +00:00
2024-07-31 16:54:49 +00:00
</style>