li.shaoyi 2 年之前
父節點
當前提交
42e699b04b

+ 1 - 1
.env.pc

@@ -1,5 +1,5 @@
 VUE_APP_ENV = 'pc'
-VUE_APP_NAME = 多元世纪
+VUE_APP_NAME = 多元世纪交易中心
 VUE_APP_ROOT = src/packages/pc/
 VUE_APP_TRADE_CHANNEL = ws
 VUE_APP_API_BETA = http://103.40.249.126:18280/cfg?key=mtp_20

+ 3 - 0
oem/gstj/config/appconfig.json

@@ -7,5 +7,8 @@
   "modules": [
     "register",
     "delivery"
+  ],
+  "quotationPropertys": [
+    "totalvolume"
   ]
 }

+ 3 - 0
oem/qdhs/config/appconfig.json

@@ -6,5 +6,8 @@
   "tradeChannel": "ws",
   "modules": [
     "delivery"
+  ],
+  "quotationPropertys": [
+    "holdvolume"
   ]
 }

+ 3 - 0
oem/qxst/config/appconfig.json

@@ -6,5 +6,8 @@
   "tradeChannel": "http",
   "modules": [
     "register"
+  ],
+  "quotationPropertys": [
+    "holdvolume"
   ]
 }

+ 3 - 0
oem/sbyj/config/appconfig.json

@@ -7,5 +7,8 @@
   "modules": [
     "register",
     "delivery"
+  ],
+  "quotationPropertys": [
+    "holdvolume"
   ]
 }

+ 3 - 0
oem/tc/config/appconfig.json

@@ -7,5 +7,8 @@
   "modules": [
     "register",
     "delivery"
+  ],
+  "quotationPropertys": [
+    "holdvolume"
   ]
 }

+ 3 - 0
oem/zrwyt/config/appconfig.json

@@ -7,5 +7,8 @@
   "modules": [
     "register",
     "delivery"
+  ],
+  "quotationPropertys": [
+    "holdvolume"
   ]
 }

+ 5 - 1
public/config/appconfig.json

@@ -1,5 +1,5 @@
 {
-  "appName": "多元世纪",
+  "appName": "多元世纪交易中心",
   "version": "1.0.5",
   "versionCode": "10005",
   "apiUrl": "http://192.168.31.204:8080/cfg?key=test_204",
@@ -7,5 +7,9 @@
   "modules": [
     "register",
     "delivery"
+  ],
+  "quotationPropertys": [
+    "totalvolume",
+    "holdvolume"
   ]
 }

+ 5 - 4
src/business/login/index.ts

@@ -2,7 +2,7 @@ import { shallowRef, reactive } from 'vue'
 import { v4 } from 'uuid'
 import { timerTask } from '@/utils/timer'
 import { wsLogin, httpLogin, logout, queryLoginId } from '@/services/api/account'
-import { useLoginStore, useEnumStore, useErrorInfoStore, useUserStore, useFuturesStore, useAccountStore, useNoticeStore } from '@/stores'
+import { useGlobalStore, useLoginStore, useEnumStore, useErrorInfoStore, useUserStore, useFuturesStore, useAccountStore, useNoticeStore } from '@/stores'
 import service from '@/services'
 import quoteSocket from '@/services/websocket/quote'
 import tradeSocket from '@/services/websocket/trade'
