feat(mes/qc): 迁移质检指标管理

pull/350/head
YunaiV 2026-05-29 00:38:14 +08:00
parent 0ec301cfb3
commit 16d6ab0722
12 changed files with 1786 additions and 0 deletions

View File

@ -0,0 +1,2 @@
export { default as QcIndicatorSelectDialog } from './qc-indicator-select-dialog.vue';
export { default as QcIndicatorSelect } from './qc-indicator-select.vue';

View File

@ -0,0 +1,201 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { nextTick, ref } from 'vue';
import { Button, message, Modal } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getIndicatorPage } from '#/api/mes/qc/indicator';
import { useSelectGridColumns, useSelectGridFormSchema } from '../data';
const emit = defineEmits<{
selected: [rows: MesQcIndicatorApi.Indicator[]];
}>();
const open = ref(false); //
const multiple = ref(true); //
const selectedRows = ref<MesQcIndicatorApi.Indicator[]>([]); //
const preSelectedIds = ref<number[]>([]); //
/** 获取多选记录,包含 VXE reserve 跨页记录 */
function getMultipleSelectedRows() {
const selectedMap = new Map<number, MesQcIndicatorApi.Indicator>();
const records = [
...(gridApi.grid.getCheckboxReserveRecords?.() ?? []),
...(gridApi.grid.getCheckboxRecords?.() ?? []),
] as MesQcIndicatorApi.Indicator[];
records.forEach((row) => {
if (row.id != null) {
selectedMap.set(row.id, row);
}
});
return [...selectedMap.values()];
}
/** 处理勾选变化 */
function handleCheckboxSelectChange() {
selectedRows.value = getMultipleSelectedRows();
}
/** 处理单选变化 */
function handleRadioChange(row: MesQcIndicatorApi.Indicator) {
selectedRows.value = [row];
}
/** 多选模式下切换行勾选 */
async function toggleMultipleRow(row: MesQcIndicatorApi.Indicator) {
const selected = gridApi.grid.isCheckedByCheckboxRow(row);
await gridApi.grid.setCheckboxRow(row, !selected);
selectedRows.value = getMultipleSelectedRows();
}
/** 处理行双击 */
async function handleCellDblclick({
row,
}: {
row: MesQcIndicatorApi.Indicator;
}) {
if (multiple.value) {
await toggleMultipleRow(row);
return;
}
selectedRows.value = [row];
await gridApi.grid.setRadioRow(row);
handleConfirm();
}
/** 回显预选指标 */
async function applyPreSelection() {
if (preSelectedIds.value.length === 0) {
return;
}
const rows = gridApi.grid.getData() as MesQcIndicatorApi.Indicator[];
for (const row of rows) {
if (row.id == null || !preSelectedIds.value.includes(row.id)) {
continue;
}
if (multiple.value) {
await gridApi.grid.setCheckboxRow(row, true);
} else {
await gridApi.grid.setRadioRow(row);
selectedRows.value = [row];
return;
}
}
if (multiple.value) {
selectedRows.value = getMultipleSelectedRows();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useSelectGridFormSchema(),
},
gridOptions: {
columns: useSelectGridColumns(true),
height: 520,
keepSource: true,
checkboxConfig: {
highlight: true,
range: true,
reserve: true,
},
radioConfig: {
highlight: true,
trigger: 'row',
},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getIndicatorPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<MesQcIndicatorApi.Indicator>,
gridEvents: {
cellDblclick: handleCellDblclick,
checkboxAll: handleCheckboxSelectChange,
checkboxChange: handleCheckboxSelectChange,
radioChange: ({ row }: { row: MesQcIndicatorApi.Indicator }) => {
handleRadioChange(row);
},
},
});
/** 重置查询和选择状态 */
async function resetQueryState() {
selectedRows.value = [];
await gridApi.grid.clearCheckboxRow();
await gridApi.grid.clearCheckboxReserve();
await gridApi.grid.clearRadioRow();
await gridApi.formApi.resetForm();
}
/** 打开质检指标选择弹窗 */
async function openModal(
selectedIds?: number[],
options?: { multiple?: boolean },
) {
open.value = true;
multiple.value = options?.multiple ?? true;
preSelectedIds.value = selectedIds || [];
await nextTick();
gridApi.setGridOptions({
columns: useSelectGridColumns(multiple.value),
});
await resetQueryState();
await gridApi.query();
await nextTick();
await applyPreSelection();
}
/** 关闭弹窗 */
function closeModal() {
open.value = false;
}
/** 确认选择 */
function handleConfirm() {
const rows = multiple.value ? getMultipleSelectedRows() : selectedRows.value;
if (rows.length === 0) {
message.warning(multiple.value ? '请至少选择一条数据' : '请选择一条数据');
return;
}
emit('selected', multiple.value ? rows : [rows[0]!]);
open.value = false;
}
defineExpose({ open: openModal });
</script>
<template>
<Modal
v-model:open="open"
:destroy-on-close="true"
title="质检指标选择"
width="70%"
@cancel="closeModal"
@ok="handleConfirm"
>
<Grid table-title="" />
<template #footer>
<Button @click="closeModal"> </Button>
<Button type="primary" @click="handleConfirm"> </Button>
</template>
</Modal>
</template>

