瀏覽代碼

Merge branch 'dev_zyh' of United_Software/k_online_ui into dev

Jack Zhou 8 月之前
父節點
當前提交
30edaeb1ea

+ 2 - 2
src/router/index.ts

@@ -126,7 +126,7 @@ router.beforeEach(async (to, from, next) => {
   const userStore = useUserStore()
   // 如果手动跳转登录页,清除登录信息
   if (to.path === '/login') {
-    if (userStore.userInfo?.uname) {
+    if (userStore.isLogin) {
       await userStore.logout()
     }
     sessionStorage.removeItem('trackingTablePageInfo')
@@ -153,7 +153,7 @@ router.beforeEach(async (to, from, next) => {
   // 未登录白名单
   const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
   // 判断是否登录
-  if (!whiteList.includes(to.path) && !userStore.userInfo?.uname) {
+  if (!whiteList.includes(to.path) && !userStore.isLogin) {
     const userStore = useUserStore()
     await userStore.logout()
     if (whiteList.includes(from.path)) {

+ 3 - 0
src/stores/modules/user.ts

@@ -68,6 +68,9 @@ export const useUserStore = defineStore('user', {
     expireDay(state) {
       const userInfo = state.userInfo
       return userInfo.PASSWORD_CHANGE_CYCLE - dayjs().diff(dayjs(userInfo.last_pwd_change), 'day')
+    },
+    isLogin(state) {
+      return !(!state.userInfo?.uname || (state.userInfo?.uname && state.isFirstLogin === true))
     }
   },
   actions: {

+ 7 - 13
src/views/Layout/src/components/Header/HeaderView.vue

@@ -35,7 +35,7 @@ const handleSearch = () => {
   }
   // 先判断是否登录
   // 未登录
-  if (!userStore.userInfo?.uname) {
+  if (!userStore.isLogin) {
     $api.getPublicTrackingDetail({ reference_number: searchValue.value }).then((res) => {
       if (res.code === 200) {
         const { data } = res
@@ -183,14 +183,14 @@ const closePopover = () => {
 const notificationDrawer = ref(false)
 
 onBeforeRouteUpdate((to, from, next) => {
-  if (from.name === 'Login' && userStore.userName) {
+  if (from.name === 'Login' && userStore.isLogin) {
     notificationMsgStore.hasUnreadMessages()
   }
   next()
 })
 onMounted(() => {
   // 检查是否有新消息 (在页面刷新时重新检查)
-  if (userStore.userName) {
+  if (userStore.isLogin) {
     notificationMsgStore.hasUnreadMessages()
   }
 })
@@ -217,7 +217,7 @@ onMounted(() => {
           <span style="margin-top: -1px" class="font_family icon-icon_search_b"></span>
         </template>
       </el-input>
-      <div class="notice-icon" v-if="userStore.userInfo?.uname">
+      <div class="notice-icon" v-if="userStore.isLogin">
         <span v-if="notificationMsgStore.hasNewMsg" class="unread-tip-icon"></span>
         <el-button
           style="height: 40px; width: 40px; margin-right: 0px"
@@ -329,16 +329,13 @@ onMounted(() => {
           </div>
         </div>
         <template #reference>
-          <div class="header-avatar" v-if="userStore.userName && userStore.isFirstLogin !== true">
+          <div class="header-avatar" v-if="userStore.isLogin">
             <div>{{ userStore.userName.slice(0, 1) }}</div>
           </div>
         </template>
       </el-popover>
       <el-button
-        v-if="
-          !userStore.userInfo?.uname ||
-          (userStore.userInfo?.uname && userStore.isFirstLogin === true)
-        "
+        v-if="!userStore.isLogin"
         class="el-button--main el-button--pain-theme"
         style="padding: 8px 10px; margin-right: 20px; margin-left: 0"
         plain
@@ -348,10 +345,7 @@ onMounted(() => {
         Download KLN Portal
       </el-button>
       <el-button
-        v-if="
-          !userStore.userInfo?.uname ||
-          (userStore.userInfo?.uname && userStore.isFirstLogin === true)
-        "
+        v-if="!userStore.isLogin"
         class="el-button--main"
         style="margin-left: -10px"
         @click="handleLogin"

+ 1 - 1
src/views/Layout/src/components/Header/components/TrainingCard.vue

@@ -65,7 +65,7 @@ const initTrainingCard = () => {
 }
 
 onBeforeRouteUpdate((to, from, next) => {
-  if (from.name === 'Login' && userStore.userName) {
+  if (from.name === 'Login' && userStore.isLogin) {
     getNotificationList()
   }
   if (to.name === 'Login') {

+ 1 - 1
src/views/Layout/src/components/Menu/MenuView.vue

@@ -54,7 +54,7 @@ const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/re
 // 判断是否允许跳转
 const isAllowJump = (path: any) => {
   // 判断是否登录
-  if (!whiteList.includes(path) && !userStore.userInfo?.uname) {
+  if (!whiteList.includes(path) && !userStore.isLogin) {
     ElMessage.warning({
       message: 'Please log in to use this feature.',
       grouping: true

+ 2 - 2
src/views/Login/src/components/ChangePasswordCard.vue

@@ -22,6 +22,7 @@ const loginForm = ref({
   confirmPassword: ''
 })
 loginForm.value.username = userStore.userInfo?.uname || ''
+// 没有用户名时,跳转到登录页
 if (!loginForm.value.username) {
   router.push({
     name: 'Login'
@@ -124,7 +125,7 @@ const checkPassword = () => {
 }
 
 onUnmounted(() => {
-  userStore.logout(false)
+  userStore.logout(true)
 })
 </script>
 
@@ -135,7 +136,6 @@ onUnmounted(() => {
         <span class="welcome">Change Password</span>
         <span class="tips">{{ tips }}</span>
       </div>
-
       <div class="login-form">
         <div class="label">
           <span>User Name</span>

+ 1 - 1
src/views/Login/src/loginView.vue

@@ -221,7 +221,7 @@ const handleResult = (res: any) => {
         type: 'warning',
         confirmButtonClass: 'el-button--dark'
       })
-      userStore.setUserInfo(res.data?.user_info || {})
+      userStore.setUserInfo(res.data?.user_info || {}, true)
       router.push({
         name: 'Reset Password'
       })