style: system views code style

This commit is contained in:
xingyu4j
2025-04-22 11:25:11 +08:00
parent 4e1d6812ff
commit da3fd5b718
84 changed files with 1200 additions and 624 deletions

View File

@@ -1,16 +1,17 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemUserApi } from '#/api/system/user';
import { useAccess } from '@vben/access';
import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
import { CommonStatusEnum } from '#/utils/constants';
import { getDeptList } from '#/api/system/dept';
import { getSimplePostList } from '#/api/system/post';
import { getSimpleRoleList } from '#/api/system/role';
import { handleTree } from '#/utils/tree';
import { CommonStatusEnum } from '#/utils/constants';
import { getRangePickerDefaultProps } from '#/utils/date';
import { useAccess } from '@vben/access';
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
import { handleTree } from '#/utils/tree';
const { hasAccessByCodes } = useAccess();
@@ -101,7 +102,7 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'Input',
componentProps: {
placeholder: '请输入手机号码',
}
},
},
{
fieldName: 'sex',
@@ -131,7 +132,7 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
}
},
},
];
}
@@ -174,7 +175,7 @@ export function useResetPasswordFormSchema(): VbenFormSchema[] {
triggerFields: ['newPassword'],
},
},
]
];
}
/** 分配角色的表单 */
@@ -217,7 +218,7 @@ export function useAssignRoleFormSchema(): VbenFormSchema[] {
placeholder: '请选择角色',
},
},
]
];
}
/** 用户导入的表单 */
@@ -244,7 +245,6 @@ export function useImportFormSchema(): VbenFormSchema[] {
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
@@ -281,7 +281,10 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 列表的字段 */
export function useGridColumns<T = SystemUserApi.SystemUser>(
onActionClick: OnActionClickFn<T>,
onStatusChange?: (newStatus: number, row: T) => PromiseLike<boolean | undefined>,
onStatusChange?: (
newStatus: number,
row: T,
) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
return [
{

View File

@@ -1,26 +1,36 @@
<script lang="ts" setup>
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemUserApi } from '#/api/system/user';
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { SystemDeptApi } from '#/api/system/dept';
import type { SystemUserApi } from '#/api/system/user';
import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { Button, message, Modal } from 'ant-design-vue';
import { Plus, Download, Upload } from '@vben/icons';
import Form from './modules/form.vue';
import ResetPasswordForm from './modules/reset-password-form.vue';
import AssignRoleForm from './modules/assign-role-form.vue';
import ImportForm from './modules/import-form.vue';
import DeptTree from './modules/dept-tree.vue';
import { DocAlert } from '#/components/doc-alert';
import { Download, Plus, Upload } from '@vben/icons';
import { Button, message, Modal } from 'ant-design-vue';
import { $t } from '#/locales';
import { ref } from 'vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getUserPage, deleteUser, exportUser, updateUserStatus } from '#/api/system/user';
import { downloadByData } from '#/utils/download';
import {
deleteUser,
exportUser,
getUserPage,
updateUserStatus,
} from '#/api/system/user';
import { DocAlert } from '#/components/doc-alert';
import { $t } from '#/locales';
import { DICT_TYPE, getDictLabel } from '#/utils/dict';
import { downloadByData } from '#/utils/download';
import { useGridColumns, useGridFormSchema } from './data';
import AssignRoleForm from './modules/assign-role-form.vue';
import DeptTree from './modules/dept-tree.vue';
import Form from './modules/form.vue';
import ImportForm from './modules/import-form.vue';
import ResetPasswordForm from './modules/reset-password-form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
@@ -55,7 +65,7 @@ async function onExport() {
/** 选择部门 */
const searchDeptId = ref<number | undefined>(undefined);
async function onDeptSelect (dept: SystemDeptApi.SystemDept) {
async function onDeptSelect(dept: SystemDeptApi.SystemDept) {
searchDeptId.value = dept.id;
onRefresh();
}
@@ -89,7 +99,7 @@ async function onDelete(row: SystemUserApi.SystemUser) {
key: 'action_process_msg',
});
onRefresh();
} catch (error) {
} catch {
hideLoading();
}
}
@@ -106,7 +116,10 @@ function onAssignRole(row: SystemUserApi.SystemUser) {
// TODO @芋艿:后续怎么简化一下 confirm 的实现。
/** 更新用户状态 */
async function onStatusChange(newStatus: number, row: SystemUserApi.SystemUser): Promise<boolean | undefined> {
async function onStatusChange(
newStatus: number,
row: SystemUserApi.SystemUser,
): Promise<boolean | undefined> {
return new Promise((resolve, reject) => {
Modal.confirm({
title: '切换状态',
@@ -116,16 +129,18 @@ async function onStatusChange(newStatus: number, row: SystemUserApi.SystemUser):
},
onOk() {
// 更新用户状态
updateUserStatus(row.id as number, newStatus).then(() => {
// 提示并返回成功
message.success({
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
updateUserStatus(row.id as number, newStatus)
.then(() => {
// 提示并返回成功
message.success({
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
});
resolve(true);
})
.catch((error) => {
reject(error);
});
resolve(true);
}).catch((error) => {
reject(error);
});
},
});
});
@@ -137,20 +152,20 @@ function onActionClick({
row,
}: OnActionClickParams<SystemUserApi.SystemUser>) {
switch (code) {
case 'edit': {
onEdit(row);
case 'assign-role': {
onAssignRole(row);
break;
}
case 'delete': {
onDelete(row);
break;
}
case 'reset-password': {
onResetPassword(row);
case 'edit': {
onEdit(row);
break;
}
case 'assign-role': {
onAssignRole(row);
case 'reset-password': {
onResetPassword(row);
break;
}
}
@@ -191,7 +206,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
<Page auto-content-height>
<DocAlert title="用户体系" url="https://doc.iocoder.cn/user-center/" />
<DocAlert title="三方登陆" url="https://doc.iocoder.cn/social-user/" />
<DocAlert title="Excel 导入导出" url="https://doc.iocoder.cn/excel-import-and-export/" />
<DocAlert
title="Excel 导入导出"
url="https://doc.iocoder.cn/excel-import-and-export/"
/>
<FormModal @success="onRefresh" />
<ResetPasswordModal @success="onRefresh" />
@@ -207,15 +225,29 @@ const [Grid, gridApi] = useVbenVxeGrid({
<div class="w-18/24">
<Grid table-title="用户列表">
<template #toolbar-tools>
<Button type="primary" @click="onCreate" v-access:code="['system:user:create']">
<Button
type="primary"
@click="onCreate"
v-access:code="['system:user:create']"
>
<Plus class="size-5" />
{{ $t('ui.actionTitle.create', ['用户']) }}
</Button>
<Button type="primary" class="ml-2" @click="onExport" v-access:code="['system:user:export']">
<Button
type="primary"
class="ml-2"
@click="onExport"
v-access:code="['system:user:export']"
>
<Download class="size-5" />
{{ $t('ui.actionTitle.export') }}
</Button>
<Button type="primary" class="ml-2" @click="onImport" v-access:code="['system:user:import']">
<Button
type="primary"
class="ml-2"
@click="onImport"
v-access:code="['system:user:import']"
>
<Upload class="size-5" />
{{ $t('ui.actionTitle.import', ['用户']) }}
</Button>

View File

@@ -2,11 +2,12 @@
import type { SystemUserApi } from '#/api/system/user';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { $t } from '#/locales';
import { useVbenForm } from '#/adapter/form';
import { getUserRoleList, assignUserRole } from '#/api/system/permission';
import { assignUserRole, getUserRoleList } from '#/api/system/permission';
import { $t } from '#/locales';
import { useAssignRoleFormSchema } from '../data';

View File

@@ -1,10 +1,12 @@
<script lang="ts" setup>
import { type SystemDeptApi} from '#/api/system/dept';
import type { SystemDeptApi } from '#/api/system/dept';
import { Tree, Input, Spin } from 'ant-design-vue';
import { onMounted, ref } from 'vue';
import { ref, onMounted } from 'vue';
import { Search } from '@vben/icons';
import { Input, Spin, Tree } from 'ant-design-vue';
import { getSimpleDeptList } from '#/api/system/dept';
import { handleTree } from '#/utils/tree';
@@ -19,12 +21,14 @@ const searchValue = ref(''); // 搜索值
function handleSearch(e: any) {
const value = e.target.value;
searchValue.value = value;
const filteredList = value ? deptList.value.filter(item =>
item.name.toLowerCase().includes(value.toLowerCase())
) : deptList.value;
const filteredList = value
? deptList.value.filter((item) =>
item.name.toLowerCase().includes(value.toLowerCase()),
)
: deptList.value;
deptTree.value = handleTree(filteredList);
// 展开所有节点
expandedKeys.value = deptTree.value.map(node => node.id as number);
expandedKeys.value = deptTree.value.map((node) => node.id as number);
}
/** 选中部门 */
@@ -52,7 +56,7 @@ onMounted(async () => {
<div class="mb-2">
<Input
placeholder="搜索部门"
allowClear
allow-clear
v-model:value="searchValue"
@change="handleSearch"
class="w-full"
@@ -67,11 +71,11 @@ onMounted(async () => {
class="pt-2"
v-if="deptTree.length > 0"
:tree-data="deptTree"
:fieldNames="{ title: 'name', key: 'id', children: 'children' }"
:field-names="{ title: 'name', key: 'id', children: 'children' }"
@select="handleSelect"
:defaultExpandAll="true"
:default-expand-all="true"
/>
<div v-else-if="!loading" class="text-center text-gray-500 py-4">
<div v-else-if="!loading" class="py-4 text-center text-gray-500">
暂无数据
</div>
</Spin>

View File

@@ -1,12 +1,14 @@
<script lang="ts" setup>
import type { SystemUserApi } from '#/api/system/user';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { computed, ref } from 'vue';
import { useVbenForm } from '#/adapter/form';
import { createUser, updateUser, getUser } from '#/api/system/user';
import { createUser, getUser, updateUser } from '#/api/system/user';
import { $t } from '#/locales';
import { useFormSchema } from '../data';

View File

@@ -2,12 +2,12 @@
import type { FileType } from 'ant-design-vue/es/upload/interface';
import { useVbenModal } from '@vben/common-ui';
import { message} from 'ant-design-vue';
import { Button, Upload } from 'ant-design-vue';
import { $t } from '#/locales';
import { Button, message, Upload } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { importUser, importUserTemplate } from '#/api/system/user';
import { $t } from '#/locales';
import { downloadByData } from '#/utils/download';
import { useImportFormSchema } from '../data';
@@ -41,7 +41,7 @@ const [Modal, modalApi] = useVbenModal({
} finally {
modalApi.lock(false);
}
}
},
});
/** 上传前 */
@@ -62,7 +62,11 @@ async function onDownload() {
<Form class="mx-4">
<template #file>
<div class="w-full">
<Upload :max-count="1" accept=".xls,.xlsx" :beforeUpload="beforeUpload">
<Upload
:max-count="1"
accept=".xls,.xlsx"
:before-upload="beforeUpload"
>
<Button type="primary"> 选择 Excel 文件 </Button>
</Upload>
</div>

View File

@@ -2,11 +2,12 @@
import type { SystemUserApi } from '#/api/system/user';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { $t } from '#/locales';
import { useVbenForm } from '#/adapter/form';
import { resetUserPassword } from '#/api/system/user';
import { $t } from '#/locales';
import { useResetPasswordFormSchema } from '../data';