feat: member user
parent
564fd5b64c
commit
868c0f822f
|
@ -0,0 +1,267 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { Tag } from 'ant-design-vue';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getSimpleGroupList } from '#/api/member/group';
|
||||
import { getSimpleLevelList } from '#/api/member/level';
|
||||
import { getSimpleTagList } from '#/api/member/tag';
|
||||
import { getAreaTree } from '#/api/system/area';
|
||||
import {
|
||||
CommonStatusEnum,
|
||||
DICT_TYPE,
|
||||
getDictOptions,
|
||||
getRangePickerDefaultProps,
|
||||
} from '#/utils';
|
||||
|
||||
/** 修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'mobile',
|
||||
label: '手机号',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE).optional(),
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'nickname',
|
||||
label: '用户昵称',
|
||||
},
|
||||
{
|
||||
component: 'ImageUpload',
|
||||
fieldName: 'avatar',
|
||||
label: '头像',
|
||||
componentProps: {
|
||||
maxSize: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '真实名字',
|
||||
},
|
||||
{
|
||||
fieldName: 'sex',
|
||||
label: '用户性别',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
fieldName: 'birthday',
|
||||
label: '出生日期',
|
||||
componentProps: {
|
||||
format: 'YYYY-MM-DD',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'ApiTreeSelect',
|
||||
fieldName: 'areaId',
|
||||
label: '所在地',
|
||||
componentProps: {
|
||||
api: () => getAreaTree(),
|
||||
fieldNames: { label: 'name', value: 'id', children: 'children' },
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
fieldName: 'tagIds',
|
||||
label: '用户标签',
|
||||
componentProps: {
|
||||
api: () => getSimpleTagList(),
|
||||
fieldNames: { label: 'name', value: 'id' },
|
||||
mode: 'multiple',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
fieldName: 'groupId',
|
||||
label: '用户分组',
|
||||
componentProps: {
|
||||
api: () => getSimpleGroupList(),
|
||||
fieldNames: { label: 'name', value: 'id' },
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
fieldName: 'mark',
|
||||
label: '会员备注',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '用户昵称',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'mobile',
|
||||
label: '手机号',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'loginDate',
|
||||
label: '登录时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '注册时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'tagIds',
|
||||
label: '用户标签',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: () => getSimpleTagList(),
|
||||
fieldNames: { label: 'name', value: 'id' },
|
||||
mode: 'multiple',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'levelId',
|
||||
label: '用户等级',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: () => getSimpleLevelList(),
|
||||
fieldNames: { label: 'name', value: 'id' },
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'groupId',
|
||||
label: '用户分组',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: () => getSimpleGroupList(),
|
||||
fieldNames: { label: 'name', value: 'id' },
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
field: 'id',
|
||||
title: '用户编号',
|
||||
},
|
||||
{
|
||||
field: 'avatar',
|
||||
title: '头像',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
return h('img', {
|
||||
src: row.avatar,
|
||||
style: { width: '40px' },
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'mobile',
|
||||
title: '手机号',
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '昵称',
|
||||
},
|
||||
{
|
||||
field: 'levelName',
|
||||
title: '等级',
|
||||
},
|
||||
{
|
||||
field: 'groupName',
|
||||
title: '分组',
|
||||
},
|
||||
{
|
||||
field: 'tagNames',
|
||||
title: '用户标签',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
return row.tagNames?.map((tagName: string, index: number) => {
|
||||
return h(
|
||||
Tag,
|
||||
{
|
||||
key: index,
|
||||
class: 'mr-5px',
|
||||
color: 'blue',
|
||||
},
|
||||
() => tagName,
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'point',
|
||||
title: '积分',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'loginDate',
|
||||
title: '登录时间',
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '注册时间',
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 200,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
|
@ -1,34 +1,170 @@
|
|||
<script lang="ts" setup>
|
||||
import { Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MemberUserApi } from '#/api/member/user';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getUserPage } from '#/api/member/user';
|
||||
import { DocAlert } from '#/components/doc-alert';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格数据 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 设置选中 ID */
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function setCheckedIds({ records }: { records: MemberUserApi.User[] }) {
|
||||
checkedIds.value = records.map((item) => item.id as number);
|
||||
}
|
||||
|
||||
/** 发送优惠券 */
|
||||
function handleSendCoupon() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑会员 */
|
||||
function handleEdit(row: MemberUserApi.User) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 修改会员等级 */
|
||||
function handleUpdateLevel(row: MemberUserApi.User) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 修改会员积分 */
|
||||
function handleUpdatePoint(row: MemberUserApi.User) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 修改会员余额 */
|
||||
function handleUpdateBalance(row: MemberUserApi.User) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 查看会员详情 */
|
||||
function handleViewDetail(row: MemberUserApi.User) {
|
||||
router.push({ name: 'MemberUserDetail', params: { id: row.id } });
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
labelField: 'checkbox',
|
||||
},
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getUserPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MemberUserApi.User>,
|
||||
gridEvents: {
|
||||
checkboxAll: setCheckedIds,
|
||||
checkboxChange: setCheckedIds,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="会员用户、标签、分组"
|
||||
url="https://doc.iocoder.cn/member/user/"
|
||||
/>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/member/user/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/member/user/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<FormModal @success="onRefresh" />
|
||||
<Grid table-title="会员列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '发送优惠券',
|
||||
type: 'primary',
|
||||
icon: 'lucide:mouse-pointer-2',
|
||||
auth: ['promotion:coupon:send'],
|
||||
onClick: handleSendCoupon,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
onClick: handleViewDetail.bind(null, row),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
auth: ['member:user:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '修改等级',
|
||||
type: 'link',
|
||||
auth: ['member:user:update-level'],
|
||||
onClick: handleUpdateLevel.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '修改积分',
|
||||
type: 'link',
|
||||
auth: ['member:user:update-point'],
|
||||
onClick: handleUpdatePoint.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '修改余额',
|
||||
type: 'link',
|
||||
auth: ['pay:wallet:update-balance'],
|
||||
onClick: handleUpdateBalance.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MemberUserApi } from '#/api/member/user';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { getUser, updateUser } from '#/api/member/user';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<MemberUserApi.User>();
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MemberUserApi.User;
|
||||
try {
|
||||
await updateUser(data);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<MemberUserApi.User>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getUser(data.id as number);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-[600px]" :title="$t('ui.actionTitle.edit', ['会员'])">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
Loading…
Reference in New Issue