记录时间:2024-02-27
一、useDataStore模块实现
store/useDataStore.ts
import { defineStore } from 'pinia' import { DICT_PAGE, DICT_COMMON, DICT_DEVICE, DICT_SYSTEM, DICT_STATIC, DICT_NULL, DICT_CONFIG, DICT_OUT } from '@/const'export const useDataStore = defineStore('data', { state: () => ({ dict: { // 版本信息 version: '', // 版本数据 versionData: {},
// 终端信息 terminalIp: '', operatorId: '', terminal: {}, deviceList: [],
// 流程信息 flowKey: '', flow: {}, linkFlowKey: '', linkFlowPage: '', businessTrace: '', tradeId: '',
// 参数信息 page: {}, common: {}, device: {}, system: {}, staticValue: {}, nullValue: {}, config: {}, out: {},
// 页面信息 msg: '', error: '', voice: '',
// 凭条信息 receiptList: [],
// 前台管理信息 manage: {} },
// 加载和标志位 DataDictPageLoadFlag: false, FrontManageFlag: false, BankSignInFlag: false, NetOnlineFlag: false,
// 页面目录 BasePageDir: null, BizPageDir: null,
// 医保签到标志 YBSignNo: null, YBSignDate: null,
// 打印机纸张索引列表 ReceiptPrinterPaperIndexList: [0], LabelPrinterPaperIndexList: [0], DocumentPrinterPaperIndexList: [0, 1] }), actions: { // 设置版本信息 setVersion(version: string) { this.dict.version = version },
// 设置版本数据 setVersionData(key: string, value: any) { if (key && this.dict.versionData) { this.dict.versionData[key] = value } },
// 设置终端Ip setTerminalIp(terminalIp: string) { this.dict.terminalIp = terminalIp },
// 设置操作员 setOperatorId(operatorId: string) { this.dict.operatorId = operatorId },
// 设置终端信息 setTerminal(terminal: any) { this.dict.terminal = terminal },
// 设置设备列表 setDeviceList(deviceList: any) { this.dict.deviceList = deviceList },
// 设置流程键 setFlowKey(flowKey: string) { this.dict.flowKey = flowKey },
// 设置流程信息 setFlow(flow: any) { this.dict.flow = flow },
// 设置链接流程键 setLinkFlowKey(linkFlowKey: string) { this.dict.linkFlowKey = linkFlowKey },
// 设置链接流程页 setLinkFlowPage(linkFlowPage: any) { this.dict.linkFlowPage = linkFlowPage },
// 设置业务流程 setBusinessTrace(businessTrace: any) { this.dict.businessTrace = businessTrace },
// 设置交易ID setTradeId(tradeId: string) { this.dict.tradeId = tradeId },
// 设置参数信息 syncData(dictType: string, key: string, value: any) { const dictMap = { [DICT_PAGE]: this.dict.page, [DICT_COMMON]: this.dict.common, [DICT_DEVICE]: this.dict.device, [DICT_SYSTEM]: this.dict.system, [DICT_STATIC]: this.dict.staticValue, [DICT_NULL]: this.dict.nullValue, [DICT_CONFIG]: this.dict.config, [DICT_OUT]: this.dict.out }
if (key && dictMap[dictType]) { dictMap[dictType][key] = value } else { console.warn(`Unknown dictType: ${dictType} or invalid key: ${key}`) } },
// 设置消息信息 setMsg(msg: string) { this.dict.msg = msg },
// 设置错误信息 setError(error: string) { this.dict.error = error },
// 设置错误信息(未定义流程) setErrorUndefinedFlow(flowKey: string) { this.dict.error = `流程[${flowKey}]未定义。` },
// 设置错误信息(未定义流水) setErrorUndefinedTrace(adapterTrace: string) { this.dict.error = `交易流水[${adapterTrace}]未定义。` },
// 设置语音信息 setVoice(voice: string) { this.dict.voice = voice },
// 设置凭条信息 setReceiptList(receiptList: any) { this.dict.receiptList = receiptList },
// 设置前台管理信息 setManage(key: string, value: any) { if (key && this.dict.manage) { this.dict.manage[key] = value } } }, getters: { // 获取版本信息 getVersion: (state) => state.dict.version, // 获取版本数据 getversionData: (state) => state.dict.versionData, // 获取终端Ip getTerminalIp: (state) => state.dict.terminalIp, // 获取操作员 getOperatorId: (state) => state.dict.operatorId, // 获取终端信息 getTerminal: (state) => state.dict.terminal, // 获取设备列表 getDeviceList: (state) => state.dict.deviceList, // 获取流程键 getFlowKey: (state) => state.dict.flowKey, // 获取流程信息 getFlow: (state) => state.dict.flow, // 获取链接流程键 getLinkFlowKey: (state) => state.dict.linkFlowKey, // 获取链接流程页 getLinkFlowPage: (state) => state.dict.linkFlowPage, // 获取业务流程 getBusinessTrace: (state) => state.dict.businessTrace, // 获取交易ID getTradeId: (state) => state.dict.tradeId, // 获取参数信息 getPage: (state) => state.dict.page, getCommon: (state) => state.dict.common, getDevice: (state) => state.dict.device, getSystem: (state) => state.dict.system, getStatic: (state) => state.dict.staticValue, getNull: (state) => state.dict.nullValue, getConfig: (state) => state.dict.config, getOut: (state) => state.dict.out, // 获取消息信息 getMsg: (state) => state.dict.msg, // 获取错误信息 getError: (state) => state.dict.error, // 获取语音信息 getVoice: (state) => state.dict.voice, // 获取凭条信息 getReceiptList: (state) => state.dict.receiptList, // 获取前台管理信息 getManage: (state) => state.dict.manage } })
二、调用示例
test-page-use-data-store.vue <script setup lang="ts"> import { DICT_SYSTEM } from '@/const' import { useDataStore } from '@/store/useDataStore'const dataStore = useDataStore() dataStore.setVersion('1.0.0') dataStore.syncData(DICT_SYSTEM, 'test', '123')
</script>
<template> <div> <p> <button @click="dataStore.setVersion('1.0.0')">setVersion('1.0.0')</button> <button @click="dataStore.setVersion('2.0.0')">setVersion('2.0.0')</button> </p> <p>version: {{ dataStore.getVersion }}</p> <p>system: {{ dataStore.getSystem }}</p> </div> </template>
<style scoped></style>
三、运行测试
翻译
搜索
复制
<iframe></iframe> 标签:设置,web,string,ssts,hospital,state,DICT,key,dict From: https://www.cnblogs.com/lizhigang/p/18038799