View File

@ -0,0 +1,134 @@
<script lang="ts" setup>
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { computed, ref, useAttrs, watch } from 'vue';
import { IconifyIcon } from '@vben/icons';
import { Input, Tooltip } from 'ant-design-vue';
import { getIndicator } from '#/api/mes/qc/indicator';
import QcIndicatorSelectDialog from './qc-indicator-select-dialog.vue';
defineOptions({ name: 'QcIndicatorSelect', inheritAttrs: false });
const props = withDefaults(
defineProps<{
allowClear?: boolean;
disabled?: boolean;
modelValue?: number;
placeholder?: string;
}>(),
{
allowClear: true,
disabled: false,
modelValue: undefined,
placeholder: '请选择质检指标',
},
);
const emit = defineEmits<{
change: [item: MesQcIndicatorApi.Indicator | undefined];
'update:modelValue': [value: number | undefined];
}>();
const attrs = useAttrs(); //
const dialogRef = ref<InstanceType<typeof QcIndicatorSelectDialog>>(); //
const hovering = ref(false); //
const selectedItem = ref<MesQcIndicatorApi.Indicator>(); //
const displayLabel = computed(() => selectedItem.value?.name ?? ''); //
const showClear = computed(() => //
props.allowClear &&
!props.disabled &&
hovering.value &&
props.modelValue != null,
);
/** 根据 ID 单条查询指标信息(用于编辑回显) */
async function resolveItemById(id: number | undefined) {
if (id == null) {
selectedItem.value = undefined;
return;
}
if (selectedItem.value?.id === id) {
return;
}
try {
selectedItem.value = await getIndicator(id);
} catch (error) {
console.error('[QcIndicatorSelect] resolveItemById failed:', error);
}
}
watch(() => props.modelValue, resolveItemById, { immediate: true });
/** 清空已选指标 */
function clearSelected() {
selectedItem.value = undefined;
emit('update:modelValue', undefined);
emit('change', undefined);
}
/** 打开质检指标选择弹窗 */
function handleClick(event: MouseEvent) {
if (props.disabled) {
return;
}
const target = event.target as HTMLElement;
if (showClear.value && target.closest('.ant-input-suffix')) {
event.stopPropagation();
clearSelected();
return;
}
const selectedIds = props.modelValue == null ? [] : [props.modelValue];
dialogRef.value?.open(selectedIds, { multiple: false });
}
/** 弹窗选中回调 */
function handleSelected(rows: MesQcIndicatorApi.Indicator[]) {
const item = rows[0];
if (!item) {
return;
}
selectedItem.value = item;
emit('update:modelValue', item.id);
emit('change', item);
}
</script>
<template>
<div
v-bind="attrs"
class="w-full"
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
@click="handleClick"
@mouseenter="hovering = true"
@mouseleave="hovering = false"
>
<Tooltip :mouse-enter-delay="0.5" :open="selectedItem ? undefined : false">
<template #title>
<div v-if="selectedItem" class="leading-6">
<div>编码{{ selectedItem.code || '-' }}</div>
<div>名称{{ selectedItem.name || '-' }}</div>
<div>检测工具{{ selectedItem.tool || '-' }}</div>
</div>
</template>
<Input
:disabled="disabled"
:placeholder="placeholder"
:value="displayLabel"
readonly
>
<template #suffix>
<IconifyIcon
class="size-4"
:icon="showClear ? 'lucide:circle-x' : 'lucide:search'"
/>
</template>
</Input>
</Tooltip>
</div>
<QcIndicatorSelectDialog ref="dialogRef" @selected="handleSelected" />
</template>

