init: 初始化 dpb 桃育种系统代码库
前后端 + 后端 FastAPI 全量源码、部署脚本与文档。
This commit is contained in:
@@ -0,0 +1,531 @@
|
||||
<template>
|
||||
<div class="fa-full-height">
|
||||
<FaSearchBar
|
||||
v-show="showSearchBar"
|
||||
ref="searchBarRef"
|
||||
v-model="searchForm"
|
||||
:items="PlanSearchItems"
|
||||
: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:plan:create']"
|
||||
:perm-import="['module_bre:plan:import']"
|
||||
:perm-export="['module_bre:plan:export']"
|
||||
:perm-delete="['module_bre:plan: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="PlanDetailItems"
|
||||
max-height="70vh"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<FaForm
|
||||
:key="PlanFormRenderKey"
|
||||
scrollbar
|
||||
max-height="70vh"
|
||||
ref="dataFormRef"
|
||||
v-model="formData"
|
||||
:items="PlanDialogFormItems"
|
||||
: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="PlanImportContentConfig"
|
||||
default-template-file-name="plan_import_template.xlsx"
|
||||
@upload="handleCrudImportUpload"
|
||||
/>
|
||||
|
||||
<FaExportDialog
|
||||
v-model="exportVisible"
|
||||
:content-config="PlanExportContentConfig"
|
||||
: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 PlanAPI, { type PlanForm, type PlanPageQuery, type PlanTable } from "@/api/module_bre/plan";
|
||||
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: "Plan",
|
||||
inheritAttrs: false,
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
const createInitialFormData = (): PlanForm => ({
|
||||
id: undefined,
|
||||
plan_code: undefined,
|
||||
plan_name: undefined,
|
||||
objective: undefined,
|
||||
start_year: undefined,
|
||||
end_year: undefined,
|
||||
leader: undefined,
|
||||
remark: undefined,
|
||||
});
|
||||
|
||||
type PlanSearchFormParams = {
|
||||
plan_code?: string;
|
||||
plan_name?: string;
|
||||
start_year?: number;
|
||||
end_year?: number;
|
||||
} & AuditSearchFormParams;
|
||||
|
||||
const searchForm = ref<PlanSearchFormParams>({
|
||||
plan_code: undefined,
|
||||
plan_name: undefined,
|
||||
start_year: undefined,
|
||||
end_year: 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 PlanSearchItems = computed(() => [
|
||||
{
|
||||
label: "计划编号",
|
||||
key: "plan_code",
|
||||
type: "input",
|
||||
placeholder: "请输入计划编号",
|
||||
clearable: true,
|
||||
span: 8,
|
||||
},
|
||||
{
|
||||
label: "计划名称",
|
||||
key: "plan_name",
|
||||
type: "input",
|
||||
placeholder: "请输入计划名称",
|
||||
clearable: true,
|
||||
span: 8,
|
||||
},
|
||||
{
|
||||
label: "起始年份",
|
||||
key: "start_year",
|
||||
type: "input",
|
||||
placeholder: "请输入起始年份",
|
||||
clearable: true,
|
||||
span: 8,
|
||||
},
|
||||
{
|
||||
label: "结束年份",
|
||||
key: "end_year",
|
||||
type: "input",
|
||||
placeholder: "请输入结束年份",
|
||||
clearable: true,
|
||||
span: 8,
|
||||
},
|
||||
]);
|
||||
|
||||
const faTableRef = ref<{ elTableRef?: { clearSelection: () => void } } | null>(null);
|
||||
const { selectedRows, selectedIds, batchDeleting, onTableSelectionChange } = useTableSelection<PlanTable>();
|
||||
|
||||
const createLoading = ref(false);
|
||||
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
pagination,
|
||||
searchParams,
|
||||
getData,
|
||||
replaceSearchParams,
|
||||
resetSearchParams,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData,
|
||||
refreshCreate,
|
||||
refreshUpdate,
|
||||
refreshRemove,
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: PlanAPI.getPlanList,
|
||||
apiParams: {
|
||||
page_no: 1,
|
||||
page_size: 10,
|
||||
},
|
||||
columnsFactory: (): ColumnOption<PlanTable>[] => [
|
||||
{ type: "globalIndex", width: 56, label: "序号" },
|
||||
{ type: "selection", width: 48, fixed: "left" },
|
||||
{ prop: "plan_code", label: "计划编号", minWidth: 140, showOverflowTooltip: true },
|
||||
{ prop: "plan_name", label: "计划名称", minWidth: 140, showOverflowTooltip: true },
|
||||
{ prop: "start_year", label: "起始年份", minWidth: 100 },
|
||||
{ prop: "end_year", label: "结束年份", minWidth: 100 },
|
||||
{ prop: "leader", 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: PlanTable) => row.created_by?.name ?? "—",
|
||||
},
|
||||
{
|
||||
prop: "updated_by",
|
||||
label: "更新人",
|
||||
minWidth: 100,
|
||||
formatter: (row: PlanTable) => row.updated_by?.name ?? "—",
|
||||
},
|
||||
{
|
||||
prop: "operation",
|
||||
label: "操作",
|
||||
width: 180,
|
||||
fixed: "right",
|
||||
align: "center",
|
||||
formatter: (row: PlanTable) => formatPlanOperationCell(row),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const PlanCrudCols = toCrudCols(columns);
|
||||
|
||||
const exportQueryParams = computed(() => {
|
||||
return stripPaginationParams(searchParams as Record<string, unknown>);
|
||||
});
|
||||
|
||||
const PlanImportContentConfig = computed<IContentConfig>(() => ({
|
||||
permPrefix: "module_bre:plan",
|
||||
cols: PlanCrudCols.value,
|
||||
indexAction: async () => ({}),
|
||||
importTemplate: () => PlanAPI.downloadTemplatePlan(),
|
||||
}));
|
||||
|
||||
const PlanExportContentConfig = computed(() => ({
|
||||
permPrefix: "module_bre:plan",
|
||||
cols: PlanCrudCols.value,
|
||||
exportsBlobAction: async (params: IObject) => {
|
||||
const merged = {
|
||||
...(exportQueryParams.value as unknown as Record<string, unknown>),
|
||||
...params,
|
||||
} as unknown as PlanPageQuery;
|
||||
const res = await PlanAPI.exportPlan(merged);
|
||||
return res.data as Blob;
|
||||
},
|
||||
}));
|
||||
|
||||
const { dialogVisible } = useCrudDialog();
|
||||
|
||||
const detailFormData = ref<PlanTable>({});
|
||||
|
||||
const PlanDetailItems: import("@/components/others/fa-descriptions/index.vue").DescriptionsItem[] = [
|
||||
{ label: "计划编号", prop: "plan_code" },
|
||||
{ label: "计划名称", prop: "plan_name" },
|
||||
{ label: "计划目标", prop: "objective" },
|
||||
{ label: "起始年份", prop: "start_year" },
|
||||
{ label: "结束年份", prop: "end_year" },
|
||||
{ label: "负责人", prop: "leader" },
|
||||
{ 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 PlanDialogFormItems = computed<FormItem[]>(() => [
|
||||
{
|
||||
key: "plan_code",
|
||||
label: "计划编号",
|
||||
type: "input",
|
||||
props: { placeholder: "请输入计划编号", maxlength: 100 },
|
||||
span: 12,
|
||||
},
|
||||
{
|
||||
key: "plan_name",
|
||||
label: "计划名称",
|
||||
type: "input",
|
||||
props: { placeholder: "请输入计划名称", maxlength: 100 },
|
||||
span: 12,
|
||||
},
|
||||
{
|
||||
key: "objective",
|
||||
label: "计划目标",
|
||||
type: "input",
|
||||
props: { type: "textarea", rows: 3, placeholder: "请输入计划目标" },
|
||||
span: 24,
|
||||
},
|
||||
{
|
||||
key: "start_year",
|
||||
label: "起始年份",
|
||||
type: "number",
|
||||
props: { placeholder: "请输入起始年份" },
|
||||
span: 12,
|
||||
},
|
||||
{
|
||||
key: "end_year",
|
||||
label: "结束年份",
|
||||
type: "number",
|
||||
props: { placeholder: "请输入结束年份" },
|
||||
span: 12,
|
||||
},
|
||||
{
|
||||
key: "leader",
|
||||
label: "负责人",
|
||||
type: "input",
|
||||
props: { placeholder: "请输入负责人", maxlength: 100 },
|
||||
span: 12,
|
||||
},
|
||||
{
|
||||
key: "remark",
|
||||
label: "备注",
|
||||
type: "input",
|
||||
props: { type: "textarea", rows: 3, placeholder: "请输入备注" },
|
||||
span: 24,
|
||||
},
|
||||
]);
|
||||
|
||||
const formData = ref<PlanForm>(createInitialFormData());
|
||||
|
||||
const rules = reactive({
|
||||
plan_code: [{ required: true, message: "请输入计划编号", trigger: "blur" }],
|
||||
plan_name: [{ required: true, message: "请输入计划名称", trigger: "blur" }],
|
||||
});
|
||||
|
||||
const dataFormRef = ref<InstanceType<typeof FaForm> | null>(null);
|
||||
const PlanFormRenderKey = ref(0);
|
||||
|
||||
const crud = useCrudForm<PlanForm>({
|
||||
formData,
|
||||
initialFormData: createInitialFormData(),
|
||||
dialogVisible,
|
||||
dataFormRef,
|
||||
formRenderKey: PlanFormRenderKey,
|
||||
detailApi: PlanAPI.getPlanDetail,
|
||||
createApi: PlanAPI.createPlan,
|
||||
updateApi: PlanAPI.updatePlan,
|
||||
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: PlanSearchFormParams) => {
|
||||
await searchBarRef.value?.validate();
|
||||
replaceSearchParams({
|
||||
plan_code: params.plan_code,
|
||||
plan_name: params.plan_name,
|
||||
start_year: params.start_year,
|
||||
end_year: params.end_year,
|
||||
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 = {
|
||||
plan_code: undefined,
|
||||
plan_name: undefined,
|
||||
start_year: undefined,
|
||||
end_year: undefined,
|
||||
created_id: undefined,
|
||||
updated_id: undefined,
|
||||
created_time: [],
|
||||
updated_time: [],
|
||||
};
|
||||
await resetSearchParams();
|
||||
};
|
||||
|
||||
function buildPlanRowActions(row: PlanTable): TableOperationAction[] {
|
||||
const all: TableOperationAction[] = [
|
||||
{
|
||||
key: "detail",
|
||||
label: "详情",
|
||||
artType: "view",
|
||||
perm: "module_bre:plan:detail",
|
||||
run: () => void crud.handleOpenDialog("detail", row.id),
|
||||
},
|
||||
{
|
||||
key: "edit",
|
||||
label: "编辑",
|
||||
artType: "edit",
|
||||
icon: "ri:edit-2-line",
|
||||
perm: "module_bre:plan:update",
|
||||
run: () => void crud.handleOpenDialog("update", row.id),
|
||||
},
|
||||
{
|
||||
key: "delete",
|
||||
label: "删除",
|
||||
artType: "delete",
|
||||
icon: "ri:delete-bin-4-line",
|
||||
perm: "module_bre:plan:delete",
|
||||
run: () => deletePlanRow(row),
|
||||
},
|
||||
];
|
||||
return all;
|
||||
}
|
||||
|
||||
function formatPlanOperationCell(row: PlanTable) {
|
||||
return renderTableOperationCell(buildPlanRowActions(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 deletePlanRow = async (row: PlanTable) => {
|
||||
if (!row.id) return;
|
||||
try {
|
||||
await confirmDelete(`确定删除「${row.plan_code ?? row.id}」吗?此操作不可恢复!`);
|
||||
await PlanAPI.deletePlan([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 PlanAPI.deletePlan(ids);
|
||||
faTableRef.value?.elTableRef?.clearSelection();
|
||||
await refreshRemove();
|
||||
} catch {
|
||||
// 用户取消
|
||||
} finally {
|
||||
batchDeleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCrudImportUpload(uploadFormData: FormData) {
|
||||
try {
|
||||
const res = await PlanAPI.importPlan(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>
|
||||
Reference in New Issue
Block a user