@@ -18,6 +18,7 @@ import cryptojs from 'crypto-js'
  * @returns 
  */
 export function useLogin(persist = false) {
+    const globalStore = useGlobalStore()
     const enumStore = useEnumStore()
     const errorInfoStore = useErrorInfoStore()
     const loginStore = useLoginStore()
@@ -53,7 +54,7 @@ export function useLogin(persist = false) {
         noticeStore.getNoticeList()
         checkTokenLoop()
 
-        if (service.getSystemInfo('tradeChannel') === 'http') {
+        if (globalStore.getSystemInfo('tradeChannel') === 'http') {
             tradeV2Socket.connect()
         }
     }
@@ -73,7 +74,7 @@ export function useLogin(persist = false) {
                         reject('自动登录失败')
                     }
                 } else {
-                    if (service.getSystemInfo('tradeChannel') === 'ws') {
+                    if (globalStore.getSystemInfo('tradeChannel') === 'ws') {
                         // websocket 登录参数
                         queryLoginId({
                             data: {
@@ -99,7 +100,7 @@ export function useLogin(persist = false) {
                 }
             })
 
-            if (service.getSystemInfo('tradeChannel') === 'ws') {
+            if (globalStore.getSystemInfo('tradeChannel') === 'ws') {
                 // websocket 登录
                 const res = await wsLogin({
                     LoginID: payload.userName,

+ 3 - 1
src/filters/index.ts

@@ -2,6 +2,7 @@ import CryptoJS from 'crypto-js'
 import service from '@/services'
 import Long from 'long'
 import moment from 'moment'
+import { useGlobalStore } from '@/stores'
 
 /**
  * 获取url对象方法
@@ -133,7 +134,8 @@ export function handleNumberValue(value: number | string = 0, suffix = '') {
  * @returns 
  */
 export function handleRequestBigNumber(value: string) {
-    if (service.getSystemInfo('tradeChannel') === 'ws') {
+    const globalStore = useGlobalStore()
+    if (globalStore.getSystemInfo('tradeChannel') === 'ws') {
         return Long.fromString(value)
     }
     return value

+ 1 - 1
src/packages/gstj/views/home/main/Index.vue

@@ -1,7 +1,7 @@
 <template>
   <app-view class="home-main">
     <template #header>
-      <app-navbar :title="globalStore.appName" :show-back-button="false" />
+      <app-navbar :title="globalStore.getSystemInfo('appName')" :show-back-button="false" />
     </template>
     <Banner :data-list="topBanners" />
     <PullRefresh class="home-main__container" v-model="refreshing" @refresh="onRefresh">

+ 3 - 1
src/packages/mobile/components/layouts/login/index.vue

@@ -21,7 +21,7 @@
       </div>
     </Form>
     <div class="login-link">
-      <span @click="navigationTo('user-register')" v-if="service.hasSystemModule('register')">用户注册</span>
+      <span @click="navigationTo('user-register')" v-if="globalStore.hasSystemModule('register')">用户注册</span>
       <span @click="navigationTo('user-forget')">忘记密码</span>
     </div>
     <div class="login-footer">
@@ -46,6 +46,7 @@ import { Button, Field, CellGroup, Form, Checkbox, showFailToast, showSuccessToa
 import { fullloading } from '@/utils/vant'
 import { useLogin } from '@/business/login'
 import { useNavigation } from '@mobile/router/navigation'
+import { useGlobalStore } from '@/stores'
 import service from '@/services'
 import SliderVerify from '@/components/base/slider-verify/index.vue' // 临时调用,待优化
 import logoImage from '../../../assets/images/login-logo.png'
@@ -57,6 +58,7 @@ defineProps({
   }
 })
 
+const globalStore = useGlobalStore()
 const { routerBack, routerTo } = useNavigation()
 const { formData, userLogin } = useLogin()
 const checked = shallowRef(false) // 是否同意协议管理

+ 1 - 1
src/packages/mobile/views/home/main/Index.vue

@@ -1,7 +1,7 @@
 <template>
   <app-view class="home-main">
     <template #header>
-      <app-navbar :title="globalStore.appName" :show-back-button="false" />
+      <app-navbar :title="globalStore.getSystemInfo('appName')" :show-back-button="false" />
     </template>
     <Banner :data-list="topBanners" />
     <PullRefresh class="home-main__container" v-model="refreshing" @refresh="onRefresh">

+ 3 - 2
src/packages/mobile/views/order/position/components/goods/list/Index.vue

@@ -46,7 +46,7 @@
                 <div class="g-order-list__btnbar" v-if="item.enableqty">
                     <Button size="small" @click="showComponent('close', item)" round>转让</Button>
                     <Button size="small" @click="showComponent(item.trademode === 16 ? 'delivery16' : 'delivery50', item)"
-                        round v-if="service.hasSystemModule('delivery')">交收</Button>
+                        round v-if="globalStore.hasSystemModule('delivery')">交收</Button>
                 </div>
             </div>
         </div>
@@ -63,7 +63,7 @@ import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
 import { getBuyOrSellName } from '@/constants/order'
 import { formatDecimal, handleNumberValue } from '@/filters'
 import { usePosition } from '@/business/position'
-import service from '@/services'
+import { useGlobalStore } from '@/stores'
 import eventBus from '@/services/bus'
 
 const componentMap = new Map<string, unknown>([
@@ -72,6 +72,7 @@ const componentMap = new Map<string, unknown>([
     ['delivery16', defineAsyncComponent(() => import('../delivery16/index.vue'))]
 ])
 
+const globalStore = useGlobalStore()
 const { positionList, loading } = usePosition(50, 16)
 const selectedRow = shallowRef<Model.TradePositionRsp>()
 const pullRefreshRef = shallowRef()

+ 9 - 9
src/packages/pc/components/layouts/header/index.vue

@@ -2,7 +2,7 @@
     <div class="app-header">
         <div class="app-header__left">
             <slot name="left"></slot>
-            <span>{{ globalStore.appName }}</span>
+            <span>{{ globalStore.getSystemInfo('appName') }}</span>
         </div>
         <div class="app-header__right">
             <slot name="right"></slot>
@@ -12,8 +12,8 @@
                 </el-badge>
                 <app-icon icon="Tickets" @click="openComponent('report')" />
                 <app-icon icon="Setting" @click="openComponent('setting')" />
-                <app-icon icon="g-icon-minimize" @click="exitFullSreen" v-if="fullScreen" />
-                <app-icon icon="g-icon-maximize" @click="setFullSreen" v-else />
+                <!-- <app-icon icon="g-icon-minimize" @click="exitFullSreen" v-if="fullScreen" />
+                <app-icon icon="g-icon-maximize" @click="setFullSreen" v-else /> -->
             </div>
             <el-dropdown class="user-dropdown" trigger="click">
                 <span class="user-dropdown__link">
@@ -69,14 +69,14 @@ const userAvatar = computed(() => {
 })
 
 // 全屏
-const setFullSreen = () => {
-    document.documentElement.requestFullscreen();
-}
+// const setFullSreen = () => {
+//     document.documentElement.requestFullscreen();
+// }
 
 // 退出全屏
-const exitFullSreen = () => {
-    document.exitFullscreen();
-}
+// const exitFullSreen = () => {
+//     document.exitFullscreen();
+// }
 
 onMounted(() => {
     const reportAgree = localData.getValue('reportAgree')

+ 16 - 0
src/packages/pc/components/layouts/page/index.less

@@ -58,6 +58,22 @@
         }
     }
 
+    &__footer {
+        .iconbar {
+            display: flex;
+            align-items: center;
+            justify-content: flex-end;
+            gap: 20px;
+            font-size: 16px;
+            color: #fff;
+            padding: 0 20px;
+
+            span {
+                cursor: pointer;
+            }
+        }
+    }
+
     &__wrapper {
         flex: 1;
         display: flex;

+ 22 - 24
src/packages/pc/components/layouts/page/index.vue

@@ -4,7 +4,7 @@
       <app-header>
         <!-- <template #left>
           <i class="icon-fold-expand" title="折叠/展开" @click="isCollapse = !isCollapse">
-            <span :class="isCollapse ? 'g-icon--expand' : 'g-icon--fold'"></span>
+            <span :class="isCollapse ? 'g-icon-expand' : 'g-icon-fold'"></span>
           </i>
         </template> -->
       </app-header>
@@ -27,12 +27,12 @@
       </div>
     </div>
     <app-footer class="app-page__footer" :style="footerStyles" @tab-change="onTabChange">
-      <div style="display: flex;align-items: center; font-size: 16px; gap: 20px;justify-content: flex-end;padding: 0 20px;color: #fff;">
-        <span @click="minimize" style="cursor: pointer;">
+      <div class="iconbar">
+        <span @click="minimize">
           <AppIcon icon="ArrowUp" v-if="footerWinType === -1" />
           <AppIcon icon="ArrowDown" v-else />
         </span>
-        <span @click="maximize" style="cursor: pointer;">
+        <span @click="maximize">
           <AppIcon icon="g-icon-minimize2" v-if="footerWinType === 1" />
           <AppIcon icon="g-icon-maximize2" v-else />
         </span>
@@ -76,8 +76,23 @@ import AppFooter from '../footer/index.vue'
 import AppNavbar from '../navbar/index.vue'
 import AppSidebar from '../sidebar/index.vue'
 
-
+const globalStore = useGlobalStore()
+const loginStore = useLoginStore()
+const fullLoading = ref(false)
+const isCollapse = ref(globalStore.isMobile)
 const footerWinType = ref(0) // -1最小化,0默认,1最大化
+const serverTime = ref<Moment>()
+
+const meta = document.getElementsByTagName('meta')
+const version = meta.namedItem('revised')?.content ?? '0'
+
+// 手动给组件添加 name 属性,处理缓存 exclude 无效的问题
+const handleComponent = (component: Record<'type', { name: RouteRecordName | undefined }>, route: RouteRecordNormalized) => {
+  if (component) {
+    component.type.name = route.name
+  }
+  return component
+}
 
 const bodyStyles = computed(() => {
   if (footerWinType.value === 1) {
@@ -113,6 +128,7 @@ const footerStyles = computed(() => {
   }
 })
 
+// 最小化
 const minimize = () => {
   if (footerWinType.value === -1) {
     footerWinType.value = 0
@@ -121,6 +137,7 @@ const minimize = () => {
   }
 }
 
+// 最大化
 const maximize = () => {
   if (footerWinType.value === 1) {
     footerWinType.value = 0
@@ -135,25 +152,6 @@ const onTabChange = () => {
   }
 }
 
-
-
-const globalStore = useGlobalStore()
-const loginStore = useLoginStore()
-const fullLoading = ref(false)
-const isCollapse = ref(globalStore.isMobile)
-const serverTime = ref<Moment>()
-
-const meta = document.getElementsByTagName('meta')
-const version = meta.namedItem('revised')?.content ?? '0'
-
-// 手动给组件添加 name 属性,处理缓存 exclude 无效的问题
-const handleComponent = (component: Record<'type', { name: RouteRecordName | undefined }>, route: RouteRecordNormalized) => {
-  if (component) {
-    component.type.name = route.name
-  }
-  return component
-}
-
 // 校验服务器时间
 const checkServerTime = () => {
   getServerTime().then((res) => {

+ 7 - 6
src/packages/pc/components/modules/quote/price/index.vue

@@ -53,18 +53,18 @@
                     <span>振幅</span>
                     <span>{{ parsePercent(quote.amplitude) }}</span>
                 </li>
-                <!-- <li>
-                    <span>成交量</span>
-                    <span>{{ handleNumberValue(quote.totalvolume) }}</span>
-                </li> -->
                 <li>
                     <span>成交额</span>
                     <span>{{ quote.totalturnover ? changeUnit(quote.totalturnover) : handleNumberValue() }}</span>
                 </li>
-                <li>
+                <li v-if="globalStore.hasQuotationProperty('holdvolume')">
                     <span>持仓量</span>
                     <span>{{ handleNumberValue(quote.holdvolume) }}</span>
                 </li>
+                <li v-if="globalStore.hasQuotationProperty('totalvolume')">
+                    <span>成交量</span>
+                    <span>{{ handleNumberValue(quote.totalvolume) }}</span>
+                </li>
             </ul>
         </div>
     </div>
@@ -72,7 +72,7 @@
 
 <script lang="ts" setup>
 import { parsePercent, handleNumberValue, changeUnit } from '@/filters'
-import { useFuturesStore } from '@/stores'
+import { useGlobalStore, useFuturesStore } from '@/stores'
 
 const props = defineProps({
     goodsCode: {
@@ -81,6 +81,7 @@ const props = defineProps({
     }
 })
 
+const globalStore = useGlobalStore()
 const futuresStore = useFuturesStore()
 const quote = futuresStore.getGoodsQuote(props.goodsCode)
 </script>

+ 1 - 1
src/packages/pc/router/index.ts

@@ -45,7 +45,7 @@ const router = historyRouter.create({
 router.beforeEach((to, from, next) => {
     const isLoginOrRegister = to.name === 'login' || to.name === 'register'
     const title = to.meta.title
-    document.title = globalStore.appName + (title ? ` - ${title}` : '')
+    document.title = globalStore.getSystemInfo('appName') + (title ? ` - ${title}` : '')
 
     // 判断服务是否加载完成
     if (service.isReady) {

+ 3 - 2
src/packages/pc/views/auth/login/index.vue

@@ -49,7 +49,7 @@ import { useRoute, useRouter } from 'vue-router'
 import { ElMessage } from 'element-plus'
 import type { FormInstance, FormRules } from 'element-plus'
 import { useLogin } from '@/business/login'
-import { useMenuStore } from '@/stores'
+import { useGlobalStore, useMenuStore } from '@/stores'
 import service from '@/services'
 import SignLayout from '../components/layout/index.vue'
 import Forget from "../forget/index.vue"
@@ -59,6 +59,7 @@ import SliderVerify from '@/components/base/slider-verify/index.vue' // 临时
 const { formData, userLogin } = useLogin()
 const route = useRoute()
 const router = useRouter()
+const globalStore = useGlobalStore()
 const menuStore = useMenuStore()
 const formRef = shallowRef<FormInstance>()
 const loading = shallowRef(false)
@@ -127,7 +128,7 @@ const formSubmit = () => {
 }
 
 service.systemInfoAsync.then(() => {
-  shwoRegister.value = service.hasSystemModule('register')
+  shwoRegister.value = globalStore.hasSystemModule('register')
 })
 </script>
 

+ 1 - 1
src/packages/qdhs/views/home/main/Index.vue

@@ -1,7 +1,7 @@
 <template>
   <app-view class="home-main">
     <template #header>
-      <app-navbar :title="globalStore.appName" :show-back-button="false" />
+      <app-navbar :title="globalStore.getSystemInfo('appName')" :show-back-button="false" />
     </template>
     <Banner :data-list="topBanners" />
     <PullRefresh class="home-main__container" v-model="refreshing" @refresh="onRefresh">

+ 1 - 1
src/packages/qxst/views/home/main/Index.vue

@@ -1,7 +1,7 @@
 <template>
   <app-view class="home-main">
     <template #header>
-      <app-navbar :title="globalStore.appName" :show-back-button="false" />
+      <app-navbar :title="globalStore.getSystemInfo('appName')" :show-back-button="false" />
     </template>
     <Banner :data-list="topBanners" />
     <PullRefresh class="home-main__container" v-model="refreshing" @refresh="onRefresh">

+ 1 - 1
src/packages/tc/views/home/main/Index.vue

@@ -1,7 +1,7 @@
 <template>
   <app-view class="home-main">
     <template #header>
-      <app-navbar :title="globalStore.appName" :show-back-button="false" />
+      <app-navbar :title="globalStore.getSystemInfo('appName')" :show-back-button="false" />
     </template>
     <Banner :data-list="topBanners" />
     <PullRefresh class="home-main__container" v-model="refreshing" @refresh="onRefresh">

+ 1 - 1
src/packages/zrwyt/views/home/main/Index.vue

@@ -1,7 +1,7 @@
 <template>
   <app-view class="home-main">
     <template #header>
-      <app-navbar :title="globalStore.appName" :show-back-button="false" />
+      <app-navbar :title="globalStore.getSystemInfo('appName')" :show-back-button="false" />
     </template>
     <Banner :data-list="topBanners" />
     <PullRefresh class="home-main__container" v-model="refreshing" @refresh="onRefresh">

+ 3 - 2
src/services/api/account/index.ts

@@ -1,8 +1,9 @@
 import service from '@/services'
 import http from '@/services/http'
 import { RequestConfig } from '@/services/http/types'
-import { useLoginStore } from '@/stores'
+import { useGlobalStore, useLoginStore } from '@/stores'
 
+const globalStore = useGlobalStore()
 const loginStore = useLoginStore()
 
 /**
@@ -41,7 +42,7 @@ export function logout(config: RequestConfig = {}) {
  * Token校验
  */
 export function tokenCheck() {
-    if (service.getSystemInfo('tradeChannel') === 'ws') {
+    if (globalStore.getSystemInfo('tradeChannel') === 'ws') {
         return http.mqRequest<Proto.TokenCheckRsp>({
             data: <Proto.TokenCheckReq>{
                 LoginID: loginStore.loginId,

+ 5 - 3
src/services/http/index.ts

@@ -5,7 +5,7 @@ import cryptojs from 'crypto-js'
 //import { addPending, removePending } from './pending'
 import { encryptBody, decryptBody } from '@/services/websocket/package/crypto'
 import { IMessageHead } from '@/types/proto/proto'
-import { useLoginStore, useAccountStore, useErrorInfoStore } from '@/stores'
+import { useGlobalStore, useLoginStore, useAccountStore, useErrorInfoStore } from '@/stores'
 import { CommonResult, ResultCode, SendMsgToMQ } from './types'
 import { FunCode } from '@/constants/funcode'
 import service from '@/services'
@@ -21,10 +21,11 @@ export default new (class {
         // 请求拦截器
         this.axiosInstance.interceptors.request.use(
             (config) => {
+                const globalStore = useGlobalStore()
                 const loginStore = useLoginStore()
                 //addPending(config) //将当前请求添加到列表中
                 //设置请求头
-                if (service.getSystemInfo('tradeChannel') === 'ws') {
+                if (globalStore.getSystemInfo('tradeChannel') === 'ws') {
                     config.headers = {
                         Authorization: loginStore.token
                     }
@@ -181,6 +182,7 @@ export default new (class {
         RetDesc: string;
         Status?: number;
     }>({ data, requestCode, responseCode, marketId = 0 }: SendMsgToMQ<{ Header?: IMessageHead }>, errMsg?: string) {
+        const globalStore = useGlobalStore()
         const loginStore = useLoginStore()
         const accountStore = useAccountStore()
         const requestId = FunCode[requestCode]
@@ -199,7 +201,7 @@ export default new (class {
         console.log(requestCode, data)
 
         try {
-            if (service.getSystemInfo('tradeChannel') === 'ws') {
+            if (globalStore.getSystemInfo('tradeChannel') === 'ws') {
                 // websocket 通道
                 const res = await tradeService.send<T>({
                     data,

+ 6 - 51
src/services/index.ts

@@ -1,24 +1,15 @@
 import axios from 'axios'
-import plus from '@/utils/h5plus'
+import { useGlobalStore } from '@/stores/modules/global'
 
-// 可配置的模块
-const modules = ['register', 'delivery'] as const
+const { getSystemConfig } = useGlobalStore()
 
 export default new (class {
     constructor() {
-        this.systemInfoAsync = this.getAppConfig()
+        this.systemInfoAsync = getSystemConfig()
     }
 
     systemInfoAsync
 
-    systemInfo = {
-        version: '1.0.0',
-        versionCode: '100000',
-        apiUrl: 'http://localhost',
-        tradeChannel: <'http' | 'ws'>'ws', // 交易服务通道
-        modules // 启用的模块
-    }
-
     /** 服务配置信息 */
     config = {
         commSearchUrl: '',
@@ -91,36 +82,18 @@ export default new (class {
         })
     }
 
-    private async getAppConfig(): Promise<typeof this.systemInfo> {
-        const filePath = './config/appconfig.json'
-        if (plus.hasPlus()) {
-            const res = await plus.getLocalFileContent(filePath)
-            this.systemInfo = {
-                ...this.systemInfo,
-                ...JSON.parse(res)
-            }
-        } else {
-            const res = await axios(filePath)
-            this.systemInfo = {
-                ...this.systemInfo,
-                ...res.data
-            }
-        }
-        return this.systemInfo
-    }
-
     /**
      * 初始化服务配置
      */
     private async init(): Promise<typeof this.config> {
         this.isPending = true
         await this.systemInfoAsync.catch(() => {
-            this.systemInfoAsync = this.getAppConfig()
+            this.systemInfoAsync = getSystemConfig()
         })
         return new Promise((resolve, reject) => {
-            this.systemInfoAsync.then(() => {
+            this.systemInfoAsync.then((res) => {
                 // 获取服务接口地址
-                axios(this.systemInfo.apiUrl).then((res) => {
+                axios(res.apiUrl).then((res) => {
                     this.config = res.data.data
                     this.isReady = true
                     resolve(this.config)
@@ -153,22 +126,4 @@ export default new (class {
     getConfig<K extends keyof typeof this.config>(key: K) {
         return this.config[key]
     }
-
-    /**
-     * 获取系统信息
-     * @param key 
-     * @returns 
-     */
-    getSystemInfo<K extends keyof typeof this.systemInfo>(key: K) {
-        return this.systemInfo[key]
-    }
-
-    /**
-     * 是否包含某个系统模块
-     * @param module 
-     * @returns 
-     */
-    hasSystemModule(module: typeof modules[number]) {
-        return this.systemInfo.modules.includes(module)
-    }
 })

+ 58 - 1
src/stores/modules/global.ts

@@ -2,19 +2,72 @@ import { reactive, toRefs } from 'vue'
 import { AppTheme } from '@/constants/theme'
 import { defineStore } from '../store'
 import { localData } from '../storage'
+import axios from 'axios'
 import plus from '@/utils/h5plus'
 
+export interface SystemInfo {
+    appName: string; // 应用名称
+    version: string; // 应用版本
+    versionCode: string; // 应用版本号
+    apiUrl: string; // 接口地址
+    tradeChannel: 'http' | 'ws'; // 交易通道
+    modules: ('register' | 'delivery')[]; // 应用包含的模块
+    quotationPropertys: (keyof Model.QuoteDayRsp)[]; // 盘面可显示的属性
+}
+
 export const useGlobalStore = defineStore(() => {
     const appTheme = localData.getRef('appTheme')
 
     const state = reactive({
-        appName: document.title,
         showGoodsListing: false, // 是否显示订单交易挂牌
         showTransferListing: false, // 是否显示定金转让挂牌
         clientWidth: 0, // 客户端宽度
         isMobile: false, // 是否移动设备
+        systemInfo: <SystemInfo>{
+            appName: document.title,
+            version: '1.0.0',
+            versionCode: '100000',
+            apiUrl: 'http://localhost',
+            tradeChannel: 'ws',
+            modules: [],
+            quotationPropertys: []
+        }
     })
 
+    // 获取系统配置项
+    const getSystemConfig = async () => {
+        const filePath = './config/appconfig.json'
+        if (plus.hasPlus()) {
+            const res = await plus.getLocalFileContent(filePath)
+            state.systemInfo = {
+                ...state.systemInfo,
+                ...JSON.parse(res)
+            }
+        } else {
+            const res = await axios(filePath)
+            state.systemInfo = {
+                ...state.systemInfo,
+                ...res.data
+            }
+        }
+        return state.systemInfo
+    }
+
+    // 获取系统信息
+    const getSystemInfo = <K extends keyof SystemInfo>(key: K) => {
+        return state.systemInfo[key]
+    }
+
+    // 判断应用是否包含某个模块
+    const hasSystemModule = (module: SystemInfo['modules'][number]) => {
+        return state.systemInfo.modules.includes(module)
+    }
+
+    // 判断盘面是否包含某个属性
+    const hasQuotationProperty = (prop: keyof Model.QuoteDayRsp) => {
+        return state.systemInfo.quotationPropertys.includes(prop)
+    }
+
     // 设置状态栏主题色
     const setStatusBarTheme = (theme: AppTheme) => {
         switch (theme) {
@@ -106,6 +159,10 @@ export const useGlobalStore = defineStore(() => {
     return {
         ...toRefs(state),
         appTheme,
+        getSystemConfig,
+        getSystemInfo,
+        hasSystemModule,
+        hasQuotationProperty,
         setStatusBarTheme,
         setTheme,
         screenAdapter,