From 352f7bbb74f1b6c57b3d3e576849d0565932fbd4 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 16:50:36 +0800
Subject: [PATCH] 审批模板集成页面
---
src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue | 846 ++++++--------------------------------------------------
1 files changed, 94 insertions(+), 752 deletions(-)
diff --git a/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue b/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue
index b04a9cd..17303aa 100644
--- a/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue
+++ b/src/views/officeProcessAutomation/AttendManage/overtime-apply/index.vue
@@ -10,22 +10,20 @@
placeholder="濮撳悕鎴栫紪鍙�"
clearable
:prefix-icon="Search"
- @keyup.enter="handleQuery"
+ @keyup.enter="onSearch"
/>
<span class="search_title" style="margin-left: 12px">鍔犵彮绫诲瀷锛�</span>
<el-select v-model="searchForm.overtimeType" placeholder="鍏ㄩ儴" clearable style="width: 180px">
<el-option v-for="opt in OVERTIME_TYPE_OPTIONS" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
- <el-button type="primary" style="margin-left: 10px" @click="handleQuery">鎼滅储</el-button>
+ <el-button type="primary" style="margin-left: 10px" @click="onSearch">鎼滅储</el-button>
<el-button @click="resetSearch">閲嶇疆</el-button>
</div>
<div class="search_actions">
- <el-button type="success" plain @click="handleImportClick">瀵煎叆</el-button>
<el-button type="warning" plain @click="handleExport">瀵煎嚭</el-button>
<el-button type="primary" @click="openAddWithTemplate">鏂板鍔犵彮鐢宠</el-button>
</div>
</div>
- <input ref="importInputRef" type="file" accept="application/json,.json" class="sr-only-input" @change="onImportFile" />
<div class="table_list">
<PIMTable
@@ -35,66 +33,38 @@
:page="page"
:isSelection="false"
:tableLoading="tableLoading"
- @pagination="pagination"
+ @pagination="onPagination"
:total="page.total"
/>
</div>
- <!-- 鏂板 / 缂栬緫 -->
- <el-dialog
- v-if="formDialog.visible"
- v-model="formDialog.visible"
- :title="formDialog.title"
- width="960px"
- append-to-body
- destroy-on-close
- class="overtime-apply-form-dialog"
- @closed="onFormClosed"
+ <ApprovalInstanceSubmitDialog
+ v-model="submitDialog.visible"
+ :title="submitDialogTitle"
+ :form="submitForm"
+ :rules="submitFormRules"
+ :fields="submitFormFields"
+ :active-template="activeTemplate"
+ :user-options="flowUserOptions"
+ :is-edit="isSubmitEdit"
+ :saving="submitSaving"
+ :form-ref="submitFormRef"
+ flow-attachments-only
+ @submit="onSubmit"
>
- <el-form ref="formRef" :model="form" :rules="formRules" label-width="140px" class="overtime-apply-form">
- <el-form-item v-if="form.templateSnapshot" label="瀹℃壒妯℃澘">
- <span class="template-name">{{ form.templateSnapshot.label || form.templateName }}</span>
- <el-button
- v-if="formDialog.mode === 'add'"
- type="primary"
- link
- class="ml12"
- @click="reopenTemplateBind"
- >
- 鏇存崲妯℃澘
- </el-button>
- </el-form-item>
-
- <FormPayloadFields :fields="templateDisplayFields" :form-payload="form.formPayload" />
+ <template #before="{ form, fields }">
+ <FormPayloadFields :fields="displayTemplateFields(fields)" :form-payload="form.formPayload" />
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="鍔犵彮鏃堕暱">
- <el-input :model-value="overtimeHoursDisplay" readonly placeholder="鏍规嵁妯℃澘涓姞鐝椂闂磋嚜鍔ㄨ绠�">
+ <el-input :model-value="overtimeHoursDisplay(form)" readonly placeholder="鏍规嵁妯℃澘涓姞鐝椂闂磋嚜鍔ㄨ绠�">
<template #append>灏忔椂</template>
</el-input>
</el-form-item>
</el-col>
</el-row>
- <ApprovalTemplateFormSection
- :active-template="form.templateSnapshot"
- :fields="form.formFieldDefs"
- :form-payload="form.formPayload"
- v-model:flow-nodes="form.flowNodes"
- v-model:attachments="form.storageBlobDTOs"
- :template-attachments="form.templateAttachments"
- :user-options="flowUserOptions"
- flow-attachments-only
- hide-template-name
- :allow-change-template="false"
- />
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="submitForm">纭� 瀹�</el-button>
- <el-button @click="formDialog.visible = false">鍙� 娑�</el-button>
- </div>
</template>
- </el-dialog>
+ </ApprovalInstanceSubmitDialog>
<ApprovalTemplateBindDialog
v-model:visible="templateBindVisible"
@@ -104,167 +74,52 @@
@closed="onTemplateBindClosed"
/>
- <!-- 璇︽儏 -->
- <el-dialog v-model="detailDialog.visible" title="鍔犵彮鐢宠璇︽儏" width="720px" append-to-body>
- <el-descriptions :column="1" border>
- <el-descriptions-item label="鐢宠浜虹紪鍙�">{{ detailRow.applicantNo || "鈥�" }}</el-descriptions-item>
- <el-descriptions-item label="鐢宠浜�">{{ detailRow.applicantName }}</el-descriptions-item>
- <el-descriptions-item label="鍔犵彮绫诲瀷">{{ overtimeTypeLabel(detailRow.overtimeType) }}</el-descriptions-item>
- <el-descriptions-item label="鍔犵彮鏃ユ湡">{{ detailRow.overtimeDate || "鈥�" }}</el-descriptions-item>
- <el-descriptions-item label="鍔犵彮寮�濮嬫棩鏈�">{{ detailRow.overtimeStartTime || "鈥�" }}</el-descriptions-item>
- <el-descriptions-item label="鍔犵彮缁撴潫鏃ユ湡">{{ detailRow.overtimeEndTime || "鈥�" }}</el-descriptions-item>
- <el-descriptions-item label="鍔犵彮鏃堕暱">{{ formatHours(detailRow.overtimeHours) }}</el-descriptions-item>
- <el-descriptions-item label="鍔犵彮浜嬬敱">{{ detailRow.overtimeReason }}</el-descriptions-item>
- <el-descriptions-item label="瀹℃壒娴佺▼">
- <template v-if="detailFlowSteps(detailRow).length">
- <div class="detail-flow-chain">
- <template v-for="(step, i) in detailFlowSteps(detailRow)" :key="i">
- <span class="detail-flow-step">{{ step }}</span>
- <span v-if="i < detailFlowSteps(detailRow).length - 1" class="detail-flow-sep">鈫�</span>
- </template>
- </div>
- </template>
- <span v-else>鈥�</span>
- </el-descriptions-item>
- <el-descriptions-item label="瀹℃壒缁撴灉">{{ approvalResultLabel(detailRow.approvalResult) }}</el-descriptions-item>
- <el-descriptions-item label="鍒涘缓鏃堕棿">{{ detailRow.createTime || "鈥�" }}</el-descriptions-item>
- <el-descriptions-item label="闄勪欢">
- <template v-if="rowAttachmentList(detailRow).length">
- <el-tag v-for="(f, i) in rowAttachmentList(detailRow)" :key="i" class="mr6 mb6" type="info">
- {{ f.name }}
- </el-tag>
- </template>
- <span v-else>鏃�</span>
- </el-descriptions-item>
- </el-descriptions>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="detailDialog.visible = false">鍏� 闂�</el-button>
- </div>
- </template>
- </el-dialog>
-
- <!-- 闄勪欢鍒楄〃 -->
- <el-dialog v-model="filesDialog.visible" title="闄勪欢" width="520px" append-to-body>
- <el-table v-if="rowAttachmentList(filesDialog.row).length" :data="rowAttachmentList(filesDialog.row)" border>
- <el-table-column type="index" label="搴忓彿" width="60" align="center" />
- <el-table-column prop="name" label="鏂囦欢鍚�" min-width="200" show-overflow-tooltip />
- <el-table-column label="鎿嶄綔" width="100" align="center">
- <template #default="{ row }">
- <el-button link type="primary" @click="mockDownload(row)">涓嬭浇</el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-empty v-else description="鏆傛棤闄勪欢" />
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="filesDialog.visible = false">鍏� 闂�</el-button>
- </div>
- </template>
- </el-dialog>
+ <ApprovalInstanceDetailDialog
+ v-model="detailDialog.visible"
+ title="鍔犵彮鐢宠璇︽儏"
+ :row="detailRow"
+ @edit="openEditFromDetail"
+ />
</div>
</template>
<script setup>
import { Search } from "@element-plus/icons-vue";
import dayjs from "dayjs";
-import { userListNoPageByTenantId } from "@/api/system/user.js";
-import { computed, getCurrentInstance, nextTick, onMounted, reactive, ref, watch } from "vue";
-import ApprovalTemplateBindDialog from "../../ApproveManage/approve-shared/components/ApprovalTemplateBindDialog.vue";
-import ApprovalTemplateFormSection from "../../ApproveManage/approve-shared/components/ApprovalTemplateFormSection.vue";
+import { ElMessage } from "element-plus";
+import { getCurrentInstance, onMounted, reactive, ref } from "vue";
import FormPayloadFields from "../../ApproveManage/approve-list/components/FormPayloadFields.vue";
+import ApprovalInstanceDetailDialog from "../../ApproveManage/approve-shared/components/ApprovalInstanceDetailDialog.vue";
+import ApprovalInstanceSubmitDialog from "../../ApproveManage/approve-shared/components/ApprovalInstanceSubmitDialog.vue";
+import ApprovalTemplateBindDialog from "../../ApproveManage/approve-shared/components/ApprovalTemplateBindDialog.vue";
+import { buildInstanceTableColumns } from "../../ApproveManage/approve-shared/approvalInstanceFormConfigTable.js";
import { APPROVAL_MODULE_KEYS } from "../../ApproveManage/approve-shared/approvalModuleRegistry.js";
-import {
- applyBindingToForm,
- attachmentDisplayName,
- buildFormPayloadRules,
- validateTemplateBinding,
-} from "../../ApproveManage/approve-shared/approvalTemplateBindingUtils.js";
+import { useApprovalInstanceModule } from "../../ApproveManage/approve-shared/useApprovalInstanceModule.js";
import { useFlowUserOptions } from "../../ApproveManage/approve-shared/useFlowUserOptions.js";
-import { SELECT_OPTION_SOURCE } from "../../ApproveManage/approve-template/selectOptionSource.js";
-/** 鍔犵彮绫诲瀷锛坴alue 涓庡悗绔榻愬崰浣嶏級 */
const OVERTIME_TYPE_OPTIONS = [
{ label: "宸ヤ綔鏃ュ姞鐝�", value: "weekday" },
{ label: "浼戞伅鏃ュ姞鐝�", value: "weekend" },
{ label: "娉曞畾鑺傚亣鏃ュ姞鐝�", value: "holiday" },
];
-function overtimeTypeLabel(v) {
- const hit = OVERTIME_TYPE_OPTIONS.find((x) => x.value === v);
- return hit?.label || "鈥�";
-}
-
-const createEmptyForm = () => ({
- id: undefined,
- applicantId: "",
- applicantNo: "",
- applicantName: "",
- overtimeType: "",
- overtimeDate: "",
- overtimeStartTime: "",
- overtimeEndTime: "",
- overtimeHours: null,
- overtimeReason: "",
- hasTemplateBinding: false,
- templateId: "",
- templateName: "",
- templateSnapshot: null,
- formFieldDefs: [],
- formPayload: {},
- flowNodes: [],
- templateAttachments: [],
- storageBlobDTOs: [],
-});
-
-const { proxy } = getCurrentInstance();
-
-function unwrapArray(payload) {
- if (Array.isArray(payload)) return payload;
- if (payload && Array.isArray(payload.data)) return payload.data;
- if (payload && Array.isArray(payload.rows)) return payload.rows;
- return [];
-}
-
-function userById(id) {
- if (id == null || id === "") return undefined;
- return allUsersCache.value.find((u) => String(u.userId ?? u.id) === String(id));
-}
-
-function applicantNoFromUser(u) {
- if (!u) return "";
- return (
- u.userName ??
- u.userCode ??
- u.jobNumber ??
- u.workNo ??
- (u.userId != null ? String(u.userId) : "")
- );
-}
-
-function isOvertimeHoursField(field) {
+function isOvertimeDurationField(field) {
const label = String(field?.label || "");
return label.includes("鍔犵彮鏃堕暱") || field?.key === "overtimeHours";
+}
+
+function displayTemplateFields(fields = []) {
+ return (fields || []).filter((f) => !isOvertimeDurationField(f));
}
function findOvertimeTimeTemplateField(fields = []) {
return (
fields.find((f) => f?.type === "datetimerange" && String(f?.label || "").includes("鍔犵彮鏃堕棿")) ||
- fields.find((f) => f?.type === "datetimerange" && f?.key === "dateRange") ||
fields.find((f) => f?.type === "datetimerange") ||
null
);
}
-function findApplicantTemplateField(fields = []) {
- return (
- fields.find((f) => String(f?.label || "").includes("鐢宠浜�")) ||
- fields.find((f) => f?.type === "select" && f?.optionSource === SELECT_OPTION_SOURCE.USER) ||
- null
- );
-}
-
-/** 浠庢ā鏉垮~鎶ラ」瑙f瀽鍔犵彮璧锋鏃堕棿 */
function resolveOvertimeTimeRange(payload, overtimeTimeField) {
if (!overtimeTimeField?.key) return { start: "", end: "" };
const val = payload?.[overtimeTimeField.key];
@@ -272,296 +127,94 @@
return { start: val[0] || "", end: val[1] || "" };
}
-/** 鎸夎捣姝㈡椂闂磋绠楀姞鐝椂闀匡紙灏忔椂锛屼繚鐣欎袱浣嶅皬鏁帮級 */
function computeOvertimeHours(startStr, endStr) {
if (!startStr || !endStr) return null;
const t0 = dayjs(startStr);
const t1 = dayjs(endStr);
if (!t0.isValid() || !t1.isValid() || !t1.isAfter(t0)) return null;
- const hours = t1.diff(t0, "millisecond") / (60 * 60 * 1000);
- return Math.round(hours * 100) / 100;
+ return Math.round((t1.diff(t0, "millisecond") / 3600000) * 100) / 100;
}
-function formatHours(v) {
- if (v == null || v === "") return "鈥�";
- return `${v} 灏忔椂`;
+function overtimeHoursDisplay(form) {
+ const field = findOvertimeTimeTemplateField(form.formFieldDefs);
+ const { start, end } = resolveOvertimeTimeRange(form.formPayload, field);
+ const h = computeOvertimeHours(start, end);
+ return h == null ? "" : String(h);
}
-function mapStorageBlobsToAttachmentList(blobs) {
- return (blobs || []).map((f) => ({
- name: attachmentDisplayName(f),
- url: f.url || f.downloadURL || f.previewURL || f.previewUrl,
- }));
-}
-
-function rowAttachmentList(row) {
- if (!row) return [];
- if (row.attachmentList?.length) return row.attachmentList;
- return mapStorageBlobsToAttachmentList(row.storageBlobDTOs);
-}
-
-function approvalResultLabel(v) {
- if (v === "approved") return "宸查�氳繃";
- if (v === "rejected") return "宸查┏鍥�";
- if (v === "cancelled") return "宸叉挙閿�";
- return "寰呭鎵�";
-}
-
-function sortedApprovalNodes(row) {
- const list = row?.approvalFlowNodes;
- if (!Array.isArray(list) || !list.length) return [];
- return [...list].sort((a, b) => (a.sortOrder ?? a.nodeOrder ?? 0) - (b.sortOrder ?? b.nodeOrder ?? 0));
-}
-
-function approvalNodeLabel(n) {
- const name = (n.approverName || "").trim();
- return name || "鏈�夋嫨瀹℃壒浜�";
-}
-
-/** 璇︽儏瀹℃壒娴佺▼锛氫紭鍏堟ā鏉� flowNodes锛屽吋瀹规棫鐗� approvalFlowNodes */
-function detailFlowSteps(row) {
- const nodes = row?.flowNodes;
- if (Array.isArray(nodes) && nodes.length) {
- return [...nodes]
- .sort((a, b) => (a.nodeOrder ?? 0) - (b.nodeOrder ?? 0))
- .map((n, i) => {
- const names = (n.approvers || [])
- .map((a) => (a.approverName || "").trim())
- .filter(Boolean)
- .join("銆�");
- return `${i + 1}. ${names || "鏈�夋嫨瀹℃壒浜�"}`;
- });
- }
- return sortedApprovalNodes(row).map((n, i) => `${i + 1}. ${approvalNodeLabel(n)}`);
-}
-
-function syncApplicantFromUser(uid) {
- const u = userById(uid);
- if (u) {
- form.applicantId = uid != null && uid !== "" ? uid : "";
- form.applicantName = u.nickName || u.userName || "";
- form.applicantNo = applicantNoFromUser(u);
- } else {
- form.applicantId = "";
- form.applicantName = "";
- form.applicantNo = "";
- }
-}
-
-const allUsersCache = ref([]);
-
-async function loadUserPool() {
- try {
- const res = await userListNoPageByTenantId();
- allUsersCache.value = unwrapArray(res);
- } catch {
- allUsersCache.value = [];
- }
-}
-
-const allRows = ref([]);
+const { proxy } = getCurrentInstance();
const searchForm = reactive({
applicantKeyword: "",
overtimeType: "",
});
-const tableLoading = ref(false);
-const page = reactive({
- current: 1,
- size: 10,
- total: 0,
+const mod = useApprovalInstanceModule({
+ moduleKey: APPROVAL_MODULE_KEYS.OVERTIME,
+ beforeSave: validateOvertimeBeforeSave,
});
-const filteredList = computed(() => {
- let list = [...allRows.value];
- const kw = (searchForm.applicantKeyword || "").trim().toLowerCase();
- if (kw) {
- list = list.filter((r) => {
- const name = (r.applicantName || "").toLowerCase();
- const no = (r.applicantNo || "").toLowerCase();
- return name.includes(kw) || no.includes(kw);
- });
- }
- if (searchForm.overtimeType) {
- list = list.filter((r) => r.overtimeType === searchForm.overtimeType);
- }
- return list.sort((a, b) => (String(a.createTime) < String(b.createTime) ? 1 : -1));
-});
+const {
+ tableData,
+ tableLoading,
+ page,
+ detailDialog,
+ detailRow,
+ submitDialog,
+ submitForm,
+ submitFormRef,
+ submitSaving,
+ isSubmitEdit,
+ activeTemplate,
+ submitFormFields,
+ submitFormRules,
+ submitDialogTitle,
+ templateBindVisible,
+ handleQuery,
+ initModuleList,
+ pagination,
+ openAddWithTemplate,
+ onTemplateBound,
+ onTemplateBindClosed,
+ openEditFromDetail,
+ submitInstanceForm,
+ buildTableActions,
+} = mod;
-watch(
- filteredList,
- (list) => {
- page.total = list.length;
- const maxPage = Math.max(1, Math.ceil(list.length / page.size) || 1);
- if (page.current > maxPage) {
- page.current = maxPage;
- }
- },
- { immediate: true }
-);
-
-const tableData = computed(() => {
- const list = filteredList.value;
- const start = (page.current - 1) * page.size;
- return list.slice(start, start + page.size);
-});
-
-const tableColumn = ref([
- { label: "鐢宠浜虹紪鍙�", prop: "applicantNo", width: 120 },
- { label: "鐢宠浜�", prop: "applicantName", minWidth: 100 },
- { label: "鍔犵彮鏃ユ湡", prop: "overtimeDate", width: 120 },
- { label: "鍔犵彮寮�濮嬫棩鏈�", prop: "overtimeStartTime", width: 170 },
- { label: "鍔犵彮缁撴潫鏃ユ湡", prop: "overtimeEndTime", width: 170 },
- {
- label: "鍔犵彮鏃堕暱",
- prop: "overtimeHours",
- width: 120,
- formatData: (v) => (v == null || v === "" ? "鈥�" : `${v} 灏忔椂`),
- },
- {
- label: "瀹℃壒缁撴灉",
- prop: "approvalResult",
- width: 110,
- dataType: "tag",
- formatData: (v) => approvalResultLabel(v),
- formatType: (v) => {
- if (v === "approved") return "success";
- if (v === "rejected") return "danger";
- if (v === "cancelled") return "info";
- return "warning";
- },
- },
- { label: "鍒涘缓鏃堕棿", prop: "createTime", width: 170 },
- {
- dataType: "action",
- label: "鎿嶄綔",
- align: "center",
- fixed: "right",
- width: 220,
- operation: [
- {
- name: "缂栬緫",
- type: "text",
- clickFun: (row) => openFormDialog("edit", row),
- },
- {
- name: "鏌ョ湅璇︽儏",
- type: "text",
- clickFun: (row) => openDetail(row),
- },
- {
- name: "闄勪欢",
- type: "text",
- clickFun: (row) => openFiles(row),
- },
- ],
- },
-]);
-
-const formDialog = reactive({
- visible: false,
- title: "",
- mode: "add",
-});
-const formRef = ref();
-const form = reactive(createEmptyForm());
-const templateBindVisible = ref(false);
-const pendingTemplateBinding = ref(null);
const { flowUserOptions, loadFlowUsers } = useFlowUserOptions();
-const overtimeTimeTemplateField = computed(() => findOvertimeTimeTemplateField(form.formFieldDefs));
-const applicantTemplateField = computed(() => findApplicantTemplateField(form.formFieldDefs));
-
-const templateDisplayFields = computed(() =>
- (form.formFieldDefs || []).filter((f) => !isOvertimeHoursField(f))
-);
-
-const overtimeHoursDisplay = computed(() => {
- const { start, end } = resolveOvertimeTimeRange(form.formPayload, overtimeTimeTemplateField.value);
- const h = computeOvertimeHours(start, end);
- return h == null ? "" : String(h);
-});
-
-const formRules = computed(() => buildFormPayloadRules(templateDisplayFields.value));
-
-watch(
- () => {
- const key = applicantTemplateField.value?.key;
- return key ? form.formPayload[key] : undefined;
- },
- async (uid) => {
- if (!applicantTemplateField.value) return;
- if (!allUsersCache.value.length) {
- await loadUserPool();
- }
- syncApplicantFromUser(uid);
+function validateOvertimeBeforeSave() {
+ const field = findOvertimeTimeTemplateField(submitForm.formFieldDefs);
+ const { start, end } = resolveOvertimeTimeRange(submitForm.formPayload, field);
+ if (computeOvertimeHours(start, end) == null) {
+ ElMessage.warning("璇锋鏌ユā鏉夸腑鐨勫姞鐝椂闂达紝缁撴潫鏃堕棿椤绘櫄浜庡紑濮嬫椂闂�");
+ throw new Error("invalid overtime time");
}
-);
+}
-watch(
- () => {
- const key = overtimeTimeTemplateField.value?.key;
- return key ? form.formPayload[key] : undefined;
- },
- () => {
- const { start, end } = resolveOvertimeTimeRange(form.formPayload, overtimeTimeTemplateField.value);
- form.overtimeStartTime = start;
- form.overtimeEndTime = end;
- form.overtimeHours = computeOvertimeHours(start, end);
- if (start) {
- form.overtimeDate = dayjs(start).format("YYYY-MM-DD");
- }
- },
- { deep: true }
-);
+const tableColumn = buildInstanceTableColumns(tableData, buildTableActions);
-const detailDialog = reactive({ visible: false });
-const detailRow = ref({});
-
-const filesDialog = reactive({ visible: false, row: null });
-const importInputRef = ref(null);
-
-function handleQuery() {
- page.current = 1;
- tableLoading.value = true;
- setTimeout(() => {
- tableLoading.value = false;
- }, 150);
+function onSearch() {
+ handleQuery(searchForm);
}
function resetSearch() {
searchForm.applicantKeyword = "";
searchForm.overtimeType = "";
- handleQuery();
+ onSearch();
}
-function pagination(obj) {
- page.current = obj.page;
- page.size = obj.limit;
+function onPagination(obj) {
+ pagination(obj, searchForm);
}
-function openDetail(row) {
- detailRow.value = { ...row };
- detailDialog.visible = true;
-}
-
-function openFiles(row) {
- filesDialog.row = row;
- filesDialog.visible = true;
-}
-
-function mockDownload(row) {
- const url = row.url || row.downloadURL || row.previewURL || row.previewUrl;
- if (url) {
- window.open(url, "_blank");
- return;
- }
- proxy?.$modal?.msgWarning?.("鏆傛棤涓嬭浇鍦板潃");
+async function onSubmit() {
+ const ok = await submitInstanceForm({ skipValidate: true });
+ if (ok) ElMessage.success(isSubmitEdit.value ? "淇敼鎴愬姛" : "鎻愪氦鎴愬姛");
}
function handleExport() {
- const data = filteredList.value;
+ const data = tableData.value;
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json;charset=utf-8" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
@@ -569,274 +222,12 @@
a.download = `鍔犵彮鐢宠瀵煎嚭_${dayjs().format("YYYYMMDDHHmmss")}.json`;
a.click();
URL.revokeObjectURL(url);
- proxy?.$modal?.msgSuccess?.(`宸插鍑� ${data.length} 鏉★紙褰撳墠绛涢�夌粨鏋滐紝JSON锛塦);
+ proxy?.$modal?.msgSuccess?.(`宸插鍑� ${data.length} 鏉★紙褰撳墠椤靛垪琛ㄦ暟鎹級`);
}
-function handleImportClick() {
- importInputRef.value?.click?.();
-}
-
-function normalizeImportedRow(raw, idx) {
- const id = raw.id != null && String(raw.id).length ? `imp_${String(raw.id)}_${idx}` : `imp_${Date.now()}_${idx}`;
- const hours =
- raw.overtimeHours != null && raw.overtimeHours !== ""
- ? Number(raw.overtimeHours)
- : computeOvertimeHours(raw.overtimeStartTime, raw.overtimeEndTime);
- return {
- id,
- applicantId: raw.applicantId != null ? String(raw.applicantId) : `imp_user_${idx}`,
- applicantNo: raw.applicantNo ?? "",
- applicantName: raw.applicantName ?? "鏈煡",
- overtimeType: raw.overtimeType || "weekday",
- overtimeDate: raw.overtimeDate ?? "",
- overtimeStartTime: raw.overtimeStartTime ?? "",
- overtimeEndTime: raw.overtimeEndTime ?? "",
- overtimeHours: hours == null || Number.isNaN(hours) ? 0 : Math.round(hours * 100) / 100,
- overtimeReason: raw.overtimeReason ?? "",
- hasTemplateBinding: false,
- approvalFlowNodes: Array.isArray(raw.approvalFlowNodes) && raw.approvalFlowNodes.length
- ? raw.approvalFlowNodes.map((n) => ({ ...n }))
- : [],
- approvalResult: raw.approvalResult && ["pending", "approved", "rejected", "cancelled"].includes(raw.approvalResult)
- ? raw.approvalResult
- : "pending",
- attachmentList: Array.isArray(raw.attachmentList) ? raw.attachmentList : [],
- createTime: raw.createTime || dayjs().format("YYYY-MM-DD HH:mm:ss"),
- };
-}
-
-function onImportFile(e) {
- const input = e.target;
- const file = input.files?.[0];
- input.value = "";
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => {
- try {
- const text = String(reader.result || "");
- const parsed = JSON.parse(text);
- const arr = Array.isArray(parsed) ? parsed : parsed?.rows || parsed?.data;
- if (!Array.isArray(arr) || !arr.length) {
- proxy?.$modal?.msgWarning?.("瀵煎叆鏂囦欢鏍煎紡涓嶆纭紝闇�涓哄姞鐝敵璇峰璞℃暟缁� JSON");
- return;
- }
- let n = 0;
- for (let i = 0; i < arr.length; i++) {
- allRows.value.unshift(normalizeImportedRow(arr[i], i));
- n++;
- }
- proxy?.$modal?.msgSuccess?.(`鎴愬姛瀵煎叆 ${n} 鏉★紙鏈湴鍚堝苟锛塦);
- handleQuery();
- } catch {
- proxy?.$modal?.msgError?.("瑙f瀽澶辫触锛岃浣跨敤瀵煎嚭鏂囦欢鎴栫害瀹� JSON 缁撴瀯");
- }
- };
- reader.readAsText(file, "utf-8");
-}
-
-function openAddWithTemplate() {
- formDialog.visible = false;
- pendingTemplateBinding.value = null;
- templateBindVisible.value = true;
-}
-
-function onTemplateBound(binding) {
- pendingTemplateBinding.value = binding;
-}
-
-async function onTemplateBindClosed() {
- const binding = pendingTemplateBinding.value;
- if (!binding) return;
- pendingTemplateBinding.value = null;
- await openFormWithBinding(binding);
-}
-
-async function openFormWithBinding(binding) {
- Object.assign(form, createEmptyForm());
- applyBindingToForm(form, binding);
- form.hasTemplateBinding = true;
- formDialog.mode = "add";
- formDialog.title = "鏂板鍔犵彮鐢宠";
- await Promise.all([loadUserPool(), loadFlowUsers()]);
- const applicantKey = applicantTemplateField.value?.key;
- if (applicantKey && form.formPayload[applicantKey]) {
- syncApplicantFromUser(form.formPayload[applicantKey]);
- }
- const { start, end } = resolveOvertimeTimeRange(form.formPayload, overtimeTimeTemplateField.value);
- form.overtimeStartTime = start;
- form.overtimeEndTime = end;
- form.overtimeHours = computeOvertimeHours(start, end);
- if (start) form.overtimeDate = dayjs(start).format("YYYY-MM-DD");
- formDialog.visible = true;
- nextTick(() => formRef.value?.clearValidate?.());
-}
-
-function reopenTemplateBind() {
- formDialog.visible = false;
- pendingTemplateBinding.value = null;
- templateBindVisible.value = true;
-}
-
-async function openFormDialog(mode, row) {
- if (mode === "edit" && row && !row.hasTemplateBinding) {
- proxy?.$modal?.msgWarning?.("璇ヨ褰曚负鏃х増鏁版嵁锛岃閲嶆柊閫氳繃妯℃澘鍙戣捣鐢宠");
- return;
- }
- formDialog.mode = mode;
- formDialog.title = "缂栬緫鍔犵彮鐢宠";
- Object.assign(form, createEmptyForm());
- if (mode === "edit" && row) {
- Object.assign(form, {
- id: row.id,
- applicantId: row.applicantId,
- applicantNo: row.applicantNo,
- applicantName: row.applicantName,
- overtimeType: row.overtimeType,
- overtimeDate: row.overtimeDate,
- overtimeStartTime: row.overtimeStartTime,
- overtimeEndTime: row.overtimeEndTime,
- overtimeHours: row.overtimeHours,
- overtimeReason: row.overtimeReason,
- hasTemplateBinding: true,
- templateId: row.templateId,
- templateName: row.templateName,
- templateSnapshot: row.templateSnapshot,
- formFieldDefs: row.formFieldDefs || [],
- formPayload: JSON.parse(JSON.stringify(row.formPayload || {})),
- flowNodes: JSON.parse(JSON.stringify(row.flowNodes || [])),
- templateAttachments: JSON.parse(JSON.stringify(row.templateAttachments || [])),
- storageBlobDTOs: JSON.parse(JSON.stringify(row.storageBlobDTOs || [])),
- });
- await loadUserPool();
- const applicantKey = applicantTemplateField.value?.key;
- if (applicantKey) {
- syncApplicantFromUser(form.formPayload[applicantKey]);
- }
- loadFlowUsers();
- }
- formDialog.visible = true;
- nextTick(() => formRef.value?.clearValidate?.());
-}
-
-function onFormClosed() {
- formRef.value?.resetFields?.();
-}
-
-/** 浠庢ā鏉垮~鎶ラ」鍚屾鍒楄〃灞曠ず瀛楁 */
-function syncOvertimeFieldsFromPayload() {
- const defs = form.formFieldDefs || [];
- const payload = form.formPayload || {};
- const overtimeTimeField = findOvertimeTimeTemplateField(defs);
-
- for (const f of defs) {
- const label = String(f.label || "");
- const val = payload[f.key];
-
- if (label.includes("鐢宠浜�") && !label.includes("鏃ユ湡") && !label.includes("鏃堕棿")) {
- if (val != null && val !== "") {
- form.applicantId = val;
- const u = userById(val);
- if (u) {
- form.applicantName = u.nickName || u.userName || "";
- form.applicantNo = applicantNoFromUser(u);
- }
- }
- }
- if ((label.includes("鍔犵彮绫诲瀷") || f.key === "overtimeType") && f.type === "select") {
- form.overtimeType = val != null && val !== "" ? val : "";
- }
- if (label.includes("鍔犵彮鏃ユ湡") && f.type === "date") {
- form.overtimeDate = val || "";
- }
- if (label.includes("浜嬬敱") || f.key === "summary" || label.includes("鍔犵彮浜嬬敱")) {
- form.overtimeReason = val != null ? String(val) : "";
- }
- }
-
- const { start, end } = resolveOvertimeTimeRange(payload, overtimeTimeField);
- form.overtimeStartTime = start;
- form.overtimeEndTime = end;
- form.overtimeHours = computeOvertimeHours(start, end);
- if (!form.overtimeDate && start) {
- form.overtimeDate = dayjs(start).format("YYYY-MM-DD");
- }
-}
-
-async function submitForm() {
- try {
- await formRef.value?.validate?.();
- } catch {
- return;
- }
- const flowCheck = validateTemplateBinding({ flowNodes: form.flowNodes });
- if (!flowCheck.ok) {
- proxy?.$modal?.msgWarning?.(flowCheck.message || "璇峰畬鍠勫鎵规祦绋�");
- return;
- }
- form.flowNodes = flowCheck.nodes;
-
- const applicantKey = applicantTemplateField.value?.key;
- if (applicantKey) {
- syncApplicantFromUser(form.formPayload[applicantKey]);
- }
- syncOvertimeFieldsFromPayload();
-
- if (form.overtimeHours == null) {
- proxy?.$modal?.msgWarning?.("璇锋鏌ユā鏉夸腑鐨勫姞鐝椂闂达紝缁撴潫鏃堕棿椤绘櫄浜庡紑濮嬫椂闂�");
- return;
- }
-
- const attachmentList = mapStorageBlobsToAttachmentList(form.storageBlobDTOs);
- const payload = {
- applicantId: form.applicantId,
- applicantNo: form.applicantNo,
- applicantName: form.applicantName,
- overtimeType: form.overtimeType,
- overtimeDate: form.overtimeDate,
- overtimeStartTime: form.overtimeStartTime,
- overtimeEndTime: form.overtimeEndTime,
- overtimeHours: form.overtimeHours,
- overtimeReason: form.overtimeReason,
- hasTemplateBinding: true,
- templateId: form.templateId,
- templateName: form.templateName,
- templateSnapshot: form.templateSnapshot,
- formFieldDefs: form.formFieldDefs,
- formPayload: JSON.parse(JSON.stringify(form.formPayload || {})),
- flowNodes: JSON.parse(JSON.stringify(form.flowNodes || [])),
- templateAttachments: JSON.parse(JSON.stringify(form.templateAttachments || [])),
- storageBlobDTOs: JSON.parse(JSON.stringify(form.storageBlobDTOs || [])),
- attachmentList,
- };
- if (formDialog.mode === "add") {
- const id = `local_${Date.now()}`;
- allRows.value.unshift({
- id,
- ...payload,
- approvalResult: "pending",
- createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
- });
- proxy?.$modal?.msgSuccess?.("鏂板鎴愬姛");
- } else {
- const idx = allRows.value.findIndex((r) => r.id === form.id);
- if (idx !== -1) {
- const prev = allRows.value[idx];
- allRows.value[idx] = {
- ...prev,
- id: form.id,
- ...payload,
- approvalResult: prev.approvalResult ?? "pending",
- createTime: prev.createTime ?? dayjs().format("YYYY-MM-DD HH:mm:ss"),
- };
- }
- proxy?.$modal?.msgSuccess?.("淇濆瓨鎴愬姛");
- }
- formDialog.visible = false;
- handleQuery();
-}
-
-onMounted(() => {
+onMounted(async () => {
loadFlowUsers();
+ await initModuleList(searchForm);
});
</script>
@@ -854,59 +245,10 @@
.search_actions {
display: flex;
flex-wrap: wrap;
- align-items: center;
gap: 8px;
}
.search_title {
font-size: 14px;
color: var(--el-text-color-regular);
-}
-.sr-only-input {
- position: absolute;
- width: 1px;
- height: 1px;
- padding: 0;
- margin: -1px;
- overflow: hidden;
- clip: rect(0, 0, 0, 0);
- white-space: nowrap;
- border: 0;
-}
-.mr6 {
- margin-right: 6px;
-}
-.mb6 {
- margin-bottom: 6px;
-}
-.overtime-apply-form :deep(.el-row) {
- margin-bottom: 0;
-}
-.overtime-apply-form :deep(.el-form-item) {
- margin-bottom: 18px;
-}
-.template-name {
- font-weight: 600;
- color: var(--el-text-color-primary);
-}
-.ml12 {
- margin-left: 12px;
-}
-.overtime-apply-form-dialog :deep(.el-dialog__body) {
- padding-top: 12px;
-}
-.detail-flow-chain {
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- gap: 6px 8px;
- line-height: 1.6;
-}
-.detail-flow-step {
- font-size: 14px;
- color: var(--el-text-color-primary);
-}
-.detail-flow-sep {
- color: var(--el-text-color-secondary);
- font-size: 13px;
}
</style>
--
Gitblit v1.9.3