feat: crm permission

pull/127/MERGE
xingyu4j 2025-06-04 14:20:19 +08:00
parent b6075a6611
commit 6cede50dcc
4 changed files with 255 additions and 207 deletions

View File

@ -0,0 +1,231 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { BizTypeEnum, PermissionLevelEnum } from '#/api/crm/permission';
import { getSimpleUserList } from '#/api/system/user';
import { DICT_TYPE, getDictOptions } from '#/utils';
/** 新增/修改的表单 */
export function useTransferFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'ownerUserId',
label: '选择新负责人',
component: 'ApiSelect',
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
},
rules: 'required',
},
{
fieldName: 'oldOwnerHandler',
label: '老负责人',
component: 'RadioGroup',
componentProps: {
options: [
{
label: '加入团队',
value: true,
},
{
label: '移除',
value: false,
},
],
},
rules: 'required',
},
{
fieldName: 'oldOwnerPermissionLevel',
label: '老负责人权限级别',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(
DICT_TYPE.CRM_PERMISSION_LEVEL,
'number',
).filter((dict) => dict.value !== PermissionLevelEnum.OWNER),
},
dependencies: {
triggerFields: ['oldOwnerHandler'],
show: (values) => values.oldOwnerHandler,
trigger(values) {
if (!values.oldOwnerHandler) {
values.oldOwnerPermissionLevel = undefined;
}
},
},
rules: 'required',
},
{
fieldName: 'toBizTypes',
label: '同时转移',
component: 'CheckboxGroup',
componentProps: {
options: [
{
label: '联系人',
value: BizTypeEnum.CRM_CONTACT,
},
{
label: '商机',
value: BizTypeEnum.CRM_BUSINESS,
},
{
label: '合同',
value: BizTypeEnum.CRM_CONTRACT,
},
],
},
},
];
}
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'bizId',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'ids',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'userId',
label: '选择人员',
component: 'ApiSelect',
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
},
dependencies: {
triggerFields: ['ids'],
show: (values) => {
return values.ids === undefined;
},
},
},
{
fieldName: 'level',
label: '权限级别',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(
DICT_TYPE.CRM_PERMISSION_LEVEL,
'number',
).filter((dict) => dict.value !== PermissionLevelEnum.OWNER),
},
rules: 'required',
},
{
fieldName: 'bizType',
label: 'Crm 类型',
component: 'RadioGroup',
componentProps: {
options: [
{
label: '联系人',
value: BizTypeEnum.CRM_CONTACT,
},
{
label: '商机',
value: BizTypeEnum.CRM_BUSINESS,
},
{
label: '合同',
value: BizTypeEnum.CRM_CONTRACT,
},
],
},
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'toBizTypes',
label: '同时添加至',
component: 'CheckboxGroup',
componentProps: {
options: [
{
label: '联系人',
value: BizTypeEnum.CRM_CONTACT,
},
{
label: '商机',
value: BizTypeEnum.CRM_BUSINESS,
},
{
label: '合同',
value: BizTypeEnum.CRM_CONTRACT,
},
],
},
dependencies: {
triggerFields: ['ids', 'bizType'],
show: (values) => {
return (
values.ids === undefined &&
values.bizType === BizTypeEnum.CRM_CUSTOMER
);
},
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 50,
},
{
field: 'nickname',
title: '姓名',
},
{
field: 'deptName',
title: '部门',
},
{
field: 'postNames',
title: '岗位',
},
{
field: 'level',
title: '权限级别',
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_PERMISSION_LEVEL },
},
},
{
field: 'createTime',
title: '加入时间',
formatter: 'formatDateTime',
},
];
}

View File

