595 lines
16 KiB
Plaintext
595 lines
16 KiB
Plaintext
<template>
|
|
<div class="fa-full-height">
|
|
<FaSearchBar
|
|
v-show="showSearchBar"
|
|
ref="searchBarRef"
|
|
v-model="searchForm"
|
|
:items="TraitSearchItems"
|
|
:rules="searchBarRules"
|
|
:is-expand="false"
|
|
:show-expand="true"
|
|
:show-reset="true"
|
|
:show-search="true"
|
|
:disabled-search="false"
|
|
:default-expanded="false"
|
|
include-audit
|
|
@search="handleSearch"
|
|
@reset="onResetSearch"
|
|
/>
|
|
|
|
<ElCard class="fa-table-card" :style="{ 'margin-top': showSearchBar ? '12px' : '0' }">
|
|
<FaTableHeader
|
|
v-model:columns="columnChecks"
|
|
v-model:showSearchBar="showSearchBar"
|
|
:loading="loading"
|
|
@refresh="refreshData"
|
|
>
|
|
<template #left>
|
|
<FaTableHeaderLeft
|
|
:remove-ids="selectedIds"
|
|
:perm-create="['module_bre:trait:create']"
|
|
:perm-import="['module_bre:trait:import']"
|
|
:perm-export="['module_bre:trait:export']"
|
|
:perm-delete="['module_bre:trait:delete']"
|
|
:delete-loading="batchDeleting"
|
|
:create-loading="createLoading"
|
|
@add="handleAdd"
|
|
@import="openImport"
|
|
@export="openExport"
|
|
@delete="handleBatchDelete"
|
|
/>
|
|
</template>
|
|
</FaTableHeader>
|
|
|
|
<FaTable
|
|
ref="faTableRef"
|
|
:loading="loading"
|
|
:data="data"
|
|
:columns="columns"
|
|
:pagination="pagination"
|
|
@selection-change="onTableSelectionChange"
|
|
@pagination:size-change="handleSizeChange"
|
|
@pagination:current-change="handleCurrentChange"
|
|
/>
|
|
</ElCard>
|
|
|
|
<FaDialog
|
|
v-model="dialogVisible.visible"
|
|
:title="dialogVisible.title"
|
|
width="920px"
|
|
dialog-class="crud-embed-dialog"
|
|
modal-class="crud-embed-dialog"
|
|
:form-mode="dialogVisible.type"
|
|
:confirm-loading="submitLoading"
|
|
:close-on-click-modal="false"
|
|
@cancel="crud.handleCloseDialog"
|
|
@close="crud.handleCloseDialog"
|
|
@confirm="crud.handleSubmit"
|
|
>
|
|
<template v-if="dialogVisible.type === 'detail'">
|
|
<FaDescriptions
|
|
:column="4"
|
|
:data="detailFormData"
|
|
:items="TraitDetailItems"
|
|
max-height="70vh"
|
|
/>
|
|
</template>
|
|
<template v-else>
|
|
<FaForm
|
|
:key="TraitFormRenderKey"
|
|
scrollbar
|
|
max-height="70vh"
|
|
ref="dataFormRef"
|
|
v-model="formData"
|
|
:items="TraitDialogFormItems"
|
|
:rules="rules"
|
|
label-suffix=":"
|
|
:label-width="120"
|
|
label-position="right"
|
|
:span="12"
|
|
:gutter="16"
|
|
:show-reset="false"
|
|
:show-submit="false"
|
|
class="crud-dialog-art-form"
|
|
/>
|
|
</template>
|
|
</FaDialog>
|
|
|
|
<FaImportDialog
|
|
v-model="importVisible"
|
|
:content-config="TraitImportContentConfig"
|
|
default-template-file-name="trait_import_template.xlsx"
|
|
@upload="handleCrudImportUpload"
|
|
/>
|
|
|
|
<FaExportDialog
|
|
v-model="exportVisible"
|
|
:content-config="TraitExportContentConfig"
|
|
:query-params="exportQueryParams"
|
|
:page-data="data"
|
|
:selection-data="selectedRows"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { TableOperationAction } from "@/utils/table";
|
|
import { renderTableOperationCell, stripPaginationParams, toCrudCols } from "@utils";
|
|
import { useCrudForm } from "@/hooks/core/useCrudForm";
|
|
import { ResultEnum } from "@/enums/api/result.enum";
|
|
import type { IContentConfig, IObject } from "@/components/modal/types";
|
|
import type { AuditSearchFormParams } from "@/components/forms/fa-search-bar/auditSearchFormItems";
|
|
import type { FormItem } from "@/components/forms/fa-form/index.vue";
|
|
import TraitAPI, { type TraitForm, type TraitPageQuery, type TraitTable } from "@/api/module_bre/trait";
|
|
import type { ColumnOption } from "@/types/component";
|
|
import FaDescriptions from "@/components/others/fa-descriptions/index.vue";
|
|
import FaForm from "@/components/forms/fa-form/index.vue";
|
|
import FaTableHeader from "@/components/tables/fa-table-header/index.vue";
|
|
|
|
defineOptions({
|
|
name: "Trait",
|
|
inheritAttrs: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
const createInitialFormData = (): TraitForm => ({
|
|
id: undefined,
|
|
trait_code: undefined,
|
|
trait_name: undefined,
|
|
category: undefined,
|
|
data_type: undefined,
|
|
unit: undefined,
|
|
is_core: undefined,
|
|
scale_json: undefined,
|
|
valid_min: undefined,
|
|
valid_max: undefined,
|
|
ontology_uri: undefined,
|
|
remark: undefined,
|
|
});
|
|
|
|
type TraitSearchFormParams = {
|
|
trait_code?: string;
|
|
trait_name?: string;
|
|
category?: string;
|
|
data_type?: string;
|
|
is_core?: string;
|
|
} & AuditSearchFormParams;
|
|
|
|
const searchForm = ref<TraitSearchFormParams>({
|
|
trait_code: undefined,
|
|
trait_name: undefined,
|
|
category: undefined,
|
|
data_type: undefined,
|
|
is_core: undefined,
|
|
created_id: undefined,
|
|
updated_id: undefined,
|
|
created_time: [],
|
|
updated_time: [],
|
|
});
|
|
|
|
const showSearchBar = ref(true);
|
|
const searchBarRef = ref<{ validate: () => Promise<boolean> } | null>(null);
|
|
const searchBarRules: Record<string, unknown> = {};
|
|
|
|
const TraitSearchItems = computed(() => [
|
|
{
|
|
label: "性状编码",
|
|
key: "trait_code",
|
|
type: "input",
|
|
placeholder: "请输入性状编码",
|
|
clearable: true,
|
|
span: 8,
|
|
},
|
|
{
|
|
label: "性状名称",
|
|
key: "trait_name",
|
|
type: "input",
|
|
placeholder: "请输入性状名称",
|
|
clearable: true,
|
|
span: 8,
|
|
},
|
|
{
|
|
label: "性状类别",
|
|
key: "category",
|
|
type: "input",
|
|
placeholder: "请输入性状类别",
|
|
clearable: true,
|
|
span: 8,
|
|
},
|
|
{
|
|
label: "数据类型",
|
|
key: "data_type",
|
|
type: "radiogroup",
|
|
props: {
|
|
placeholder: "请选择数据类型",
|
|
options: [{ label: "数值型", value: "numeric" }, { label: "分类型", value: "categorical" }],
|
|
clearable: true,
|
|
},
|
|
span: 8,
|
|
},
|
|
{
|
|
label: "是否核心性状",
|
|
key: "is_core",
|
|
type: "radiogroup",
|
|
props: {
|
|
placeholder: "请选择是否核心性状",
|
|
options: [{ label: "是", value: "1" }, { label: "否", value: "0" }],
|
|
clearable: true,
|
|
},
|
|
span: 8,
|
|
},
|
|
]);
|
|
|
|
const faTableRef = ref<{ elTableRef?: { clearSelection: () => void } } | null>(null);
|
|
const { selectedRows, selectedIds, batchDeleting, onTableSelectionChange } = useTableSelection<TraitTable>();
|
|
|
|
const createLoading = ref(false);
|
|
|
|
const {
|
|
columns,
|
|
columnChecks,
|
|
data,
|
|
loading,
|
|
pagination,
|
|
searchParams,
|
|
getData,
|
|
replaceSearchParams,
|
|
resetSearchParams,
|
|
handleSizeChange,
|
|
handleCurrentChange,
|
|
refreshData,
|
|
refreshCreate,
|
|
refreshUpdate,
|
|
refreshRemove,
|
|
} = useTable({
|
|
core: {
|
|
apiFn: TraitAPI.getTraitList,
|
|
apiParams: {
|
|
page_no: 1,
|
|
page_size: 10,
|
|
},
|
|
columnsFactory: (): ColumnOption<TraitTable>[] => [
|
|
{ type: "globalIndex", width: 56, label: "序号" },
|
|
{ type: "selection", width: 48, fixed: "left" },
|
|
{ prop: "trait_code", label: "性状编码", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "trait_name", label: "性状名称", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "category", label: "性状类别", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "data_type", label: "数据类型", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "unit", label: "单位", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "is_core", label: "是否核心性状", minWidth: 140, showOverflowTooltip: true },
|
|
{
|
|
prop: "created_time",
|
|
label: "创建时间",
|
|
width: 168,
|
|
sortable: true,
|
|
showOverflowTooltip: true,
|
|
},
|
|
{
|
|
prop: "updated_time",
|
|
label: "更新时间",
|
|
width: 168,
|
|
sortable: true,
|
|
showOverflowTooltip: true,
|
|
},
|
|
{
|
|
prop: "created_by",
|
|
label: "创建人",
|
|
minWidth: 100,
|
|
formatter: (row: TraitTable) => row.created_by?.name ?? "—",
|
|
},
|
|
{
|
|
prop: "updated_by",
|
|
label: "更新人",
|
|
minWidth: 100,
|
|
formatter: (row: TraitTable) => row.updated_by?.name ?? "—",
|
|
},
|
|
{
|
|
prop: "operation",
|
|
label: "操作",
|
|
width: 180,
|
|
fixed: "right",
|
|
align: "center",
|
|
formatter: (row: TraitTable) => formatTraitOperationCell(row),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
const TraitCrudCols = toCrudCols(columns);
|
|
|
|
const exportQueryParams = computed(() => {
|
|
return stripPaginationParams(searchParams as Record<string, unknown>);
|
|
});
|
|
|
|
const TraitImportContentConfig = computed<IContentConfig>(() => ({
|
|
permPrefix: "module_bre:trait",
|
|
cols: TraitCrudCols.value,
|
|
indexAction: async () => ({}),
|
|
importTemplate: () => TraitAPI.downloadTemplateTrait(),
|
|
}));
|
|
|
|
const TraitExportContentConfig = computed(() => ({
|
|
permPrefix: "module_bre:trait",
|
|
cols: TraitCrudCols.value,
|
|
exportsBlobAction: async (params: IObject) => {
|
|
const merged = {
|
|
...(exportQueryParams.value as unknown as Record<string, unknown>),
|
|
...params,
|
|
} as unknown as TraitPageQuery;
|
|
const res = await TraitAPI.exportTrait(merged);
|
|
return res.data as Blob;
|
|
},
|
|
}));
|
|
|
|
const { dialogVisible } = useCrudDialog();
|
|
|
|
const detailFormData = ref<TraitTable>({});
|
|
|
|
const TraitDetailItems: import("@/components/others/fa-descriptions/index.vue").DescriptionsItem[] = [
|
|
{ label: "性状编码", prop: "trait_code" },
|
|
{ label: "性状名称", prop: "trait_name" },
|
|
{ label: "性状类别", prop: "category" },
|
|
{ label: "数据类型", prop: "data_type" },
|
|
{ label: "单位", prop: "unit" },
|
|
{ label: "是否核心性状", prop: "is_core" },
|
|
{ label: "量规/分级JSON", prop: "scale_json" },
|
|
{ label: "有效最小值", prop: "valid_min" },
|
|
{ label: "有效最大值", prop: "valid_max" },
|
|
{ label: "本体IRI", prop: "ontology_uri" },
|
|
{ label: "备注", prop: "remark" },
|
|
{ label: "UUID", prop: "uuid" },
|
|
{ label: "创建人", prop: "created_by.name" },
|
|
{ label: "更新人", prop: "updated_by.name" },
|
|
{ label: "创建时间", prop: "created_time" },
|
|
{ label: "更新时间", prop: "updated_time" },
|
|
];
|
|
|
|
const TraitDialogFormItems = computed<FormItem[]>(() => [
|
|
{
|
|
key: "trait_code",
|
|
label: "性状编码",
|
|
type: "input",
|
|
props: { placeholder: "请输入性状编码", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "trait_name",
|
|
label: "性状名称",
|
|
type: "input",
|
|
props: { placeholder: "请输入性状名称", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "category",
|
|
label: "性状类别",
|
|
type: "input",
|
|
props: { placeholder: "请输入性状类别", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "data_type",
|
|
label: "数据类型",
|
|
type: "radiogroup",
|
|
props: {
|
|
placeholder: "请选择数据类型",
|
|
options: [{ label: "数值型", value: "numeric" }, { label: "分类型", value: "categorical" }],
|
|
clearable: true,
|
|
},
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "unit",
|
|
label: "单位",
|
|
type: "input",
|
|
props: { placeholder: "请输入单位", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "is_core",
|
|
label: "是否核心性状",
|
|
type: "radiogroup",
|
|
props: {
|
|
placeholder: "请选择是否核心性状",
|
|
options: [{ label: "是", value: "1" }, { label: "否", value: "0" }],
|
|
clearable: true,
|
|
},
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "scale_json",
|
|
label: "量规/分级JSON",
|
|
type: "input",
|
|
props: { type: "textarea", rows: 3, placeholder: "请输入量规/分级JSON" },
|
|
span: 24,
|
|
},
|
|
{
|
|
key: "valid_min",
|
|
label: "有效最小值",
|
|
type: "number",
|
|
props: { placeholder: "请输入有效最小值" },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "valid_max",
|
|
label: "有效最大值",
|
|
type: "number",
|
|
props: { placeholder: "请输入有效最大值" },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "ontology_uri",
|
|
label: "本体IRI",
|
|
type: "input",
|
|
props: { placeholder: "请输入本体IRI", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "remark",
|
|
label: "备注",
|
|
type: "input",
|
|
props: { type: "textarea", rows: 3, placeholder: "请输入备注" },
|
|
span: 24,
|
|
},
|
|
]);
|
|
|
|
const formData = ref<TraitForm>(createInitialFormData());
|
|
|
|
const rules = reactive({
|
|
trait_code: [{ required: true, message: "请输入性状编码", trigger: "blur" }],
|
|
trait_name: [{ required: true, message: "请输入性状名称", trigger: "blur" }],
|
|
});
|
|
|
|
const dataFormRef = ref<InstanceType<typeof FaForm> | null>(null);
|
|
const TraitFormRenderKey = ref(0);
|
|
|
|
const crud = useCrudForm<TraitForm>({
|
|
formData,
|
|
initialFormData: createInitialFormData(),
|
|
dialogVisible,
|
|
dataFormRef,
|
|
formRenderKey: TraitFormRenderKey,
|
|
detailApi: TraitAPI.getTraitDetail,
|
|
createApi: TraitAPI.createTrait,
|
|
updateApi: TraitAPI.updateTrait,
|
|
titles: { create: "新增性状字典", update: "修改性状字典", detail: "性状字典详情" },
|
|
detailFormData,
|
|
onCreateSuccess: async () => {
|
|
await refreshCreate();
|
|
},
|
|
onUpdateSuccess: async () => {
|
|
await refreshUpdate();
|
|
},
|
|
});
|
|
|
|
const { submitLoading } = crud;
|
|
|
|
const { importVisible, exportVisible, openImport, openExport } = useImportExport();
|
|
|
|
const handleSearch = async (params: TraitSearchFormParams) => {
|
|
await searchBarRef.value?.validate();
|
|
replaceSearchParams({
|
|
trait_code: params.trait_code,
|
|
trait_name: params.trait_name,
|
|
category: params.category,
|
|
data_type: params.data_type,
|
|
is_core: params.is_core,
|
|
created_id: params.created_id ?? undefined,
|
|
updated_id: params.updated_id ?? undefined,
|
|
created_time:
|
|
Array.isArray(params.created_time) && params.created_time.length === 2
|
|
? params.created_time
|
|
: undefined,
|
|
updated_time:
|
|
Array.isArray(params.updated_time) && params.updated_time.length === 2
|
|
? params.updated_time
|
|
: undefined,
|
|
} as Record<string, unknown>);
|
|
await getData();
|
|
};
|
|
|
|
const onResetSearch = async () => {
|
|
searchForm.value = {
|
|
trait_code: undefined,
|
|
trait_name: undefined,
|
|
category: undefined,
|
|
data_type: undefined,
|
|
is_core: undefined,
|
|
created_id: undefined,
|
|
updated_id: undefined,
|
|
created_time: [],
|
|
updated_time: [],
|
|
};
|
|
await resetSearchParams();
|
|
};
|
|
|
|
function buildTraitRowActions(row: TraitTable): TableOperationAction[] {
|
|
const all: TableOperationAction[] = [
|
|
{
|
|
key: "detail",
|
|
label: "详情",
|
|
artType: "view",
|
|
perm: "module_bre:trait:detail",
|
|
run: () => void crud.handleOpenDialog("detail", row.id),
|
|
},
|
|
{
|
|
key: "edit",
|
|
label: "编辑",
|
|
artType: "edit",
|
|
icon: "ri:edit-2-line",
|
|
perm: "module_bre:trait:update",
|
|
run: () => void crud.handleOpenDialog("update", row.id),
|
|
},
|
|
{
|
|
key: "delete",
|
|
label: "删除",
|
|
artType: "delete",
|
|
icon: "ri:delete-bin-4-line",
|
|
perm: "module_bre:trait:delete",
|
|
run: () => deleteTraitRow(row),
|
|
},
|
|
];
|
|
return all;
|
|
}
|
|
|
|
function formatTraitOperationCell(row: TraitTable) {
|
|
return renderTableOperationCell(buildTraitRowActions(row), {
|
|
wrapperClass: "inline-flex flex-wrap items-center justify-end gap-1",
|
|
});
|
|
}
|
|
|
|
async function handleAdd() {
|
|
createLoading.value = true;
|
|
try {
|
|
await crud.handleOpenDialog("create");
|
|
} finally {
|
|
createLoading.value = false;
|
|
}
|
|
}
|
|
|
|
const deleteTraitRow = async (row: TraitTable) => {
|
|
if (!row.id) return;
|
|
try {
|
|
await confirmDelete(`确定删除「${row.trait_code ?? row.id}」吗?此操作不可恢复!`);
|
|
await TraitAPI.deleteTrait([row.id!]);
|
|
faTableRef.value?.elTableRef?.clearSelection();
|
|
await refreshRemove();
|
|
} catch {
|
|
// 用户取消
|
|
}
|
|
};
|
|
|
|
async function handleBatchDelete() {
|
|
const ids = selectedIds.value;
|
|
if (ids.length === 0) return;
|
|
try {
|
|
await confirmBatchDelete(ids.length);
|
|
batchDeleting.value = true;
|
|
await TraitAPI.deleteTrait(ids);
|
|
faTableRef.value?.elTableRef?.clearSelection();
|
|
await refreshRemove();
|
|
} catch {
|
|
// 用户取消
|
|
} finally {
|
|
batchDeleting.value = false;
|
|
}
|
|
}
|
|
|
|
async function handleCrudImportUpload(uploadFormData: FormData) {
|
|
try {
|
|
const res = await TraitAPI.importTrait(uploadFormData);
|
|
if (res.data.code === ResultEnum.SUCCESS) {
|
|
ElMessage.success(res.data.msg || "导入成功");
|
|
importVisible.value = false;
|
|
await refreshData();
|
|
}
|
|
} catch (error: unknown) {
|
|
if (import.meta.env.DEV) console.error("[Import]", error);
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
});
|
|
</script>
|