فهرست منبع

feat: 更新项目描述和状态逻辑,调整角色管理中的角色列表获取方式

laiqi 11 ماه پیش
والد
کامیت
ebb2702cb0

+ 2 - 2
.cursor/rules/vben-cli-tools.mdc

@@ -1,6 +1,6 @@
 ---
-description:
-globs:
+description: 项目 CLI 工具
+globs: 
 alwaysApply: false
 ---
 # Vben 项目 CLI 工具

+ 2 - 2
.cursor/rules/vben-project-structure.mdc

@@ -1,6 +1,6 @@
 ---
-description:
-globs:
+description: 项目结构概览
+globs: 
 alwaysApply: false
 ---
 # Vben 项目结构概览

+ 2 - 2
.cursor/rules/vben-quick-start.mdc

@@ -1,6 +1,6 @@
 ---
-description:
-globs:
+description: 项目启动
+globs: 
 alwaysApply: false
 ---
 # Vben 项目快速启动

+ 2 - 2
.cursor/rules/vben-standards.mdc

@@ -1,6 +1,6 @@
 ---
-description:
-globs:
+description: 项目规范和代码检查
+globs: 
 alwaysApply: false
 ---
 # Vben 项目规范和代码检查

+ 3 - 3
apps/web-ele/src/views/system-manage/role-manage/form.vue

@@ -57,10 +57,10 @@ const [BaseForm, baseFormApi] = useVbenForm({
       component: 'Switch',
       fieldName: 'available',
       label: '状态',
-      defaultValue: 0,
+      defaultValue: 1,
       componentProps: {
-        activeValue: 0,
-        inactiveValue: 1,
+        activeValue: 1,
+        inactiveValue: 0,
         activeText: '启用',
         inactiveText: '禁用',
       },

+ 4 - 4
apps/web-ele/src/views/system-manage/role-manage/index.vue

@@ -43,8 +43,8 @@ const formOptions: VbenFormProps = {
         placeholder: $t('ui.placeholder.select'),
         allowClear: true,
         options: [
-          { label: '启用', value: 0 },
-          { label: '禁用', value: 1 },
+          { label: '启用', value: 1 },
+          { label: '禁用', value: 0 },
         ],
       },
     },
@@ -98,10 +98,10 @@ const gridOptions: VxeGridProps<any> = {
           return h(
             ElTag,
             {
-              type: row.available === 0 ? 'success' : 'info',
+              type: row.available === 1 ? 'success' : 'info',
             },
             {
-              default: () => (row.available === 0 ? '启用' : '禁用'),
+              default: () => (row.available === 1 ? '启用' : '禁用'),
             },
           );
         },

+ 1 - 1
apps/web-ele/src/views/system-manage/user-manage/form.vue

@@ -33,7 +33,7 @@ async function fetchRoleOptions() {
 
     if (res && res.Data) {
       roleOptions.value = res.Data.filter(
-        (item: RoleGroupEntity) => item.available === 0,
+        (item: RoleGroupEntity) => item.available === 1,
       ).map((item: RoleGroupEntity) => ({
         label: item.title,
         value: item.id.toString(),

+ 53 - 2
apps/web-ele/src/views/system-manage/user-manage/index.vue

@@ -1,9 +1,10 @@
 <script lang="ts" setup>
 import type { VbenFormProps } from '@vben/common-ui';
+import type { RoleGroupEntity } from '@vben/types';
 
 import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
 
-import { h } from 'vue';
+import { h, onMounted, ref } from 'vue';
 
 import { Page, useVbenModal } from '@vben/common-ui';
 import { MdiDelete, MdiDetail, MdiEdit } from '@vben/icons';
@@ -12,6 +13,7 @@ import { ElMessage, ElMessageBox, ElTag } from 'element-plus';
 
 import { useVbenVxeGrid } from '#/adapter/vxe-table';
 import { deleteAccountApi, getAccountListApi } from '#/api/account';
+import { getRoleListApi } from '#/api/role';
 import { $t } from '#/locales';
 
 import AccountForm from './form.vue';
@@ -103,7 +105,16 @@ const gridOptions: VxeGridProps<any> = {
       },
     },
     { title: '备注', field: 'accountbz', sortable: true },
-    { title: '角色组', field: 'accountgrouplist', sortable: true },
+    {
+      title: '角色组',
+      field: 'accountgrouplist',
+      sortable: true,
+      slots: {
+        default: ({ row }) => {
+          return formatRoleNames(row.accountgrouplist);
+        },
+      },
+    },
     { title: '创建人', field: 'accountcreateuser', sortable: true },
     { title: '开通时间', field: 'accountcreatedate', sortable: true },
     // { title: '到期时间', field: 'accountenddate' },
@@ -139,6 +150,46 @@ const [Modal, modalApi] = useVbenModal({
   connectedComponent: AccountForm,
 });
 
+// 角色数据映射
+const roleMap = ref<Map<string, string>>(new Map());
+
+// 获取角色列表并创建ID到名称的映射
+async function fetchRoleList() {
+  try {
+    const res = await getRoleListApi({
+      pageindex: 1,
+      rows: 1000,
+    });
+
+    if (res && res.Data) {
+      const map = new Map<string, string>();
+      res.Data.filter((item: RoleGroupEntity) => item.available === 1).forEach(
+        (item: RoleGroupEntity) => {
+          map.set(item.id.toString(), item.title);
+        },
+      );
+      roleMap.value = map;
+    }
+  } catch (error) {
+    console.error('获取角色列表失败', error);
+  }
+}
+
+// 将角色ID转换为角色名称
+function formatRoleNames(roleIds: string): string {
+  if (!roleIds) return '';
+
+  const ids = roleIds.split(',').filter(Boolean);
+  const names = ids.map((id) => roleMap.value.get(id) || id).filter(Boolean);
+
+  return names.join(', ');
+}
+
+// 初始化时获取角色列表
+onMounted(() => {
+  fetchRoleList();
+});
+
 /* 创建 */
 function handleCreate() {
   modalApi.setState({ showCancelButton: true });