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 { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form'; import { useVbenForm } from '#/adapter/form';
import { import { createPermission, updatePermission } from '#/api/crm/permission';
BizTypeEnum,
createPermission,
PermissionLevelEnum,
updatePermission,
} from '#/api/crm/permission';
import { getSimpleUserList } from '#/api/system/user';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions } from '#/utils';
import { useFormSchema } from './data';
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
const formData = ref<CrmPermissionApi.Permission>(); const formData = ref<CrmPermissionApi.Permission>();
@ -35,74 +30,7 @@ const [Form, formApi] = useVbenForm({
labelWidth: 80, labelWidth: 80,
}, },
layout: 'horizontal', layout: 'horizontal',
schema: [ schema: useFormSchema(),
{
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
);
},
},
},
],
showDefaultActions: false, showDefaultActions: false,
}); });
@ -114,8 +42,7 @@ const [Modal, modalApi] = useVbenModal({
} }
modalApi.lock(); modalApi.lock();
// //
let data = (await formApi.getValues()) as CrmPermissionApi.Permission; const data = (await formApi.getValues()) as CrmPermissionApi.Permission;
data = Object.assign(data, formData.value);
try { try {
await (formData.value?.ids await (formData.value?.ids
? updatePermission(data) ? updatePermission(data)
@ -141,7 +68,7 @@ const [Modal, modalApi] = useVbenModal({
modalApi.lock(); modalApi.lock();
try { try {
formData.value = { formData.value = {
ids: data.ids || [data.id] || undefined, ids: data.ids ?? (data.id ? [data.id] : undefined),
userId: undefined, userId: undefined,
bizType: data.bizType, bizType: data.bizType,
bizId: data.bizId, bizId: data.bizId,

View File

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

View File

@ -13,10 +13,10 @@ import { transferClue } from '#/api/crm/clue';
import { transferContact } from '#/api/crm/contact'; import { transferContact } from '#/api/crm/contact';
import { transferContract } from '#/api/crm/contract'; import { transferContract } from '#/api/crm/contract';
import { transferCustomer } from '#/api/crm/customer'; import { transferCustomer } from '#/api/crm/customer';
import { BizTypeEnum, PermissionLevelEnum } from '#/api/crm/permission'; import { BizTypeEnum } from '#/api/crm/permission';
import { getSimpleUserList } from '#/api/system/user';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { DICT_TYPE, getDictOptions } from '#/utils';
import { useTransferFormSchema } from './data';
defineOptions({ name: 'CrmTransferForm' }); defineOptions({ name: 'CrmTransferForm' });
@ -56,87 +56,7 @@ const [Form, formApi] = useVbenForm({
labelWidth: 120, labelWidth: 120,
}, },
layout: 'horizontal', layout: 'horizontal',
schema: [ schema: useTransferFormSchema(),
{
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,
},
],
},
},
],
showDefaultActions: false, showDefaultActions: false,
}); });