Commit 965eec33 authored by 罗超's avatar 罗超

修改自动登录

parent b3aa323e
...@@ -3,9 +3,9 @@ import Api,{ HttpResponse, Result } from './../utils/request'; ...@@ -3,9 +3,9 @@ import Api,{ HttpResponse, Result } from './../utils/request';
class UserServices{ class UserServices{
static async AutoLoginAsync(userId:number):Promise<HttpResponse>{ static async AutoLoginAsync(t:string):Promise<HttpResponse>{
let msg = {EmployeeId:userId} let msg = {t}
return Api.Post("admin_get_GetErpLoginInfoByUid",msg) return Api.Post("travel_auto_login",msg)
} }
static async PasswordLoginAsync(account:string,pwd:string,tid:string=''):Promise<HttpResponse>{ static async PasswordLoginAsync(account:string,pwd:string,tid:string=''):Promise<HttpResponse>{
......
...@@ -23,6 +23,10 @@ export interface UserLoginResult { ...@@ -23,6 +23,10 @@ export interface UserLoginResult {
status:'ERROR'|'CHOSEN'|'SUCCESS', status:'ERROR'|'CHOSEN'|'SUCCESS',
data?:any[] data?:any[]
} }
export interface AutoLoginResult{
isSuccess:boolean,
message:string
}
export const useUserStore = defineStore('user', { export const useUserStore = defineStore('user', {
state:()=>({ state:()=>({
...@@ -46,34 +50,38 @@ export const useUserStore = defineStore('user', { ...@@ -46,34 +50,38 @@ export const useUserStore = defineStore('user', {
}, },
}, },
actions:{ actions:{
async setUserAutoLoginAsync(userId:number){ async setUserAutoLoginAsync(tempToken:string):Promise<AutoLoginResult> {
try { try {
let response = await UserService.AutoLoginAsync(userId) const response = await UserService.AutoLoginAsync(tempToken)
if (response.data.resultCode == ApiResult.SUCCESS) { if (response.data.resultCode == ApiResult.SUCCESS) {
const d = response.data.data const d = response.data.data
// d.nickname=d.emName
// d.photo = d.Icon
// d.company = d.GroupName
// d.logo = d.GroupPic
// d.isTemplate = d.IsEditTripTemplate
// d.ia = 0
// d.it = true
// d.expire = d.Expire
// d.ic = d.IsGroupCreate
// d.id = d.DisplayId
// d.iv = 0
this.token = d.token this.token = d.token
d.nickname=d.emName this.userInfo = d.userinfo
d.photo = d.Icon
d.company = d.GroupName
d.logo = d.GroupPic
d.isTemplate = d.IsEditTripTemplate
d.ia = 0
d.it = true
d.expire = d.Expire
d.ic = d.IsGroupCreate
d.id = d.DisplayId
d.iv = 0
this.userInfo = d
if(!this.userInfo.photo || !this.userInfo.photo.includes('http://')|| !this.userInfo.photo.includes('https://')){ if(!this.userInfo.photo || !this.userInfo.photo.includes('http://')|| !this.userInfo.photo.includes('https://')){
this.userInfo.photo = USER_DEFAULT_HEADER this.userInfo.photo = USER_DEFAULT_HEADER
} }
if(!this.userInfo.logo || !this.userInfo.logo.includes('http://')|| !this.userInfo.logo.includes('https://')){ if(!this.userInfo.logo || !this.userInfo.logo.includes('http://')|| !this.userInfo.logo.includes('https://')){
this.userInfo.logo = ENTERPRISE_DEFAULT_HEADER this.userInfo.logo = ENTERPRISE_DEFAULT_HEADER
} }
return true return { isSuccess:true, message:''}
}else{
return { isSuccess:false, message:response.data.message}
} }
} catch (error) {} } catch (error) {
return false return { isSuccess:false, message:'登录异常,请刷新页面重试'}
}
}, },
setUserLoginOut(){ setUserLoginOut(){
this.token='' this.token=''
......
<template> <template>
<div class="full-height column flex-center items-center" v-if="!result"> <div class="full-height column flex-center items-center" v-if="result && !result.isSuccess">
<el-empty :image-size="200" description="抱歉,你的账户信息不存在" /> <el-empty :image-size="200" :description="result.message" />
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useUserStore } from '@/store/user'; import { AutoLoginResult, useUserStore } from '@/store/user';
import { query } from '@/utils/common'; import { query } from '@/utils/common';
import { ElLoading } from 'element-plus'; import { ElLoading } from 'element-plus';
import { ref } from 'vue'; import { ref } from 'vue';
...@@ -14,16 +14,16 @@ import { useRouter } from 'vue-router'; ...@@ -14,16 +14,16 @@ import { useRouter } from 'vue-router';
const router = useRouter(); const router = useRouter();
const forword = decodeURIComponent(router.currentRoute.value.query.forword) const forword = decodeURIComponent(router.currentRoute.value.query.forword)
const param = query(forword) const param = query(forword)
const result = ref(true) const result = ref<AutoLoginResult|null>(null)
const userLoginHandler = async ()=>{ const userLoginHandler = async ()=>{
const loading = ElLoading.service({ const loading = ElLoading.service({
fullscreen:true, fullscreen:true,
lock:true lock:true
}) })
if(param.uid){ if(param.uid && param.uid!=''){
let response = await useUserStore().setUserAutoLoginAsync(parseInt(param.uid)) const response = await useUserStore().setUserAutoLoginAsync(param.uid)
if(response){ if(response.isSuccess){
if(param.model=='0') { if(param.model=='0') {
router.push({ router.push({
path: `/team_editor/${param.ConfigId}` path: `/team_editor/${param.ConfigId}`
...@@ -37,11 +37,11 @@ const userLoginHandler = async ()=>{ ...@@ -37,11 +37,11 @@ const userLoginHandler = async ()=>{
path: "/space" path: "/space"
}) })
} }
return
}
} }
result.value=false result.value = response
} else
result.value = { isSuccess:false, message:'无法获取到令牌信息'}
loading.close()
} }
userLoginHandler() userLoginHandler()
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment