From df1406d0f571972d033dffd6a93fb4b94febeb56 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 24 六月 2025 16:46:44 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- src/views/production/components/useCoalData.js | 152 +++++++++++++++++++++++++------------------------- 1 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/views/production/components/useCoalData.js b/src/views/production/components/useCoalData.js index 37b2245..9a86b81 100644 --- a/src/views/production/components/useCoalData.js +++ b/src/views/production/components/useCoalData.js @@ -2,9 +2,9 @@ * 鐓ょ鏁版嵁绠$悊缁勫悎寮忓嚱鏁� * 鎻愪緵鐓ょ鏁版嵁鐨勮幏鍙栥�佺紦瀛樸�佽浆鎹㈢瓑鍔熻兘 */ -import { ref, computed, watch } from 'vue'; -import { getCoalInfoList } from "@/api/production"; -import { ElMessage } from 'element-plus'; +import {ref, computed, watch} from 'vue'; +import {getCoalInfoList} from "@/api/production"; +import {ElMessage} from 'element-plus'; // 鍏ㄥ眬鐓ょ鏁版嵁缂撳瓨 const coalData = ref([]); @@ -12,85 +12,85 @@ const isLoaded = ref(false); export function useCoalData() { - - // 鑾峰彇鐓ょ鏁版嵁 - const getCoalData = async (forceRefresh = false) => { - if (isLoaded.value && !forceRefresh) { - return coalData.value; - } - if (isLoading.value) { - // 濡傛灉姝e湪鍔犺浇锛岀瓑寰呭姞杞藉畬鎴� - return new Promise((resolve) => { - const unwatch = watch(isLoading, (loading) => { - if (!loading) { - unwatch(); - resolve(coalData.value); - } - }); - }); - } + // 鑾峰彇鐓ょ鏁版嵁 + const getCoalData = async (forceRefresh = false) => { + if (isLoaded.value && !forceRefresh) { + return coalData.value; + } - isLoading.value = true; - try { - const res = await getCoalInfoList(); - if (res.code === 200) { - coalData.value = res.data; - isLoaded.value = true; - return coalData.value; - } else { - ElMessage.error('鑾峰彇鐓ょ鏁版嵁澶辫触'); - return []; - } - } catch (error) { - ElMessage.error('鑾峰彇鐓ょ鏁版嵁澶辫触'); - console.error('鐓ょ鏁版嵁鑾峰彇閿欒:', error); - return []; - } finally { - isLoading.value = false; - } - }; + if (isLoading.value) { + // 濡傛灉姝e湪鍔犺浇锛岀瓑寰呭姞杞藉畬鎴� + return new Promise((resolve) => { + const unwatch = watch(isLoading, (loading) => { + if (!loading) { + unwatch(); + resolve(coalData.value); + } + }); + }); + } - // 鏍规嵁ID鑾峰彇鐓ょ鍚嶇О - const getCoalNameById = (id) => { - if (!id || coalData.value.length === 0) return id; - const coal = coalData.value.find(item => item.id == id); - return coal ? coal.coal : id; - }; + isLoading.value = true; + try { + const res = await getCoalInfoList(); + if (res.code === 200) { + coalData.value = res.data; + isLoaded.value = true; + return coalData.value; + } else { + ElMessage.error('鑾峰彇鐓ょ鏁版嵁澶辫触'); + return []; + } + } catch (error) { + ElMessage.error('鑾峰彇鐓ょ鏁版嵁澶辫触'); + console.error('鐓ょ鏁版嵁鑾峰彇閿欒:', error); + return []; + } finally { + isLoading.value = false; + } + }; - // 鏍规嵁鍚嶇О鑾峰彇鐓ょID - const getCoalIdByName = (name) => { - if (!name || coalData.value.length === 0) return ''; - const coal = coalData.value.find(item => item.coal === name); - return coal ? coal.id : ''; - }; + // 鏍规嵁ID鑾峰彇鐓ょ鍚嶇О + const getCoalNameById = (id) => { + if (!id || coalData.value.length === 0) return id; + const coal = coalData.value.find(item => item.id == id); + return coal ? coal.coal : id; + }; - // 鐢熸垚涓嬫媺閫夐」 - const coalOptions = computed(() => { - return coalData.value.map(item => ({ - label: item.coal, - value: item.coal, - key: item.id - })); - }); + // 鏍规嵁鍚嶇О鑾峰彇鐓ょID + const getCoalIdByName = (name) => { + if (!name || coalData.value.length === 0) return ''; + const coal = coalData.value.find(item => item.coal === name); + return coal ? coal.id : ''; + }; - // 鐢熸垚key-value鏄犲皠 - const coalMap = computed(() => { - const map = {}; - coalData.value.forEach(item => { - map[item.id] = item.coal; + // 鐢熸垚涓嬫媺閫夐」 + const coalOptions = computed(() => { + return coalData.value.map(item => ({ + label: item.coal, + value: item.coal, + key: item.id + })); }); - return map; - }); - return { - coalData: computed(() => coalData.value), - coalOptions, - coalMap, - isLoading: computed(() => isLoading.value), - isLoaded: computed(() => isLoaded.value), - getCoalData, - getCoalNameById, - getCoalIdByName - }; + // 鐢熸垚key-value鏄犲皠 + const coalMap = computed(() => { + const map = {}; + coalData.value.forEach(item => { + map[item.id] = item.coal; + }); + return map; + }); + + return { + coalData: computed(() => coalData.value), + coalOptions, + coalMap, + isLoading: computed(() => isLoading.value), + isLoaded: computed(() => isLoaded.value), + getCoalData, + getCoalNameById, + getCoalIdByName + }; } -- Gitblit v1.9.3