Эх сурвалжийг харах

feat:更新用户信息获取函数,重命名为`QeurUserInfo`并在相关文件中同步修改。新增用户信息的本地存储,更新登录表单和用户状态管理的逻辑以获取新用户权限。

张涛 1 жил өмнө
parent
commit
dfa013df79

+ 1 - 1
src/apis/login.js

@@ -24,7 +24,7 @@ export function asycData(userFlag) {
   });
 }
 // 获取用户信息
-export function getInfo() {
+export function QueyrUserInfo() {
   return request({
     url: '/api/user/user_info',
     method: 'get'

+ 2 - 0
src/base/storage.js

@@ -13,6 +13,8 @@ export const localST_Locale = new MyLocalStorage('locale'); // 多语言
 export const localST_RecentAgent = new MyLocalStorage('recent_agent'); // 近期使用的agent
 export const localST_AllAgent = new MyLocalStorage('full_agent'); // 所有可用的agent
 
+export const localST_UserInfo = new MyLocalStorage('user_info'); // 所有可用的agent
+
 /**
  * session storage定义
  * 任意 sessionStorage的定义,必须添加 sessionST_ 前缀

+ 9 - 11
src/base/store/use-current-user.js

@@ -1,6 +1,6 @@
 import { defineStore } from 'pinia';
-import { login, getInfo } from '../../apis/login';
-import { kuky_Authorization } from '../storage';
+import { login, QueyrUserInfo } from '../../apis/login';
+import { kuky_Authorization, localST_UserInfo } from '../storage';
 
 /**
  * 当前登录的用户信息
@@ -60,16 +60,14 @@ export const useCurrentUserStore = defineStore('current_user', {
           });
       });
     },
-    async getInfo() {
+    async getUserInfo() {
       try {
-        const res = await getInfo();
-        if (res.code === 200) {
-          this.dept = res.data.dept;
-          this.roles = res.roles || ['ROLE_DEFAULT'];
-          this.permissions = res.permissions;
-          return res.msg;
-        } else {
-          throw new Error(res.msg);
+        const {
+          code,
+          data: { permissions, dept, roles }
+        } = await QueyrUserInfo();
+        if (code === 200) {
+          localST_UserInfo.setItem(JSON.stringify({ permissions, dept, roles }));
         }
       } catch (err) {
         throw err;

+ 19 - 19
src/modules/login/FormItem.vue

@@ -2,14 +2,8 @@
   <div class="form-title">
     {{ form_type ? $t('login.registerModel') : $t('login.loginModel') }}
   </div>
-  <a-form
-    ref="ref_form"
-    :model="form"
-    :rules="rules"
-    :style="{ width: 'calc(100% - 40px)' }"
-    layout="validate"
-    @submit-success="handleSubmit"
-  >
+  <a-form ref="ref_form" :model="form" :rules="rules" :style="{ width: 'calc(100% - 40px)' }" layout="validate"
+    @submit-success="handleSubmit">
     <a-form-item field="username">
       <a-input v-model="form.username" :placeholder="$t('login.usernameTips')">
         <template #prefix> <icon-user /> </template>
@@ -21,23 +15,19 @@
       </a-input>
     </a-form-item>
     <a-form-item field="password">
-      <a-input-password
-        v-model="form.password"
-        :placeholder="$t('login.passwordTips')"
-        :defaultVisibility="true"
-        allow-clear
-      >
+      <a-input-password v-model="form.password" :placeholder="$t('login.passwordTips')" :defaultVisibility="true"
+        allow-clear>
         <template #prefix>
           <icon-user />
         </template>
       </a-input-password>
     </a-form-item>
     <a-form-item>
-      <a-button v-if="!form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading"
-        >{{ $t('login.loginBtn') }}
+      <a-button v-if="!form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading">{{
+        $t('login.loginBtn') }}
       </a-button>
-      <a-button v-if="form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading"
-        >{{ $t('login.registerBtn') }}
+      <a-button v-if="form_type" class="submit-btn" type="primary" html-type="submit" :loading="loading">{{
+        $t('login.registerBtn') }}
       </a-button>
     </a-form-item>
   </a-form>
@@ -88,6 +78,10 @@ const handleSubmit = (data) => {
       .toLogin({ username: data.username, password: data.password })
       .then((res) => {
         $message.success(res);
+
+        // 登录成功后,获取用户权限
+        userStore.getUserInfo()
+
         router.push({ path: '/knowledge' });
       })
       .catch((err) => {
@@ -130,6 +124,7 @@ const changeFormType = (e) => {
   font-size: 30px;
   font-weight: 500;
 }
+
 .submit-btn {
   width: 100%;
   height: 54px;
@@ -138,10 +133,12 @@ const changeFormType = (e) => {
   font-size: 20px;
   border-radius: 3px;
 }
+
 .submit-btn:hover {
   background-color: rgba(var(--arcoblue-6), 0.8);
   color: var(--color-neutral-1);
 }
+
 .tips-register {
   position: absolute;
   right: 20px;
@@ -149,6 +146,7 @@ const changeFormType = (e) => {
   font-size: 20px;
   color: var(--color-neutral-4);
 }
+
 .reg-link {
   color: rgb(var(--arcoblue-6));
 }
@@ -156,12 +154,14 @@ const changeFormType = (e) => {
 .arco-form-item-label-col {
   padding: 0px;
 }
+
 .arco-input-wrapper {
   height: 54px;
   background-color: var(--color-bg-1);
   border-color: var(--color-neutral-3);
 }
-:deep .arco-form-item-label-col > .arco-form-item-label {
+
+:deep .arco-form-item-label-col>.arco-form-item-label {
   display: none;
 }
 </style>

+ 1 - 0
src/modules/permission/account/index.vue

@@ -325,6 +325,7 @@ const getDeptTree = async () => {
     dept_list.value = rows;
   }
 }
+
 onMounted(() => {
   getUserList()
   getDeptTree()

+ 1 - 1
src/modules/permission/resource/ResourceForm.vue

@@ -40,7 +40,7 @@
 <script setup>
 import { ref, toRefs } from 'vue';
 import Upload from './Upload.vue';
-
+// TODO 图标上传功能待实现
 const uploadAction = '/api/v1/llm/upload'; // 替换为你的上传API
 const fileList = ref([]);
 const imageUrls = ref([]);