瀏覽代碼

feat(role): 新增权限控制

tangning 3 年之前
父節點
當前提交
6ef3a1f690

+ 12 - 0
src/api/staff/list.ts

@@ -10,6 +10,7 @@ enum Api {
   update = '/zfb-api/zfb/shop/sys/user/update',
   checkUser = '/zfb-api/zfb/user/checkUserExists',
   deleteStaff = '/zfb-api/zfb/shop/sys/user/deleteStaff',
+  getNumByStaff = '/zfb-api/zfb/shop/sys/user/getNumByStaff',
 }
 
 /**
@@ -26,6 +27,17 @@ export const ListApi = (params: PageParams) =>
       ignoreCancelToken: true,
     },
   });
+
+export const getNumByStaff = (params: any) =>
+  defHttp.get<Result>({
+    url: Api.getNumByStaff,
+    params,
+    data: params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
 export const delApi = (params: DelParams) =>
   defHttp.post<Result>({
     url: Api.deleteStaff,

+ 1 - 1
src/components/Upload/src/BasicUpload.vue

@@ -12,7 +12,7 @@
           </template>
         </template>
         <a-button @click="openPreviewModal">
-          <Icon icon="bi:eye" />
+          <Icon icon="bi:eye" /> 预览
           <template v-if="fileList.length && showPreviewNumber">
             {{ fileList.length }}
           </template>

+ 6 - 5
src/enums/roleEnum.ts

@@ -1,8 +1,9 @@
 export enum RoleEnum {
   // super admin
-  SUPER = 'super',
-  PLAT_ADMIN = 'plat_admin',
-  COMPANY_ADMIN = 'company_admin',
-  STAFF = 'staff',
-  HOST = 'host',
+  SUPER = 'super', //超级管理员
+  PLAT_ADMIN = 'plat_admin', //平台管理员
+  COMPANY_ADMIN = 'company_admin', //公司管理员
+  STAFF = 'staff', //员工
+  HOST = 'host', //主持人
+  TOURIST = 'tourist', //游客
 }

+ 9 - 2
src/layouts/default/header/components/user-dropdown/index.vue

@@ -15,7 +15,7 @@
           key="setting"
           :text="t('layout.header.userSetting')"
           icon="ion:document-text-outline"
-          v-if="getShowDoc"
+          v-if="true"
         />
         <!-- <MenuDivider v-if="getShowDoc" /> -->
         <MenuItem
@@ -52,6 +52,7 @@
   import { propTypes } from '/@/utils/propTypes';
   import { openWindow } from '/@/utils';
   import { useGo } from '/@/hooks/web/usePage';
+  // import { useRouter } from 'vue-router'
 
   import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
 
@@ -72,10 +73,15 @@
     setup() {
       const { prefixCls } = useDesign('header-user-dropdown');
       const { t } = useI18n();
+      // const router = useRouter()
       const { getShowDoc, getUseLockPage } = useHeaderSetting();
       const userStore = useUserStore();
       const go = useGo();
-
+      // const routerLIst = computed(() => {
+      //   let list =  router.options.routes
+      //   console.log('name: "账户设置"',list)
+      //   return true
+      // })
       const getUserInfo = computed(() => {
         const { realName = '', head, desc } = userStore.getUserInfo || {};
         return { realName, avatar: head || headerImg, desc };
@@ -127,6 +133,7 @@
         getShowDoc,
         register,
         getUseLockPage,
+        // routerLIst,
       };
     },
   });

+ 9 - 4
src/store/modules/user.ts

@@ -16,6 +16,7 @@ import { usePermissionStore } from '/@/store/modules/permission';
 import { RouteRecordRaw } from 'vue-router';
 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
 import { isArray } from '/@/utils/is';
+import { intersection } from 'lodash-es';
 import { h } from 'vue';
 
 interface UserState {
@@ -140,6 +141,8 @@ export const useUserStore = defineStore({
           switch (item) {
             case 1:
               return RoleEnum.SUPER;
+            case 2:
+              return RoleEnum.TOURIST;
             case 5:
               return RoleEnum.PLAT_ADMIN;
             case 6:
@@ -192,13 +195,15 @@ export const useUserStore = defineStore({
       });
     },
 
-    getCheckRole(val): boolean {
+    getCheckRole(value): boolean {
       const roleList = this.roleList;
-      if (roleList.includes(val)) {
+      if (!value) {
         return true;
-      } else {
-        return false;
       }
+      if (!isArray(value)) {
+        return roleList?.includes(value as RoleEnum);
+      }
+      return (intersection(value, roleList) as RoleEnum[]).length > 0;
     },
   },
 });

+ 1 - 1
src/views/advertisement/schemas.ts

@@ -30,7 +30,7 @@ export const padsSchemas: FormSchema[] = [
   },
   {
     field: 'connectId',
-    label: '直播ID',
+    label: '直播间名称',
     component: 'ApiSelect',
     required: true,
     itemProps: {

+ 1 - 1
src/views/corporation/index.vue

@@ -174,7 +174,7 @@
           title: t('routes.corporation.bgMusic'),
           dataIndex: 'bgMusic',
           slots: { customRender: 'bgMusic' },
-          width: 160,
+          width: 190,
         },
         {
           title: t('routes.corporation.cameraNum'),

+ 6 - 2
src/views/product/category.vue

@@ -1,7 +1,7 @@
 <template>
   <div>
     <BasicTable @register="registerTable">
-      <template #toolbar>
+      <template #toolbar v-if="!getCheckRole('tourist')">
         <a-button primary color="error" @click="handleCreate"> 新增商品分类</a-button>
         <a-button ghost color="warning" @click="expandAll">展开全部</a-button>
         <a-button type="primary" @click="collapseAll">折叠全部</a-button>
@@ -39,6 +39,7 @@
   import { useI18n } from '/@/hooks/web/useI18n';
   import { useMessage } from '/@/hooks/web/useMessage';
   import { makeTree } from '/@/utils/treeUtils';
+  import { useUserStore } from '/@/store/modules/user';
 
   import AddCategoryModal from './addCategoryModal.vue';
   import EditCategoryModal from './editCategoryModal.vue';
@@ -48,7 +49,8 @@
     components: { BasicTable, TableAction, AddCategoryModal, EditCategoryModal },
     setup() {
       const { createMessage } = useMessage();
-
+      const userStore = useUserStore();
+      const { getCheckRole } = userStore;
       const { t } = useI18n();
 
       const columns: BasicColumn[] = [
@@ -107,6 +109,7 @@
         rowKey: 'id',
         bordered: true,
         actionColumn: {
+          ifShow: !getCheckRole('tourist'),
           width: 80,
           title: '操作',
           dataIndex: 'action',
@@ -142,6 +145,7 @@
         registeraddCategoryModal,
         registerEditCategoryModal,
         reload,
+        getCheckRole,
       };
     },
   });

+ 4 - 1
src/views/product/list.data.ts

@@ -5,7 +5,9 @@ import { h } from 'vue';
 import { Switch } from 'ant-design-vue';
 import { useMessage } from '/@/hooks/web/useMessage';
 import { useI18n } from '/@/hooks/web/useI18n';
-
+import { useUserStore } from '/@/store/modules/user';
+const userStore = useUserStore();
+const { getCheckRole } = userStore;
 export const searchForm: Partial<FormProps> = {
   labelWidth: 100,
   schemas: [
@@ -137,6 +139,7 @@ export const columns: BasicColumn[] = [
     title: '操作',
     dataIndex: '',
     slots: { customRender: 'action' },
+    ifShow: !getCheckRole('tourist'),
     fixed: 'right',
     width: 140,
   },

+ 5 - 2
src/views/product/list.vue

@@ -4,7 +4,7 @@
       @register="registerTable"
       :rowSelection="{ type: 'checkbox', onChange: onSelectChange }"
     >
-      <template #toolbar>
+      <template #toolbar v-if="!getCheckRole('tourist')">
         <a-button type="primary" @click="handleCreate"> 新增商品</a-button>
         <PopConfirmButton
           title="是否确定批量删除?"
@@ -80,6 +80,7 @@
   import { useDrawer } from '/@/components/Drawer';
   import ProductDrawer from './productDrawer.vue';
   // import { PageWrapper } from '/@/components/Page';
+  import { useUserStore } from '/@/store/modules/user';
   import { columns, searchForm } from './list.data';
   import { Time } from '/@/components/Time';
 
@@ -90,7 +91,8 @@
       const go = useGo();
       const { t } = useI18n();
       const [registerDrawer, { openDrawer }] = useDrawer();
-
+      const userStore = useUserStore();
+      const { getCheckRole } = userStore;
       const [registerTable, { reload, getSelectRowKeys }] = useTable({
         title: '商品列表',
         api: ListApi,
@@ -186,6 +188,7 @@
         handlePatchEnSale,
         handlePatchUnSale,
         uploadApi: uploadApi as any,
+        getCheckRole,
       };
     },
   });

+ 8 - 1
src/views/product/ref.vue

@@ -2,7 +2,9 @@
   <div>
     <BasicTable @register="registerTable">
       <template #toolbar>
-        <a-button type="primary" @click="handleCreate"> 新增商品属性</a-button>
+        <a-button v-show="!getCheckRole('tourist')" type="primary" @click="handleCreate">
+          新增商品属性</a-button
+        >
       </template>
       <template #action="{ record, column }">
         <TableAction :actions="createActions(record, column)" />
@@ -29,6 +31,7 @@
   import { useModal } from '/@/components/Modal';
   import addModal from './addModal.vue';
   import { useMessage } from '/@/hooks/web/useMessage';
+  import { useUserStore } from '/@/store/modules/user';
 
   export default defineComponent({
     components: { BasicTable, TableAction, addModal },
@@ -36,6 +39,8 @@
       const { createConfirm, createMessage: msg } = useMessage();
       const [registerModal, { openModal }] = useModal();
       const currentEditKeyRef = ref('');
+      const userStore = useUserStore();
+      const { getCheckRole } = userStore;
       const { t } = useI18n();
       console.log('registerModal', registerModal);
       const columns: BasicColumn[] = [
@@ -103,6 +108,7 @@
           ],
         },
         actionColumn: {
+          ifShow: !getCheckRole('tourist'),
           width: 160,
           title: '操作',
           dataIndex: 'action',
@@ -209,6 +215,7 @@
         handleDelete,
         expandAll,
         collapseAll,
+        getCheckRole,
       };
     },
   });

+ 12 - 2
src/views/scenes/live.vue

@@ -2,7 +2,13 @@
   <div class="p-4">
     <BasicTable @register="registerTable" :rowSelection="{ type: 'checkbox' }">
       <template #toolbar>
-        <a-button type="primary" @click="handleAddLiveScene"> 新增</a-button>
+        <a-button
+          type="primary"
+          v-show="!getCheckRole(['host', 'tourist'])"
+          @click="handleAddLiveScene"
+        >
+          新增</a-button
+        >
         <!-- <a-button type="primary" color="warning" @click="() => {}"> 编辑</a-button>
         <a-button type="primary" color="error" @click="() => {}"> 删除</a-button> -->
       </template>
@@ -67,7 +73,7 @@
   import { h } from 'vue';
   import { ListApi, brandTypeListApi, LiveSceneDeleteApi } from '/@/api/scene/live';
   import { useI18n } from '/@/hooks/web/useI18n';
-
+  import { useUserStore } from '/@/store/modules/user';
   import { useModal } from '/@/components/Modal';
   import { useDrawer } from '/@/components/Drawer';
   import bindModal from './bindModal.vue';
@@ -77,6 +83,8 @@
     components: { BasicTable, TableAction, TableImg, bindModal, LiveDrawer },
     setup() {
       const { createMessage } = useMessage();
+      const userStore = useUserStore();
+      const { getCheckRole } = userStore;
       const { t } = useI18n();
       const [registerBindModal, { openModal: openBindModal }] = useModal();
 
@@ -147,6 +155,7 @@
           title: t('common.operation'),
           dataIndex: '',
           slots: { customRender: 'action' },
+          ifShow: !getCheckRole(['host', 'tourist']),
           width: 250,
           fixed: 'right',
         },
@@ -300,6 +309,7 @@
         handleAddLiveScene,
         handleDeleteLiveScene,
         handleEditLiveScene,
+        getCheckRole,
       };
     },
   });

+ 23 - 4
src/views/staff/list.vue

@@ -6,6 +6,9 @@
           >新增</a-button
         >
       </template>
+      <template #headerTop>
+        <Alert :message="`可添加员工数为${surplusSubNum}人`" type="info" />
+      </template>
       <template #role="{ record }">
         {{ renderRoleType(record.role) }}
       </template>
@@ -49,7 +52,7 @@
   </div>
 </template>
 <script lang="ts">
-  import { defineComponent, computed } from 'vue';
+  import { defineComponent, computed, onMounted, ref } from 'vue';
   import { BasicTable, useTable, BasicColumn, FormProps, TableAction } from '/@/components/Table';
   import { useMessage } from '/@/hooks/web/useMessage';
   import { useModal } from '/@/components/Modal';
@@ -57,9 +60,9 @@
   import SetpaswordModal from './setpaswordModal.vue';
   import DetailsModal from './detailsModal.vue';
   import DelListModal from './delListModal.vue';
-  // import { Switch } from 'ant-design-vue';
+  import { Alert } from 'ant-design-vue';
   // import { h } from 'vue';
-  import { ListApi, delApi, preDelApi } from '/@/api/staff/list';
+  import { ListApi, delApi, preDelApi, getNumByStaff } from '/@/api/staff/list';
   import { useI18n } from '/@/hooks/web/useI18n';
   // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
   import { RoleEnum } from '/@/enums/roleEnum';
@@ -67,9 +70,18 @@
   import { Time } from '/@/components/Time';
   import { useUserStore } from '/@/store/modules/user';
   export default defineComponent({
-    components: { BasicTable, TableAction, Time, SetpaswordModal, DetailsModal, DelListModal },
+    components: {
+      BasicTable,
+      TableAction,
+      Time,
+      SetpaswordModal,
+      DetailsModal,
+      DelListModal,
+      Alert,
+    },
     setup() {
       const [register, { openModal }] = useModal();
+      const surplusSubNum = ref(0);
       const [registerDetail, { openModal: openDetaileModal }] = useModal();
       const [registerDelList, { openModal: openDelListeModal }] = useModal();
       const { createConfirm, createMessage } = useMessage();
@@ -78,6 +90,12 @@
       console.log('getRoleList', roleList);
       const go = useGo();
       const { t } = useI18n();
+      onMounted(() => {
+        getNumByStaff({}).then((res) => {
+          let { totalSubNum = 0 } = res;
+          surplusSubNum.value = totalSubNum;
+        });
+      });
       const columns: BasicColumn[] = [
         {
           title: 'ID',
@@ -247,6 +265,7 @@
         handleDelete,
         uploadApi: uploadApi as any,
         RoleEnum,
+        surplusSubNum,
       };
     },
   });