From d01af540b961aaaa17f68e70374f78a6695219cc Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期一, 17 十一月 2025 10:25:32 +0800
Subject: [PATCH] fix: bug

---
 src/views/Permission/RoleManage.vue |  298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 298 insertions(+), 0 deletions(-)

diff --git a/src/views/Permission/RoleManage.vue b/src/views/Permission/RoleManage.vue
new file mode 100644
index 0000000..2e32a69
--- /dev/null
+++ b/src/views/Permission/RoleManage.vue
@@ -0,0 +1,298 @@
+<template>
+  <LoadingLayout :loading="state.loading">
+    <AppContainer>
+      <ProTableQueryFilterBar @on-reset="reset">
+        <template #query>
+          <QueryFilterItem>
+            <SearchInput
+              v-model="extraParamState.queryCondition"
+              style="width: 200px"
+              placeholder="瑙掕壊鍚嶇О"
+              @on-click-search="getList"
+              @keyup.enter="getList()"
+            >
+            </SearchInput>
+          </QueryFilterItem>
+        </template>
+        <template #btn>
+          <el-button
+            v-if="checkSubModuleItemShow('pageButton', 'addBtn')"
+            @click="openDialog()"
+            icon="Plus"
+            type="primary"
+            >鏂板</el-button
+          >
+        </template>
+      </ProTableQueryFilterBar>
+      <ProTableV2 v-bind="proTableProps" :columns="column" :operationBtns="operationBtns">
+      </ProTableV2>
+    </AppContainer>
+    <AddOrEditRoleDialog v-bind="dialogProps" />
+    <DialogAuthorizeV2 v-bind="dialogAuthorizeProps" authorizeType="Role" />
+    <!-- <DialogMember v-model:visibleId="rowState.setMemberRoleId" /> -->
+  </LoadingLayout>
+</template>
+
+<script setup lang="ts">
+import {
+  ProTableQueryFilterBar,
+  OperationBtnType,
+  ProTableV2,
+  SearchInput,
+  LoadingLayout,
+  AppContainer,
+  QueryFilterItem,
+  useTable,
+  useFormDialog,
+  FieldRadio,
+} from '@bole-core/components';
+import { useAccess } from '@/hooks';
+import { Message } from '@bole-core/core';
+import AddOrEditRoleDialog from './components/AddOrEditRoleDialog.vue';
+import { EnumUserType } from '@/constants';
+import DialogAuthorizeV2 from './components/dialogAuthorizeV2.vue';
+import * as roleServices from '@/services/api/role';
+import { useQueryClient } from '@tanstack/vue-query';
+
+defineOptions({
+  name: 'RoleManage',
+});
+
+const operationBtnMap: Record<string, OperationBtnType> = {
+  editBtn: {
+    emits: { onClick: (role) => openDialog(role) },
+    extraProps: {
+      hide: (role: API.GetRolesQueryResultItem) => role.isPublic,
+    },
+  },
+  delBtn: {
+    emits: { onClick: (role) => handleDeleteRole(role) },
+    props: { type: 'danger' },
+    extraProps: {
+      hide: (role: API.GetRolesQueryResultItem) => role.isPublic,
+    },
+  },
+  authorize: {
+    emits: { onClick: (role) => openAuthorizeDialog(role) },
+    extraProps: {
+      hide: (role: API.GetRolesQueryResultItem) => role.isPublic,
+    },
+  },
+  // member: { emits: { onClick: (role) => openMemberDialog(role) } },
+  disabledBtn: {
+    emits: { onClick: (role) => roleEnableOrForbid(role) },
+    props: { type: 'danger' },
+    extraProps: {
+      hide: (row: API.GetRolesQueryResultItem) => !(!row.isPublic && !row.isDisabled),
+    },
+  },
+  enableBtn: {
+    emits: { onClick: (role) => roleEnableOrForbid(role) },
+    extraProps: {
+      hide: (row: API.GetRolesQueryResultItem) => !(row.isDisabled && !row.isPublic),
+    },
+  },
+};
+
+const { checkSubModuleItemShow, column, operationBtns } = useAccess({
+  operationBtnMap,
+});
+
+const BaseState = {
+  loading: true,
+};
+
+const state = reactive({ ...BaseState });
+
+onMounted(async () => {
+  await getList();
+  state.loading = false;
+});
+
+const {
+  getDataSource: getList,
+  proTableProps,
+  paginationState,
+  extraParamState,
+  reset,
+} = useTable(
+  async ({ pageIndex, pageSize }, extraParamState) => {
+    try {
+      let params: API.GetRolesQuery = {
+        pageModel: {
+          rows: pageSize,
+          page: pageIndex,
+          orderInput: extraParamState.orderInput,
+        },
+        userType: AppLocalConfig.userType,
+        clientType: AppLocalConfig.clientType,
+        enterpriseType: AppLocalConfig.enterpriseType,
+        keywords: extraParamState.queryCondition,
+      };
+      let res = await roleServices.getRoles(params, {
+        showLoading: !state.loading,
+      });
+      return res;
+    } catch (error) {}
+  },
+  {
+    defaultExtraParams: {
+      queryCondition: '',
+      orderInput: [{ property: 'id', order: EnumPagedListOrder.Desc }],
+    },
+    queryKey: ['roleServices/getRoles'],
+    columnsRenderProps: {
+      dataPower: { type: 'enum', valueEnum: EnumRoleWebApiDataPowerText },
+    },
+  }
+);
+
+async function openDialog(row?: API.GetRolesQueryResultItem) {
+  try {
+    if (row) {
+      const detail = await roleServices.getRole({ id: row.id });
+      handleEdit({
+        id: row.id,
+        name: row.name,
+        remark: row.remark,
+        userType: row.userType,
+        clientType: row.clientType,
+        dataRange: row.dataPower,
+        detail: detail,
+        minLevel: row.minLevel,
+        enterpriseType: row.enterpriseType,
+      });
+    } else {
+      handleAdd({
+        userType: AppLocalConfig.userType,
+        clientType: AppLocalConfig.clientType,
+      });
+    }
+  } catch (error) {}
+}
+
+const { dialogProps, handleAdd, handleEdit, editForm, dialogState } = useFormDialog({
+  onConfirm: handleAddOrEdit,
+  defaultFormParams: {
+    id: '',
+    name: '',
+    remark: '',
+    userType: AppLocalConfig.userType,
+    clientType: AppLocalConfig.clientType,
+    dataRange: EnumRoleWebApiDataPower.All,
+    detail: null as API.GetRoleQueryResult,
+    minLevel: 1,
+    enterpriseType: AppLocalConfig.enterpriseType,
+  },
+});
+
+const queryClient = useQueryClient();
+
+async function handleAddOrEdit() {
+  try {
+    const isEdit = editForm.id;
+    let params: API.SaveRoleCommand = {
+      name: editForm.name,
+      remark: editForm.remark,
+      dataPower: editForm.dataRange,
+      userType: editForm.userType,
+      clientType: editForm.clientType,
+      minLevel: editForm.minLevel,
+    };
+    if (editForm.userType === EnumUserType.Enterprise) {
+      params.enterpriseType = editForm.enterpriseType;
+    }
+    if (isEdit) {
+      params = {
+        ...editForm.detail,
+        ...params,
+      };
+    }
+    let res = await roleServices.saveRole(params);
+    if (res) {
+      Message.successMessage('鎿嶄綔鎴愬姛');
+      getList(isEdit ? paginationState.pageIndex : 1);
+      queryClient.invalidateQueries(['userServices/getUserInfoRoles']);
+    }
+  } catch (error) {}
+}
+
+async function handleDeleteRole(row: API.GetRolesQueryResultItem) {
+  try {
+    await Message.deleteMessage();
+    let params: API.DeleteRoleCommand = {
+      ids: [row.id],
+    };
+    let res = await roleServices.deleteRole(params);
+    if (res) {
+      Message.successMessage('鎿嶄綔鎴愬姛');
+      getList(paginationState.pageIndex);
+      queryClient.invalidateQueries(['userServices/getUserInfoRoles']);
+    }
+  } catch (error) {}
+}
+
+async function roleEnableOrForbid(row: API.GetRolesQueryResultItem) {
+  try {
+    await Message.tipMessage(`鏄惁${row.isDisabled ? '鍚敤' : '绂佺敤'}瑙掕壊`);
+    let res = await roleServices.setRoleIsDisabled({
+      ids: [row.id],
+      isDisabled: !row.isDisabled,
+    });
+    if (res) {
+      Message.successMessage('鎿嶄綔鎴愬姛');
+      getList(paginationState.pageIndex);
+      queryClient.invalidateQueries(['userServices/getUserInfoRoles']);
+      return !!res;
+    }
+  } catch (error) {}
+}
+
+const rowState = reactive({
+  authorizeId: '',
+  setMemberRoleId: '',
+});
+
+const {
+  dialogProps: dialogAuthorizeProps,
+  handleAdd: handleAuthorizeAdd,
+  editForm: authorizeForm,
+} = useFormDialog({
+  onConfirm: handleAuthorize,
+  defaultFormParams: {
+    detail: null as API.GetRoleQueryResult,
+  },
+});
+
+async function openAuthorizeDialog(row: API.GetRolesQueryResultItem) {
+  try {
+    const detail = await roleServices.getRole({ id: row.id });
+    handleAuthorizeAdd({
+      detail: detail,
+    });
+  } catch (error) {}
+}
+
+async function handleAuthorize(selectedMenuIds: string[]) {
+  console.log('selectedMenuIds: ', selectedMenuIds);
+  try {
+    let params: API.SaveRoleCommand = {
+      ...authorizeForm.detail,
+      menuIds: selectedMenuIds,
+      // resources: resourceIds.map((x) => ({
+      //   resourceId: x,
+      //   dataPower: EnumRoleWebApiDataPower.All,
+      // })),
+    };
+    let res = await roleServices.saveRole(params);
+    if (res) {
+      Message.successMessage('鎿嶄綔鎴愬姛');
+      getList(paginationState.pageIndex);
+    }
+  } catch (error) {}
+}
+
+// function openMemberDialog(row: API.IdentityRoleDto) {
+//   rowState.setMemberRoleId = row.id;
+// }
+</script>

--
Gitblit v1.9.1