|
|
@@ -0,0 +1,51 @@
|
|
|
+
|
|
|
+import { reactive, toRefs, computed } from 'vue'
|
|
|
+import { defineStore } from '../store'
|
|
|
+import { getClientDocumnetConfigs } from '@/services/api/common'
|
|
|
+import { Language } from '@/constants/language'
|
|
|
+import { i18n } from './language'
|
|
|
+
|
|
|
+export const useCommonStore = defineStore(() => {
|
|
|
+ const state = reactive({
|
|
|
+ loading: false,
|
|
|
+ documents: <Model.DocumnetConfigsRsp[]>[], // 文档集合
|
|
|
+ })
|
|
|
+
|
|
|
+ // 本地化商品集合
|
|
|
+ const documents = computed<Model.DocumnetConfigsRsp[]>(() => state.documents.map((e) => {
|
|
|
+ const localizedProperties: { [K in Language]: { [P in 'documentcontent']: string } } = {
|
|
|
+ 'zh-CN': { documentcontent: e.documentcontent },
|
|
|
+ 'en-US': { documentcontent: e.documentcontenten },
|
|
|
+ 'th': { documentcontent: e.documentcontentth },
|
|
|
+ 'zh-TW': { documentcontent: e.documentcontenttw },
|
|
|
+ }
|
|
|
+
|
|
|
+ const localizedValues = localizedProperties[i18n.global.locale] // 本地化语言
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...e,
|
|
|
+ ...localizedValues
|
|
|
+ }
|
|
|
+ }))
|
|
|
+
|
|
|
+ // 根据商品 ID 查找对应的商品信息
|
|
|
+ const getDocumentById = (id: number) => documents.value.find((e) => e.documenttype === id)
|
|
|
+
|
|
|
+ // 获取商品集合列表
|
|
|
+ const fetcheDocuments = async () => {
|
|
|
+ try {
|
|
|
+ state.loading = true
|
|
|
+ const res = await getClientDocumnetConfigs()
|
|
|
+ state.documents = res.data
|
|
|
+ } finally {
|
|
|
+ state.loading = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...toRefs(state),
|
|
|
+ fetcheDocuments,
|
|
|
+ documents,
|
|
|
+ getDocumentById
|
|
|
+ }
|
|
|
+})
|