Răsfoiți Sursa

feat(claim&user): 新增管理员权限控制与用户权限持久化

1.  用户store新增从本地缓存加载权限和角色数据
2.  认领页面新增管理员角色判断,仅管理员可见待认领相关操作和标签页
3.  根据用户权限动态切换标签页列表
4.  修复非管理员无法正确初始化查询状态的问题
张旭伟 23 ore în urmă
părinte
comite
aa9ffb17a1
2 a modificat fișierele cu 28 adăugiri și 6 ștergeri
  1. 26 4
      pages/fund/claim/index.vue
  2. 2 2
      store/modules/user.ts

+ 26 - 4
pages/fund/claim/index.vue

@@ -73,7 +73,7 @@
                 }}</text>
             </view> -->
           </view>
-          <view class="card-actions" @click.stop v-if="item.status == '10' || item.status == '30'">
+          <view class="card-actions" @click.stop v-if="isAdmin && (item.status == '10' || item.status == '30')">
             <view class="btn-box" v-if="item.status == '10'">
               <uv-button text="认领" type="primary" shape="circle" size="small" @click="toClaim(item.id)"></uv-button>
             </view>
@@ -93,19 +93,40 @@
 </template>
 
 <script setup lang="ts">
-import { ref, nextTick, watch } from 'vue';
+import { ref, nextTick, watch, computed } from 'vue';
 import { onLoad } from '@dcloudio/uni-app';
 import { debounce } from 'lodash-es';
+import { storeToRefs } from 'pinia';
+import { useUserStore } from '@/store/modules/user';
 import { useFundApi } from '@/api/fund/index';
 import { useSystemApi } from '@/api/system/index';
 import { onRouterPush } from '@/utils/router';
 import { DEFAULT_PAGE_SIZE } from '@/constants/index';
 import { formatDate } from '@/utils/date';
 
+const userStore = useUserStore();
+const { roles } = storeToRefs(userStore);
+
+const ADMIN_ROLES = ['scientific_research_secretary', 'scientific_research_admin', 'sys_admin', 'admin'];
+
+const isAdmin = computed(() => {
+  const userRoles = roles.value || [];
+  return ADMIN_ROLES.some(adminRole =>
+    userRoles.some((r: any) => r.roleCode === adminRole)
+  );
+});
+
+const allTabs = [{ name: '待认领', type: '10' }, { name: '已认领', type: '20' }, { name: '认领中', type: '30' }];
+const tabList = computed(() => {
+  if (isAdmin.value) {
+    return allTabs;
+  }
+  return [{ name: '已认领', type: '20' }];
+});
+
 const fundApi = useFundApi();
 const systemApi = useSystemApi();
 
-const tabList = ref([{ name: '待认领', type: '10' }, { name: '已认领', type: '20' }, { name: '认领中', type: '30' }]);
 const currentTab = ref(0);
 
 const queryParams = ref({
@@ -228,7 +249,7 @@ const toClaim = (id: number) => {
 };
 
 const handleCardClick = (item: any) => {
-  if (item.status == '10') {
+  if (isAdmin.value && item.status == '10') {
     toClaim(item.id);
   } else {
     toViewDetail(item.id);
@@ -236,6 +257,7 @@ const handleCardClick = (item: any) => {
 };
 
 onLoad(() => {
+  queryParams.value.status = tabList.value[0]?.type || '20';
   getDict();
   fetchListData(true);
 });

+ 2 - 2
store/modules/user.ts

@@ -18,8 +18,8 @@ export const useUserStore = defineStore('user', () => {
   // ==================== State ====================
   const token = ref<string>(Local.get(CACHE_KEY.TOKEN) || '');
   const userInfo = ref<UserInfo>(Local.get(CACHE_KEY.USER_INFO) || ({} as UserInfo));
-  const perms = ref<string[]>([]);
-  const roles = ref<string[]>([]);
+  const perms = ref<string[]>(Local.get(CACHE_KEY.PERMS) || []);
+  const roles = ref<any[]>(Local.get(CACHE_KEY.ROLES) || []);
   const configSetting = ref<any>({});
 
   // 页面请求加载状态