From 01c045e6ebc486e2a050b1739fad075b7f424254 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期一, 18 五月 2026 14:47:50 +0800
Subject: [PATCH] 优化设备保养:在新增和编辑保养计划时,清除本地存储中的repairId,确保数据一致性。
---
src/pages/equipmentManagement/upkeep/add.vue | 92 ++++++++++++++++++++++++++++++---------------
1 files changed, 61 insertions(+), 31 deletions(-)
diff --git a/src/pages/equipmentManagement/upkeep/add.vue b/src/pages/equipmentManagement/upkeep/add.vue
index c0e7e34..ff5339b 100644
--- a/src/pages/equipmentManagement/upkeep/add.vue
+++ b/src/pages/equipmentManagement/upkeep/add.vue
@@ -40,6 +40,22 @@
<u-icon name="arrow-right" @click="showDatePicker" />
</template>
</u-form-item>
+
+ <u-form-item label="淇濆吇浜�" prop="maintenancePerson" border-bottom>
+ <u-input
+ v-model="form.maintenancePerson"
+ placeholder="璇疯緭鍏ヤ繚鍏讳汉"
+ clearable
+ />
+ </u-form-item>
+
+ <u-form-item label="淇濆吇椤圭洰" prop="maintenanceItems" border-bottom>
+ <u-input
+ v-model="form.maintenanceItems"
+ placeholder="璇疯緭鍏ヤ繚鍏婚」鐩�"
+ clearable
+ />
+ </u-form-item>
<!-- 鎻愪氦鎸夐挳 -->
<view class="footer-btns">
@@ -69,12 +85,15 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue';
-import { onShow } from '@dcloudio/uni-app';
+import { onShow, onUnload } from '@dcloudio/uni-app';
import PageHeader from '@/components/PageHeader.vue';
import { getDeviceLedger } from '@/api/equipmentManagement/ledger';
import { addUpkeep, editUpkeep, getUpkeepById } from '@/api/equipmentManagement/upkeep';
+import useUserStore from '@/store/modules/user';
import dayjs from "dayjs";
import { formatDateToYMD } from '@/utils/ruoyi';
+
+const userStore = useUserStore();
defineOptions({
name: "璁惧淇濆吇璁″垝琛ㄥ崟",
@@ -85,6 +104,13 @@
icon: 'none'
})
}
+
+const normalizeId = (raw) => {
+ if (raw === null || raw === undefined) return undefined;
+ const val = String(raw).trim();
+ if (!val || val === 'undefined' || val === 'null') return undefined;
+ return val;
+};
// 琛ㄥ崟寮曠敤
const formRef = ref(null);
@@ -122,6 +148,8 @@
deviceLedgerId: undefined, // 璁惧ID
deviceModel: undefined, // 瑙勬牸鍨嬪彿
maintenancePlanTime: dayjs().format("YYYY-MM-DD"), // 璁″垝淇濆吇鏃ユ湡
+ maintenancePerson: userStore.nickName || undefined, // 淇濆吇浜�
+ maintenanceItems: undefined, // 淇濆吇椤圭洰
});
// 鍔犺浇璁惧鍒楄〃
@@ -144,6 +172,8 @@
form.value.deviceLedgerId = data.deviceLedgerId;
form.value.deviceModel = data.deviceModel;
form.value.maintenancePlanTime = dayjs(data.maintenancePlanTime).format("YYYY-MM-DD");
+ form.value.maintenancePerson = data.maintenancePerson;
+ form.value.maintenanceItems = data.maintenanceItems || data.maintenanceLocation;
// 璁剧疆璁惧鍚嶇О鏄剧ず
const device = deviceOptions.value.find(item => item.id === data.deviceLedgerId);
if (device) {
@@ -187,24 +217,25 @@
}
isScanning.value = true;
- showToast('鎵爜鎴愬姛锛�3绉掑悗鑷姩濉厖璁惧淇℃伅');
+ showToast('鎵爜鎴愬姛');
// 3绉掑悗澶勭悊鎵爜缁撴灉
scanTimer.value = setTimeout(() => {
processScanResult(scanResult);
isScanning.value = false;
- }, 3000);
+ }, 1000);
};
-
+function getDeviceIdByRegExp(url) {
+ // 鍖归厤deviceId=鍚庨潰鐨勬暟瀛�
+ const reg = /deviceId=(\d+)/;
+ const match = url.match(reg);
+ // 濡傛灉鍖归厤鍒扮粨鏋滐紝杩斿洖鏁板瓧绫诲瀷锛屽惁鍒欒繑鍥瀗ull
+ return match ? Number(match[1]) : null;
+}
// 澶勭悊鎵爜缁撴灉骞跺尮閰嶈澶�
const processScanResult = (scanResult) => {
- // 鍦ㄨ澶囧垪琛ㄤ腑鏌ユ壘鍖归厤鐨勮澶�
- // 鍋囪浜岀淮鐮佸唴瀹规槸璁惧鍚嶇О鎴栬澶囩紪鍙�
- const matchedDevice = deviceOptions.value.find(device =>
- device.deviceName === scanResult ||
- device.deviceCode === scanResult ||
- device.id.toString() === scanResult
- );
+ const deviceId = getDeviceIdByRegExp(scanResult);
+ const matchedDevice = deviceOptions.value.find(item => item.id == deviceId);
if (matchedDevice) {
// 鎵惧埌鍖归厤鐨勮澶囷紝鑷姩濉厖
@@ -288,6 +319,7 @@
if (code == 200) {
showToast(`${id ? "缂栬緫" : "鏂板"}璁″垝鎴愬姛`);
setTimeout(() => {
+ uni.removeStorageSync('repairId');
uni.navigateBack();
}, 1500);
} else {
@@ -301,32 +333,30 @@
// 杩斿洖涓婁竴椤�
const goBack = () => {
+ // 娓呴櫎瀛樺偍鐨刬d
+ uni.removeStorageSync('repairId');
uni.navigateBack();
-};
-
-// 鑾峰彇椤甸潰鍙傛暟
-const getPageParams = () => {
- const pages = getCurrentPages();
- const currentPage = pages[pages.length - 1];
- const options = currentPage.options;
-
- // 鏍规嵁鏄惁鏈塱d鍙傛暟鏉ュ垽鏂槸鏂板杩樻槸缂栬緫
- if (options.id) {
- // 缂栬緫妯″紡锛岃幏鍙栬鎯�
- loadForm(options.id);
- } else {
- // 鏂板妯″紡
- loadForm();
- }
};
// 鑾峰彇椤甸潰ID
const getPageId = () => {
- const pages = getCurrentPages();
- const currentPage = pages[pages.length - 1];
- const options = currentPage.options;
- return options.id;
+ return normalizeId(uni.getStorageSync('repairId'));
};
+
+// 鑾峰彇椤甸潰鍙傛暟
+const getPageParams = () => {
+ const id = getPageId();
+ if (id) {
+ loadForm(id);
+ } else {
+ operationType.value = 'add';
+ loadForm();
+ }
+};
+
+onUnload(() => {
+ uni.removeStorageSync('repairId');
+});
</script>
<style scoped lang="scss">
--
Gitblit v1.9.3