1. 管理员管理模块拆分
2. 图片上传自动压缩(大于850kb) 3. 省市区选择组件重构,支持搜索
This commit is contained in:
291
apps/web-antd/src/views/system/admin/_shared/admin-page.vue
Normal file
291
apps/web-antd/src/views/system/admin/_shared/admin-page.vue
Normal file
@@ -0,0 +1,291 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button, Image, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
import {
|
||||
createAdmin,
|
||||
deleteAdmin,
|
||||
generateLoginAccount,
|
||||
resetPassword,
|
||||
updateAdmin,
|
||||
} from '#/views/system/admin/api';
|
||||
|
||||
import { normalizeAdminPayload } from './admin-payload';
|
||||
import { createAdminModalFormProps } from './form-schemas';
|
||||
import { createAdminSearchOptions } from './search-config';
|
||||
import { formatAddressDisplay } from '#/util/address-index';
|
||||
|
||||
import { createAdminGridOptions } from './table-config';
|
||||
import { getRoleMeta } from './role-meta';
|
||||
|
||||
function formatAdminRegion(row: {
|
||||
province_id?: number;
|
||||
city_id?: number;
|
||||
}): string {
|
||||
if (row.province_id && row.city_id) {
|
||||
return formatAddressDisplay([row.province_id, row.city_id]);
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
|
||||
const DEFAULT_AVATAR =
|
||||
'https://xiaokang88.oss-cn-hangzhou.aliyuncs.com/xk_upload_20251022/20251022104156946505ca86d97626c08882f31797dbcef49c.png';
|
||||
|
||||
const props = defineProps<{
|
||||
roleId: number;
|
||||
}>();
|
||||
|
||||
const meta = computed(() => getRoleMeta(props.roleId));
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
const isUpdate = ref(false);
|
||||
const modalGridApi = ref();
|
||||
|
||||
const [Form, formApi] = useVbenForm(
|
||||
createAdminModalFormProps(props.roleId, meta.value.formType),
|
||||
);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
const e = await formApi.validate();
|
||||
if (e.valid) {
|
||||
const values = await formApi.getValues();
|
||||
const payload = normalizeAdminPayload(
|
||||
{ ...values, role_id: props.roleId },
|
||||
meta.value.formType,
|
||||
);
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
const submitApi = isUpdate.value ? updateAdmin : createAdmin;
|
||||
submitApi(payload)
|
||||
.then(() => {
|
||||
message.success('保存成功');
|
||||
modalGridApi.value?.reload();
|
||||
modalApi.close();
|
||||
})
|
||||
.finally(() => {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
});
|
||||
}
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
const data = modalApi.getData<Record<string, any>>();
|
||||
modalGridApi.value = isOpen ? data?.gridApi : null;
|
||||
if (isOpen) {
|
||||
const { values = {}, update = false } = data ?? {};
|
||||
isUpdate.value = !!update;
|
||||
|
||||
if (update && values?.id) {
|
||||
const formValues = { ...values };
|
||||
if (formValues.province_id && formValues.city_id) {
|
||||
formValues.address = [formValues.province_id, formValues.city_id];
|
||||
}
|
||||
formValues.role_id = props.roleId;
|
||||
formApi.setValues(formValues);
|
||||
return;
|
||||
}
|
||||
|
||||
isUpdate.value = false;
|
||||
formApi.resetForm();
|
||||
formApi.setValues({
|
||||
role_id: props.roleId,
|
||||
avatar: DEFAULT_AVATAR,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const gridEvents: VxeGridListeners<any> = {
|
||||
checkboxChange() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: createAdminSearchOptions(),
|
||||
gridOptions: createAdminGridOptions(props.roleId, meta.value.formType),
|
||||
gridEvents,
|
||||
});
|
||||
|
||||
const showModal = (data: Record<string, any> = {}, update = false) => {
|
||||
modalApi.setData({
|
||||
values: data,
|
||||
update,
|
||||
gridApi,
|
||||
});
|
||||
modalApi.open();
|
||||
};
|
||||
|
||||
const deleteApi = (row: number | false) => {
|
||||
let ids: number[] = [];
|
||||
if (row) {
|
||||
ids.push(row);
|
||||
} else {
|
||||
ids = gridApi.grid.getCheckboxRecords().map((item) => item.id);
|
||||
}
|
||||
deleteAdmin({ ids }).then(() => {
|
||||
message.success('删除成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
|
||||
const resetPasswordApi = (id: number) => {
|
||||
resetPassword(id).then(() => {
|
||||
message.success('重置成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
|
||||
const generateAccountApi = async (row: { id: number }) => {
|
||||
try {
|
||||
const result = await generateLoginAccount(row.id);
|
||||
if (result.login_account) {
|
||||
message.success('生成账号成功');
|
||||
gridApi.query();
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '生成账号失败');
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = async (text: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
message.success('复制成功');
|
||||
} catch {
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-999999px';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
message.success('复制成功');
|
||||
} catch {
|
||||
message.error('复制失败');
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height :title="meta.title">
|
||||
<Modal
|
||||
:title="`${isUpdate ? '编辑' : '新增'}${meta.title}`"
|
||||
class="w-[60%]"
|
||||
>
|
||||
<Form />
|
||||
</Modal>
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增',
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
onClick: () => showModal({}, false),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '删除',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
ifShow: hasTopTableDropDownActions,
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, false),
|
||||
},
|
||||
},
|
||||
]"
|
||||
>
|
||||
<template #more>
|
||||
<Button style="margin-left: 16px">
|
||||
批量操作
|
||||
<Icon icon="ant-design:down-outlined" />
|
||||
</Button>
|
||||
</template>
|
||||
</TableAction>
|
||||
</template>
|
||||
<template #avatar="{ row }">
|
||||
<Image :src="row.avatar" height="30" width="30" />
|
||||
</template>
|
||||
<template #region="{ row }">
|
||||
{{ formatAdminRegion(row) }}
|
||||
</template>
|
||||
<template #login_account="{ row }">
|
||||
<span v-if="row.login_account">
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
@click="copyToClipboard(row.login_account)"
|
||||
>
|
||||
{{ row.login_account }}
|
||||
</Button>
|
||||
</span>
|
||||
<Button
|
||||
v-else
|
||||
type="link"
|
||||
size="small"
|
||||
@click="generateAccountApi(row)"
|
||||
>
|
||||
生成账号
|
||||
</Button>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
type: 'link',
|
||||
icon: 'uil:edit',
|
||||
size: 'small',
|
||||
onClick: showModal.bind(null, row, true),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
size: 'small',
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '重置密码',
|
||||
type: 'link',
|
||||
icon: 'bitcoin-icons:refresh-filled',
|
||||
size: 'small',
|
||||
popConfirm: {
|
||||
title: '确定重置密码吗?',
|
||||
confirm: resetPasswordApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { AdminFormType } from './role-meta';
|
||||
|
||||
const UNUSED_ID_FIELDS = [
|
||||
'store_id',
|
||||
'doctor_id',
|
||||
'pharmacist_id',
|
||||
'supplier_id',
|
||||
] as const;
|
||||
|
||||
function isEmptyId(value: unknown): boolean {
|
||||
return value === '' || value === null || value === undefined;
|
||||
}
|
||||
|
||||
function toZeroOrOmit(
|
||||
payload: Record<string, unknown>,
|
||||
field: string,
|
||||
omitWhenEmpty: boolean,
|
||||
): void {
|
||||
if (!(field in payload)) {
|
||||
return;
|
||||
}
|
||||
if (isEmptyId(payload[field])) {
|
||||
if (omitWhenEmpty) {
|
||||
delete payload[field];
|
||||
} else {
|
||||
payload[field] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交前归一化:避免整型列收到 '';不削弱各角色必填校验(在 validate 之后调用)。
|
||||
*/
|
||||
export function normalizeAdminPayload(
|
||||
values: Record<string, unknown>,
|
||||
formType: AdminFormType,
|
||||
): Record<string, unknown> {
|
||||
const payload = { ...values };
|
||||
delete payload.confirmPassword;
|
||||
|
||||
switch (formType) {
|
||||
case 'basic':
|
||||
for (const field of UNUSED_ID_FIELDS) {
|
||||
toZeroOrOmit(payload, field, true);
|
||||
}
|
||||
break;
|
||||
case 'address':
|
||||
for (const field of UNUSED_ID_FIELDS) {
|
||||
toZeroOrOmit(payload, field, true);
|
||||
}
|
||||
break;
|
||||
case 'supplier':
|
||||
toZeroOrOmit(payload, 'store_id', true);
|
||||
toZeroOrOmit(payload, 'doctor_id', true);
|
||||
toZeroOrOmit(payload, 'pharmacist_id', true);
|
||||
break;
|
||||
case 'clinic':
|
||||
toZeroOrOmit(payload, 'doctor_id', true);
|
||||
toZeroOrOmit(payload, 'pharmacist_id', true);
|
||||
toZeroOrOmit(payload, 'supplier_id', true);
|
||||
break;
|
||||
case 'doctor':
|
||||
toZeroOrOmit(payload, 'pharmacist_id', true);
|
||||
toZeroOrOmit(payload, 'supplier_id', true);
|
||||
if (isEmptyId(payload.doctor_id)) {
|
||||
payload.doctor_id = 0;
|
||||
}
|
||||
break;
|
||||
case 'pharmacist':
|
||||
toZeroOrOmit(payload, 'doctor_id', true);
|
||||
toZeroOrOmit(payload, 'supplier_id', true);
|
||||
if (isEmptyId(payload.pharmacist_id)) {
|
||||
payload.pharmacist_id = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
243
apps/web-antd/src/views/system/admin/_shared/form-schemas.ts
Normal file
243
apps/web-antd/src/views/system/admin/_shared/form-schemas.ts
Normal file
@@ -0,0 +1,243 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
import { useUserStore } from '@vben/stores';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getStoreOption } from '#/views/system/store/api';
|
||||
import { getSupplierOption } from '#/views/system/supplier/api';
|
||||
|
||||
import type { AdminFormType } from './role-meta';
|
||||
import { ROLE_CITY_MANAGER, ROLE_SALESPERSON } from './role-meta';
|
||||
|
||||
const defaultPassword = 'Xk123456@';
|
||||
const defaultAvatar =
|
||||
'https://xiaokang88.oss-cn-hangzhou.aliyuncs.com/xk_upload_20251022/20251022104156946505ca86d97626c08882f31797dbcef49c.png';
|
||||
|
||||
function passwordFields() {
|
||||
return [
|
||||
{
|
||||
fieldName: 'password',
|
||||
label: '密码',
|
||||
component: 'InputPassword',
|
||||
help: '5-18位数字、字母、特殊字符组成。',
|
||||
componentProps: {
|
||||
placeholder: '请输入密码',
|
||||
allowClear: true,
|
||||
},
|
||||
defaultValue: defaultPassword,
|
||||
rules: z
|
||||
.string()
|
||||
.regex(
|
||||
/^(?=.*[A-Z0-9])(?=.*[!@#$%^&*])[A-Z0-9!@#$%^&*]{5,18}$/i,
|
||||
'密码由5-18位数字、字母、特殊字符组成。',
|
||||
),
|
||||
dependencies: {
|
||||
if({ id }: { id?: number }) {
|
||||
return !id;
|
||||
},
|
||||
triggerFields: ['id'],
|
||||
},
|
||||
formItemClass: 'col-span-6',
|
||||
},
|
||||
{
|
||||
fieldName: 'confirmPassword',
|
||||
label: '确认密码',
|
||||
component: 'InputPassword',
|
||||
componentProps: {
|
||||
placeholder: '请输入确认密码',
|
||||
allowClear: true,
|
||||
},
|
||||
defaultValue: defaultPassword,
|
||||
rules: z
|
||||
.string()
|
||||
.regex(/[\w!@#$%^&*]{5,18}/, '密码由5-18位数字、字母、特殊字符组成。'),
|
||||
dependencies: {
|
||||
if({ id }: { id?: number }) {
|
||||
return !id;
|
||||
},
|
||||
triggerFields: ['id', 'confirmPassword'],
|
||||
rules: (values: { password?: string }) => {
|
||||
return z
|
||||
.string()
|
||||
.regex(
|
||||
/[\w!@#$%^&*]{5,18}/,
|
||||
'密码由5-18位数字、字母、特殊字符组成。',
|
||||
)
|
||||
.refine(
|
||||
(confirmPassword) => confirmPassword === values.password,
|
||||
{ message: '确认密码必须与密码一致' },
|
||||
);
|
||||
},
|
||||
},
|
||||
formItemClass: 'col-span-6',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function shouldShowAddress(roleId: number, formType: AdminFormType): boolean {
|
||||
if (formType !== 'address') {
|
||||
return false;
|
||||
}
|
||||
const userStore = useUserStore();
|
||||
const currentRoleId = (userStore.userInfo as { roles?: { id?: number } })
|
||||
?.roles?.id;
|
||||
if (
|
||||
roleId === ROLE_SALESPERSON &&
|
||||
currentRoleId === ROLE_CITY_MANAGER
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function createAdminModalFormProps(
|
||||
roleId: number,
|
||||
formType: AdminFormType,
|
||||
): VbenFormProps {
|
||||
const schema: VbenFormProps['schema'] = [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
formItemClass: 'col-span-6',
|
||||
dependencies: {
|
||||
show: false,
|
||||
triggerFields: ['id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
fieldName: 'role_id',
|
||||
label: '角色ID',
|
||||
defaultValue: roleId,
|
||||
dependencies: {
|
||||
show: false,
|
||||
triggerFields: ['role_id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入管理员昵称',
|
||||
},
|
||||
fieldName: 'nick_name',
|
||||
label: '昵称',
|
||||
rules: 'required',
|
||||
formItemClass: 'col-span-6',
|
||||
},
|
||||
{
|
||||
component: 'Avatar',
|
||||
fieldName: 'avatar',
|
||||
label: '头像',
|
||||
rules: 'required',
|
||||
formItemClass: 'col-span-6',
|
||||
defaultValue: defaultAvatar,
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入管理员手机号码',
|
||||
},
|
||||
fieldName: 'phone',
|
||||
label: '手机号',
|
||||
rules: 'required',
|
||||
formItemClass: 'col-span-6',
|
||||
},
|
||||
];
|
||||
|
||||
if (shouldShowAddress(roleId, formType)) {
|
||||
schema.push({
|
||||
component: 'RegionAddressPicker',
|
||||
fieldName: 'address',
|
||||
label: '省市区',
|
||||
rules: 'required',
|
||||
formItemClass: 'col-span-12',
|
||||
});
|
||||
}
|
||||
|
||||
if (formType === 'supplier') {
|
||||
schema.push({
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
filterOption: true,
|
||||
showSearch: true,
|
||||
afterFetch: (data: { id: number; name: string }[]) => {
|
||||
return data.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
}));
|
||||
},
|
||||
api: getSupplierOption,
|
||||
placeholder: '请选择',
|
||||
},
|
||||
fieldName: 'supplier_id',
|
||||
formItemClass: 'col-span-6',
|
||||
label: '所属供应商',
|
||||
rules: 'required',
|
||||
});
|
||||
}
|
||||
|
||||
if (formType === 'clinic' || formType === 'doctor' || formType === 'pharmacist') {
|
||||
schema.push({
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
filterOption: (input: string, option: { label?: string }) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
showSearch: true,
|
||||
afterFetch: (data: { id: number; name: string }[]) => {
|
||||
return data.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
}));
|
||||
},
|
||||
api: getStoreOption,
|
||||
placeholder: '请选择诊所',
|
||||
},
|
||||
fieldName: 'store_id',
|
||||
formItemClass: 'col-span-6',
|
||||
label: '所属诊所',
|
||||
rules: 'required',
|
||||
});
|
||||
}
|
||||
|
||||
if (formType === 'doctor') {
|
||||
schema.push({
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '关联医生档案 ID(可选,建议在医生管理中创建)',
|
||||
},
|
||||
fieldName: 'doctor_id',
|
||||
label: '医生ID',
|
||||
formItemClass: 'col-span-6',
|
||||
});
|
||||
}
|
||||
|
||||
if (formType === 'pharmacist') {
|
||||
schema.push({
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '关联药师档案 ID(可选)',
|
||||
},
|
||||
fieldName: 'pharmacist_id',
|
||||
label: '药师ID',
|
||||
formItemClass: 'col-span-6',
|
||||
});
|
||||
}
|
||||
|
||||
schema.push(...passwordFields());
|
||||
|
||||
return {
|
||||
wrapperClass: 'grid-cols-12',
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-12',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema,
|
||||
showDefaultActions: false,
|
||||
};
|
||||
}
|
||||
40
apps/web-antd/src/views/system/admin/_shared/role-meta.ts
Normal file
40
apps/web-antd/src/views/system/admin/_shared/role-meta.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export type AdminFormType =
|
||||
| 'basic'
|
||||
| 'address'
|
||||
| 'supplier'
|
||||
| 'clinic'
|
||||
| 'doctor'
|
||||
| 'pharmacist';
|
||||
|
||||
export interface AdminRoleMeta {
|
||||
id: number;
|
||||
title: string;
|
||||
slug: string;
|
||||
formType: AdminFormType;
|
||||
}
|
||||
|
||||
/** 与后端 RoleEnum 一致 */
|
||||
export const ADMIN_ROLE_LIST: AdminRoleMeta[] = [
|
||||
{ id: 1, title: '超级管理员', slug: 'super', formType: 'basic' },
|
||||
{ id: 2, title: '系统管理员', slug: 'platform', formType: 'basic' },
|
||||
{ id: 3, title: '省级管理员', slug: 'province', formType: 'address' },
|
||||
{ id: 4, title: '市级管理员', slug: 'city', formType: 'address' },
|
||||
{ id: 5, title: '区级管理员', slug: 'district', formType: 'address' },
|
||||
{ id: 6, title: '业务员', slug: 'salesperson', formType: 'address' },
|
||||
{ id: 7, title: '供应商', slug: 'supplier', formType: 'supplier' },
|
||||
{ id: 8, title: '诊所管理员', slug: 'clinic', formType: 'clinic' },
|
||||
{ id: 9, title: '诊所员工', slug: 'clinic-staff', formType: 'clinic' },
|
||||
{ id: 10, title: '医生', slug: 'doctor', formType: 'doctor' },
|
||||
{ id: 11, title: '药师', slug: 'pharmacist', formType: 'pharmacist' },
|
||||
];
|
||||
|
||||
export const ROLE_CITY_MANAGER = 4;
|
||||
export const ROLE_SALESPERSON = 6;
|
||||
|
||||
export function getRoleMeta(roleId: number): AdminRoleMeta {
|
||||
const meta = ADMIN_ROLE_LIST.find((r) => r.id === roleId);
|
||||
if (!meta) {
|
||||
throw new Error(`Unknown admin role id: ${roleId}`);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
export function createAdminSearchOptions(): VbenFormProps {
|
||||
return {
|
||||
collapsed: false,
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入名称',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'nick_name',
|
||||
label: '管理员名称',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入手机号码',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'phone',
|
||||
label: '手机号码',
|
||||
},
|
||||
],
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
content: '查询',
|
||||
},
|
||||
submitOnChange: true,
|
||||
submitOnEnter: false,
|
||||
};
|
||||
}
|
||||
137
apps/web-antd/src/views/system/admin/_shared/table-config.ts
Normal file
137
apps/web-antd/src/views/system/admin/_shared/table-config.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getAdminList } from '#/views/system/admin/api';
|
||||
|
||||
import type { AdminFormType } from './role-meta';
|
||||
|
||||
interface RowType {
|
||||
id: string;
|
||||
nick_name: string;
|
||||
email: string;
|
||||
avatar: string;
|
||||
open_id: string;
|
||||
code: string;
|
||||
phone: string;
|
||||
login_account: string;
|
||||
desc: string;
|
||||
created_at: string;
|
||||
store_id?: number;
|
||||
doctor_id?: number;
|
||||
pharmacist_id?: number;
|
||||
province_id?: number;
|
||||
city_id?: number;
|
||||
}
|
||||
|
||||
function buildColumns(formType: AdminFormType) {
|
||||
const cols: VxeGridProps<RowType>['columns'] = [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{ field: 'id', align: 'left', title: 'ID', width: 100 },
|
||||
{ field: 'nick_name', align: 'left', title: '名称' },
|
||||
{
|
||||
field: 'avatar',
|
||||
align: 'left',
|
||||
title: '头像',
|
||||
slots: { default: 'avatar' },
|
||||
width: 130,
|
||||
},
|
||||
{ field: 'open_id', title: 'Open ID' },
|
||||
];
|
||||
|
||||
if (formType === 'address' || formType === 'supplier') {
|
||||
cols.push({ field: 'code', title: '业务推广码' });
|
||||
}
|
||||
|
||||
if (formType === 'address') {
|
||||
cols.push({
|
||||
field: 'region',
|
||||
title: '省市区',
|
||||
minWidth: 180,
|
||||
slots: { default: 'region' },
|
||||
});
|
||||
}
|
||||
|
||||
if (formType === 'supplier') {
|
||||
cols.push({ field: 'supplier.name', title: '所属供应商' });
|
||||
}
|
||||
|
||||
if (formType === 'clinic' || formType === 'doctor' || formType === 'pharmacist') {
|
||||
cols.push({ field: 'store_id', title: '诊所ID', width: 100 });
|
||||
}
|
||||
|
||||
if (formType === 'doctor') {
|
||||
cols.push({ field: 'doctor_id', title: '医生ID', width: 100 });
|
||||
}
|
||||
|
||||
if (formType === 'pharmacist') {
|
||||
cols.push({ field: 'pharmacist_id', title: '药师ID', width: 100 });
|
||||
}
|
||||
|
||||
if (formType === 'basic') {
|
||||
cols.push({ field: 'platform.name', title: '所属平台' });
|
||||
}
|
||||
|
||||
cols.push(
|
||||
{ field: 'phone', title: '手机号码' },
|
||||
{
|
||||
field: 'login_account',
|
||||
align: 'left',
|
||||
title: '登录账号',
|
||||
slots: { default: 'login_account' },
|
||||
width: 150,
|
||||
},
|
||||
{ field: 'email', title: '邮箱' },
|
||||
{ field: 'created_at', title: '注册时间' },
|
||||
{ type: 'html', title: '操作', width: 200, slots: { default: 'action' } },
|
||||
);
|
||||
|
||||
return cols;
|
||||
}
|
||||
|
||||
export function createAdminGridOptions(
|
||||
roleId: number,
|
||||
formType: AdminFormType,
|
||||
): VxeGridProps<RowType> {
|
||||
return {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
labelField: '',
|
||||
},
|
||||
columnConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
rowConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
columns: buildColumns(formType),
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getAdminList({
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
role_id: roleId,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
height: 'auto',
|
||||
border: false,
|
||||
toolbarConfig: {
|
||||
search: true,
|
||||
refresh: true,
|
||||
print: false,
|
||||
export: false,
|
||||
zoom: true,
|
||||
slots: {
|
||||
buttons: 'toolbar-buttons',
|
||||
},
|
||||
custom: {
|
||||
icon: 'vxe-icon-menu',
|
||||
},
|
||||
},
|
||||
showOverflow: false,
|
||||
};
|
||||
}
|
||||
6
apps/web-antd/src/views/system/admin/city/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/city/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="4" />
|
||||
</template>
|
||||
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="9" />
|
||||
</template>
|
||||
6
apps/web-antd/src/views/system/admin/clinic/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/clinic/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="8" />
|
||||
</template>
|
||||
@@ -3,7 +3,6 @@ import type { VbenFormProps } from '#/adapter/form';
|
||||
import { z } from '#/adapter/form';
|
||||
import { getRoleOption } from '#/views/system/role/api';
|
||||
import { getSupplierOption } from '#/views/system/supplier/api';
|
||||
import {addressOption} from "#/util/address";
|
||||
|
||||
const defaultPassword = 'Xk123456@';
|
||||
|
||||
@@ -86,11 +85,7 @@ export const modalFormProps: VbenFormProps = {
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Cascader',
|
||||
componentProps: {
|
||||
placeholder: '请选省市区',
|
||||
options: addressOption,
|
||||
},
|
||||
component: 'RegionAddressPicker',
|
||||
dependencies: {
|
||||
show: (values) => {
|
||||
return values.role_id === pharmacistId || values.role_id === cityId || values.role_id === districtId;
|
||||
|
||||
6
apps/web-antd/src/views/system/admin/district/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/district/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="5" />
|
||||
</template>
|
||||
6
apps/web-antd/src/views/system/admin/doctor/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/doctor/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="10" />
|
||||
</template>
|
||||
@@ -1,197 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
import { onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { ref } from 'vue';
|
||||
const router = useRouter();
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button, Image, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
|
||||
import { deleteAdmin, resetPassword, generateLoginAccount } from './api';
|
||||
import FormModalDemo from './components/modal.vue';
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
|
||||
const gridEvents: VxeGridListeners<any> = {
|
||||
checkboxChange() {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
gridEvents,
|
||||
onMounted(() => {
|
||||
router.replace('/system/admin/platform');
|
||||
});
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: FormModalDemo,
|
||||
});
|
||||
|
||||
const showModal = (data = {}, isUpdate = false) => {
|
||||
formModalApi.setData({
|
||||
// 表单值
|
||||
values: data,
|
||||
update: isUpdate,
|
||||
gridApi,
|
||||
});
|
||||
formModalApi.open();
|
||||
};
|
||||
|
||||
const deleteApi = (row: any) => {
|
||||
let ids = [];
|
||||
if (row) {
|
||||
ids.push(row);
|
||||
} else {
|
||||
ids = gridApi.grid.getCheckboxRecords().map((item) => item.id);
|
||||
}
|
||||
deleteAdmin({ ids }).then(() => {
|
||||
message.success('删除成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
|
||||
const resetPasswordApi = (id: number) => {
|
||||
resetPassword(id).then(() => {
|
||||
message.success('删除成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
|
||||
const generateAccountApi = async (row: any) => {
|
||||
try {
|
||||
const result = await generateLoginAccount(row.id);
|
||||
if (result.login_account) {
|
||||
message.success('生成账号成功');
|
||||
gridApi.query();
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '生成账号失败');
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = async (text: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
message.success('复制成功');
|
||||
} catch (error) {
|
||||
// 降级方案:使用传统方法
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-999999px';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
message.success('复制成功');
|
||||
} catch (err) {
|
||||
message.error('复制失败');
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="管理员管理">
|
||||
<FormModal />
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增',
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
// auth: ['超级管理员', 'sys:user:save'],
|
||||
onClick: showModal.bind(null),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '删除',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
ifShow: hasTopTableDropDownActions,
|
||||
// auth: ['超级管理员', 'sys:user:save'],
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, false),
|
||||
},
|
||||
},
|
||||
]"
|
||||
>
|
||||
<template #more>
|
||||
<Button style="margin-left: 16px">
|
||||
批量操作
|
||||
<Icon icon="ant-design:down-outlined" />
|
||||
</Button>
|
||||
</template>
|
||||
</TableAction>
|
||||
</template>
|
||||
<template #avatar="{ row }">
|
||||
<Image :src="row.avatar" height="30" width="30" />
|
||||
</template>
|
||||
<template #login_account="{ row }">
|
||||
<span v-if="row.login_account">
|
||||
<Button type="link" size="small" @click="copyToClipboard(row.login_account)">
|
||||
{{ row.login_account }}
|
||||
</Button>
|
||||
</span>
|
||||
<Button v-else type="link" size="small" @click="generateAccountApi(row)">
|
||||
生成账号
|
||||
</Button>
|
||||
</template>
|
||||
<template #toolbar-tools></template>
|
||||
<template #action="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
type: 'link',
|
||||
icon: 'uil:edit',
|
||||
size: 'small',
|
||||
// auth: ['admin', 'sys:role:detail'],
|
||||
onClick: showModal.bind(null, row, true),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
size: 'small',
|
||||
// auth: ['admin', 'sys:role:detail'],
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '重置密码',
|
||||
type: 'link',
|
||||
icon: 'bitcoin-icons:refresh-filled',
|
||||
size: 'small',
|
||||
popConfirm: {
|
||||
title: '确定重置密码吗?',
|
||||
confirm: resetPasswordApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
<div />
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="11" />
|
||||
</template>
|
||||
6
apps/web-antd/src/views/system/admin/platform/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/platform/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="2" />
|
||||
</template>
|
||||
6
apps/web-antd/src/views/system/admin/province/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/province/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="3" />
|
||||
</template>
|
||||
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="6" />
|
||||
</template>
|
||||
6
apps/web-antd/src/views/system/admin/super/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/super/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="1" />
|
||||
</template>
|
||||
6
apps/web-antd/src/views/system/admin/supplier/index.vue
Normal file
6
apps/web-antd/src/views/system/admin/supplier/index.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import AdminPage from '../_shared/admin-page.vue';
|
||||
</script>
|
||||
<template>
|
||||
<AdminPage :role-id="7" />
|
||||
</template>
|
||||
Reference in New Issue
Block a user