perf: code style

pull/120/head^2
xingyu4j 2025-05-29 01:51:38 +08:00
parent f6a5ca97a4
commit 5f6581b1c6
5 changed files with 75 additions and 101 deletions

View File

@ -1,19 +1,15 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmClueApi } from '#/api/crm/clue';
import type { DescriptionItemSchema } from '#/components/description'; import type { DescriptionItemSchema } from '#/components/description';
import { h } from 'vue'; import { h } from 'vue';
import { useAccess } from '@vben/access';
import { formatDateTime } from '@vben/utils'; import { formatDateTime } from '@vben/utils';
import { getAreaTree } from '#/api/system/area'; import { getAreaTree } from '#/api/system/area';
import { DictTag } from '#/components/dict-tag'; import { DictTag } from '#/components/dict-tag';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils'; import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@ -164,14 +160,11 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns<T = CrmClueApi.Clue>( export function useGridColumns(): VxeTableGridOptions['columns'] {
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [ return [
{ {
field: 'name', field: 'name',
title: '线索名称', title: '线索名称',
minWidth: 160,
fixed: 'left', fixed: 'left',
slots: { slots: {
default: 'name', default: 'name',
@ -180,7 +173,6 @@ export function useGridColumns<T = CrmClueApi.Clue>(
{ {
field: 'source', field: 'source',
title: '线索来源', title: '线索来源',
minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.CRM_CUSTOMER_SOURCE }, props: { type: DICT_TYPE.CRM_CUSTOMER_SOURCE },
@ -189,27 +181,22 @@ export function useGridColumns<T = CrmClueApi.Clue>(
{ {
field: 'mobile', field: 'mobile',
title: '手机', title: '手机',
minWidth: 120,
}, },
{ {
field: 'telephone', field: 'telephone',
title: '电话', title: '电话',
minWidth: 130,
}, },
{ {
field: 'email', field: 'email',
title: '邮箱', title: '邮箱',
minWidth: 180,
}, },
{ {
field: 'detailAddress', field: 'detailAddress',
title: '地址', title: '地址',
minWidth: 180,
}, },
{ {
field: 'industryId', field: 'industryId',
title: '客户行业', title: '客户行业',
minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.CRM_CUSTOMER_INDUSTRY }, props: { type: DICT_TYPE.CRM_CUSTOMER_INDUSTRY },
@ -218,7 +205,6 @@ export function useGridColumns<T = CrmClueApi.Clue>(
{ {
field: 'level', field: 'level',
title: '客户级别', title: '客户级别',
minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.CRM_CUSTOMER_LEVEL }, props: { type: DICT_TYPE.CRM_CUSTOMER_LEVEL },
@ -227,66 +213,40 @@ export function useGridColumns<T = CrmClueApi.Clue>(
{ {
field: 'ownerUserName', field: 'ownerUserName',
title: '负责人', title: '负责人',
minWidth: 100,
}, },
{ {
field: 'ownerUserDeptName', field: 'ownerUserDeptName',
title: '所属部门', title: '所属部门',
minWidth: 100,
}, },
{ {
field: 'contactNextTime', field: 'contactNextTime',
title: '下次联系时间', title: '下次联系时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'contactLastTime', field: 'contactLastTime',
title: '最后跟进时间', title: '最后跟进时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'updateTime', field: 'updateTime',
title: '更新时间', title: '更新时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'createTime', field: 'createTime',
title: '创建时间', title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'creatorName', field: 'creatorName',
title: '创建人', title: '创建人',
minWidth: 100,
}, },
{ {
field: 'operation',
title: '操作', title: '操作',
width: 130, width: 140,
fixed: 'right', fixed: 'right',
align: 'center', slots: { default: 'actions' },
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '线索',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['crm:clue:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['crm:clue:delete']),
},
],
},
}, },
]; ];
} }

View File

@ -1,19 +1,15 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { import type { VxeTableGridOptions } from '#/adapter/vxe-table';
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { CrmClueApi } from '#/api/crm/clue'; import type { CrmClueApi } from '#/api/crm/clue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
import { Download, Plus } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteClue, exportClue, getCluePage } from '#/api/crm/clue'; import { deleteClue, exportClue, getCluePage } from '#/api/crm/clue';
import { DocAlert } from '#/components/doc-alert'; import { DocAlert } from '#/components/doc-alert';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -33,55 +29,43 @@ function onRefresh() {
gridApi.query(); gridApi.query();
} }
/** 导出表格 */
async function onExport() {
const data = await exportClue(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '线索.xls', source: data });
}
/** 创建线索 */ /** 创建线索 */
function onCreate() { function handleCreate() {
formModalApi.setData(null).open(); formModalApi.setData(null).open();
} }
/** 编辑线索 */ /** 编辑线索 */
function onEdit(row: CrmClueApi.Clue) { function handleEdit(row: CrmClueApi.Clue) {
formModalApi.setData(row).open(); formModalApi.setData(row).open();
} }
/** 删除线索 */ /** 删除线索 */
async function onDelete(row: CrmClueApi.Clue) { async function handleDelete(row: CrmClueApi.Clue) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]), content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0, key: 'action_key_msg',
key: 'action_process_msg',
}); });
try { try {
await deleteClue(row.id as number); await deleteClue(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.name])); message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh(); onRefresh();
} catch { } catch {
hideLoading(); hideLoading();
} }
} }
/** 查看线索详情 */ /** 导出表格 */
function onDetail(row: CrmClueApi.Clue) { async function handleExport() {
push({ name: 'CrmClueDetail', params: { id: row.id } }); const data = await exportClue(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '线索.xls', source: data });
} }
/** 表格操作按钮的回调函数 */ /** 查看线索详情 */
function onActionClick({ code, row }: OnActionClickParams<CrmClueApi.Clue>) { function handleDetail(row: CrmClueApi.Clue) {
switch (code) { push({ name: 'CrmClueDetail', params: { id: row.id } });
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
} }
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
@ -89,7 +73,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
schema: useGridFormSchema(), schema: useGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(onActionClick), columns: useGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@ -130,29 +114,54 @@ const [Grid, gridApi] = useVbenVxeGrid({
<FormModal @success="onRefresh" /> <FormModal @success="onRefresh" />
<Grid table-title="线"> <Grid table-title="线">
<template #toolbar-tools> <template #toolbar-tools>
<Button <TableAction
type="primary" :actions="[
@click="onCreate" {
v-access:code="['crm:clue:create']" label: $t('ui.actionTitle.create', ['线索']),
> type: 'primary',
<Plus class="size-5" /> icon: ACTION_ICON.ADD,
{{ $t('ui.actionTitle.create', ['线索']) }} auth: ['crm:clue:create'],
</Button> onClick: handleCreate,
<Button },
type="primary" {
class="ml-2" label: $t('ui.actionTitle.export'),
@click="onExport" type: 'primary',
v-access:code="['crm:clue:export']" icon: ACTION_ICON.DOWNLOAD,
> auth: ['crm:clue:export'],
<Download class="size-5" /> onClick: handleExport,
{{ $t('ui.actionTitle.export') }} },
</Button> ]"
/>
</template> </template>
<template #name="{ row }"> <template #name="{ row }">
<Button type="link" @click="onDetail(row)"> <Button type="link" @click="handleDetail(row)">
{{ row.name }} {{ row.name }}
</Button> </Button>
</template> </template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['crm:clue:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['crm:clue:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid> </Grid>
</Page> </Page>
</template> </template>

View File

@ -9,6 +9,7 @@ import { useAccess } from '@vben/access';
import { formatDateTime } from '@vben/utils'; import { formatDateTime } from '@vben/utils';
import { getAreaTree } from '#/api/system/area'; import { getAreaTree } from '#/api/system/area';
import { getSimpleUserList } from '#/api/system/user';
import { DictTag } from '#/components/dict-tag'; import { DictTag } from '#/components/dict-tag';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils'; import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
@ -48,9 +49,13 @@ export function useFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'ownerUserId', fieldName: 'ownerUserId',
label: '负责人', label: '负责人',
component: 'Select', component: 'ApiSelect',
componentProps: { componentProps: {
api: 'getSimpleUserList', api: () => getSimpleUserList(),
fieldNames: {
label: 'nickname',
value: 'id',
},
}, },
rules: 'required', rules: 'required',
}, },

View File

@ -147,7 +147,7 @@ function onChangeSceneType(key: number | string) {
<FormModal @success="onRefresh" /> <FormModal @success="onRefresh" />
<Grid> <Grid>
<template #toolbar-actions> <template #top>
<Tabs class="border-none" @change="onChangeSceneType"> <Tabs class="border-none" @change="onChangeSceneType">
<Tabs.TabPane tab="我负责的" key="1" /> <Tabs.TabPane tab="我负责的" key="1" />
<Tabs.TabPane tab="我参与的" key="2" /> <Tabs.TabPane tab="我参与的" key="2" />

View File

@ -29,9 +29,9 @@ const [Form, formApi] = useVbenForm({
componentProps: { componentProps: {
class: 'w-full', class: 'w-full',
}, },
formItemClass: 'col-span-2',
labelWidth: 120,
}, },
// 2
wrapperClass: 'grid-cols-2',
layout: 'horizontal', layout: 'horizontal',
schema: useFormSchema(), schema: useFormSchema(),
showDefaultActions: false, showDefaultActions: false,