init: 初始化 dpb 桃育种系统代码库

前后端 + 后端 FastAPI 全量源码、部署脚本与文档。
This commit is contained in:
34047007@qq.com
2026-08-06 00:17:49 +08:00
commit b95053c52c
1469 changed files with 322298 additions and 0 deletions
@@ -0,0 +1,623 @@
<template>
<div class="fa-full-height">
<FaSearchBar
v-show="showSearchBar"
ref="searchBarRef"
v-model="searchForm"
:items="SelectionRuleSearchItems"
: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:selection_rule:create']"
:perm-import="['module_bre:selection_rule:import']"
:perm-export="['module_bre:selection_rule:export']"
:perm-delete="['module_bre:selection_rule: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="SelectionRuleDetailItems"
max-height="70vh"
/>
</template>
<template v-else>
<FaForm
:key="SelectionRuleFormRenderKey"
scrollbar
max-height="70vh"
ref="dataFormRef"
v-model="formData"
:items="SelectionRuleDialogFormItems"
: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="SelectionRuleImportContentConfig"
default-template-file-name="selection_rule_import_template.xlsx"
@upload="handleCrudImportUpload"
/>
<FaExportDialog
v-model="exportVisible"
:content-config="SelectionRuleExportContentConfig"
: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 TargetAPI, { type TargetOption } from "@/api/module_bre/target";
import SelectionRuleAPI, { type SelectionRuleForm, type SelectionRulePageQuery, type SelectionRuleTable } from "@/api/module_bre/selection_rule";
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: "SelectionRule",
inheritAttrs: false,
});
const targetOptions = ref<TargetOption[]>([]);
const targetOptionsMap = computed(() => {
const m: Record<number, string> = {};
for (const o of targetOptions.value) m[o.value] = o.label;
return m;
});
async function loadTargetOptions() {
try {
const res = await TargetAPI.getTargetOptions();
if (res.data.code === ResultEnum.SUCCESS) {
targetOptions.value = res.data.data ?? [];
}
} catch (error: unknown) {
if (import.meta.env.DEV) console.error("[SelectionRule] loadTargetOptions", error);
}
}
const createInitialFormData = (): SelectionRuleForm => ({
id: undefined,
rule_name: undefined,
target_id: undefined,
stage: undefined,
conditions_json: undefined,
logic: undefined,
action: undefined,
priority: undefined,
enabled: undefined,
remark: undefined,
});
type SelectionRuleSearchFormParams = {
rule_name?: string;
target_id?: number;
stage?: string;
logic?: string;
action?: string;
enabled?: string;
} & AuditSearchFormParams;
const searchForm = ref<SelectionRuleSearchFormParams>({
rule_name: undefined,
target_id: undefined,
stage: undefined,
logic: undefined,
action: undefined,
enabled: 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 SelectionRuleSearchItems = computed(() => [
{
label: "规则名称",
key: "rule_name",
type: "input",
placeholder: "请输入规则名称",
clearable: true,
span: 8,
},
{
label: "育种目标",
key: "target_id",
type: "select",
props: {
placeholder: "请选择育种目标",
options: targetOptions.value,
clearable: true,
filterable: true,
},
span: 8,
},
{
label: "适用阶段",
key: "stage",
type: "input",
placeholder: "请输入适用阶段",
clearable: true,
span: 8,
},
{
label: "逻辑关系",
key: "logic",
type: "radiogroup",
props: {
placeholder: "请选择逻辑关系",
options: [{ label: "与", value: "and" }, { label: "或", value: "or" }],
clearable: true,
},
span: 8,
},
{
label: "动作",
key: "action",
type: "radiogroup",
props: {
placeholder: "请选择动作",
options: [{ label: "保留", value: "keep" }, { label: "淘汰", value: "eliminate" }],
clearable: true,
},
span: 8,
},
{
label: "是否启用",
key: "enabled",
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<SelectionRuleTable>();
const createLoading = ref(false);
const {
columns,
columnChecks,
data,
loading,
pagination,
searchParams,
getData,
replaceSearchParams,
resetSearchParams,
handleSizeChange,
handleCurrentChange,
refreshData,
refreshCreate,
refreshUpdate,
refreshRemove,
} = useTable({
core: {
apiFn: SelectionRuleAPI.getSelectionRuleList,
apiParams: {
page_no: 1,
page_size: 10,
},
columnsFactory: (): ColumnOption<SelectionRuleTable>[] => [
{ type: "globalIndex", width: 56, label: "序号" },
{ type: "selection", width: 48, fixed: "left" },
{ prop: "rule_name", label: "规则名称", minWidth: 140, showOverflowTooltip: true },
{ prop: "target_name", label: "育种目标", minWidth: 140, showOverflowTooltip: true },
{ prop: "stage", label: "适用阶段", minWidth: 140, showOverflowTooltip: true },
{ prop: "logic", label: "逻辑关系", minWidth: 140, showOverflowTooltip: true },
{ prop: "action", label: "动作", minWidth: 140, showOverflowTooltip: true },
{ prop: "priority", label: "优先级", minWidth: 100 },
{ prop: "enabled", 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: SelectionRuleTable) => row.created_by?.name ?? "—",
},
{
prop: "updated_by",
label: "更新人",
minWidth: 100,
formatter: (row: SelectionRuleTable) => row.updated_by?.name ?? "—",
},
{
prop: "operation",
label: "操作",
width: 180,
fixed: "right",
align: "center",
formatter: (row: SelectionRuleTable) => formatSelectionRuleOperationCell(row),
},
],
},
});
const SelectionRuleCrudCols = toCrudCols(columns);
const exportQueryParams = computed(() => {
return stripPaginationParams(searchParams as Record<string, unknown>);
});
const SelectionRuleImportContentConfig = computed<IContentConfig>(() => ({
permPrefix: "module_bre:selection_rule",
cols: SelectionRuleCrudCols.value,
indexAction: async () => ({}),
importTemplate: () => SelectionRuleAPI.downloadTemplateSelectionRule(),
}));
const SelectionRuleExportContentConfig = computed(() => ({
permPrefix: "module_bre:selection_rule",
cols: SelectionRuleCrudCols.value,
exportsBlobAction: async (params: IObject) => {
const merged = {
...(exportQueryParams.value as unknown as Record<string, unknown>),
...params,
} as unknown as SelectionRulePageQuery;
const res = await SelectionRuleAPI.exportSelectionRule(merged);
return res.data as Blob;
},
}));
const { dialogVisible } = useCrudDialog();
const detailFormData = ref<SelectionRuleTable>({});
const SelectionRuleDetailItems: import("@/components/others/fa-descriptions/index.vue").DescriptionsItem[] = [
{ label: "规则名称", prop: "rule_name" },
{ label: "育种目标", prop: "target_name" },
{ label: "适用阶段", prop: "stage" },
{ label: "条件(JSON)", prop: "conditions_json" },
{ label: "逻辑关系", prop: "logic" },
{ label: "动作", prop: "action" },
{ label: "优先级", prop: "priority" },
{ label: "是否启用", prop: "enabled" },
{ 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 SelectionRuleDialogFormItems = computed<FormItem[]>(() => [
{
key: "rule_name",
label: "规则名称",
type: "input",
props: { placeholder: "请输入规则名称", maxlength: 100 },
span: 12,
},
{
key: "target_id",
label: "育种目标",
type: "select",
props: {
placeholder: "请选择育种目标",
options: targetOptions.value,
clearable: true,
filterable: true,
},
span: 12,
},
{
key: "stage",
label: "适用阶段",
type: "input",
props: { placeholder: "请输入适用阶段", maxlength: 100 },
span: 12,
},
{
key: "conditions_json",
label: "条件(JSON)",
type: "input",
props: { type: "textarea", rows: 3, placeholder: "请输入条件(JSON)" },
span: 24,
},
{
key: "logic",
label: "逻辑关系",
type: "radiogroup",
props: {
placeholder: "请选择逻辑关系",
options: [{ label: "与", value: "and" }, { label: "或", value: "or" }],
clearable: true,
},
span: 12,
},
{
key: "action",
label: "动作",
type: "radiogroup",
props: {
placeholder: "请选择动作",
options: [{ label: "保留", value: "keep" }, { label: "淘汰", value: "eliminate" }],
clearable: true,
},
span: 12,
},
{
key: "priority",
label: "优先级",
type: "number",
props: { placeholder: "请输入优先级" },
span: 12,
},
{
key: "enabled",
label: "是否启用",
type: "radiogroup",
props: {
placeholder: "请选择是否启用",
options: [{ label: "启用", value: "1" }, { label: "停用", value: "0" }],
clearable: true,
},
span: 12,
},
{
key: "remark",
label: "备注",
type: "input",
props: { type: "textarea", rows: 3, placeholder: "请输入备注" },
span: 24,
},
]);
const formData = ref<SelectionRuleForm>(createInitialFormData());
const rules = reactive({
rule_name: [{ required: true, message: "请输入规则名称", trigger: "blur" }],
target_id: [{ required: true, message: "请选择育种目标", trigger: "change" }],
});
const dataFormRef = ref<InstanceType<typeof FaForm> | null>(null);
const SelectionRuleFormRenderKey = ref(0);
const crud = useCrudForm<SelectionRuleForm>({
formData,
initialFormData: createInitialFormData(),
dialogVisible,
dataFormRef,
formRenderKey: SelectionRuleFormRenderKey,
detailApi: SelectionRuleAPI.getSelectionRuleDetail,
createApi: SelectionRuleAPI.createSelectionRule,
updateApi: SelectionRuleAPI.updateSelectionRule,
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: SelectionRuleSearchFormParams) => {
await searchBarRef.value?.validate();
replaceSearchParams({
rule_name: params.rule_name,
target_id: params.target_id,
stage: params.stage,
logic: params.logic,
action: params.action,
enabled: params.enabled,
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 = {
rule_name: undefined,
target_id: undefined,
stage: undefined,
logic: undefined,
action: undefined,
enabled: undefined,
created_id: undefined,
updated_id: undefined,
created_time: [],
updated_time: [],
};
await resetSearchParams();
};
function buildSelectionRuleRowActions(row: SelectionRuleTable): TableOperationAction[] {
const all: TableOperationAction[] = [
{
key: "detail",
label: "详情",
artType: "view",
perm: "module_bre:selection_rule:detail",
run: () => void crud.handleOpenDialog("detail", row.id),
},
{
key: "edit",
label: "编辑",
artType: "edit",
icon: "ri:edit-2-line",
perm: "module_bre:selection_rule:update",
run: () => void crud.handleOpenDialog("update", row.id),
},
{
key: "delete",
label: "删除",
artType: "delete",
icon: "ri:delete-bin-4-line",
perm: "module_bre:selection_rule:delete",
run: () => deleteSelectionRuleRow(row),
},
];
return all;
}
function formatSelectionRuleOperationCell(row: SelectionRuleTable) {
return renderTableOperationCell(buildSelectionRuleRowActions(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 deleteSelectionRuleRow = async (row: SelectionRuleTable) => {
if (!row.id) return;
try {
await confirmDelete(`确定删除「${row.rule_name ?? row.id}」吗?此操作不可恢复!`);
await SelectionRuleAPI.deleteSelectionRule([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 SelectionRuleAPI.deleteSelectionRule(ids);
faTableRef.value?.elTableRef?.clearSelection();
await refreshRemove();
} catch {
// 用户取消
} finally {
batchDeleting.value = false;
}
}
async function handleCrudImportUpload(uploadFormData: FormData) {
try {
const res = await SelectionRuleAPI.importSelectionRule(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(() => {
loadTargetOptions();
});
</script>