Browse Source

获取当前角色

wanghairong 5 months ago
parent
commit
a2a131f950
2 changed files with 27 additions and 25 deletions
  1. 8 3
      src/store/modules/systemStore.js
  2. 19 22
      src/views/login/login-form.vue

+ 8 - 3
src/store/modules/systemStore.js

@@ -13,7 +13,7 @@ const INITIALIZE = {
   stsClientInfo: {},
   stsClientInfo: {},
 };
 };
 try {
 try {
-  const  SYSTEM_STORE = getLocalStorage("SYSTEM_STORE")
+  const SYSTEM_STORE = getLocalStorage("SYSTEM_STORE")
   for (const key in SYSTEM_STORE) {
   for (const key in SYSTEM_STORE) {
     const value = getLocalStorage(key)
     const value = getLocalStorage(key)
     if (value) INITIALIZE[key] = value
     if (value) INITIALIZE[key] = value
@@ -28,7 +28,7 @@ export const useSystemStore = defineStore({
     ...INITIALIZE,
     ...INITIALIZE,
   }),
   }),
   getters: {
   getters: {
-    getLocalLoading(){
+    getLocalLoading() {
       return this.local_loading
       return this.local_loading
     },
     },
     getToken() {
     getToken() {
@@ -82,7 +82,7 @@ export const useSystemStore = defineStore({
             return infoData
             return infoData
           }
           }
           getInfoData(info)
           getInfoData(info)
-        
+
           const client = new windowVar.OSS({
           const client = new windowVar.OSS({
             ...this.stsClientInfo,
             ...this.stsClientInfo,
             refreshSTSToken: async () => {
             refreshSTSToken: async () => {
@@ -110,6 +110,11 @@ export const useSystemStore = defineStore({
       };
       };
       return stsFn
       return stsFn
     },
     },
+    getRole() {
+      if (this.role) return this.role;
+      this.role = window.localStorage?.role || "";
+      return this.role;
+    },
   },
   },
   actions: {
   actions: {
     localLoading(value = false) {
     localLoading(value = false) {

+ 19 - 22
src/views/login/login-form.vue

@@ -2,34 +2,25 @@
   <div class="login-form-wrapper">
   <div class="login-form-wrapper">
     <div class="login-form-title">登陆 Admin</div>
     <div class="login-form-title">登陆 Admin</div>
     <div class="login-form-sub-title">Login to ADMIN</div>
     <div class="login-form-sub-title">Login to ADMIN</div>
-    
-    <a-form ref="loginForm" :model="formData" class="login-form"  @submit-success="handleSubmit">
-      <a-form-item
-        field="username"
-        :rules="[{ required: true, message: '用户名不能为空' }]"
-        :validate-trigger="['change', 'blur']"
-        hide-label
-      >
+
+    <a-form ref="loginForm" :model="formData" class="login-form" @submit-success="handleSubmit">
+      <a-form-item field="username" :rules="[{ required: true, message: '用户名不能为空' }]"
+        :validate-trigger="['change', 'blur']" hide-label>
         <a-input v-model="formData.username" placeholder="用户名:">
         <a-input v-model="formData.username" placeholder="用户名:">
           <template #prefix>
           <template #prefix>
             <icon-user />
             <icon-user />
           </template>
           </template>
         </a-input>
         </a-input>
       </a-form-item>
       </a-form-item>
-      <a-form-item
-        field="password"
-        :rules="[{ required: true, message: '密码不能为空' }]"
-        :validate-trigger="['change', 'blur']"
-        hide-label
-        
-      >
+      <a-form-item field="password" :rules="[{ required: true, message: '密码不能为空' }]"
+        :validate-trigger="['change', 'blur']" hide-label>
         <a-input-password v-model="formData.password" placeholder="密码:" allow-clear>
         <a-input-password v-model="formData.password" placeholder="密码:" allow-clear>
           <template #prefix>
           <template #prefix>
             <icon-lock />
             <icon-lock />
           </template>
           </template>
         </a-input-password>
         </a-input-password>
       </a-form-item>
       </a-form-item>
-    
+
 
 
       <a-space :size="16" direction="vertical">
       <a-space :size="16" direction="vertical">
         <div class="login-form-password-actions">
         <div class="login-form-password-actions">
@@ -48,14 +39,14 @@
 import { ref, reactive } from 'vue'
 import { ref, reactive } from 'vue'
 import { encryptByDES } from "@/utils"
 import { encryptByDES } from "@/utils"
 import { loginApi } from "@/api/path/login.api"
 import { loginApi } from "@/api/path/login.api"
-import { useSystemStore  } from "@/store/modules/systemStore"
+import { useSystemStore } from "@/store/modules/systemStore"
 import { useRouter } from 'vue-router'
 import { useRouter } from 'vue-router'
 import { updateRouteByMenu } from '@/router/router.update'
 import { updateRouteByMenu } from '@/router/router.update'
 
 
 
 
 const router = useRouter()
 const router = useRouter()
 const formData = ref({
 const formData = ref({
-  username:localStorage.remember_user_name
+  username: localStorage.remember_user_name
 })
 })
 const formLoading = ref(false)
 const formLoading = ref(false)
 const rememberPassword = ref(true)
 const rememberPassword = ref(true)
@@ -68,7 +59,7 @@ const handleSubmit = async () => {
     password: encryptByDES(formData.value.password)
     password: encryptByDES(formData.value.password)
   })
   })
   window.localStorage.setItem('remember_user_name', formData.value.username)
   window.localStorage.setItem('remember_user_name', formData.value.username)
- 
+
   systemStore.setStateValue({
   systemStore.setStateValue({
     key: 'token',
     key: 'token',
     value: data.token,
     value: data.token,
@@ -79,6 +70,11 @@ const handleSubmit = async () => {
     value: JSON.stringify(data.userInfo),
     value: JSON.stringify(data.userInfo),
     localStorage: true,
     localStorage: true,
   })
   })
+  systemStore.setStateValue({
+    key: 'role',
+    value: data.user_type,
+    localStorage: true,
+  })
   await updateRouteByMenu(router, systemStore)
   await updateRouteByMenu(router, systemStore)
   router.push({
   router.push({
     path: "/",
     path: "/",
@@ -93,18 +89,19 @@ const setRememberPassword = (e) => {
 </script>
 </script>
 
 
 <style lang="less" scoped>
 <style lang="less" scoped>
-
-.login-form-wrapper{
+.login-form-wrapper {
   margin: 0 1rem;
   margin: 0 1rem;
 }
 }
+
 .login-form {
 .login-form {
   margin-top: 32px;
   margin-top: 32px;
+
   &-wrapper {
   &-wrapper {
     width: 320px;
     width: 320px;
   }
   }
 
 
   &-title {
   &-title {
-    color:  @text_color_1;
+    color: @text_color_1;
     font-weight: 500;
     font-weight: 500;
     font-size: 24px;
     font-size: 24px;
     line-height: 32px;
     line-height: 32px;