/** 此数据源跟表列不一致,(后端接口重复使用因逻辑复杂, 经商定不动后端接口, 设置此数据源) 适用于消息 */ /** 抽取公用代码更加复杂模糊-暂存数据源 */ import { listDemo, updateDemo } from '@/api/WarningList/index'; import { defineStore } from 'pinia'; import { ref, computed } from 'vue'; import { any } from 'vue-types'; export const useWarningListStore = defineStore('warningListStore', () => { // --- State (状态) --- const warningList = ref(); const warningListTotal = ref(0); // --- Getters (计算属性) --- // --- Actions (动作) --- async function getWarningList(query?: any) { try { const response = await listDemo({ ...query // deviceId, // status: 0, // pageNum: 1, // pageSize: 10 }); warningList.value = response.data; warningListTotal.value = response.data.total || 0; } catch (error) { console.error('获取消息列表失败', error); } } async function handleAction(ids: string | number | Array) { try { await updateDemo(ids); } catch (error) { console.error('处理告警失败', error); } } // 核心点:必须把需要暴露出去的变量和方法 return 出去! return { warningList, warningListTotal, getWarningList, handleAction }; });