View File

@ -0,0 +1,315 @@
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { h } from 'vue';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { Button } from 'ant-design-vue';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { getSimpleDictTypeList } from '#/api/system/dict/type';
import {
MesAutoCodeRuleCode,
MesQcResultValueType,
} from '#/views/mes/utils/constants';
/** 新增/修改的表单 */
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'code',
label: '检测项编码',
component: 'Input',
componentProps: {
maxlength: 64,
placeholder: '请输入检测项编码',
},
rules: 'required',
suffix: () =>
h(
Button,
{
type: 'default',
onClick: async () => {
try {
const code = await generateAutoCode(
MesAutoCodeRuleCode.QC_INDICATOR_CODE,
);
await formApi?.setFieldValue('code', code);
} catch (error) {
console.error(error);
}
},
},
{ default: () => '自动生成' },
),
},
{
fieldName: 'name',
label: '检测项名称',
component: 'Input',
componentProps: {
maxlength: 100,
placeholder: '请输入检测项名称',
},
rules: 'required',
},
{
fieldName: 'type',
label: '检测项类型',
component: 'Select',
componentProps: {
allowClear: true,
options: getDictOptions(DICT_TYPE.MES_INDICATOR_TYPE, 'number'),
placeholder: '请选择检测项类型',
},
rules: 'required',
},
{
fieldName: 'tool',
label: '检测工具',
component: 'Input',
componentProps: {
maxlength: 100,
placeholder: '请输入检测工具',
},
},
{
fieldName: 'resultType',
label: '结果值类型',
component: 'Select',
componentProps: {
allowClear: true,
// 结果值类型变化时清空结果值属性
onChange: () =>
formApi?.setFieldValue('resultSpecification', undefined),
options: getDictOptions(DICT_TYPE.MES_QC_RESULT_TYPE, 'number'),
placeholder: '请选择结果值类型',
},
rules: 'required',
},
{
fieldName: 'resultSpecification',
label: '文件类型',
component: 'RadioGroup',
componentProps: {
options: [
{ label: '图片/照片', value: 'IMG' },
{ label: '文件', value: 'FILE' },
],
},
dependencies: {
triggerFields: ['resultType'],
show: (values) => values.resultType === MesQcResultValueType.FILE,
},
rules: 'required',
},
{
fieldName: 'resultSpecification',
label: '字典类型',
component: 'ApiSelect',
componentProps: {
allowClear: true,
api: getSimpleDictTypeList,
filterOption: (input: string, option: any) =>
(option.label as string).toLowerCase().includes(input.toLowerCase()),
labelField: 'name',
placeholder: '请选择字典类型',
showSearch: true,
valueField: 'type',
},
dependencies: {
triggerFields: ['resultType'],
show: (values) => values.resultType === MesQcResultValueType.DICT,
},
rules: 'required',
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
maxlength: 250,
placeholder: '请输入备注',
rows: 3,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'code',
label: '检测项编码',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入检测项编码',
},
},
{
fieldName: 'name',
label: '检测项名称',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入检测项名称',
},
},
{
fieldName: 'type',
label: '检测项类型',
component: 'Select',
componentProps: {
allowClear: true,
options: getDictOptions(DICT_TYPE.MES_INDICATOR_TYPE, 'number'),
placeholder: '请选择检测项类型',
},
},
{
fieldName: 'resultType',
label: '结果值类型',
component: 'Select',
componentProps: {
allowClear: true,
options: getDictOptions(DICT_TYPE.MES_QC_RESULT_TYPE, 'number'),
placeholder: '请选择结果值类型',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<MesQcIndicatorApi.Indicator>['columns'] {
return [
{
field: 'code',
title: '检测项编码',
width: 140,
},
{
field: 'name',
title: '检测项名称',
minWidth: 160,
},
{
field: 'type',
title: '检测项类型',
width: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.MES_INDICATOR_TYPE },
},
},
{
field: 'tool',
title: '检测工具',
width: 140,
},
{
field: 'resultType',
title: '结果值类型',
width: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.MES_QC_RESULT_TYPE },
},
},
{
field: 'remark',
title: '备注',
minWidth: 160,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 160,
fixed: 'right',
slots: { default: 'actions' },
},
];
}
/** 选择弹窗的搜索表单 */
export function useSelectGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '检测项名称',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入检测项名称',
},
},
{
fieldName: 'type',
label: '检测项类型',
component: 'Select',
componentProps: {
allowClear: true,
options: getDictOptions(DICT_TYPE.MES_INDICATOR_TYPE, 'number'),
placeholder: '请选择检测项类型',
},
},
];
}
/** 选择弹窗的字段 */
export function useSelectGridColumns(
multiple = true,
): VxeTableGridOptions<MesQcIndicatorApi.Indicator>['columns'] {
return [
{
type: multiple ? 'checkbox' : 'radio',
width: 50,
},
{
field: 'code',
title: '检测项编码',
width: 140,
},
{
field: 'name',
title: '检测项名称',
minWidth: 160,
},
{
field: 'type',
title: '检测项类型',
width: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.MES_INDICATOR_TYPE },
},
},
{
field: 'tool',
title: '检测工具',
width: 120,
},
{
field: 'remark',
title: '备注',
minWidth: 140,
},
];
}