@ -8,15 +8,10 @@ import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
BizTypeEnum,
createPermission,
PermissionLevelEnum,
updatePermission,
} from '#/api/crm/permission';
import { getSimpleUserList } from '#/api/system/user';
import { createPermission, updatePermission } from '#/api/crm/permission';
import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions } from '#/utils';
import { useFormSchema } from './data';
const emit = defineEmits(['success']);
const formData = ref<CrmPermissionApi.Permission>();
@ -35,74 +30,7 @@ const [Form, formApi] = useVbenForm({
labelWidth: 80,
},
layout: 'horizontal',
schema: [
{
fieldName: 'ids',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'userId',
label: '选择人员',
component: 'ApiSelect',
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
},
dependencies: {
triggerFields: ['ids'],
show: (values) => {
return values.ids === undefined;
},
},
},
{
fieldName: 'level',
label: '权限级别',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(
DICT_TYPE.CRM_PERMISSION_LEVEL,
'number',
).filter((dict) => dict.value !== PermissionLevelEnum.OWNER),
},
rules: 'required',
},
{
fieldName: 'toBizTypes',
label: '同时添加至',
component: 'CheckboxGroup',
componentProps: {
options: [
{
label: '联系人',
value: BizTypeEnum.CRM_CONTACT,
},
{
label: '商机',
value: BizTypeEnum.CRM_BUSINESS,
},
{
label: '合同',
value: BizTypeEnum.CRM_CONTRACT,
},
],
},
dependencies: {
triggerFields: ['ids', 'bizType'],
show: (values) => {
return (
values.ids === undefined &&
formData.value?.bizType === BizTypeEnum.CRM_CUSTOMER
);
},
},
},
],
schema: useFormSchema(),
showDefaultActions: false,
});
@ -114,8 +42,7 @@ const [Modal, modalApi] = useVbenModal({
}
modalApi.lock();
//
let data = (await formApi.getValues()) as CrmPermissionApi.Permission;
data = Object.assign(data, formData.value);
const data = (await formApi.getValues()) as CrmPermissionApi.Permission;
try {
await (formData.value?.ids
? updatePermission(data)
@ -141,7 +68,7 @@ const [Modal, modalApi] = useVbenModal({
modalApi.lock();
try {
formData.value = {
ids: data.ids || [data.id] || undefined,
ids: data.ids ?? (data.id ? [data.id] : undefined),
userId: undefined,
bizType: data.bizType,
bizId: data.bizId,

View File

@ -17,8 +17,8 @@ import {
PermissionLevelEnum,
} from '#/api/crm/permission';
import { $t } from '#/locales';
import { DICT_TYPE } from '#/utils';
import { useGridColumns } from './data';
import Form from './permission-form.vue';
defineOptions({ name: 'CrmPermissionList' });
@ -50,13 +50,13 @@ function onRefresh() {
gridApi.query();
}
const checkedIds = ref<CrmPermissionApi.Permission[]>([]);
function setCheckedIds({
const checkedRows = ref<CrmPermissionApi.Permission[]>([]);
function setCheckedRows({
records,
}: {
records: CrmPermissionApi.Permission[];
}) {
checkedIds.value = records;
checkedRows.value = records;
}
function handleCreate() {
@ -69,11 +69,11 @@ function handleCreate() {
}
function handleEdit() {
if (checkedIds.value.length === 0) {
if (checkedRows.value.length === 0) {
message.error('请先选择团队成员后操作!');
return;
}
if (checkedIds.value.length > 1) {
if (checkedRows.value.length > 1) {
message.error('只能选择一个团队成员进行编辑!');
return;
}
@ -81,25 +81,25 @@ function handleEdit() {
.setData({
bizType: props.bizType,
bizId: props.bizId,
id: checkedIds.value[0]?.id,
level: checkedIds.value[0]?.level,
id: checkedRows.value[0]?.id,
level: checkedRows.value[0]?.level,
})
.open();
}
function handleDelete() {
if (checkedIds.value.length === 0) {
if (checkedRows.value.length === 0) {
message.error('请先选择团队成员后操作!');
return;
}
return new Promise((resolve, reject) => {
confirm({
content: `你要将${checkedIds.value.map((item) => item.nickname).join(',')}移出团队吗?`,
content: `你要将${checkedRows.value.map((item) => item.nickname).join(',')}移出团队吗?`,
})
.then(async () => {
//
const res = await deletePermissionBatch(
checkedIds.value.map((item) => item.id as number),
checkedRows.value.map((item) => item.id as number),
);
if (res) {
//
@ -144,37 +144,7 @@ async function handleQuit() {
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: [
{
type: 'checkbox',
width: 50,
},
{
field: 'nickname',
title: '姓名',
},
{
field: 'deptName',
title: '部门',
},
{
field: 'postNames',
title: '岗位',
},
{
field: 'level',
title: '权限级别',
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_PERMISSION_LEVEL },
},
},
{
field: 'createTime',
title: '加入时间',
formatter: 'formatDateTime',
},
],
columns: useGridColumns(),
height: 'auto',
pagerConfig: {
enabled: false,
@ -201,8 +171,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
} as VxeTableGridOptions<CrmPermissionApi.Permission>,
gridEvents: {
checkboxAll: setCheckedIds,
checkboxChange: setCheckedIds,
checkboxAll: setCheckedRows,
checkboxChange: setCheckedRows,
},
});

View File

@ -13,10 +13,10 @@ import { transferClue } from '#/api/crm/clue';
import { transferContact } from '#/api/crm/contact';
import { transferContract } from '#/api/crm/contract';
import { transferCustomer } from '#/api/crm/customer';
import { BizTypeEnum, PermissionLevelEnum } from '#/api/crm/permission';
import { getSimpleUserList } from '#/api/system/user';
import { BizTypeEnum } from '#/api/crm/permission';
import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions } from '#/utils';
import { useTransferFormSchema } from './data';
defineOptions({ name: 'CrmTransferForm' });
@ -56,87 +56,7 @@ const [Form, formApi] = useVbenForm({
labelWidth: 120,
},
layout: 'horizontal',
schema: [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'ownerUserId',
label: '选择新负责人',
component: 'ApiSelect',
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
},
rules: 'required',
},
{
fieldName: 'oldOwnerHandler',
label: '老负责人',
component: 'RadioGroup',
componentProps: {
options: [
{
label: '加入团队',
value: true,
},
{
label: '移除',
value: false,
},
],
},
rules: 'required',
},
{
fieldName: 'oldOwnerPermissionLevel',
label: '老负责人权限级别',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(
DICT_TYPE.CRM_PERMISSION_LEVEL,
'number',
).filter((dict) => dict.value !== PermissionLevelEnum.OWNER),
},
dependencies: {
triggerFields: ['oldOwnerHandler'],
show: (values) => values.oldOwnerHandler,
trigger(values) {
if (!values.oldOwnerHandler) {
formApi.setFieldValue('oldOwnerPermissionLevel', undefined);
}
},
},
rules: 'required',
},
{
fieldName: 'toBizTypes',
label: '同时转移',
component: 'CheckboxGroup',
componentProps: {
options: [
{
label: '联系人',
value: BizTypeEnum.CRM_CONTACT,
},
{
label: '商机',
value: BizTypeEnum.CRM_BUSINESS,
},
{
label: '合同',
value: BizTypeEnum.CRM_CONTRACT,
},
],
},
},
],
schema: useTransferFormSchema(),
showDefaultActions: false,
});