首页 > 其他分享 >ssts-hospital-web-master项目实战记录二十九:项目迁移-Hook实现(useDictStore)

ssts-hospital-web-master项目实战记录二十九:项目迁移-Hook实现(useDictStore)

时间:2024-02-28 16:37:41浏览次数:21  
标签:web const useDictStore ssts 获取 state dict key DICT

记录时间:2024-02-28

一、useDictStore模块实现

const/index.ts

// 常量 const DICT_VERSIONDATA = 'versionData' const DICT_PAGE = 'page' const DICT_COMMON = 'common' const DICT_DEVICE = 'device' const DICT_SYSTEM = 'system' const DICT_STATIC = 'static' const DICT_NULL = 'null' const DICT_CONFIG = 'config' const DICT_OUT = 'out' const DICT_MANAGE = 'manage'
export {   DICT_VERSIONDATA,   DICT_PAGE,   DICT_COMMON,   DICT_DEVICE,   DICT_SYSTEM,   DICT_STATIC,   DICT_NULL,   DICT_CONFIG,   DICT_OUT,   DICT_MANAGE }  

store/useDictStore.ts

import { defineStore } from 'pinia' import { Dict } from '@/types/dict' import {   DICT_VERSIONDATA,   DICT_PAGE,   DICT_COMMON,   DICT_DEVICE,   DICT_SYSTEM,   DICT_STATIC,   DICT_NULL,   DICT_CONFIG,   DICT_OUT,   DICT_MANAGE } from '@/const' type DictKey = keyof Dict
export const useDataStore = defineStore('data', {   state: () => ({     dict: {} as Dict // 使用类型断言初始化,现在这是安全的,因为所有属性都是可选的   }),   actions: {     // 初始化字典     initDict() {       this.dict = {         version: '',         versionData: {},         terminal: {},         operatorId: '',         terminalIp: '',         deviceList: [],         flowKey: '',         flow: {},         linkFlowKey: '',         linkFlowPage: '',         tradeId: '',         page: {},         common: {},         device: {},         system: {},         staticValue: {},         nullValue: {},         config: {},         out: {},         msg: '',         error: '',         voice: '',         receiptList: [],         manage: {},         DataDictPageLoadFlag: false,         FrontManageFlag: false,         BankSignInFlag: false,         NetOnlineFlag: true,         BasePageDir: '',         BizPageDir: '',         YBSignNo: '',         YBSignDate: '',         ReceiptPrinterPaperIndexList: [],         LabelPrinterPaperIndexList: [],         DocumentPrinterPaperIndexList: []       }     },
    // 通用设置方法     setDictValue(key: DictKey, value: any) {       if (Object.prototype.hasOwnProperty.call(this.dict, key)) {         this.dict[key] = value       } else {         console.warn(`Unknown key: ${key}`)       }     },
    // 针对特定字典类型的设置方法     syncData(dictType: string, key: string, value: any) {       const dictMap: { [key: string]: any } = {         // 注意:这里需要确保dict中的属性与DICT_*常量对应         [DICT_VERSIONDATA]: this.dict.versionData,         [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,         [DICT_MANAGE]: this.dict.manage       }
      const targetDict = dictMap[dictType]       if (targetDict && key) {         targetDict[key] = value       } else {         console.warn(`Unknown dictType: ${dictType} or invalid key: ${key}`)       }     },
    // 设置凭条信息     setReceiptList(receiptList: any) {       this.dict.receiptList = receiptList     }   },   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-dict-store.vue <script setup lang="ts"> import { DICT_SYSTEM } from '@/const' import { useDataStore } from '@/store/useDictStore'
const dataStore = useDataStore() dataStore.initDict() dataStore.setDictValue('version', '1.0.0') dataStore.syncData(DICT_SYSTEM, 'test', '123') </script>
<template>   <div>     <p>       <button @click="dataStore.setDictValue('version', '1.0.0')">         setVersion('1.0.0')       </button>       <button @click="dataStore.setDictValue('version', '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,const,useDictStore,ssts,获取,state,dict,key,DICT
From: https://www.cnblogs.com/lizhigang/p/18040901

相关文章

  • ssts-hospital-web-master项目实战记录二十八:项目迁移-Hook实现(useFlowStore)
    记录时间:2024-02-28一、useFlowStore模块实现store/useFlowStore.tsimport{defineStore}from'pinia'import{Flow,Flows}from'@/types/flow'exportconstuseFlowStore=defineStore('flow',{ state:()=>({  flow:{}as......
  • webpack-dev-server 插件问题 Content not from webpack is served from
    在安装了webpack-dev-server插件后启动然后一直报错 Contentnotfromwebpackisservedfrom XXXX在浏览器中访问 一直显示cannot  / 解决办法在wenbpack.config.js的配置文件中加入输出文件路径配置  devServer:{    static:{     ......
  • GitHub上整理的一些工具(Web 前端相关)
    Web服务器性能/压力测试工具/负载均衡器http_load:程序非常小,解压后也不到100Kwebbench:是Linux下的一个网站压力测试工具,最多可以模拟3万个并发连接去测试网站的负载能力ab:ab是apache自带的一款功能强大的测试工具Siege:一款开源的压力测试工具,可以根据配置对一个WEB......
  • Taurus.MVC WebMVC 入门开发教程4:数据列表绑定List<Model>
    前言:在本篇Taurus.MVCWebMVC入门开发教程的第四篇文章中,我们将学习如何实现数据列表的绑定,通过使用List<Model>来展示多个数据项。我们将继续使用Taurus.Mvc命名空间,同时探讨如何在视图中绑定并显示一个Model列表。步骤1:创建Model首先,我们需要更新我们的Model类,......
  • rn 调用webview组件调用h5传参
    webview组件调用html页面并实现互相传值的功能1.rn页面 html——> rnhtml页面传参 if(window.ReactNativeWebView){  window.ReactNativeWebView.postMessage('值');}接收html的数据使用接收onMessage={(event)=>this.onMessage(event)} 2.html页面......
  • SpringBoot 2x 系列之(七)web场景
    web场景1.SpringMVC自动配置概览SpringBootprovidesauto-configurationforSpringMVCthatworkswellwithmostapplications.(大多场景我们都无需自定义配置)Theauto-configurationaddsthefollowingfeaturesontopofSpring’sdefaults:InclusionofCont......
  • SpringBoot 1x 系列之(四)Spring Boot与Web开发
    SpringBoot与Web开发Thymeleaf、Web定制、容器定制1.如何使用SpringBoot创建SpringBoot应用,选中我们需要的模块SpringBoot已经默认将这些场景配置好了,我们只需要在配置文件中指定少量配置就可以运行起来编写业务代码2.SpringBoot对静态资源的映射规则普通的web应用......
  • ssts-hospital-web-master项目实战记录二十七:项目迁移-Vue项目与模型数据有关的问题
    记录时间:2024-02-28一、准备工作【使用“文心一言”搜索】Vue项目,推荐与模型数据有关的问题当然,以下是与Vue项目中模型数据相关的一些推荐问题:模型数据应该存储在哪里?考虑到数据的大小、敏感性和使用频率,我应该将模型数据存储在客户端、服务器端还是两者都存储?对于存储在......
  • ssts-hospital-web-master项目实战记录二十六:项目迁移-Hook实现(useDataStore)
    记录时间:2024-02-27一、useDataStore模块实现store/useDataStore.tsimport{defineStore}from'pinia'import{ DICT_PAGE, DICT_COMMON, DICT_DEVICE, DICT_SYSTEM, DICT_STATIC, DICT_NULL, DICT_CONFIG, DICT_OUT}from'@/const'ex......
  • 从sql注入到web安全
    一、事情起因去年底的时候我看到几个国内开源框架又出来SQL注入,联想起HVV时候的各种OA、ERP的SQL注入。我觉得SQL注入这个事情是该有人管管了。二、Mybatis的一点回顾https://github.com/mybatis/mybatis-3/issues/1941如上,我在2020年开始就一直在和官方讨论${}的风险问题,官......