View File

@ -0,0 +1,151 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteIndicator,
exportIndicator,
getIndicatorPage,
} from '#/api/mes/qc/indicator';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建质检指标 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑质检指标 */
function handleEdit(row: MesQcIndicatorApi.Indicator) {
formModalApi.setData(row).open();
}
/** 删除质检指标 */
async function handleDelete(row: MesQcIndicatorApi.Indicator) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
});
try {
await deleteIndicator(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
}
/** 导出表格 */
async function handleExport() {
const data = await exportIndicator(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '质检指标.xls', source: data });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getIndicatorPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<MesQcIndicatorApi.Indicator>,
});
</script>
<template>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【质量】检测项设置、常见缺陷"
url="https://doc.iocoder.cn/mes/qc/base/"
/>
</template>
<FormModal @success="handleRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['质检指标']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['mes:qc-indicator:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['mes:qc-indicator:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['mes:qc-indicator:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['mes:qc-indicator:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,92 @@
<script lang="ts" setup>
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
createIndicator,
getIndicator,
updateIndicator,
} from '#/api/mes/qc/indicator';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<MesQcIndicatorApi.Indicator>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['质检指标'])
: $t('ui.actionTitle.create', ['质检指标']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
formItemClass: 'col-span-2',
labelWidth: 120,
},
layout: 'horizontal',
schema: [],
showDefaultActions: false,
});
/** 表单 schema 需要 formApi 引用(生成编码、跨字段联动),所以通过 setState 设置 schema */
formApi.setState({ schema: useFormSchema(formApi) });
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data = (await formApi.getValues()) as MesQcIndicatorApi.Indicator;
try {
await (formData.value?.id
? updateIndicator(data)
: createIndicator(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;
}
await formApi.resetForm();
//
const data = modalApi.getData<MesQcIndicatorApi.Indicator>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getIndicator(data.id);
// values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-2/5">
<Form class="mx-4" />
</Modal>
</template>

View File

@ -0,0 +1,2 @@
export { default as QcIndicatorSelectDialog } from './qc-indicator-select-dialog.vue';
export { default as QcIndicatorSelect } from './qc-indicator-select.vue';

View File

@ -0,0 +1,200 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { nextTick, ref } from 'vue';
import { ElButton, ElDialog, ElMessage } from 'element-plus';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getIndicatorPage } from '#/api/mes/qc/indicator';
import { useSelectGridColumns, useSelectGridFormSchema } from '../data';
const emit = defineEmits<{
selected: [rows: MesQcIndicatorApi.Indicator[]];
}>();
const open = ref(false); //
const multiple = ref(true); //
const selectedRows = ref<MesQcIndicatorApi.Indicator[]>([]); //
const preSelectedIds = ref<number[]>([]); //
/** 获取多选记录,包含 VXE reserve 跨页记录 */
function getMultipleSelectedRows() {
const selectedMap = new Map<number, MesQcIndicatorApi.Indicator>();
const records = [
...(gridApi.grid.getCheckboxReserveRecords?.() ?? []),
...(gridApi.grid.getCheckboxRecords?.() ?? []),
] as MesQcIndicatorApi.Indicator[];
records.forEach((row) => {
if (row.id != null) {
selectedMap.set(row.id, row);
}
});
return [...selectedMap.values()];
}
/** 处理勾选变化 */
function handleCheckboxSelectChange() {
selectedRows.value = getMultipleSelectedRows();
}
/** 处理单选变化 */
function handleRadioChange(row: MesQcIndicatorApi.Indicator) {
selectedRows.value = [row];
}
/** 多选模式下切换行勾选 */
async function toggleMultipleRow(row: MesQcIndicatorApi.Indicator) {
const selected = gridApi.grid.isCheckedByCheckboxRow(row);
await gridApi.grid.setCheckboxRow(row, !selected);
selectedRows.value = getMultipleSelectedRows();
}
/** 处理行双击 */
async function handleCellDblclick({
row,
}: {
row: MesQcIndicatorApi.Indicator;
}) {
if (multiple.value) {
await toggleMultipleRow(row);
return;
}
selectedRows.value = [row];
await gridApi.grid.setRadioRow(row);
handleConfirm();
}
/** 回显预选指标 */
async function applyPreSelection() {
if (preSelectedIds.value.length === 0) {
return;
}
const rows = gridApi.grid.getData() as MesQcIndicatorApi.Indicator[];
for (const row of rows) {
if (row.id == null || !preSelectedIds.value.includes(row.id)) {
continue;
}
if (multiple.value) {
await gridApi.grid.setCheckboxRow(row, true);
} else {
await gridApi.grid.setRadioRow(row);
selectedRows.value = [row];
return;
}
}
if (multiple.value) {
selectedRows.value = getMultipleSelectedRows();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useSelectGridFormSchema(),
},
gridOptions: {
columns: useSelectGridColumns(true),
height: 520,
keepSource: true,
checkboxConfig: {
highlight: true,
range: true,
reserve: true,
},
radioConfig: {
highlight: true,
trigger: 'row',
},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getIndicatorPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<MesQcIndicatorApi.Indicator>,
gridEvents: {
cellDblclick: handleCellDblclick,
checkboxAll: handleCheckboxSelectChange,
checkboxChange: handleCheckboxSelectChange,
radioChange: ({ row }: { row: MesQcIndicatorApi.Indicator }) => {
handleRadioChange(row);
},
},
});
/** 重置查询和选择状态 */
async function resetQueryState() {
selectedRows.value = [];
await gridApi.grid.clearCheckboxRow();
await gridApi.grid.clearCheckboxReserve();
await gridApi.grid.clearRadioRow();
await gridApi.formApi.resetForm();
}
/** 打开质检指标选择弹窗 */
async function openModal(
selectedIds?: number[],
options?: { multiple?: boolean },
) {
open.value = true;
multiple.value = options?.multiple ?? true;
preSelectedIds.value = selectedIds || [];
await nextTick();
gridApi.setGridOptions({
columns: useSelectGridColumns(multiple.value),
});
await resetQueryState();
await gridApi.query();
await nextTick();
await applyPreSelection();
}
/** 关闭弹窗 */
function closeModal() {
open.value = false;
}
/** 确认选择 */
function handleConfirm() {
const rows = multiple.value ? getMultipleSelectedRows() : selectedRows.value;
if (rows.length === 0) {
ElMessage.warning(multiple.value ? '请至少选择一条数据' : '请选择一条数据');
return;
}
emit('selected', multiple.value ? rows : [rows[0]!]);
open.value = false;
}
defineExpose({ open: openModal });
</script>
<template>
<ElDialog
v-model="open"
destroy-on-close
title="质检指标选择"
width="70%"
@close="closeModal"
>
<Grid table-title="" />
<template #footer>
<ElButton @click="closeModal"></ElButton>
<ElButton type="primary" @click="handleConfirm"></ElButton>
</template>
</ElDialog>
</template>

View File

@ -0,0 +1,132 @@
<script lang="ts" setup>
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { computed, ref, useAttrs, watch } from 'vue';
import { CircleX, Search } from '@vben/icons';
import { ElInput, ElTooltip } from 'element-plus';
import { getIndicator } from '#/api/mes/qc/indicator';
import QcIndicatorSelectDialog from './qc-indicator-select-dialog.vue';
defineOptions({ name: 'QcIndicatorSelect', inheritAttrs: false });
const props = withDefaults(
defineProps<{
clearable?: boolean;
disabled?: boolean;
modelValue?: number;
placeholder?: string;
}>(),
{
clearable: true,
disabled: false,
modelValue: undefined,
placeholder: '请选择质检指标',
},
);
const emit = defineEmits<{
change: [item: MesQcIndicatorApi.Indicator | undefined];
'update:modelValue': [value: number | undefined];
}>();
const attrs = useAttrs(); //
const dialogRef = ref<InstanceType<typeof QcIndicatorSelectDialog>>(); //
const hovering = ref(false); //
const selectedItem = ref<MesQcIndicatorApi.Indicator>(); //
const displayLabel = computed(() => selectedItem.value?.name ?? ''); //
const showClear = computed(() => //
props.clearable &&
!props.disabled &&
hovering.value &&
props.modelValue != null,
);
/** 根据 ID 单条查询指标信息(用于编辑回显) */
async function resolveItemById(id: number | undefined) {
if (id == null) {
selectedItem.value = undefined;
return;
}
if (selectedItem.value?.id === id) {
return;
}
try {
selectedItem.value = await getIndicator(id);
} catch (error) {
console.error('[QcIndicatorSelect] resolveItemById failed:', error);
}
}
watch(() => props.modelValue, resolveItemById, { immediate: true });
/** 清空已选指标 */
function clearSelected() {
selectedItem.value = undefined;
emit('update:modelValue', undefined);
emit('change', undefined);
}
/** 打开质检指标选择弹窗 */
function handleClick(event: MouseEvent) {
if (props.disabled) {
return;
}
const target = event.target as HTMLElement;
if (showClear.value && target.closest('.el-input__suffix')) {
event.stopPropagation();
clearSelected();
return;
}
const selectedIds = props.modelValue == null ? [] : [props.modelValue];
dialogRef.value?.open(selectedIds, { multiple: false });
}
/** 弹窗选中回调 */
function handleSelected(rows: MesQcIndicatorApi.Indicator[]) {
const item = rows[0];
if (!item) {
return;
}
selectedItem.value = item;
emit('update:modelValue', item.id);
emit('change', item);
}
</script>
<template>
<div
v-bind="attrs"
class="w-full"
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
@click="handleClick"
@mouseenter="hovering = true"
@mouseleave="hovering = false"
>
<ElTooltip :disabled="!selectedItem" placement="top" :show-after="500">
<template #content>
<div v-if="selectedItem" class="leading-6">
<div>编码{{ selectedItem.code || '-' }}</div>
<div>名称{{ selectedItem.name || '-' }}</div>
<div>检测工具{{ selectedItem.tool || '-' }}</div>
</div>
</template>
<ElInput
:disabled="disabled"
:model-value="displayLabel"
:placeholder="placeholder"
readonly
>
<template #suffix>
<CircleX v-if="showClear" class="size-4" />
<Search v-else class="size-4" />
</template>
</ElInput>
</ElTooltip>
</div>
<QcIndicatorSelectDialog ref="dialogRef" @selected="handleSelected" />
</template>

View File

@ -0,0 +1,314 @@
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { h } from 'vue';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { ElButton } from 'element-plus';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { getSimpleDictTypeList } from '#/api/system/dict/type';
import {
MesAutoCodeRuleCode,
MesQcResultValueType,
} from '#/views/mes/utils/constants';
/** 新增/修改的表单 */
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'code',
label: '检测项编码',
component: 'Input',
componentProps: {
maxlength: 64,
placeholder: '请输入检测项编码',
},
rules: 'required',
suffix: () =>
h(
ElButton,
{
onClick: async () => {
try {
const code = await generateAutoCode(
MesAutoCodeRuleCode.QC_INDICATOR_CODE,
);
await formApi?.setFieldValue('code', code);
} catch (error) {
console.error(error);
}
},
},
{ default: () => '自动生成' },
),
},
{
fieldName: 'name',
label: '检测项名称',
component: 'Input',
componentProps: {
maxlength: 100,
placeholder: '请输入检测项名称',
},
rules: 'required',
},
{
fieldName: 'type',
label: '检测项类型',
component: 'Select',
componentProps: {
clearable: true,
options: getDictOptions(DICT_TYPE.MES_INDICATOR_TYPE, 'number'),
placeholder: '请选择检测项类型',
},
rules: 'required',
},
{
fieldName: 'tool',
label: '检测工具',
component: 'Input',
componentProps: {
maxlength: 100,
placeholder: '请输入检测工具',
},
},
{
fieldName: 'resultType',
label: '结果值类型',
component: 'Select',
componentProps: {
clearable: true,
// 结果值类型变化时清空结果值属性
onChange: () =>
formApi?.setFieldValue('resultSpecification', undefined),
options: getDictOptions(DICT_TYPE.MES_QC_RESULT_TYPE, 'number'),
placeholder: '请选择结果值类型',
},
rules: 'required',
},
{
fieldName: 'resultSpecification',
label: '文件类型',
component: 'RadioGroup',
componentProps: {
options: [
{ label: '图片/照片', value: 'IMG' },
{ label: '文件', value: 'FILE' },
],
},
dependencies: {
triggerFields: ['resultType'],
show: (values) => values.resultType === MesQcResultValueType.FILE,
},
rules: 'required',
},
{
fieldName: 'resultSpecification',
label: '字典类型',
component: 'ApiSelect',
componentProps: {
api: getSimpleDictTypeList,
clearable: true,
filterMethod: (input: string, option: any) =>
(option.label as string).toLowerCase().includes(input.toLowerCase()),
filterable: true,
labelField: 'name',
placeholder: '请选择字典类型',
valueField: 'type',
},
dependencies: {
triggerFields: ['resultType'],
show: (values) => values.resultType === MesQcResultValueType.DICT,
},
rules: 'required',
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
maxlength: 250,
placeholder: '请输入备注',
rows: 3,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'code',
label: '检测项编码',
component: 'Input',
componentProps: {
clearable: true,
placeholder: '请输入检测项编码',
},
},
{
fieldName: 'name',
label: '检测项名称',
component: 'Input',
componentProps: {
clearable: true,
placeholder: '请输入检测项名称',
},
},
{
fieldName: 'type',
label: '检测项类型',
component: 'Select',
componentProps: {
clearable: true,
options: getDictOptions(DICT_TYPE.MES_INDICATOR_TYPE, 'number'),
placeholder: '请选择检测项类型',
},
},
{
fieldName: 'resultType',
label: '结果值类型',
component: 'Select',
componentProps: {
clearable: true,
options: getDictOptions(DICT_TYPE.MES_QC_RESULT_TYPE, 'number'),
placeholder: '请选择结果值类型',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<MesQcIndicatorApi.Indicator>['columns'] {
return [
{
field: 'code',
title: '检测项编码',
width: 140,
},
{
field: 'name',
title: '检测项名称',
minWidth: 160,
},
{
field: 'type',
title: '检测项类型',
width: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.MES_INDICATOR_TYPE },
},
},
{
field: 'tool',
title: '检测工具',
width: 140,
},
{
field: 'resultType',
title: '结果值类型',
width: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.MES_QC_RESULT_TYPE },
},
},
{
field: 'remark',
title: '备注',
minWidth: 160,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 160,
fixed: 'right',
slots: { default: 'actions' },
},
];
}
/** 选择弹窗的搜索表单 */
export function useSelectGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '检测项名称',
component: 'Input',
componentProps: {
clearable: true,
placeholder: '请输入检测项名称',
},
},
{
fieldName: 'type',
label: '检测项类型',
component: 'Select',
componentProps: {
clearable: true,
options: getDictOptions(DICT_TYPE.MES_INDICATOR_TYPE, 'number'),
placeholder: '请选择检测项类型',
},
},
];
}
/** 选择弹窗的字段 */
export function useSelectGridColumns(
multiple = true,
): VxeTableGridOptions<MesQcIndicatorApi.Indicator>['columns'] {
return [
{
type: multiple ? 'checkbox' : 'radio',
width: 50,
},
{
field: 'code',
title: '检测项编码',
width: 140,
},
{
field: 'name',
title: '检测项名称',
minWidth: 160,
},
{
field: 'type',
title: '检测项类型',
width: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.MES_INDICATOR_TYPE },
},
},
{
field: 'tool',
title: '检测工具',
width: 120,
},
{
field: 'remark',
title: '备注',
minWidth: 140,
},
];
}

View File

@ -0,0 +1,151 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteIndicator,
exportIndicator,
getIndicatorPage,
} from '#/api/mes/qc/indicator';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建质检指标 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑质检指标 */
function handleEdit(row: MesQcIndicatorApi.Indicator) {
formModalApi.setData(row).open();
}
/** 删除质检指标 */
async function handleDelete(row: MesQcIndicatorApi.Indicator) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteIndicator(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 导出表格 */
async function handleExport() {
const data = await exportIndicator(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '质检指标.xls', source: data });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getIndicatorPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<MesQcIndicatorApi.Indicator>,
});
</script>
<template>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【质量】检测项设置、常见缺陷"
url="https://doc.iocoder.cn/mes/qc/base/"
/>
</template>
<FormModal @success="handleRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['质检指标']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['mes:qc-indicator:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['mes:qc-indicator:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['mes:qc-indicator:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['mes:qc-indicator:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,92 @@
<script lang="ts" setup>
import type { MesQcIndicatorApi } from '#/api/mes/qc/indicator';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { ElMessage } from 'element-plus';
import { useVbenForm } from '#/adapter/form';
import {
createIndicator,
getIndicator,
updateIndicator,
} from '#/api/mes/qc/indicator';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<MesQcIndicatorApi.Indicator>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['质检指标'])
: $t('ui.actionTitle.create', ['质检指标']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
formItemClass: 'col-span-2',
labelWidth: 120,
},
layout: 'horizontal',
schema: [],
showDefaultActions: false,
});
/** 表单 schema 需要 formApi 引用(生成编码、跨字段联动),所以通过 setState 设置 schema */
formApi.setState({ schema: useFormSchema(formApi) });
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data = (await formApi.getValues()) as MesQcIndicatorApi.Indicator;
try {
await (formData.value?.id
? updateIndicator(data)
: createIndicator(data));
//
await modalApi.close();
emit('success');
ElMessage.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
await formApi.resetForm();
//
const data = modalApi.getData<MesQcIndicatorApi.Indicator>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getIndicator(data.id);
// values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-2/5">
<Form class="mx-4" />
</Modal>
</template>