li.shaoyi 2 年之前
父節點
當前提交
ec04c92e9d
共有 77 個文件被更改,包括 900 次插入1098 次删除
  1. 0 18
      src/business/admin/index.ts
  2. 9 11
      src/business/auth/index.ts
  3. 14 28
      src/business/bank/index.ts
  4. 11 13
      src/business/common/index.ts
  5. 7 7
      src/business/credit/index.ts
  6. 7 9
      src/business/goods/index.ts
  7. 2 3
      src/business/market/index.ts
  8. 12 17
      src/business/order/index.ts
  9. 28 38
      src/business/trade/index.ts
  10. 15 17
      src/business/user/account.ts
  11. 6 6
      src/business/user/address.ts
  12. 5 5
      src/business/user/invoice.ts
  13. 2 2
      src/constants/account.ts
  14. 2 2
      src/constants/bank.ts
  15. 2 2
      src/constants/certificate.ts
  16. 3 3
      src/constants/client.ts
  17. 2 2
      src/constants/credit.ts
  18. 2 2
      src/constants/market.ts
  19. 2 2
      src/constants/menu.ts
  20. 2 2
      src/constants/order.ts
  21. 2 2
      src/constants/receipt.ts
  22. 2 2
      src/constants/unit.ts
  23. 2 3
      src/hooks/echarts/candlestick/index.ts
  24. 2 2
      src/hooks/echarts/candlestick/options.ts
  25. 2 2
      src/hooks/echarts/line/options.ts
  26. 2 3
      src/hooks/echarts/smoothedline/index.ts
  27. 2 2
      src/hooks/echarts/smoothedline/options.ts
  28. 2 3
      src/hooks/echarts/timeline/index.ts
  29. 2 2
      src/hooks/echarts/timeline/options.ts
  30. 11 11
      src/hooks/menu/index.ts
  31. 3 3
      src/packages/mobile/router/index.ts
  32. 2 2
      src/packages/mobile/views/bank/wallet/components/deposit/index.vue
  33. 2 2
      src/packages/mobile/views/bank/wallet/components/withdraw/index.vue
  34. 2 1
      src/packages/mobile/views/contract/details/index.vue
  35. 4 4
      src/packages/mobile/views/credit/signin/index.vue
  36. 3 3
      src/packages/mobile/views/home/index.vue
  37. 4 4
      src/packages/mobile/views/mine/generalize/index.vue
  38. 8 8
      src/packages/mobile/views/mine/main/index.vue
  39. 2 2
      src/packages/mobile/views/purchase/detail/index.vue
  40. 5 5
      src/packages/mobile/views/supply-demand/detail/components/delisting/index.vue
  41. 4 4
      src/packages/mobile/views/supply-demand/detail/components/listing/index.vue
  42. 4 5
      src/packages/mobile/views/user/avatar/index.vue
  43. 3 4
      src/packages/pc/App.vue
  44. 4 4
      src/packages/pc/components/layouts/header/index.vue
  45. 1 1
      src/packages/pc/components/layouts/sidemenu/submenu.vue
  46. 1 1
      src/packages/pc/components/modules/action-menu/index.vue
  47. 2 2
      src/packages/pc/components/modules/auth-component/index.vue
  48. 1 1
      src/packages/pc/components/modules/auth-operation/index.vue
  49. 3 4
      src/packages/pc/router/dynamicRouter.ts
  50. 4 4
      src/packages/pc/router/index.ts
  51. 2 3
      src/packages/pc/views/auth/login/index.vue
  52. 3 5
      src/packages/pc/views/boot/index.vue
  53. 10 10
      src/packages/pc/views/member/index.vue
  54. 3 3
      src/packages/pc/views/profit/index.vue
  55. 1 1
      src/packages/pc/views/system/menu/components/edit/index.vue
  56. 4 4
      src/packages/pc/views/system/menu/index.vue
  57. 2 2
      src/packages/pc/views/system/role/components/auth/index.vue
  58. 10 3
      src/services/api/account/index.ts
  59. 2 3
      src/services/http/index.ts
  60. 3 4
      src/services/socket/index.ts
  61. 3 3
      src/services/socket/quote/index.ts
  62. 4 6
      src/services/socket/trade/index.ts
  63. 3 3
      src/services/subscribe/index.ts
  64. 78 37
      src/stores/base.ts
  65. 9 35
      src/stores/index.ts
  66. 34 61
      src/stores/modules/account.ts
  67. 66 75
      src/stores/modules/enum.ts
  68. 14 31
      src/stores/modules/errorInfo.ts
  69. 248 275
      src/stores/modules/futures.ts
  70. 16 33
      src/stores/modules/language.ts
  71. 37 68
      src/stores/modules/login.ts
  72. 13 30
      src/stores/modules/menu.ts
  73. 33 54
      src/stores/modules/theme.ts
  74. 39 59
      src/stores/modules/user.ts
  75. 32 0
      src/stores/storage.ts
  76. 2 2
      src/types/model/account.d.ts
  77. 5 3
      src/utils/storage/index.ts

+ 0 - 18
src/business/admin/index.ts

@@ -1,18 +0,0 @@
-import { reactive } from 'vue'
-
-export function useAdmin() {
-    const admin = reactive({
-        realName: '李兔饼',
-        avatar: '',
-    })
-
-    // 用户登出
-    const logout = () => {
-        console.log('登出')
-    }
-
-    return {
-        admin,
-        logout,
-    }
-}

+ 9 - 11
src/business/auth/index.ts

@@ -1,7 +1,7 @@
 import { ref } from 'vue'
 import { v4 } from 'uuid'
 import { timerTask } from '@/utils/timer'
-import { useStore } from '@/stores'
+import { enumStore, errorInfoStore, loginStore, userStore, futuresStore, accountStore } from '@/stores'
 import { checkTokenLoop } from '@/business/common'
 import socket from '@/services/socket'
 import cryptojs from 'crypto-js'
@@ -74,7 +74,6 @@ function useAutoLogin() {
 }
 
 export function useAuth(autoLogin = false) {
-    const { enumStore, errorInfoStore, loginStore, userStore, futuresStore,  accountStore } = useStore()
     const { getAutoLoginData, setAutoLoginData } = useAutoLogin()
     const loading = ref(false)
     const user = ref<Proto.LoginReq>(getAutoLoginData(autoLogin))
@@ -83,15 +82,15 @@ export function useAuth(autoLogin = false) {
     const login = async () => {
         try {
             loading.value = true
-            await enumStore.getAllEnumList()
-            await errorInfoStore.getErrorInfoList()
+            await enumStore.actions.getAllEnumList()
+            await errorInfoStore.actions.getErrorInfoList()
 
             const { LoginID, LoginPWD } = user.value
             if (LoginID && LoginPWD) {
-                await loginStore.userLogin(user.value)
-                await Promise.all([userStore.getUserData(), futuresStore.getGoodsList()])
-                
-                accountStore.getAccountList()
+                await loginStore.actions.userLogin(user.value)
+                await Promise.all([userStore.actions.getUserData(), futuresStore.actions.getGoodsList()])
+
+                accountStore.actions.getAccountList()
                 setAutoLoginData(user.value)
                 checkTokenLoop()
             } else {
@@ -106,14 +105,13 @@ export function useAuth(autoLogin = false) {
 
     // 用户登出
     const logout = (callback?: () => void) => {
-        const { loginStore, accountStore } = useStore()
         const { setAutoLoginData } = useAutoLogin()
 
         setAutoLoginData()
         socket.closeAll()
         timerTask.clearAll()
-        loginStore.reset()
-        accountStore.reset()
+        loginStore.actions.reset()
+        accountStore.actions.reset()
         callback && callback()
     }
 

+ 14 - 28
src/business/bank/index.ts

@@ -1,15 +1,15 @@
 import { reactive, shallowRef, computed } from 'vue'
 import { useDataTable } from '@/hooks/datatable'
-import { useLoginStore, useUserStore } from '@/stores'
+import { loginStore, userStore } from '@/stores'
 import { queryHisAmountLog, queryAmountLog, t2bBankWithdraw, queryBankAccountSign, t2bBankDeposit, queryAccountInOutApply, queryCusBankSignBank, t2bBankSign, t2bBankCancelSign, accountFundInfoReq } from '@/services/api/bank'
 import { SignStatus } from '@/constants/bank'
 import { decryptAES } from '@/utils/websocket/crypto'
 import moment from "moment"
 
+const { userId, firstAccountId } = loginStore.$mapGetters()
 
 // 历史资金流水列表
 export function useAmountStatementList() {
-    const { getFirstAccountId } = useLoginStore()
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.AmountLogRsp>()
     const loading = shallowRef(false)
 
@@ -20,7 +20,7 @@ export function useAmountStatementList() {
                 page: pageIndex.value,
                 pagesize: pageSize.value,
                 pageflag: 1,
-                accountID: getFirstAccountId().toString(),
+                accountID: firstAccountId.value.toString(),
             },
             success: (res) => {
                 total.value = res.total
@@ -46,7 +46,6 @@ export function useAmountStatementList() {
 
 // 历史出入金流水列表
 export function useHisAmountStatementList() {
-    const { getFirstAccountId } = useLoginStore()
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.HisAmountLogRsp>()
     const loading = shallowRef(false)
 
@@ -57,7 +56,7 @@ export function useHisAmountStatementList() {
                 page: pageIndex.value,
                 pagesize: pageSize.value,
                 pageflag: 1,
-                accountID: getFirstAccountId().toString(),
+                accountID: firstAccountId.value.toString(),
             },
             success: (res) => {
                 total.value = res.total
@@ -83,8 +82,6 @@ export function useHisAmountStatementList() {
 
 // 获取出入金流水列表
 export function useAccouuntInOutApplyListList() {
-
-    const { getUserId } = useLoginStore()
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.AccountOutInApplyRsp>()
     const loading = shallowRef(false)
 
@@ -92,7 +89,7 @@ export function useAccouuntInOutApplyListList() {
         loading.value = true
         return queryAccountInOutApply({
             data: {
-                userid: getUserId()
+                userid: userId.value
             },
             success: (res) => {
                 total.value = res.total
@@ -146,7 +143,6 @@ export function getCusBankSignBankList() {
 
 // 查询当前已经签约信息列表
 export function useBankAccountSign() {
-    const { getUserId } = useLoginStore()
     const { dataList } = useDataTable<Model.BankAccountSignRsp>()
     const loading = shallowRef(false)
 
@@ -154,7 +150,7 @@ export function useBankAccountSign() {
         loading.value = true
         return queryBankAccountSign({
             data: {
-                userid: getUserId()
+                userid: userId.value
             },
             success: (res) => {
                 dataList.value = res.data
@@ -179,11 +175,7 @@ export function useBankAccountSign() {
 
 // 提现请求
 export function useDoWithdraw() {
-
-    /// 获取UserId
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
-
     /// 获取当前是否已签约
     const bankAccountSign = shallowRef<Model.BankAccountSignRsp[]>([])
 
@@ -197,7 +189,7 @@ export function useDoWithdraw() {
     /// 查询签约信息
     const request = queryBankAccountSign({
         data: {
-            userid: getUserId()
+            userid: userId.value
         },
         success: (res) => {
             if (res.data.length) {
@@ -246,8 +238,6 @@ export function useDoWithdraw() {
 
 // 充值请求
 export function useDoDeposit() {
-    /// 获取UserId
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
     /// 获取当前是否已签约
     const sign = shallowRef<Model.BankAccountSignRsp[]>([])
@@ -258,7 +248,7 @@ export function useDoDeposit() {
 
     const request = queryBankAccountSign({
         data: {
-            userid: getUserId()
+            userid: userId.value
         },
         success: (res) => {
             if (res.data.length) {
@@ -302,8 +292,7 @@ export function useDoDeposit() {
 export function useDoBankSign() {
 
     const loading = shallowRef(false)
-    const { getUserInfo } = useUserStore()
-    const { getFirstAccountId } = useLoginStore()
+    const { userInfo } = userStore.$mapGetters()
 
     /// 托管银行信息
     const cusSignBank = shallowRef<Model.CusBankSignBankRsp>()
@@ -349,10 +338,10 @@ export function useDoBankSign() {
         BankCardType: 0,
         BankAccountType: 1,
         Extend_Info: JSON.stringify({ "sex": 1 }),
-        AccountCode: getFirstAccountId().toString(),
-        CertID: decryptAES(getUserInfo()?.cardnum ?? ''),
-        CertType: getUserInfo()?.cardtypeid.toString(),
-        BankAccountName: getUserInfo()?.customername,
+        AccountCode: firstAccountId.value.toString(),
+        CertID: decryptAES(userInfo.value?.cardnum ?? ''),
+        CertType: userInfo.value?.cardtypeid.toString(),
+        BankAccountName: userInfo.value?.customername,
     })
 
     console.log(formData)
@@ -437,9 +426,6 @@ export function useDoCancelBankSign() {
 
 /// 账户资金信息请求
 export function useAccountFundInfo() {
-    /// 获取UserId
-    const { getFirstAccountId } = useLoginStore()
-
     /// 数据
     const fund = shallowRef<Partial<Proto.AccountFundInfoRsp>>({})
 
@@ -448,7 +434,7 @@ export function useAccountFundInfo() {
         data: {
             QueryBitMask: 2,
             OrderId: new Date().getTime(),
-            AccountId: getFirstAccountId(),
+            AccountId: firstAccountId.value,
         },
         success: (res) => {
             fund.value = res

+ 11 - 13
src/business/common/index.ts

@@ -1,5 +1,5 @@
 import { timerTask } from '@/utils/timer'
-import { useStore } from '@/stores'
+import { enumStore, errorInfoStore, loginStore, userStore, futuresStore, menuStore, accountStore } from '@/stores'
 import { tokenCheck } from '@/services/api/account'
 import eventBus from '@/services/bus'
 
@@ -7,17 +7,16 @@ import eventBus from '@/services/bus'
  * 初始化业务数据(暂无用,后期优化废除)
  */
 export async function initBaseData() {
-    const { enumStore, errorInfoStore, loginStore, userStore, futuresStore, menuStore, accountStore } = useStore()
-    await enumStore.getAllEnumList()
-    await errorInfoStore.getErrorInfoList()
+    await enumStore.actions.getAllEnumList()
+    await errorInfoStore.actions.getErrorInfoList()
 
-    if (loginStore.getToken()) {
+    if (loginStore.getters.token) {
         await Promise.all([
-            userStore.getUserData(),
-            menuStore.getUserMenuList(),
-            futuresStore.getGoodsList(),
+            userStore.actions.getUserData(),
+            menuStore.actions.getUserMenuList(),
+            futuresStore.actions.getGoodsList(),
         ])
-        accountStore.getAccountList()
+        accountStore.actions.getAccountList()
     }
 }
 
@@ -25,12 +24,11 @@ export async function initBaseData() {
  * 令牌效验
  */
 export function checkToken() {
-    const { loginStore } = useStore()
-    const { LoginID, Token } = loginStore.loginInfo.value
+    const { loginId, token } = loginStore.$mapGetters()
     return tokenCheck({
         data: {
-            LoginID,
-            Token,
+            LoginID: loginId.value,
+            Token: token.value,
         },
         fail: () => eventBus.$emit('LogoutNotify')
     })

+ 7 - 7
src/business/credit/index.ts

@@ -3,13 +3,14 @@ import { useDataTable } from '@/hooks/datatable'
 import { v4 } from 'uuid'
 import { ClientType } from '@/constants/client'
 import { ScoreConfigType } from '@/constants/credit'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { queryUserAccount } from '@/services/api/account'
 import { queryUserScoreLog, queryTHJScoreConfig, thjRedPacketLottery } from '@/services/api/credit'
 
+const { userId } = loginStore.$mapGetters()
+
 // 积分流水列表
 export function useCreditStatementList(stype?: ScoreConfigType) {
-    const { getUserId } = useLoginStore()
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.UserScoreLogRsp>()
     const loading = shallowRef(false)
 
@@ -18,7 +19,7 @@ export function useCreditStatementList(stype?: ScoreConfigType) {
         await queryUserScoreLog({
             data: {
                 stype,
-                userid: getUserId(),
+                userid: userId.value,
                 page: pageIndex.value,
                 pagesize: pageSize.value,
             },
@@ -46,7 +47,6 @@ export function useCreditStatementList(stype?: ScoreConfigType) {
 
 // 积分抽奖
 export function useCreditLottery() {
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
     const creditList = shallowRef<Model.UserScoreLogRsp[]>([])
     const creditConfig = shallowRef<Partial<Model.THJScoreConfigRsp>>({})
@@ -60,7 +60,7 @@ export function useCreditLottery() {
     const formRefresh = () => {
         queryUserAccount({
             data: {
-                userID: getUserId()
+                userID: userId.value
             },
             success: (res) => {
                 userAccount.value = res.data
@@ -69,7 +69,7 @@ export function useCreditLottery() {
         queryUserScoreLog({
             data: {
                 stype: ScoreConfigType.Lottery,
-                userid: getUserId(),
+                userid: userId.value,
                 page: 1,
                 pagesize: 10,
             },
@@ -83,7 +83,7 @@ export function useCreditLottery() {
         loading.value = true
         return thjRedPacketLottery({
             data: {
-                UserID: getUserId(),
+                UserID: userId.value,
                 ClientType: ClientType.Web, // 终端类型
                 ClientSerialNo: v4() // 客户端流水号
             },

+ 7 - 9
src/business/goods/index.ts

@@ -3,7 +3,9 @@ import { useDataTable } from '@/hooks/datatable'
 import { EchartsDataset } from '@/hooks/echarts/line/interface'
 import { BuyOrSell } from '@/constants/order'
 import { queryTHJWrstandard, queryOrderQuote, queryOrderQuoteDetail, queryWrMarketTradeConfig, queryTHJWrstandardDetail, addUserFavoriteGoods, removeUserFavoriteGoods, queryTHJProduct, queryMarketRun, queryTHJTradeData } from '@/services/api/goods'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
+
+const { userId } = loginStore.$mapGetters()
 
 // 采购列表
 export function useWrstandardList() {
@@ -82,13 +84,11 @@ export function useWrstandardDetails(wrstandardid: number) {
 
 // 用户商品收藏信息
 export function useUserFavoriteGoods(goodsid: number) {
-    const { getUserId } = useLoginStore()
-
     // 添加收藏
     const getAddUserFavoriteGoods = () => {
         return addUserFavoriteGoods({
             data: {
-                userID: getUserId(),
+                userID: userId.value,
                 goodsID: goodsid
             },
         })
@@ -98,7 +98,7 @@ export function useUserFavoriteGoods(goodsid: number) {
     const getRemoveUserFavoriteGoods = () => {
         return removeUserFavoriteGoods({
             data: {
-                userID: getUserId(),
+                userID: userId.value,
                 goodsID: goodsid
             },
         })
@@ -114,13 +114,12 @@ export function useUserFavoriteGoods(goodsid: number) {
 export function useQueryTHJTradeDataList() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJTradeDataRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const getQueryTHJTradeDataList = async (marketid: number) => {
         loading.value = true
         await queryTHJTradeData({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 marketid: marketid,
                 page: pageIndex.value,
                 pagesize: pageSize.value,
@@ -151,14 +150,13 @@ export function useQueryTHJTradeDataList() {
 export function useQueryTHJProductLists() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJProductRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
     const active = shallowRef(0)
 
     const getQueryTHJProductLists = async () => {
         loading.value = true
         await queryTHJProduct({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 favoriteflag: false,
                 page: pageIndex.value,
                 pagesize: pageSize.value,

+ 2 - 3
src/business/market/index.ts

@@ -1,7 +1,7 @@
 import { shallowRef, computed } from 'vue'
 import { useDataTable } from '@/hooks/datatable'
 import { querySpotGoodsPrice, querySpotgoodsPrice } from '@/services/api/market'
-import { useFuturesStore } from '@/stores'
+import { futuresStore } from '@/stores'
 import subscribe from '@/services/subscribe'
 
 // 现货行情
@@ -64,8 +64,7 @@ export function useSpotGoodsPriceList() {
 
 // 期货行情列表
 export function useFuturesList() {
-    const { quoteList } = useFuturesStore()
-    const dataList = computed(() => quoteList.value.filter((e) => e.marketid === 99201))
+    const dataList = computed(() => futuresStore.getters.quoteList.filter((e) => e.marketid === 99201))
     const quoteSubscribe = subscribe.addQuoteSubscribe(dataList.value.map((e) => e.goodscode))
 
     return {

+ 12 - 17
src/business/order/index.ts

@@ -10,19 +10,20 @@ import {
     queryTHJPurchaseTransferOrder,
     queryTHJPurchaseTransferOrderDetail
 } from '@/services/api/order'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
+
+const { userId, firstAccountId } = loginStore.$mapGetters()
 
 // 查询仓单持有记录
 export function useQueryHoldLB() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.HoldLBRsp>()
     const loading = shallowRef(false)
-    const { getFirstAccountId } = useLoginStore()
 
     const getHoldLB = async (warehouseid?: number, deliverygoodsid?: number, wrstandardid?: number, wrfactortypeid?: number, dgitemname?: string) => {
         loading.value = true
         await queryHoldLB({
             data: {
-                accountid: getFirstAccountId(),
+                accountid: firstAccountId.value,
                 warehouseid: warehouseid,
                 deliverygoodsid: deliverygoodsid,
                 wrstandardid: wrstandardid,
@@ -57,13 +58,12 @@ export function useQueryHoldLB() {
 export function useQueryWrOutInApply() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.WrOutInApplyRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const getWrOutInApply = async (begindate?: string, enddate?: string) => {
         loading.value = true
         await queryWrOutInApply({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 begindate: begindate,
                 enddate: enddate,
                 page: 1,
@@ -95,9 +95,9 @@ export function useQueryWrOutInApply() {
 export function useQueryWrOrderDetail() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.WrOrderDetailRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
+
     const formData = reactive<Partial<Model.WrOrderDetailReq>>({
-        userid: getUserId(),
+        userid: userId.value,
         haswr: 1,
         page: pageIndex.value,
         pagesize: pageSize.value,
@@ -134,10 +134,9 @@ export function useQueryWrOrderDetail() {
 export function useQueryWrTradeDetail() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.WrTradeDetailRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const formData = reactive<Partial<Model.WrTradeDetailReq>>({
-        userid: getUserId(),
+        userid: userId.value,
         haswr: 1,
         page: pageIndex.value,
         pagesize: pageSize.value,
@@ -174,13 +173,12 @@ export function useQueryWrTradeDetail() {
 export function useTHJPurchaseTradeDetail() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJPurchaseTradeDetailRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const getTHJPurchaseTradeDetail = async (type?: number) => {
         loading.value = true
         await queryTHJPurchaseTradeDetail({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 type: type,
                 page: pageIndex.value,
                 pagesize: pageSize.value,
@@ -211,13 +209,12 @@ export function useTHJPurchaseTradeDetail() {
 export function useQueryTHJPromotionIncome() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJPromotionIncomeRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const getTHJPromotionIncome = async (status?: number) => {
         loading.value = true
         await queryTHJPromotionIncome({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 profitstatus: status,
                 page: pageIndex.value,
                 pagesize: pageSize.value,
@@ -248,13 +245,12 @@ export function useQueryTHJPromotionIncome() {
 export function useQueryTHJPromotionIncomeDetail(month: string) {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJPromotionIncomeDetailRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const getTHJPromotionIncomeDetail = async () => {
         loading.value = true
         await queryTHJPromotionIncomeDetail({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 mouth: month,
                 page: pageIndex.value,
                 pagesize: pageSize.value,
@@ -285,13 +281,12 @@ export function useQueryTHJPromotionIncomeDetail(month: string) {
 export function useQueryTHJPurchaseTransferOrder() {
     const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJPurchaseTransferOrderRsp>()
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const getTHJPurchaseTransferOrder = async (ordertype: number) => {
         loading.value = true
         await queryTHJPurchaseTransferOrder({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
                 page: pageIndex.value,
                 pagesize: pageSize.value,
                 ordertype: ordertype

+ 28 - 38
src/business/trade/index.ts

@@ -1,7 +1,7 @@
 import { reactive, ref, shallowRef, computed } from 'vue'
 import { v4 } from 'uuid'
 import { ClientType, OrderSrc } from '@/constants/client'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import {
     spotPresaleDestingOrder,
     spotPresaleTransferCancel,
@@ -20,14 +20,15 @@ import { formatDate } from "@/filters";
 import Long from 'long'
 import { BuyOrSell } from '@/constants/order'
 
+const { loginId, userId, firstAccountId } = loginStore.$mapGetters()
+
 // 采购摘牌
 export function usePurchaseOrderDesting() {
-    const { getUserId, getFirstAccountId } = useLoginStore()
     const loading = shallowRef(false)
 
     const formData = ref<Partial<Proto.SpotPresaleDestingOrderReq>>({
-        UserID: getUserId(), // 用户ID,必填
-        AccountID: getFirstAccountId(), // 资金账号,必填
+        UserID: userId.value, // 用户ID,必填
+        AccountID: firstAccountId.value, // 资金账号,必填
         ClientType: ClientType.Web // 终端类型
     })
 
@@ -54,14 +55,13 @@ export function usePurchaseOrderDesting() {
 
 // 铁合金现货预售交收确认
 export function useSpotPresaleDeliveryConfirm() {
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
 
     const confirmSubmit = (id: string) => {
         loading.value = true
         return spotPresaleDeliveryConfirm({
             data: {
-                UserID: getUserId(),
+                UserID: userId.value,
                 Remark: '',
                 WRTradeDetailID: Long.fromString(id),
                 ClientSerialNo: v4(), // 客户端流水号
@@ -82,13 +82,12 @@ export function useSpotPresaleDeliveryConfirm() {
 // 铁合金现货预售违约申请
 export function useSpotPresaleBreachOfContractApply() {
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const applySubmit = (id: string) => {
         loading.value = true
         return spotPresaleBreachOfContractApply({
             data: {
-                UserID: getUserId(),
+                UserID: userId.value,
                 WRTradeDetailID: Long.fromString(id),
                 ClientSerialNo: v4(), // 客户端流水号
                 ClientType: ClientType.Web // 终端类型
@@ -108,10 +107,9 @@ export function useSpotPresaleBreachOfContractApply() {
 // 铁合金现货预售付款处理接口
 export function useSpotPresalePlayment() {
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const formData = reactive<Partial<Proto.SpotPresalePlaymentReq>>({
-        UserID: getUserId(), // 用户ID,必填
+        UserID: userId.value, // 用户ID,必填
         ClientType: ClientType.Web, // 终端类型
         ClientSerialNo: v4(), // 客户端流水号
     })
@@ -138,10 +136,9 @@ export function useSpotPresalePlayment() {
 // 铁合金现货预售转让挂牌接口
 export function useSpotPresaleTransferListing() {
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const formData = reactive<Partial<Proto.SpotPresaleTransferListingReq>>({
-        UserID: getUserId(), // 用户ID,必填
+        UserID: userId.value, // 用户ID,必填
         ClientType: ClientType.Web, // 终端类型
         ClientSerialNo: v4(), // 客户端流水号
     })
@@ -173,13 +170,12 @@ export function useSpotPresaleTransferListing() {
 // 铁合金现货预售转让撤销接口请求
 export function useSpotPresaleTransferCancel() {
     const loading = shallowRef(false)
-    const { getUserId } = useLoginStore()
 
     const transferCancelSubmit = (wrtradedetailid?: string) => {
         loading.value = true
         return spotPresaleTransferCancel({
             data: {
-                UserID: getUserId(),
+                UserID: userId.value,
                 WRTradeDetailID: Long.fromString(wrtradedetailid ?? '0'),
                 ClientSerialNo: v4(), // 客户端流水号
                 ClientType: ClientType.Web // 终端类型
@@ -199,11 +195,10 @@ export function useSpotPresaleTransferCancel() {
 // 铁合金现货预售转让摘牌接口请求
 export function useSpotPresaleTransferDesting() {
     const loading = shallowRef(false)
-    const { getUserId, getFirstAccountId } = useLoginStore()
 
     const formData = reactive<Proto.SpotPresaleTransferDestingReq>({
-        UserID: getUserId(),
-        AccountID: getFirstAccountId(),
+        UserID: userId.value,
+        AccountID: firstAccountId.value,
         TransferID: Long.fromNumber(0),
         ClientType: ClientType.Web // 终端类型
     })
@@ -231,15 +226,14 @@ export function useSpotPresaleTransferDesting() {
 // 挂牌撤单请求接口
 export function useWrListingCancelOrder() {
     const loading = shallowRef(false)
-    const { getUserId, getFirstAccountId, getLoginId } = useLoginStore()
 
     const cancelSubmit = (id: string, buyorsell: number) => {
         loading.value = true
         return wrListingCancelOrder({
             data: {
-                UserID: getUserId(),
-                AccountID: getFirstAccountId(),
-                OperatorID: getLoginId(),
+                UserID: userId.value,
+                AccountID: firstAccountId.value,
+                OperatorID: loginId.value,
                 OrderSrc: OrderSrc.ORDERSRC_CLIENT,
                 OldWRTradeOrderID: Long.fromString(id),
                 ClientOrderTime: formatDate(new Date().toString(), 'YYYY-MM-DD HH:mm:ss'),
@@ -262,15 +256,14 @@ export function useWrListingCancelOrder() {
 // 仓单明细提货请求接口
 export function useWrOutInApply(holdlb?: Model.HoldLBRsp) {
     const loading = shallowRef(false)
-    const { getUserId, getFirstAccountId, getLoginId } = useLoginStore()
     const orderQty = shallowRef(0.0)
     const checked = shallowRef(3)
 
     const formData = reactive<Partial<Proto.WROutApplyReq>>({
         AppointmentRemark: '',
-        UserID: getUserId(),             // 用户ID,必填
-        AccountID: getFirstAccountId(),  // 申请人账户ID
-        CreatorID: getLoginId(),         // 创建人ID
+        UserID: userId.value,             // 用户ID,必填
+        AccountID: firstAccountId.value,  // 申请人账户ID
+        CreatorID: loginId.value,         // 创建人ID
         WRStandardID: holdlb?.wrstandardid,
         WarehouseID: holdlb?.warehouseid,
         ClientSerialID: new Date().getTime(),    // 客户端流水号
@@ -308,20 +301,19 @@ export function useWrOutInApply(holdlb?: Model.HoldLBRsp) {
 // 仓单明细挂牌请求接口
 export function useHdWROrder() {
     const loading = shallowRef(false)
-    const { getUserId, getFirstAccountId, getLoginId } = useLoginStore()
 
     const formData = reactive<Proto.HdWROrderReq>({
         Header: {
-            AccountID: getFirstAccountId(),
+            AccountID: firstAccountId.value,
         },
         IsSpecified: 0,
         PriceFactor: 1.0,
         FirstRatio: 0.0,
         CanBargain: 0,
         CanPart: 1,
-        UserID: getUserId(),
-        AccountID: getFirstAccountId(),
-        OperatorID: getLoginId(),
+        UserID: userId.value,
+        AccountID: firstAccountId.value,
+        OperatorID: loginId.value,
         ClientType: ClientType.Web,
         BuyOrSell: BuyOrSell.Sell,
         WRPriceType: 1,
@@ -363,19 +355,18 @@ export function useHdWROrder() {
 // 仓单摘牌
 export function useHdWRDealOrder() {
     const loading = shallowRef(false)
-    const { getUserId, getFirstAccountId, getLoginId } = useLoginStore()
 
     const formData = reactive<Proto.HdWRDealOrderReq>({
-        UserID: getUserId(), // 用户ID
-        AccountID: getFirstAccountId(), // 资金账号
+        UserID: userId.value, // 用户ID
+        AccountID: firstAccountId.value, // 资金账号
         RelatedWRTradeOrderID: Long.fromNumber(0), // 关联委托单号(摘牌委托关联挂牌委托单ID)
-        WRTransferUserID: getUserId(), // 仓单受让用户
+        WRTransferUserID: userId.value, // 仓单受让用户
         OrderQty: 0, // 委托数量
         OrderSrc: OrderSrc.ORDERSRC_CLIENT, // 委托来源
         ClientSerialNo: '', // 客户端流水号
         ClientOrderTime: '', // 客户端委托时间
         ClientType: ClientType.Web, // 终端类型
-        OperatorID: getLoginId(), // 操作员账号ID
+        OperatorID: loginId.value, // 操作员账号ID
         TradeDate: '', // 交易日
         HasWr: 1, // 是否有仓单-0:没有仓单1:有仓单
         IsFinancing: 0, // 是否融资购买(买摘牌时有效)-0:否1:是
@@ -407,12 +398,11 @@ export function useHdWRDealOrder() {
 // 铁合金收益支取申请接口
 export function useTHJProfitDrawApplyReq() {
     const loading = shallowRef(false)
-    const { getUserId, getLoginId } = useLoginStore()
 
     const formData = reactive<Proto.THJProfitDrawApplyReq>({
-        UserID: getUserId(), // 用户ID
+        UserID: userId.value, // 用户ID
         ApplySrc: ClientType.Web,
-        ApplyerID: getLoginId(),
+        ApplyerID: loginId.value,
         ClientType: ClientType.Web
     })
 

+ 15 - 17
src/business/user/account.ts

@@ -1,22 +1,23 @@
 import { shallowRef, reactive } from 'vue'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { useDataTable } from '@/hooks/datatable'
 import { investorDel, modifyPassword, queryWrDraftUserInfo, requestAddAuth } from '@/services/api/account'
 import cryptojs from 'crypto-js'
 
+const { loginId, userId, firstAccountId } = loginStore.$mapGetters()
+
 // 查询用户实名认证信息
 export function getWrDraftUserInfo(userstatus?: number) {
-    const { getUserId } = useLoginStore()
     const { dataList } = useDataTable<Model.UserInfo>()
     const loading = shallowRef(false)
-   
+
     const formData = reactive<Model.WrDraftUserInfoReq>({
         userstatus: userstatus,
-        userid: getUserId()
+        userid: userId.value
     })
 
     const getWrDraftUserInfoList = () => {
-        const {userstatus, userid} = formData
+        const { userstatus, userid } = formData
         loading.value = true
 
         return queryWrDraftUserInfo({
@@ -34,20 +35,19 @@ export function getWrDraftUserInfo(userstatus?: number) {
     }
 
     return {
-        loading, 
-        formData, 
-        dataList, 
+        loading,
+        formData,
+        dataList,
         getWrDraftUserInfoList
     }
 }
 
 // 用户实名认证
 export function addAuthReq() {
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
-   
+
     const formData = reactive<Partial<Model.AddAuthReq>>({
-        userid: getUserId(),
+        userid: userId.value,
         cardtype: 0
     })
 
@@ -73,20 +73,19 @@ export function addAuthReq() {
     }
 
     return {
-        loading, 
-        formData, 
+        loading,
+        formData,
         formSubmit
     }
 }
 
 // 修改密码
 export function useAccountPassword(ModifyPwdType: 0 | 1 | 2) {
-    const { getLoginId, getFirstAccountId } = useLoginStore()
     const loading = shallowRef(false)
 
     const formData = reactive<Proto.ModifyPwdReq>({
         ModifyPwdType, // 修改密码类型1:登陆密码2:资金账户密码
-        ModifyPwdID: ModifyPwdType === 1 ? getLoginId() : getFirstAccountId(), // 被修改的ID(ModifyType=1:LoginIDModifyType=2:AccountID)
+        ModifyPwdID: ModifyPwdType === 1 ? loginId.value : firstAccountId.value, // 被修改的ID(ModifyType=1:LoginIDModifyType=2:AccountID)
         OldPwd: '', // 旧资金密码
         NewPwd: '' // 新资金密码
     })
@@ -117,14 +116,13 @@ export function useAccountPassword(ModifyPwdType: 0 | 1 | 2) {
 
 // 账户注销
 export function useAccountCancellation() {
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
 
     const formSubmit = () => {
         loading.value = true
         return investorDel({
             data: {
-                UserID: getUserId()
+                UserID: userId.value
             },
             complete: () => {
                 loading.value = false

+ 6 - 6
src/business/user/address.ts

@@ -1,10 +1,11 @@
 import { shallowRef, reactive, computed } from 'vue'
 import { useDataTable } from '@/hooks/datatable'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { queryUserReceiveInfo, userReceiveInfo, delUserReceiveInfo, userReceiveIsDefault } from '@/services/api/user'
 
+const { userId } = loginStore.$mapGetters()
+
 export function useAddress() {
-    const { getUserId } = useLoginStore()
     const { dataList, total, pageIndex, pageSize } = useDataTable<Model.UserReceiveInfoRsp>()
     const loading = shallowRef(false)
     const columns = shallowRef([])
@@ -13,7 +14,7 @@ export function useAddress() {
         loading.value = true
         return queryUserReceiveInfo({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
             },
             success: (res) => {
                 total.value = res.total
@@ -37,12 +38,11 @@ export function useAddress() {
 }
 
 export function useAddressForm(selectedRow?: Model.UserReceiveInfoRsp) {
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
 
     const formData = reactive<Proto.UserReceiveInfoReq>({
         ReceiveInfoId: 0,
-        UserID: getUserId(),
+        UserID: userId.value,
         CardTypeID: 0,
         ReceiverName: '',
         CardNum: '',
@@ -103,7 +103,7 @@ export function useAddressForm(selectedRow?: Model.UserReceiveInfoRsp) {
         loading.value = true
         return userReceiveIsDefault({
             data: {
-                UserId: getUserId(),
+                UserId: userId.value,
                 AutoId: formData.ReceiveInfoId
             },
             complete: () => {

+ 5 - 5
src/business/user/invoice.ts

@@ -1,11 +1,12 @@
 import { shallowRef, reactive } from 'vue'
 import { useDataTable } from '@/hooks/datatable'
 import { queryWrUserReceiptInfo, userReceiptInfo, delUserReceiptInfo } from '@/services/api/user'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { getCertificateTypeList } from '@/constants/certificate'
 
+const { userId } = loginStore.$mapGetters()
+
 export function useInvoice() {
-    const { getUserId } = useLoginStore()
     const { dataList, total, pageIndex, pageSize } = useDataTable<Model.WrUserReceiptInfoRsp>()
     const loading = shallowRef(false)
     const columns = shallowRef([])
@@ -14,7 +15,7 @@ export function useInvoice() {
         loading.value = true
         return queryWrUserReceiptInfo({
             data: {
-                userid: getUserId(),
+                userid: userId.value,
             },
             success: (res) => {
                 total.value = res.total
@@ -38,12 +39,11 @@ export function useInvoice() {
 }
 
 export function useInvoiceForm(selectedRow?: Model.WrUserReceiptInfoRsp) {
-    const { getUserId } = useLoginStore()
     const loading = shallowRef(false)
     const certificateTypeList = getCertificateTypeList()
 
     const formData = reactive<Proto.UserReceiptInfoReq>({
-        UserID: getUserId(), // 用户ID
+        UserID: userId.value, // 用户ID
         UserName: '', // 发票抬头姓名
         ReceiptType: 1, // 发票类型
         TaxpayerID: '', // 纳税人识别号

+ 2 - 2
src/constants/account.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName, getEnumTypeValue } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName, getEnumTypeValue } = enumStore.actions
 
 /**
  * 实名认证状态

+ 2 - 2
src/constants/bank.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName } = enumStore.actions
 
 /**
  * 签约状态

+ 2 - 2
src/constants/certificate.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName } = enumStore.actions
 
 /**
  * 获取证件类型列表

+ 3 - 3
src/constants/client.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList } = useEnumStore()
+const { getEnumTypeList } = enumStore.actions
 
 /**
  * 客户端类型
@@ -30,7 +30,7 @@ export function getClientTypeList() {
 /**
  * 委托来源
  */
- export enum OrderSrc {
+export enum OrderSrc {
     /// 客户端
     ORDERSRC_CLIENT = 1,
     /// 管理端

+ 2 - 2
src/constants/credit.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName } = enumStore.actions
 
 /**
  * 积分配置类型

+ 2 - 2
src/constants/market.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName } = enumStore.actions
 
 /**
  * 交易市场

+ 2 - 2
src/constants/menu.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeName } = useEnumStore()
+const { getEnumTypeName } = enumStore.actions
 
 /**
  * 权限类型

+ 2 - 2
src/constants/order.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName } = enumStore.actions
 
 /**
  * 买卖方向

+ 2 - 2
src/constants/receipt.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeName } = useEnumStore()
+const { getEnumTypeName } = enumStore.actions
 
 /**
  * 发票类型

+ 2 - 2
src/constants/unit.ts

@@ -1,6 +1,6 @@
-import { useEnumStore } from '@/stores'
+import { enumStore } from '@/stores'
 
-const { getEnumTypeList, getEnumTypeName } = useEnumStore()
+const { getEnumTypeList, getEnumTypeName } = enumStore.actions
 
 /**
  * 获取商品单位列表

+ 2 - 3
src/hooks/echarts/candlestick/index.ts

@@ -2,13 +2,12 @@ import { ref, computed, watch } from 'vue'
 //import { timerInterceptor } from '@/utils/timer'
 import { ChartCycleType } from '@/constants/chart'
 import { queryHistoryDatas } from '@/services/api/quote'
-import { useFuturesStore } from '@/stores'
+import { futuresStore } from '@/stores'
 import { useDataset } from './dataset'
 import { useOptions } from './options'
 import moment from 'moment'
 
 export function useCandlestickChart(goodscode: string) {
-    const { getQuoteDayInfoByCode } = useFuturesStore()
     const { dataset, handleData, clearData, calcIndicator } = useDataset();
     const { options, initOptions, updateOptions } = useOptions(dataset);
 
@@ -16,7 +15,7 @@ export function useCandlestickChart(goodscode: string) {
     const isEmpty = ref(true);
     const dataIndex = ref(-1); // 当前数据索引值
     const cycleType = ref(ChartCycleType.Minutes);
-    const quote = getQuoteDayInfoByCode(goodscode); // 实时行情
+    const quote = futuresStore.actions.getQuoteDayInfoByCode(goodscode); // 实时行情
 
     // 当前选中的数据项
     const selectedItem = computed(() => {

+ 2 - 2
src/hooks/echarts/candlestick/options.ts

@@ -1,11 +1,11 @@
 import { reactive, watch } from 'vue'
 import { ECOption } from '@/components/base/echarts/core'
 import { timerInterceptor } from '@/utils/timer'
-import { useThemeStore } from '@/stores'
+import { themeStore } from '@/stores'
 import { EchartsDataset, EchartsOptions, Colors } from './interface'
 import moment from 'moment'
 
-const { appTheme } = useThemeStore();
+const { appTheme } = themeStore.$mapState()
 
 function getColors() {
     // 默认主题色配置

+ 2 - 2
src/hooks/echarts/line/options.ts

@@ -1,9 +1,9 @@
 import { reactive, watch } from 'vue'
 import { timerInterceptor } from '@/utils/timer'
-import { useThemeStore } from '@/stores'
+import { themeStore } from '@/stores'
 import { EchartsDataset, EchartsOptions, Colors } from './interface'
 
-const { appTheme } = useThemeStore();
+const { appTheme } = themeStore.$mapState()
 
 function getColors() {
     // 默认主题色配置

+ 2 - 3
src/hooks/echarts/smoothedline/index.ts

@@ -1,19 +1,18 @@
 import { ref, computed, watch } from 'vue'
-import { useFuturesStore } from '@/stores'
+import { futuresStore } from '@/stores'
 import { formatDate } from '@/filters'
 import { queryHistoryTikDatas } from '@/services/api/quote'
 import { useDataset } from './dataset'
 import { useOptions } from './options'
 
 export function useSmoothedLineChart(goodscode: string) {
-    const { getQuoteDayInfoByCode } = useFuturesStore()
     const { dataset, clearData } = useDataset()
     const { options, initOptions, updateOptions } = useOptions(dataset)
 
     const loading = ref(false)
     const isEmpty = ref(false)
     const dataIndex = ref(-1); // 当前数据索引值
-    const quote = getQuoteDayInfoByCode(goodscode) // 实时行情
+    const quote = futuresStore.actions.getQuoteDayInfoByCode(goodscode) // 实时行情
 
     // 当前选中的数据项
     const selectedItem = computed(() => {

+ 2 - 2
src/hooks/echarts/smoothedline/options.ts

@@ -1,9 +1,9 @@
 import { reactive, watch } from 'vue'
 import { timerInterceptor } from '@/utils/timer'
-import { useThemeStore } from '@/stores'
+import { themeStore } from '@/stores'
 import { EchartsDataset, EchartsOptions, Colors } from './interface'
 
-const { appTheme } = useThemeStore();
+const { appTheme } = themeStore.$mapState()
 
 function getColors() {
     // 默认主题色配置

+ 2 - 3
src/hooks/echarts/timeline/index.ts

@@ -1,20 +1,19 @@
 import { ref, computed, watch } from 'vue'
 //import { timerInterceptor } from '@/utils/timer'
 import { queryTSData } from '@/services/api/quote'
-import { useFuturesStore } from '@/stores'
+import { futuresStore } from '@/stores'
 import { useDataset } from './dataset'
 import { useOptions } from './options'
 import moment from 'moment';
 
 export function useTimelineChart(goodscode: string) {
-    const { getQuoteDayInfoByCode } = useFuturesStore()
     const { dataset, handleData, clearData, calcIndicator } = useDataset();
     const { options, initOptions, updateOptions } = useOptions(dataset);
 
     const loading = ref(false);
     const isEmpty = ref(false);
     const dataIndex = ref(-1); // 当前数据索引值
-    const quote = getQuoteDayInfoByCode(goodscode); // 实时行情
+    const quote = futuresStore.actions.getQuoteDayInfoByCode(goodscode); // 实时行情
 
     // 当前选中的数据项
     const selectedItem = computed(() => {

+ 2 - 2
src/hooks/echarts/timeline/options.ts

@@ -1,10 +1,10 @@
 import { reactive, watch } from 'vue'
 import { timerInterceptor } from '@/utils/timer'
-import { useThemeStore } from '@/stores'
+import { themeStore } from '@/stores'
 import { echarts } from '@/components/base/echarts/core'
 import { EchartsDataset, EchartsOptions, Colors } from './interface'
 
-const { appTheme } = useThemeStore();
+const { appTheme } = themeStore.$mapState()
 
 function getColors() {
     // 默认主题色配置

+ 11 - 11
src/hooks/menu/index.ts

@@ -1,17 +1,17 @@
 import { defineAsyncComponent, Component } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
-import { useMenuStore } from '@/stores'
+import { menuStore } from '@/stores'
 import { AuthType } from '@/constants/menu'
 
 export function useMenu(authCode?: string) {
-    const { userMenus } = useMenuStore()
+    const { userRoutes } = menuStore.$mapState()
     const route = useRoute()
     const router = useRouter()
     const componentMap = new Map<string, Component>()
 
     // 过滤菜单
-    const filterMenu = (data: Model.UserMenu[], parentPath = '') => {
-        const result: Model.UserMenu[] = []
+    const filterMenu = (data: Model.UserRoutes[], parentPath = '') => {
+        const result: Model.UserRoutes[] = []
         data.forEach((e) => {
             if (!e.hidden && e.authType === AuthType.Menu) {
                 const routePath = (parentPath ? parentPath + '/' : '') + e.url
@@ -29,7 +29,7 @@ export function useMenu(authCode?: string) {
      * 根据 code 查找对应的子菜单
      * @returns 
      */
-    const findChildren = (data: Model.UserMenu[], code?: string): Model.UserMenu[] => {
+    const findChildren = (data: Model.UserRoutes[], code?: string): Model.UserRoutes[] => {
         const routeName = code ?? route.name?.toString()
         for (const item of data) {
             const { code, children } = item
@@ -49,13 +49,13 @@ export function useMenu(authCode?: string) {
      */
     const getMenus = (level = 0) => {
         // 过滤层级
-        const filterLevel = (data: Model.UserMenu[], n: number): Model.UserMenu[] => {
+        const filterLevel = (data: Model.UserRoutes[], n: number): Model.UserRoutes[] => {
             if (level) {
                 return data.map((e) => ({ ...e, children: n <= 1 ? [] : filterLevel(e.children ?? [], n - 1) }))
             }
             return data
         }
-        return filterMenu(filterLevel(userMenus.value, level))
+        return filterMenu(filterLevel(userRoutes.value, level))
     }
 
     /**
@@ -64,7 +64,7 @@ export function useMenu(authCode?: string) {
     * @returns 
     */
     const getChildrenMenus = (code?: string) => {
-        const children = findChildren(userMenus.value, code)
+        const children = findChildren(userRoutes.value, code)
         return filterMenu(children)
     }
 
@@ -73,7 +73,7 @@ export function useMenu(authCode?: string) {
      * @returns 
      */
     const getAuth = (authType: AuthType) => {
-        const children = findChildren(userMenus.value, authCode)
+        const children = findChildren(userRoutes.value, authCode)
         return children.reduce((res, cur) => {
             if (!cur.hidden && cur.authType === authType) {
                 if (!componentMap.get(cur.code) && cur.component) {
@@ -87,7 +87,7 @@ export function useMenu(authCode?: string) {
                 res.push(JSON.parse(JSON.stringify(cur)))
             }
             return res
-        }, [] as Model.UserMenu[])
+        }, [] as Model.UserRoutes[])
     }
 
     /**
@@ -129,7 +129,7 @@ export function useMenu(authCode?: string) {
     return {
         route,
         router,
-        userMenus,
+        userRoutes,
         componentMap,
         getMenus,
         getChildrenMenus,

+ 3 - 3
src/packages/mobile/router/index.ts

@@ -1,10 +1,10 @@
 import { createWebHashHistory, RouteRecordRaw } from "vue-router";
-import { useLoginStore } from "@/stores";
+import { loginStore } from "@/stores";
 import service from "@/services";
 import Page from "@mobile/components/layouts/page/index.vue";
 import animateRouter from "./animateRouter";
 
-const { getToken } = useLoginStore();
+const { token } = loginStore.$mapGetters();
 
 const routes: Array<RouteRecordRaw> = [
   {
@@ -495,7 +495,7 @@ const router = animateRouter.create({
 router.beforeEach((to, from, next) => {
   // 判断服务是否加载完成
   if (service.isReady) {
-    if (to.meta.ignoreAuth || getToken()) {
+    if (to.meta.ignoreAuth || token.value) {
       next();
     } else {
       next({

+ 2 - 2
src/packages/mobile/views/bank/wallet/components/deposit/index.vue

@@ -67,13 +67,13 @@ import { Form, Field, CellGroup, Button, FieldRule, FormInstance, showFailToast,
 import { useDoDeposit } from '@/business/bank'
 import { fullloading, dialog } from '@/utils/vant'
 import { useNavigation } from '@/hooks/navigation'
-import { useUserStore } from '@/stores'
+import { userStore } from '@/stores'
 import AppUploader from '@mobile/components/base/uploader/index.vue'
 
 const formRef = shallowRef<FormInstance>()
 const { formData, onSubmit, extendInfo } = useDoDeposit()
 const { router } = useNavigation()
-const { getSystemParamValue } = useUserStore()
+const { getSystemParamValue } = userStore.actions
 const start = getSystemParamValue('012')
 const end = getSystemParamValue('013')
 

+ 2 - 2
src/packages/mobile/views/bank/wallet/components/withdraw/index.vue

@@ -48,14 +48,14 @@ import { Form, Field, CellGroup, FormInstance, Button, FieldRule, showFailToast
 import { shallowRef } from 'vue'
 import { fullloading, dialog } from '@/utils/vant'
 import { useNavigation } from '@/hooks/navigation'
-import { useUserStore } from '@/stores'
+import { userStore } from '@/stores'
 
 const { formData, onSubmit, sign } = useDoWithdraw()
 /// 资金账户信息
 const { fund } = useAccountFundInfo()
 const { router } = useNavigation()
 const formRef = shallowRef<FormInstance>()
-const { getSystemParamValue } = useUserStore()
+const { getSystemParamValue } = userStore.actions
 const start = getSystemParamValue('012')
 const end = getSystemParamValue('013')
 

+ 2 - 1
src/packages/mobile/views/contract/details/index.vue

@@ -140,7 +140,8 @@ const tableList = computed(() => {
 })
 
 const onSubmit = (item: Model.THJPurchaseTransferDetailRsp['deliverydate'][number]) => {
-    dialog('确认立即摘牌吗?', {
+    dialog({
+        message: '确认立即摘牌吗?',
         showCancelButton: true
     }).then(() => {
         formData.TransferID = Long.fromString(item.transferid)

+ 4 - 4
src/packages/mobile/views/credit/signin/index.vue

@@ -109,13 +109,13 @@
 import { shallowRef, onActivated } from 'vue'
 import { showSuccessToast, showFailToast, Button } from 'vant'
 import { fullloading } from '@/utils/vant'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { queryUserAccount } from '@/services/api/account'
 import { queryTHJScoreConfig } from '@/services/api/credit'
 import { signin } from '@/services/api/common'
 import { useNavigation } from '@/hooks/navigation'
 
-const { getUserId } = useLoginStore()
+const { userId } = loginStore.$mapGetters()
 const { routerTo, routerBack } = useNavigation()
 const headerRef = shallowRef<HTMLDivElement>()
 const userAccount = shallowRef<Partial<Model.UserAccount>>({})
@@ -150,7 +150,7 @@ const userSignin = () => {
     fullloading(() => {
         signin({
             data: {
-                userid: getUserId()
+                userid: userId.value
             },
             success: (res) => {
                 if (res.data.signinstatus === 1) {
@@ -170,7 +170,7 @@ const userSignin = () => {
 const getUserAccount = () => {
     queryUserAccount({
         data: {
-            userID: getUserId()
+            userID: userId.value
         },
         success: (res) => {
             userAccount.value = res.data

+ 3 - 3
src/packages/mobile/views/home/index.vue

@@ -13,7 +13,7 @@ import { dialog } from '@/utils/vant'
 import { Tabbar } from '@mobile/components/base/tabbar/interface'
 import { GetAppUpdateInfo } from '@/services/api/common'
 import { useNavigation } from '@/hooks/navigation'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import plus from '@/utils/h5plus'
 import AppTabbar from '@mobile/components/base/tabbar/index.vue'
 import Home from './components/main/index.vue'
@@ -28,7 +28,7 @@ const components = {
   mine: Mine,
 }
 
-const { getToken } = useLoginStore()
+const { token } = loginStore.$mapGetters()
 const { routerTo, getGlobalUrlParams } = useNavigation()
 const componentId = shallowRef('home')
 const tabIndex = shallowRef(0)
@@ -61,7 +61,7 @@ const tabList: Tabbar[] = [
 ]
 
 const onTabClick = ({ name }: Tabbar, index: number) => {
-  if (name === 'home' || getToken()) {
+  if (name === 'home' || token.value) {
     tabIndex.value = index
     componentId.value = name
   } else {

+ 4 - 4
src/packages/mobile/views/mine/generalize/index.vue

@@ -57,7 +57,7 @@
 <script lang="ts" setup>
 import { shallowRef, computed } from 'vue'
 import { DropdownItem, DropdownMenu, Progress } from 'vant'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { queryUserLevelInfo } from '@/services/api/common'
 import { queryUserAccount } from '@/services/api/account'
 import AppQrcode from '@mobile/components/base/qrcode/index.vue'
@@ -66,7 +66,7 @@ import Promotion from './components/promotion/index.vue'
 import { getServiceUrl } from '@/services/http'
 import { Market, getTHJMarketList } from '@/constants/market'
 
-const { getUserId } = useLoginStore()
+const { userId } = loginStore.$mapGetters()
 const showQRCode = shallowRef(false)
 const selectedMenu = shallowRef(0)
 const selectedType = shallowRef(Market.THJ)
@@ -117,7 +117,7 @@ const onMenuChange = () => {
 
 queryUserAccount({
     data: {
-        userID: getUserId()
+        userID: userId.value
     },
     success: (res) => {
         userAccount.value = res.data
@@ -126,7 +126,7 @@ queryUserAccount({
 
 queryUserLevelInfo({
     data: {
-        userid: getUserId()
+        userid: userId.value
     },
     success: (res) => {
         userLevelInfo.value = res.data

+ 8 - 8
src/packages/mobile/views/mine/main/index.vue

@@ -14,12 +14,12 @@
               <div>
                 <Tag :type="authStatus ? 'success' : 'primary'">{{ getAuthStatusName(authStatus) }}</Tag>
               </div>
-              <span>{{ getLoginId() }}</span>
+              <span>{{ loginId }}</span>
             </div>
           </div>
           <div class="profile-account">
             <span>正常</span>
-            <span>{{ getFirstAccountId() }}</span>
+            <span>{{ firstAccountId }}</span>
           </div>
         </div>
         <div class="bank" v-if="accountInfo">
@@ -121,7 +121,7 @@ import { Cell, CellGroup, Button, Tag, showFailToast } from 'vant'
 import { fullloading, dialog } from '@/utils/vant'
 import { getImageUrl } from '@/filters'
 import { useNavigation } from '@/hooks/navigation'
-import { useLoginStore, useAccountStore, useUserStore } from '@/stores'
+import { loginStore, accountStore, userStore } from '@/stores'
 import AppIconfont from '@mobile/components/base/iconfont/index.vue'
 import { useBankAccountSign } from '@/business/bank'
 import { queryUserAccount } from '@/services/api/account'
@@ -129,16 +129,16 @@ import { AuthStatus, getAuthStatusName } from '@/constants/account'
 import eventBus from '@/services/bus'
 
 const { router, routerTo } = useNavigation()
-const { getUserId, getLoginId, getFirstAccountId } = useLoginStore()
-const { userData } = useUserStore()
+const { userId, loginId, firstAccountId } = loginStore.$mapGetters()
+const { userInfo } = userStore.$mapGetters()
 const { getBankAccountList, bankInfo } = useBankAccountSign()
-const { accountInfo, freezeMargin, avaiableMoney } = useAccountStore()
+const { accountInfo, freezeMargin, avaiableMoney } = accountStore.$mapGetters()
 const authStatus = shallowRef(AuthStatus.Uncertified) // 实名认证状态
 const headerRef = shallowRef<HTMLDivElement>()
 
 // 用户头像
 const userAvatar = computed(() => {
-  const file = userData.value.userInfo?.headurl
+  const file = userInfo.value?.headurl
   return file ? getImageUrl(file) : ''
 })
 
@@ -195,7 +195,7 @@ onActivated(() => {
     // 获取用户账号信息
     queryUserAccount({
       data: {
-        userID: getUserId()
+        userID: userId.value
       },
       success: (res) => {
         authStatus.value = res.data.hasauth

+ 2 - 2
src/packages/mobile/views/purchase/detail/index.vue

@@ -97,7 +97,7 @@ import { getImageUrl, parsePercent } from '@/filters'
 import { getGoodsUnitName } from '@/constants/unit'
 import { useComponent } from '@/hooks/component'
 import { useNavigation } from '@/hooks/navigation'
-import { useAccountStore, } from '@/stores'
+import { accountStore, } from '@/stores'
 import { useWrstandardDetails } from '@/business/goods'
 import { usePurchaseOrderDesting } from '@/business/trade'
 import AppSelect from '@mobile/components/base/select/index.vue'
@@ -108,7 +108,7 @@ const componentMap = new Map<string, unknown>([
     ['chart', defineAsyncComponent(() => import('@mobile/components/modules/echarts-line/index.vue'))],
 ])
 
-const { avaiableMoney } = useAccountStore()
+const { avaiableMoney } = accountStore.$mapGetters()
 const { componentRef, componentId, openComponent, closeComponent } = useComponent()
 const { router, getQueryStringToNumber } = useNavigation()
 

+ 5 - 5
src/packages/mobile/views/supply-demand/detail/components/delisting/index.vue

@@ -50,7 +50,7 @@
 import { shallowRef, PropType, computed } from 'vue'
 import { Form, Field, Stepper, Button, showFailToast, FieldRule, FormInstance } from 'vant'
 import { fullloading, dialog } from '@/utils/vant'
-import { useLoginStore, useAccountStore } from '@/stores'
+import { loginStore, accountStore } from '@/stores'
 import { BuyOrSell } from '@/constants/order'
 import { queryHoldLB } from '@/services/api/order'
 import { useHdWRDealOrder } from '@/business/trade'
@@ -73,8 +73,8 @@ const props = defineProps({
     }
 })
 
-const { getFirstAccountId } = useLoginStore()
-const { avaiableMoney } = useAccountStore()
+const { firstAccountId } = loginStore.$mapGetters()
+const { avaiableMoney } = accountStore.$mapGetters()
 const { formData, formSubmit } = useHdWRDealOrder()
 const formRef = shallowRef<FormInstance>()
 const refresh = shallowRef(false) // 是否刷新父组件数据
@@ -118,7 +118,7 @@ const onSubmit = () => {
     const { wrtradeorderid = '0', marketid } = props.quoteDetail ?? {}
 
     formData.Header = {
-        AccountID: getFirstAccountId(),
+        AccountID: firstAccountId.value,
         MarketID: marketid
     }
     formData.BuyOrSell = props.buyorsell
@@ -144,7 +144,7 @@ const onSubmit = () => {
 
 queryHoldLB({
     data: {
-        accountid: getFirstAccountId(),
+        accountid: firstAccountId.value,
         wrstandardid: props.quote.wrstandardid
     },
     success: (res) => {

+ 4 - 4
src/packages/mobile/views/supply-demand/detail/components/listing/index.vue

@@ -41,7 +41,7 @@
 import { shallowRef, PropType } from 'vue'
 import { Form, Field, Stepper, Button, showFailToast, FieldRule, FormInstance } from 'vant'
 import { fullloading, dialog } from '@/utils/vant'
-import { useLoginStore, useAccountStore } from '@/stores'
+import { loginStore, accountStore } from '@/stores'
 import { BuyOrSell } from '@/constants/order'
 import { queryHoldLB } from '@/services/api/order'
 import { useHdWROrder } from '@/business/trade'
@@ -60,8 +60,8 @@ const props = defineProps({
     }
 })
 
-const { getFirstAccountId } = useLoginStore()
-const { avaiableMoney } = useAccountStore()
+const { firstAccountId } = loginStore.$mapGetters()
+const { avaiableMoney } = accountStore.$mapGetters()
 const { formData, listingSubmit, amount } = useHdWROrder()
 const formRef = shallowRef<FormInstance>()
 const showModal = shallowRef(true)
@@ -140,7 +140,7 @@ const onSubmit = () => {
 
 queryHoldLB({
     data: {
-        accountid: getFirstAccountId(),
+        accountid: firstAccountId.value,
         wrstandardid: props.quote.wrstandardid
     },
     success: (res) => {

+ 4 - 5
src/packages/mobile/views/user/avatar/index.vue

@@ -26,16 +26,15 @@ import { CellGroup, Button, Field, Form, FormInstance, FieldRule, showFailToast
 import { fullloading } from '@/utils/vant'
 import { useNavigation } from '@/hooks/navigation'
 import { updateUserHeadUrl } from '@/services/api/user'
-import { useLoginStore, useUserStore } from '@/stores'
+import { loginStore, userStore } from '@/stores'
 import AppUploader from '@mobile/components/base/uploader/index.vue'
 
-const { getUserId } = useLoginStore()
-const { getUserData } = useUserStore()
+const { userId } = loginStore.$mapGetters()
 const { router } = useNavigation()
 
 const formRef = shallowRef<FormInstance>()
 const formData = reactive<Model.UserHeadUrlReq>({
-    userid: getUserId(), // 用户ID
+    userid: userId.value, // 用户ID
     headurl: '', // 头像地址
 })
 
@@ -59,7 +58,7 @@ const onSubmit = () => {
             data: formData,
             success: () => {
                 hideLoading()
-                getUserData()
+                userStore.actions.getUserData()
                 router.back()
             },
             fail: (err) => {

+ 3 - 4
src/packages/pc/App.vue

@@ -16,11 +16,11 @@ import { ref, watch } from 'vue'
 import { useRouter, useRoute } from 'vue-router'
 import { ElMessageBox } from 'element-plus'
 import { useAuth } from '@/business/auth'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import zhCn from 'element-plus/lib/locale/lang/zh-cn'
 import eventBus from '@/services/bus'
 
-const { getToken } = useLoginStore()
+const { token } = loginStore.$mapGetters()
 const { logout } = useAuth()
 const route = useRoute()
 const router = useRouter()
@@ -37,8 +37,7 @@ eventBus.$on('LogoutNotify', (msg) => {
 })
 
 watch(() => route.name, (routeName) => {
-  const token = getToken()
-  if (routeName === 'boot' || routeName === 'login' || !token) {
+  if (routeName === 'boot' || routeName === 'login' || !token.value) {
     hasLogin.value = false
   } else {
     hasLogin.value = true

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

@@ -19,8 +19,8 @@
             </div>
             <el-dropdown class="user-dropdown" trigger="click">
                 <span class="user-dropdown__link">
-                    <img class="g-image--avatar" :title="getAccountName()" />
-                    <span v-if="!state.isMobile">{{ getAccountName() }}</span>
+                    <img class="g-image--avatar" :title="accountName" />
+                    <span v-if="!state.isMobile">{{ accountName }}</span>
                     <app-icon class="el-icon--right" icon="ArrowDown" />
                 </span>
                 <template #dropdown>
@@ -37,13 +37,13 @@
 <script lang="ts" setup>
 import { ref, onMounted } from 'vue'
 import { ArrowRight, SwitchButton } from '@element-plus/icons-vue'
-import { useUserStore } from '@/stores'
+import { userStore } from '@/stores'
 import eventBus from '@/services/bus'
 import client from '@/utils/client'
 import AppIcon from '@pc/components/base/icon/index.vue'
 
 const { state } = client
-const { getAccountName } = useUserStore()
+const { accountName } = userStore.$mapGetters()
 const fullScreen = ref(false)
 
 // 全屏

+ 1 - 1
src/packages/pc/components/layouts/sidemenu/submenu.vue

@@ -33,7 +33,7 @@ export default defineComponent({
     },
     props: {
         dataList: {
-            type: Array as PropType<Model.UserMenu[]>,
+            type: Array as PropType<Model.UserRoutes[]>,
             required: true,
         },
     },

+ 1 - 1
src/packages/pc/components/modules/action-menu/index.vue

@@ -58,7 +58,7 @@ import { ActionMenu } from './interface'
 const props = defineProps({
     // 操作菜单
     menus: {
-        type: Array as PropType<Model.UserMenu[]>,
+        type: Array as PropType<Model.UserRoutes[]>,
         required: true,
     },
     // 操作类型

+ 2 - 2
src/packages/pc/components/modules/auth-component/index.vue

@@ -30,12 +30,12 @@ const props = defineProps({
 
 const { componentMap, getAuthComponents } = useMenu(props.code)
 const { onChange } = useAttrs()
-const dataList = shallowRef<Model.UserMenu[]>([]) // 数据列表
+const dataList = shallowRef<Model.UserRoutes[]>([]) // 数据列表
 const dataIndex = shallowRef(0) // 选中的标签
 
 const componentId = computed(() => dataList.value[dataIndex.value]?.code)
 
-const onTabChange = (index: number, { code }: Model.UserMenu) => {
+const onTabChange = (index: number, { code }: Model.UserRoutes) => {
     if (onChange instanceof Function) {
         onChange(code)
     } else {

+ 1 - 1
src/packages/pc/components/modules/auth-operation/index.vue

@@ -80,7 +80,7 @@ const props = defineProps({
 const { componentMap, getAuthButtons } = useMenu(props.code);
 const componentId = shallowRef<string>();
 const contextmenuOption = shallowRef(props.contextmenu);
-const auth = shallowRef<Model.UserMenu[]>([]);
+const auth = shallowRef<Model.UserRoutes[]>([]);
 
 // 数据列表
 const dataList = computed(() => {

+ 3 - 4
src/packages/pc/router/dynamicRouter.ts

@@ -1,6 +1,6 @@
 import { RouteRecordRaw } from 'vue-router'
 import { AuthType } from '@/constants/menu'
-import { useMenuStore } from '@/stores'
+import { menuStore } from '@/stores'
 import router from '../router'
 
 export default new (class {
@@ -23,7 +23,7 @@ export default new (class {
      * @param routes 
      * @param parentName 
      */
-    private addRoutes(routes: Model.UserMenu[], parentName = '') {
+    private addRoutes(routes: Model.UserRoutes[], parentName = '') {
         routes.forEach((item) => {
             if (item.authType === AuthType.Menu && item.component) {
                 let component;
@@ -65,9 +65,8 @@ export default new (class {
      * @returns 
      */
     registerRoutes() {
-        const { userMenus } = useMenuStore();
         this.addNotFound();
-        this.addRoutes(userMenus.value);
+        this.addRoutes(menuStore.state.userRoutes);
         this.isReady = true;
     }
 })

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

@@ -1,15 +1,15 @@
 import { createWebHashHistory, RouteRecordRaw } from 'vue-router'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import dynamicRouter from './dynamicRouter'
 import historyRouter from './historyRouter'
 import service from '@/services'
 
-const { getToken } = useLoginStore()
+const { token } = loginStore.$mapGetters()
 
 const routes: Array<RouteRecordRaw> = [
     {
         path: '/',
-        redirect: () => getToken() ? '/member' : '/login', // 重定向到默认页面
+        redirect: () => token.value ? '/member' : '/login', // 重定向到默认页面
     },
     {
         path: '/login',
@@ -44,7 +44,7 @@ router.beforeEach((to, from, next) => {
 
     // 判断服务是否加载完成
     if (service.isReady) {
-        if (getToken()) {
+        if (token.value) {
             if (dynamicRouter.isReady) {
                 if (isLoginOrRegister) {
                     next('/');

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

@@ -28,11 +28,10 @@ import { useRoute, useRouter } from 'vue-router'
 import { ElMessage } from 'element-plus'
 import type { FormInstance, FormRules } from 'element-plus'
 import { useAuth } from '@/business/auth'
-import { useMenuStore } from '@/stores'
+import { menuStore } from '@/stores'
 import SignLayout from '../components/layout/index.vue'
 
 const { loading, user, login } = useAuth()
-const { getUserMenuList } = useMenuStore()
 const route = useRoute()
 const router = useRouter()
 const formRef = shallowRef<FormInstance>()
@@ -51,7 +50,7 @@ const formSubmit = () => {
   formRef.value?.validate((valid) => {
     if (valid) {
       login().then(async () => {
-        await getUserMenuList().catch(() => {
+        await menuStore.actions.getUserMenuList().catch(() => {
           loading.value = false
         })
         const redirect = route.query.redirect;

+ 3 - 5
src/packages/pc/views/boot/index.vue

@@ -6,14 +6,12 @@
 import { ref } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import { initBaseData, checkToken, checkTokenLoop } from '@/business/common'
-import { useEnumStore, useErrorInfoStore } from '@/stores'
+import { enumStore, errorInfoStore } from '@/stores'
 import service from '@/services'
 import socket from '@/services/socket'
 
 const route = useRoute()
 const router = useRouter()
-const { getAllEnumList } = useEnumStore()
-const { getErrorInfoList } = useErrorInfoStore()
 const loading = ref(true)
 
 // 初始化数据
@@ -21,9 +19,9 @@ const onLoad = (async () => {
   // 等待服务初始化
   await service.onReady()
   // 等待请求枚举
-  await getAllEnumList()
+  await enumStore.actions.getAllEnumList()
   // 等待请求系统错误信息
-  await getErrorInfoList()
+  await errorInfoStore.actions.getErrorInfoList()
   // 等待连接交易服务
   await socket.connectTrade()
   // 等待令牌效验

+ 10 - 10
src/packages/pc/views/member/index.vue

@@ -48,7 +48,7 @@ import { ElMessage, ElTree } from 'element-plus'
 import { formatDate } from '@/filters'
 import { useDataTable, useDataFilter } from '@/hooks/datatable'
 import { queryTHJFriends, queryInvestorLevelGroup } from '@/services/api/common'
-import { useLoginStore, useUserStore } from '@/stores'
+import { loginStore, userStore } from '@/stores'
 import { decryptAES } from '@/utils/websocket/crypto'
 import AppTable from '@pc/components/base/table/index.vue'
 import AppFilter from '@pc/components/base/table-filter/index.vue'
@@ -60,18 +60,18 @@ interface TreeData {
     children?: TreeData[];
 }
 
-const { getUserId } = useLoginStore()
-const { getAccountName } = useUserStore()
+const { userId } = loginStore.$mapGetters()
+const { accountName } = userStore.$mapGetters()
 const { dataList, total, pageIndex, pageSize } = useDataTable<Model.THJFriendsRsp>()
 const { filterOptons, getQueryParams } = useDataFilter<Model.THJFriendsReq>()
 const loading = shallowRef(false)
 const treeRef = shallowRef<InstanceType<typeof ElTree>>()
 const filterText = shallowRef('')
-const userId = shallowRef(getUserId()) // 当前用户ID
+const selectedId = shallowRef(userId.value) // 当前选中用户ID
 
 const treeList = reactive<TreeData[]>([{
-    label: getAccountName() ?? '登录用户',
-    userid: userId.value,
+    label: accountName.value ?? '登录用户',
+    userid: selectedId.value,
     children: []
 }])
 
@@ -122,7 +122,7 @@ const getAuthStatusName = (status: number) => {
 // 获取手机号码
 const getPhoneNumber = (value: string) => {
     const phoneNumber = decryptAES(value)
-    if (userId.value == getUserId()) {
+    if (selectedId.value == userId.value) {
         return phoneNumber
     }
     const reg = /^(\d{3})\d{4}(\d{4})$/
@@ -133,7 +133,7 @@ const getTHJFriends = (params: Partial<Model.THJFriendsReq> = {}) => {
     loading.value = true
     return queryTHJFriends({
         data: {
-            userid: userId.value,
+            userid: selectedId.value,
             page: pageIndex.value,
             pagesize: pageSize.value,
             ...params
@@ -157,8 +157,8 @@ const getTHJFriends = (params: Partial<Model.THJFriendsReq> = {}) => {
 
 // 当节点被点击的时候触发
 const onNodeClick = ({ userid }: TreeData) => {
-    if (userId.value !== userid) {
-        userId.value = userid
+    if (selectedId.value !== userid) {
+        selectedId.value = userid
         onSearch()
     }
 }

+ 3 - 3
src/packages/pc/views/profit/index.vue

@@ -25,12 +25,12 @@ import { getTHJMarketList } from '@/constants/market'
 import { getTHJProfitRoleTypeName } from '@/constants/account'
 import { useDataTable, useDataFilter } from '@/hooks/datatable'
 import { queryTHJProfits } from '@/services/api/common'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import AppTable from '@pc/components/base/table/index.vue'
 import AppFilter from '@pc/components/base/table-filter/index.vue'
 import AppPagination from '@pc/components/base/pagination/index.vue'
 
-const { getUserId } = useLoginStore()
+const { userId } = loginStore.$mapGetters()
 const { dataList, total, pageIndex, pageSize } = useDataTable<Model.THJProfitsRsp>()
 const { filterOptons, getQueryParams } = useDataFilter<Model.THJProfitsReq>()
 const loading = shallowRef(false)
@@ -82,7 +82,7 @@ const getTHJProfits = (params: Partial<Model.THJProfitsReq> = {}) => {
     loading.value = true
     return queryTHJProfits({
         data: {
-            userid: getUserId(),
+            userid: userId.value,
             page: pageIndex.value,
             pagesize: pageSize.value,
             ...params,

+ 1 - 1
src/packages/pc/views/system/menu/components/edit/index.vue

@@ -76,7 +76,7 @@ const components = {
 
 const props = defineProps({
     selectedRow: {
-        type: Object as PropType<Model.UserMenu>,
+        type: Object as PropType<Model.UserRoutes>,
         default: () => ({
             id: 0,
             authType: AuthType.Menu,

+ 4 - 4
src/packages/pc/views/system/menu/index.vue

@@ -26,9 +26,9 @@ import { useActionMenu } from '@pc/components/modules/action-menu'
 import AppActionMenu from '@pc/components/modules/action-menu/index.vue'
 import AppTable from '@pc/components/base/table/index.vue'
 
-const { userMenus } = useMenu()
-const { activeMenu, asyncComponent, getAuthButtons, openComponent, closeComponent } = useActionMenu<Model.UserMenu>()
-const { dataList = userMenus } = useDataTable<Model.UserMenu>()
+const { userRoutes } = useMenu()
+const { activeMenu, asyncComponent, getAuthButtons, openComponent, closeComponent } = useActionMenu<Model.UserRoutes>()
+const { dataList = userRoutes } = useDataTable<Model.UserRoutes>()
 const tableRef = ref()
 const isRowExpansion = ref(false)
 
@@ -45,7 +45,7 @@ const tableExpandAll = () => {
     const table = tableRef.value.elTable
     isRowExpansion.value = !isRowExpansion.value
 
-    const toggleRowExpansionAll = (data: Model.UserMenu[]) => {
+    const toggleRowExpansionAll = (data: Model.UserRoutes[]) => {
         data.forEach((item) => {
             table.toggleRowExpansion(item, isRowExpansion.value)
             if (item.children) {

+ 2 - 2
src/packages/pc/views/system/role/components/auth/index.vue

@@ -6,7 +6,7 @@
             <el-breadcrumb-item>{{ selectedRow.roleName }}</el-breadcrumb-item>
         </el-breadcrumb>
         <el-scrollbar height="300px">
-            <el-tree :data="userMenus" :props="{ label: 'title' }" :expand-on-click-node="false" show-checkbox
+            <el-tree :data="userRoutes" :props="{ label: 'title' }" :expand-on-click-node="false" show-checkbox
                 check-on-click-node default-expand-all />
         </el-scrollbar>
         <template #footer>
@@ -28,7 +28,7 @@ defineProps({
     }
 })
 
-const { userMenus } = useMenu()
+const { userRoutes } = useMenu()
 const show = ref(true)
 </script>
 

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

@@ -11,6 +11,13 @@ export function login(params: TradeParams<Proto.LoginReq, Proto.LoginRsp>) {
 }
 
 /**
+ * 用户登出
+ */
+export function logout(params: TradeParams<Proto.LoginReq, Proto.LoginRsp>) {
+    return tradeServerRequest('LogoutReq', 'LogoutRsp', params);
+}
+
+/**
  * 用户令牌校验
  */
 export function tokenCheck(params: TradeParams<Proto.TokenCheckReq, Proto.TokenCheckRsp>) {
@@ -20,7 +27,7 @@ export function tokenCheck(params: TradeParams<Proto.TokenCheckReq, Proto.TokenC
 /**
  * 查询账户菜单
  */
-export function queryAccountMenu(params: HttpParams<{ rsp: Model.UserMenu[] }>) {
+export function queryAccountMenu(params: HttpParams<{ rsp: Model.UserRoutes[] }>) {
     return httpRequest('/account/menu', 'get', params);
 }
 
@@ -62,14 +69,14 @@ export function queryAccountRole(params: HttpParams<{ rsp: Model.UserRole[] }>)
 /**
  * 查询实名认证信息
  */
- export function queryWrDraftUserInfo(params: HttpParams<{ req: Model.WrDraftUserInfoReq, rsp: Model.UserInfo[] }>) {
+export function queryWrDraftUserInfo(params: HttpParams<{ req: Model.WrDraftUserInfoReq, rsp: Model.UserInfo[] }>) {
     return httpRequest('/WrTrade2/QueryWrDraftUserInfo', 'get', params);
 }
 
 /**
  * 实名认证请求
  */
- export function requestAddAuth(params: CommonParams<{ req: Model.AddAuthReq }>) {
+export function requestAddAuth(params: CommonParams<{ req: Model.AddAuthReq }>) {
     return commonRequest(getServiceUrl('openApiUrl') + '/onlineopen/userInfo/addAuth', 'post', params);
 }
 

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

@@ -2,7 +2,7 @@ import axios, { AxiosRequestConfig, Method, AxiosInstance } from 'axios'
 //import qs from 'qs'
 //import cryptojs from 'crypto-js'
 import { addPending, removePending } from './pending'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import { HttpParams, CommonParams, HttpResponse, Payload, ResultCode } from './interface'
 import service from '@/services'
 
@@ -23,12 +23,11 @@ const httpService = new (class {
             // 请求拦截器
             this.axiosInstance.interceptors.request.use(
                 (config) => {
-                    const { getToken } = useLoginStore()
                     removePending(config) //在请求开始前,对之前的请求做检查取消操作
                     addPending(config) //将当前请求添加到列表中
                     //请求头签名
                     const sign = {
-                        token: getToken(),
+                        token: loginStore.getters.token,
                         signsecret: 'qz7qWOMXKTMT5JlDs5w4NTPwWeR3xhF1v6wqbZ9cExmP6cc3spvNAp1wJJ1SqRI5',
                         timestamp: new Date().getTime(),
                     }

+ 3 - 4
src/services/socket/index.ts

@@ -6,7 +6,7 @@ import { FunCode } from '@/constants/funcode'
 import { parseReceivePush } from './quote/build/decode'
 import protobuf from './trade/protobuf'
 import { checkToken, stopCheckToken, checkTokenLoop } from '@/business/common'
-import { useErrorInfoStore } from '@/stores/modules/errorInfo'
+import { errorInfoStore } from '@/stores'
 import service from '@/services'
 import eventBus from '@/services/bus'
 
@@ -35,7 +35,6 @@ export default new (class {
         }
 
         this.tradeServer.onPush = (p) => {
-            const { getErrorInfoByCode } = useErrorInfoStore();
             const { funCode, content } = p;
             const delay = 1000; // 延迟推送消息,防止短时间内重复请求
 
@@ -53,11 +52,11 @@ export default new (class {
                         eventBus.$emit('UserChangeNtf');
                     }, delay, funCode.toString())
                     break;
-                } 
+                }
                 case FunCode.LogoutRsp: {
                     // 通知上层 用户登出
                     protobuf.responseDecode<Proto.LogoutRsp>(FunCode[funCode], content).then(({ RetCode, RetDesc }) => {
-                        const msg = getErrorInfoByCode(RetCode)
+                        const msg = errorInfoStore.actions.getErrorInfoByCode(RetCode)
                         const error = (RetDesc || RetCode).toString();
                         eventBus.$emit('LogoutNotify', msg ?? error);
                     })

+ 3 - 3
src/services/socket/quote/index.ts

@@ -4,7 +4,7 @@ import { FunCode } from '@/constants/funcode'
 import { QuoteRequest } from './interface'
 import { subscribeListToByteArrary } from './build/encode'
 import { parseSubscribeRsp } from './build/decode'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import socket from '../index'
 
 /**
@@ -12,8 +12,8 @@ import socket from '../index'
  * @param params 
  */
 function quoteServerMiddleware(params: QuoteRequest): Promise<Proto.QuoteRsp[]> {
-    const { getLoginId, getToken } = useLoginStore();
-    const content = subscribeListToByteArrary(params.data, getToken(), Long.fromNumber(getLoginId()));
+    const { loginId, token } = loginStore.$mapGetters()
+    const content = subscribeListToByteArrary(params.data, token.value, Long.fromNumber(loginId.value));
 
     return new Promise((resolve, reject) => {
         socket.sendQuoteServer({

+ 4 - 6
src/services/socket/trade/index.ts

@@ -1,8 +1,7 @@
 import { v4 } from 'uuid'
 import { Package50 } from '@/utils/websocket/package'
 import { FunCode } from '@/constants/funcode'
-import { useLoginStore } from '@/stores/modules/login'
-import { useErrorInfoStore } from '@/stores/modules/errorInfo'
+import { loginStore, errorInfoStore } from '@/stores'
 import { IMessageHead } from './protobuf/proto'
 import { TradeParams, TradeResponse } from './interface'
 import Protobuf from './protobuf'
@@ -12,12 +11,12 @@ import socket from '../index'
  * 构建消息头部
  */
 function getProtoHeader(funCode: keyof typeof FunCode, header?: IMessageHead, marketId?: number) {
-    const { getUserId } = useLoginStore();
+    const { userId } = loginStore.$mapGetters()
     // 组合请求头
     const protoHeader: IMessageHead = {
         FunCode: FunCode[funCode],
         UUID: v4(),
-        UserID: getUserId(),
+        UserID: userId.value,
         ...(header ?? {})
     }
     if (marketId) {
@@ -74,7 +73,6 @@ function tradeServerMiddleware<Req, Rsp>(reqKey: keyof typeof FunCode, rspKey: k
  * @param marketId 
  */
 export async function tradeServerRequest<Req, Rsp>(reqKey: keyof typeof FunCode, rspKey: keyof typeof FunCode, params: TradeParams<Req, Rsp & TradeResponse>, marketId?: number) {
-    const { getErrorInfoByCode } = useErrorInfoStore();
     const { success, fail, complete } = params;
 
     await tradeServerMiddleware(reqKey, rspKey, params, marketId).then((res) => {
@@ -101,7 +99,7 @@ export async function tradeServerRequest<Req, Rsp>(reqKey: keyof typeof FunCode,
                     success && success(res);
                     return Promise.resolve();
                 }
-                const msg = getErrorInfoByCode(RetCode || Status);
+                const msg = errorInfoStore.actions.getErrorInfoByCode(RetCode || Status);
                 const error = String(RetDesc || RetCode);
                 return Promise.reject(msg ?? error);
             }

+ 3 - 3
src/services/subscribe/index.ts

@@ -1,6 +1,6 @@
 import { v4 } from 'uuid'
 import { quoteServerRequest } from '@/services/socket/quote'
-import { useLoginStore } from '@/stores'
+import { loginStore } from '@/stores'
 import eventBus from '@/services/bus'
 import socket from '@/services/socket'
 
@@ -64,7 +64,7 @@ export default new (class {
      * @returns 
      */
     addQuoteSubscribe = (goodsCodes: string[], key?: string) => {
-        const { getToken } = useLoginStore()
+        const { token } = loginStore.$mapGetters()
         const uuid = key ?? v4()
         const value = this.quoteSubscribeMap.get(uuid) ?? []
 
@@ -82,7 +82,7 @@ export default new (class {
                 if (flag) {
                     console.log('删除订阅', uuid)
                 }
-                if (getToken()) {
+                if (token.value) {
                     this.quoteSubscribe()
                 }
                 return flag

+ 78 - 37
src/stores/base.ts

@@ -1,49 +1,90 @@
-import { reactive, toRefs, ComputedRef, UnwrapNestedRefs, ToRefs } from 'vue'
+import { reactive, shallowReactive, toRefs, ToRefs, UnwrapNestedRefs, ShallowReactive } from 'vue'
 
 /**
- * 状态存储
+ * getters 属性
  */
-export interface Store<T> {
-    state: UnwrapNestedRefs<T>;
-    getters?: { [propName: string]: ComputedRef };
-    actions?: { [propName: string]: (...args: never[]) => unknown };
-    methods?: {
-        $setData: (callback: (state: UnwrapNestedRefs<T>) => void) => void;
-        $storeToRefs: () => ToRefs<UnwrapNestedRefs<T>>;
-    }
+type Getters<T> = {
+    [key in keyof T]: () => void;
 }
 
 /**
- * 状态存储控制类
+ * getters 计算属性
  */
-export abstract class VueStore<T extends object> implements Store<T>{
-    constructor(state: T) {
-        this.state = reactive<T>(state)
-    }
+type ComputedGetters<T extends Getters<T>> = { readonly [key in keyof T]: ReturnType<T[key]> };
 
-    state
-    getters = {}
-    actions = {}
-    methods = {
-        $setData: (callback: (state: UnwrapNestedRefs<T>) => void) => {
-            callback(this.state)
-        },
-        $storeToRefs: () => {
-            return toRefs(this.state)
-        },
-    }
+/**
+ * store 对象
+ */
+interface Store<S extends object, G extends Getters<G>, A extends object> {
+    state: UnwrapNestedRefs<S>;
+    getters: ComputedGetters<G>;
+    actions: A;
+    $setState: (callback: (state: UnwrapNestedRefs<S>) => void) => void;
+    $mapState: () => ToRefs<UnwrapNestedRefs<S>>;
+    $mapGetters: () => ToRefs<ShallowReactive<ComputedGetters<G>>>;
+}
+
+/**
+ * store 配置项
+ */
+interface StoreOptions<S extends object, G extends Getters<G>, A extends object> {
+    state: () => S;
+    //created?: (this: Store<S, G, A>) => void;
+    getters?: G & ThisType<Store<S, G, A>>;
+    actions?: A & ThisType<Store<S, G, A>>;
 }
 
 /**
- * 创建状态管理
- * @param store
- * @returns
+ * 创建 store 对象
+ * @param options 
+ * @returns 
  */
-// export function createStore<T extends object>(store: VueStore<T>) {
-//     return shallowReadonly({
-//         ...toRefs(store.state),
-//         ...store.getters,
-//         ...store.actions,
-//         ...store.methods,
-//     })
-// }
+export function createStore<S extends object, G extends Getters<G>, A extends object>(options: StoreOptions<S, G, A>) {
+    const state = reactive(options.state())
+    const getters: ComputedGetters<G> = Object.create(null)
+    const actions: A = Object.create(null)
+
+    const store: Store<S, G, A> = {
+        state,
+        getters,
+        actions,
+        $setState: (callback) => {
+            callback(state)
+        },
+        $mapState: () => {
+            return toRefs(state)
+        },
+        $mapGetters: () => {
+            const data = shallowReactive(store.getters)
+            return toRefs(data)
+        }
+    }
+
+    if (options.getters) {
+        for (const key in options.getters) {
+            const fn = options.getters[key]
+            // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
+            Object.defineProperty(getters, key, {
+                get: () => fn.call(store),
+                enumerable: true
+            })
+        }
+    }
+
+    if (options.actions) {
+        for (const key in options.actions) {
+            const fn = options.actions[key]
+            if (fn instanceof Function) {
+                actions[key] = fn.bind(store)
+            } else {
+                actions[key] = fn
+            }
+        }
+    }
+
+    // if (options.created) {
+    //     options.created.call(store)
+    // }
+
+    return store
+}

+ 9 - 35
src/stores/index.ts

@@ -1,35 +1,9 @@
-import { useLoginStore } from './modules/login'
-import { useUserStore } from './modules/user'
-import { useThemeStore } from './modules/theme'
-import { useMenuStore } from './modules/menu'
-import { useAccountStore } from './modules/account'
-import { useFuturesStore } from './modules/futures'
-//import { useLanguageStore } from './modules/language'
-import { useEnumStore } from './modules/enum'
-import { useErrorInfoStore } from './modules/errorInfo'
-
-export {
-    useLoginStore,
-    useUserStore,
-    useThemeStore,
-    useMenuStore,
-    useAccountStore,
-    useFuturesStore,
-    //useLanguageStore,
-    useEnumStore,
-    useErrorInfoStore,
-}
-
-export function useStore() {
-    return {
-        loginStore: useLoginStore(),
-        userStore: useUserStore(),
-        themeStore: useThemeStore(),
-        menuStore: useMenuStore(),
-        accountStore: useAccountStore(),
-        futuresStore: useFuturesStore(),
-        //languageStore: useLanguageStore(),
-        enumStore: useEnumStore(),
-        errorInfoStore: useErrorInfoStore(),
-    }
-}
+export { loginStore } from './modules/login'
+export { userStore } from './modules/user'
+export { themeStore } from './modules/theme'
+export { menuStore } from './modules/menu'
+export { accountStore } from './modules/account'
+export { futuresStore } from './modules/futures'
+//export { languageStore } from './modules/language'
+export { enumStore, enumMap } from './modules/enum'
+export { errorInfoStore } from './modules/errorInfo'

+ 34 - 61
src/stores/modules/account.ts

@@ -1,65 +1,42 @@
-import { computed, toRefs, shallowReadonly } from 'vue'
 import { queryTaAccounts } from '@/services/api/account'
-import { useLoginStore } from './login'
-import { VueStore } from '../base'
+import { loginStore } from './login'
+import { createStore } from '../base'
 import eventBus from '@/services/bus'
 
-interface StoreState {
-    loading: boolean;
-    accountList: Model.TaAccountsRsp[]; // 资金账户列表
-    accountId: number; // 当前资金账户ID
-}
-
 /**
- * 账号存储
+ * 账号存储对象
  */
-const store = new (class extends VueStore<StoreState> {
-    constructor() {
-        const state: StoreState = {
+export const accountStore = createStore({
+    state() {
+        return {
             loading: false,
-            accountList: [],
+            accountList: <Model.TaAccountsRsp[]>[],
             accountId: 0,
         }
-        super(state)
-
-        // 接收资金变动通知
-        eventBus.$on('MoneyChangedNotify', () => {
-            this.actions.getAccountList()
-        })
-    }
-
-    /** 当前资金账户信息 */
-    private accountInfo = computed(() => {
-        return this.state.accountList.find((e) => e.accountid === this.state.accountId)
-    })
-
-    /** 冻结资金 */
-    private freezeMargin = computed(() => {
-        const { freezecharge = 0, freezemargin = 0, otherfreezemargin = 0, outamountfreeze = 0 } = this.accountInfo.value ?? {}
-        return freezecharge + freezemargin + otherfreezemargin + outamountfreeze
-    })
-
-    /** 可用资金 */
-    private avaiableMoney = computed(() => {
-        const { currentbalance = 0 } = this.accountInfo.value ?? {}
-        return currentbalance - this.freezeMargin.value
-    })
-
-    getters = {
-        accountInfo: this.accountInfo,
-        freezeMargin: this.freezeMargin,
-        avaiableMoney: this.avaiableMoney
-    }
-
-    actions = {
-        /** 获取资金账户列表 */
-        getAccountList: () => {
-            const { getLoginId } = useLoginStore()
+    },
+    getters: {
+        // 当前资金账户信息
+        accountInfo() {
+            return this.state.accountList.find((e) => e.accountid === this.state.accountId)
+        },
+        // 冻结资金
+        freezeMargin() {
+            const { freezecharge = 0, freezemargin = 0, otherfreezemargin = 0, outamountfreeze = 0 } = this.getters.accountInfo ?? {}
+            return freezecharge + freezemargin + otherfreezemargin + outamountfreeze
+        },
+        // 可用资金
+        avaiableMoney() {
+            const { currentbalance = 0 } = this.getters.accountInfo ?? {}
+            return currentbalance - this.getters.freezeMargin
+        }
+    },
+    actions: {
+        // 获取资金账户列表
+        getAccountList() {
             this.state.loading = true
-
             return queryTaAccounts({
                 data: {
-                    loginID: getLoginId()
+                    loginID: loginStore.getters.loginId
                 },
                 success: (res) => {
                     const dataList = res.data
@@ -83,19 +60,15 @@ const store = new (class extends VueStore<StoreState> {
                 }
             })
         },
-        /** 重置数据 */
-        reset: () => {
+        // 重置数据
+        reset() {
             this.state.accountList = []
             this.state.accountId = 0
         }
     }
 })
 
-export function useAccountStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.getters,
-        ...store.actions,
-        ...store.methods,
-    })
-}
+// 接收资金变动通知
+export const moneyChangedNotify = eventBus.$on('MoneyChangedNotify', () => {
+    accountStore.actions.getAccountList()
+})

+ 66 - 75
src/stores/modules/enum.ts

@@ -1,7 +1,7 @@
-import { toRefs, shallowRef, shallowReadonly, ShallowRef } from 'vue'
+import { shallowRef, ShallowRef } from 'vue'
 import { queryAllEnums } from '@/services/api/common'
-import { VueStore } from '../base'
-import WebStorage from '@/utils/storage/base'
+import { createStore } from '../base'
+import { sessionData } from '../storage'
 
 /**
  * 枚举类型
@@ -12,97 +12,88 @@ export interface EnumType {
     disabled?: boolean;
 }
 
-interface StoreState {
-    loading: boolean;
-    allEnums: ShallowRef<Model.EnumRsp[]>;
-}
 const enumKeys = ['clientType', 'scoreConfigType', 'accountBusinessCode', 'certificatetype', 'signstatus', 'thjOrderStatus', 'THJDeliveryMode', 'goodsunit', 'WROutInApplyStatus2', 'THJTransferStatus', 'WRTradeOrderStatus', 'THJMarket', 'THJProfitRoleType'] as const
 
+export const enumMap = new Map<typeof enumKeys[number], ShallowRef<Model.EnumRsp[]>>()
+
+// 初始化枚举列表
+for (const key of enumKeys) {
+    enumMap.set(key, shallowRef<Model.EnumRsp[]>([]))
+}
+
 /**
- * 枚举存储类
+ * 枚举存储对象
  */
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const storage = new WebStorage<Model.EnumRsp[]>(sessionStorage, 'allEnums', [])
-        const state: StoreState = {
+export const enumStore = createStore({
+    state() {
+        return {
             loading: false,
-            allEnums: storage.getRef(),
-        }
-        super(state)
-
-        // 初始化枚举列表
-        for (const key of enumKeys) {
-            this.enumMap.set(key, shallowRef<Model.EnumRsp[]>([]))
-        }
-    }
-
-    private enumMap = new Map<typeof enumKeys[number], ShallowRef<Model.EnumRsp[]>>()
-
-    private setEnumMap = () => {
-        // 清空列表数据
-        for (const item of this.enumMap.values()) {
-            item.value = []
+            allEnums: sessionData.getRef('allEnums'),
         }
-        this.state.allEnums.forEach((e) => {
-            const mapKey = enumKeys.find((key) => key === e.enumdiccode)
-            if (mapKey && e.enumitemstatus === 1) {
-                const enumRef = this.enumMap.get(mapKey)
-                enumRef?.value.push(e)
-            }
-        })
-    }
-
-    actions = {
-        /** 获取所有枚举列表 */
-        getAllEnumList: () => {
-            if (this.state.allEnums.length) {
-                this.setEnumMap()
-                return Promise.resolve()
+    },
+    actions: {
+        // 获取所有枚举列表
+        async getAllEnumList() {
+            await new Promise<void>((resolve) => {
+                if (this.state.allEnums.length) {
+                    resolve()
+                } else {
+                    this.state.loading = true
+                    queryAllEnums({
+                        success: (res) => {
+                            this.state.allEnums = res.data
+                            resolve()
+                        },
+                        complete: () => {
+                            this.state.loading = false
+                        }
+                    })
+                }
+            })
+            // 清空列表数据
+            for (const item of enumMap.values()) {
+                item.value = []
             }
-            this.state.loading = true
-            return queryAllEnums({
-                success: (res) => {
-                    this.state.allEnums = res.data
-                    this.setEnumMap()
-                },
-                complete: () => {
-                    this.state.loading = false
+            this.state.allEnums.forEach((e) => {
+                const mapKey = enumKeys.find((key) => key === e.enumdiccode)
+                if (mapKey && e.enumitemstatus === 1) {
+                    const enumRef = enumMap.get(mapKey)
+                    enumRef?.value.push(e)
                 }
             })
         },
-        /** 获取枚举信息 */
-        getEnumTypeInfo: (enumKey: typeof enumKeys[number], value: number) => {
-            const enums = this.enumMap.get(enumKey)
+        // 获取枚举信息
+        getEnumTypeInfo(enumKey: typeof enumKeys[number], value: number) {
+            const enums = enumMap.get(enumKey)
             return enums?.value.find((e) => e.enumitemname === value)
         },
-        /** 获取枚举列表 */
-        getEnumTypeList: (enumKey: typeof enumKeys[number]) => {
-            const enums = this.enumMap.get(enumKey)
+        // 获取枚举列表
+        getEnumTypeList: (enumKey: typeof enumKeys[number], propertys?: (keyof Model.EnumRsp)[]) => {
+            const enums = enumMap.get(enumKey)
             if (enums) {
-                return enums.value.map((e) => ({
-                    label: e.enumdicname,
-                    value: e.enumitemname,
-                }))
+                return enums.value.map((e) => {
+                    const props = propertys?.reduce((res, prop) => {
+                        const value = e[prop]
+                        if (value) res.push(value)
+                        return res
+                    }, [] as unknown[])
+                    return {
+                        label: props?.length ? props.join('-') : e.enumdicname,
+                        value: e.enumitemname,
+                    }
+                })
             }
             return []
         },
-        /** 根据枚举值获取枚举名称 */
-        getEnumTypeName: (enums: EnumType[], value?: number) => {
+        // 根据枚举值获取枚举名称
+        getEnumTypeName(enums: EnumType[], value?: number) {
             const item = enums.find((e) => e.value === value)
             return item?.label ?? value?.toString() ?? '无效枚举'
         },
-        /** 根据枚举名称获取对应的值 */
-        getEnumTypeValue: (enums: EnumType[], label?: string) => {
+        // 根据枚举名称获取对应的值
+        getEnumTypeValue(enums: EnumType[], label?: string) {
             const item = enums.find((e) => e.label === label)
             return item?.value ?? label
         }
-    }
-})
-
-export function useEnumStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.actions,
-        ...store.methods,
-    })
-}
+    },
+})

+ 14 - 31
src/stores/modules/errorInfo.ts

@@ -1,29 +1,20 @@
-import { toRefs, shallowReadonly, ShallowRef } from 'vue'
 import { queryErrorInfos } from '@/services/api/common'
-import { VueStore } from '../base'
-import WebStorage from '@/utils/storage/base'
-
-interface StoreState {
-    loading: boolean;
-    errorInfos: ShallowRef<Model.ErrorInfosRsp[]>;
-}
+import { createStore } from '../base'
+import { sessionData } from '../storage'
 
 /**
- * 错误信息存储
+ * 错误信息存储对象
  */
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const storage = new WebStorage<Model.ErrorInfosRsp[]>(sessionStorage, 'errorInfos', [])
-        const state: StoreState = {
+export const errorInfoStore = createStore({
+    state() {
+        return {
             loading: false,
-            errorInfos: storage.getRef(),
+            errorInfos: sessionData.getRef('errorInfos'),
         }
-        super(state)
-    }
-
-    actions = {
-        /** 获取系统错误信息 */
-        getErrorInfoList: () => {
+    },
+    actions: {
+        // 获取系统错误信息
+        getErrorInfoList() {
             if (this.state.errorInfos.length) {
                 return Promise.resolve()
             }
@@ -37,19 +28,11 @@ const store = new (class extends VueStore<StoreState>{
                 }
             })
         },
-        /** 根据 code 获取错误信息 */
-        getErrorInfoByCode: (code: number) => {
+        // 根据 code 获取错误信息
+        getErrorInfoByCode(code: number) {
             const errorInfos = this.state.errorInfos
             const error = errorInfos.find((e) => e.errorid === code)
             return error?.description
         }
     }
-})
-
-export function useErrorInfoStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.actions,
-        ...store.methods,
-    })
-}
+})

+ 248 - 275
src/stores/modules/futures.ts

@@ -1,282 +1,79 @@
-import { computed, toRefs, shallowReadonly } from 'vue'
+import { computed } from 'vue'
 import { timerInterceptor } from '@/utils/timer'
 import { queryErmcpGoods, queryQuoteDay } from '@/services/api/goods'
-import { VueStore } from '../base'
+import { createStore } from '../base'
 import { timerTask } from '@/utils/timer'
 import eventBus from '@/services/bus'
 import moment from 'moment'
 
-interface StoreState {
-    loading: boolean;
-    goodsList: Model.GoodsRsp[]; // 商品列表
-    quoteDayList: Model.QuoteDayRsp[]; // 盘面列表
-}
-
 /**
- * 期货存储
+ * 期货存储对象
  */
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const state: StoreState = {
+export const futuresStore = createStore({
+    state() {
+        return {
             loading: false,
-            goodsList: [],
-            quoteDayList: [],
+            quotes: <Proto.Quote[]>[], // 行情数据
+            goodsList: <Model.GoodsRsp[]>[], // 商品列表
+            quoteDayList: <Model.QuoteDayRsp[]>[], // 盘面列表
         }
-        super(state)
-
-        // 接收行情推送通知
-        eventBus.$on('QuotePushNotify', (res) => {
-            const data = res as Proto.Quote[]
-            data.forEach((item) => {
-                const index = this.quotes.findIndex((e) => e.goodscode === item.goodscode)
-                if (index > -1) {
-                    this.quotes[index] = item
-                } else {
-                    this.quotes.push(item)
-                }
-            })
-            this.handleQuote()
-        })
-    }
-
-    /** 行情数据 */
-    private quotes: Proto.Quote[] = []
-
-    /** 期货行情列表 */
-    private quoteList = computed(() => {
-        return this.state.goodsList.reduce((res, cur) => {
-            const { goodscode, goodsname, goodsgroupid, marketid, decimalplace } = cur
-            const {
-                last = 0,
-                bid = 0,
-                ask = 0,
-                bidvolume = 0,
-                askvolume = 0,
-                totalvolume = 0,
-                lastvolume = 0,
-                holdvolume = 0,
-                holdincrement = 0,
-                presettle = 0,
-                totalturnover = 0,
-                opened = 0,
-                highest = 0,
-                lowest = 0,
-                lasttime = '',
-            } = this.actions.getQuoteDayInfoByCode(goodscode).value ?? {}
-
-            const change = last === 0 ? 0 : last - presettle // 涨跌额/涨跌: 最新价 - 昨结价
-
-            const item: Model.Futures = {
-                marketid,
-                goodsgroupid,
-                goodscode,
-                goodsname,
-                decimalplace,
-                last,
-                lasttime,
-                amplitude: change === 0 ? 0 : change / presettle, // 涨跌幅/幅度: (最新价 - 昨结价) / 昨结价
-                change,
-                bid,
-                ask,
-                bidvolume,
-                askvolume,
-                totalvolume,
-                lastvolume,
-                holdvolume,
-                holdincrement,
-                presettle,
-                totalturnover,
-                opened,
-                highest,
-                lowest,
-            }
-            res.push(item)
-            return res
-        }, [] as Model.Futures[])
-    })
-
-    /**
-     * 处理行情数据
-     */
-    private handleQuote = timerInterceptor.setThrottle(() => {
-        const goodsList = this.state.goodsList
-        const quoteList = this.state.quoteDayList
+    },
+    getters: {
+        quoteList() {
+            return this.state.goodsList.reduce((res, cur) => {
+                const { goodscode, goodsname, goodsgroupid, marketid, decimalplace } = cur
+                const {
+                    last = 0,
+                    bid = 0,
+                    ask = 0,
+                    bidvolume = 0,
+                    askvolume = 0,
+                    totalvolume = 0,
+                    lastvolume = 0,
+                    holdvolume = 0,
+                    holdincrement = 0,
+                    presettle = 0,
+                    totalturnover = 0,
+                    opened = 0,
+                    highest = 0,
+                    lowest = 0,
+                    lasttime = '',
+                } = this.actions.getQuoteDayInfoByCode(goodscode).value ?? {}
 
-        this.quotes.forEach((item) => {
-            const goods = goodsList.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
-            const quote = quoteList.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
-            const lasttime = (item.date && item.time) ? moment(item.date + item.time, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss') : ''
+                const change = last === 0 ? 0 : last - presettle // 涨跌额/涨跌: 最新价 - 昨结价
 
-            // 处理报价小数位
-            const last = (() => {
-                const decimal = goods?.decimalplace ?? 0
-                const num = Math.pow(10, decimal)
-                if (item.last) {
-                    return item.last / num
-                }
-                return 0
-            })()
-
-            if (quote) {
-                Object.entries(item).forEach(([key, value]) => {
-                    // 只更新存在的属性
-                    if (Reflect.has(quote, key)) {
-                        const prop = key as keyof Model.QuoteDayRsp;
-                        (<K extends typeof prop>(key: K) => quote[key] = value)(prop);
-                    }
-                })
-                quote.last = last
-                // 处理最高最低价
-                if (last) {
-                    if (last > quote.highest) {
-                        quote.highest = last;
-                    }
-                    if (last < quote.lowest) {
-                        quote.lowest = last;
-                    }
-                }
-                // 处理最新时间
-                if (lasttime) {
-                    quote.lasttime = lasttime;
-                }
-            } else {
-                console.warn('行情推送的商品 ' + item.goodscode + ' 缺少盘面信息')
-                quoteList.push({
-                    ask: item.ask ?? 0,
-                    ask2: item.ask2 ?? 0,
-                    ask3: item.ask3 ?? 0,
-                    ask4: item.ask4 ?? 0,
-                    ask5: item.ask5 ?? 0,
-                    ask6: 0,
-                    ask7: 0,
-                    ask8: 0,
-                    ask9: 0,
-                    ask10: 0,
-                    askorderid: 0,
-                    askorderid2: 0,
-                    askorderid3: 0,
-                    askorderid4: 0,
-                    askorderid5: 0,
-                    askordervolume: 0,
-                    askordervolume2: 0,
-                    askordervolume3: 0,
-                    askordervolume4: 0,
-                    askordervolume5: 0,
-                    askordervolume6: 0,
-                    askordervolume7: 0,
-                    askordervolume8: 0,
-                    askordervolume9: 0,
-                    askordervolume10: 0,
-                    askqueueinfo: "",
-                    askvolume: item.askvolume ?? 0,
-                    askvolume2: item.askvolume2 ?? 0,
-                    askvolume3: item.askvolume3 ?? 0,
-                    askvolume4: item.askvolume4 ?? 0,
-                    askvolume5: item.askvolume5 ?? 0,
-                    askvolume6: 0,
-                    askvolume7: 0,
-                    askvolume8: 0,
-                    askvolume9: 0,
-                    askvolume10: 0,
-                    averageprice: 0,
-                    bid: item.bid ?? 0,
-                    bid2: item.bid2 ?? 0,
-                    bid3: item.bid3 ?? 0,
-                    bid4: item.bid4 ?? 0,
-                    bid5: item.bid5 ?? 0,
-                    bid6: 0,
-                    bid7: 0,
-                    bid8: 0,
-                    bid9: 0,
-                    bid10: 0,
-                    bidorderid: 0,
-                    bidorderid2: 0,
-                    bidorderid3: 0,
-                    bidorderid4: 0,
-                    bidorderid5: 0,
-                    bidordervolume: 0,
-                    bidordervolume2: 0,
-                    bidordervolume3: 0,
-                    bidordervolume4: 0,
-                    bidordervolume5: 0,
-                    bidordervolume6: 0,
-                    bidordervolume7: 0,
-                    bidordervolume8: 0,
-                    bidordervolume9: 0,
-                    bidordervolume10: 0,
-                    bidqueueinfo: "",
-                    bidvolume: item.bidvolume ?? 0,
-                    bidvolume2: item.bidvolume2 ?? 0,
-                    bidvolume3: item.bidvolume3 ?? 0,
-                    bidvolume4: item.bidvolume4 ?? 0,
-                    bidvolume5: item.bidvolume5 ?? 0,
-                    bidvolume6: 0,
-                    bidvolume7: 0,
-                    bidvolume8: 0,
-                    bidvolume9: 0,
-                    bidvolume10: 0,
-                    calloptionpremiums: item.calloptionpremiums ?? 0,
-                    calloptionpremiums2: item.calloptionpremiums2 ?? 0,
-                    calloptionpremiums3: item.calloptionpremiums3 ?? 0,
-                    calloptionpremiums4: item.calloptionpremiums4 ?? 0,
-                    calloptionpremiums5: item.calloptionpremiums5 ?? 0,
-                    cleartime: 0,
-                    exchangecode: item.exchangecode ?? 0,
-                    exchangedate: item.exchangedate ?? 0,
-                    goodscode: item.goodscode ?? '',
-                    grepmarketprice: 0,
-                    highest: item.highest ?? 0,
-                    holdincrement: 0,
-                    holdvolume: item.holdvolume ?? 0,
-                    iep: 0,
-                    iev: 0,
-                    inventory: item.inventory ?? 0,
-                    iscleared: 0,
-                    issettled: 0,
+                const item: Model.Futures = {
+                    marketid,
+                    goodsgroupid,
+                    goodscode,
+                    goodsname,
+                    decimalplace,
                     last,
-                    lastlot: 0,
                     lasttime,
-                    Lastturnover: 0,
-                    lastvolume: item.lastvolume ?? 0,
-                    limitdown: item.limitlow ?? 0,
-                    limitup: item.limithigh ?? 0,
-                    lowest: item.lowest ?? 0,
-                    nontotalholdervolume: 0,
-                    nontotallot: 0,
-                    nontotalturnover: 0,
-                    nontotalvolume: 0,
-                    opened: item.opened ?? 0,
-                    opentime: '',
-                    orderid: 0,
-                    preclose: item.preclose ?? 0,
-                    preholdvolume: item.preholdvolume ?? 0,
-                    presettle: item.presettle ?? 0,
-                    publictradetype: '',
-                    putoptionpremiums: item.putoptionpremiums ?? 0,
-                    putoptionpremiums2: item.putoptionpremiums2 ?? 0,
-                    putoptionpremiums3: item.putoptionpremiums3 ?? 0,
-                    putoptionpremiums4: item.putoptionpremiums4 ?? 0,
-                    putoptionpremiums5: item.putoptionpremiums5 ?? 0,
-                    settle: item.settle ?? 0,
-                    strikeprice: 0,
-                    totalaskvolume: 0,
-                    totalbidvolume: 0,
-                    totallot: 0,
-                    totalturnover: item.totalturnover ?? 0,
-                    totalvolume: item.totalvolume ?? 0,
-                    utclasttime: ''
-                })
-            }
-        })
-    }, 200)
-
-    getters = {
-        quoteList: this.quoteList
-    }
-
-    actions = {
+                    amplitude: change === 0 ? 0 : change / presettle, // 涨跌幅/幅度: (最新价 - 昨结价) / 昨结价
+                    change,
+                    bid,
+                    ask,
+                    bidvolume,
+                    askvolume,
+                    totalvolume,
+                    lastvolume,
+                    holdvolume,
+                    holdincrement,
+                    presettle,
+                    totalturnover,
+                    opened,
+                    highest,
+                    lowest,
+                }
+                res.push(item)
+                return res
+            }, [] as Model.Futures[])
+        }
+    },
+    actions: {
         // 获取商品列表
-        getGoodsList: () => {
+        getGoodsList() {
             this.state.loading = true
             return queryErmcpGoods({
                 success: (res) => {
@@ -308,12 +105,12 @@ const store = new (class extends VueStore<StoreState>{
                 }
             })
         },
-        /** 通过 goodscode 获取盘面实时行情 */
-        getQuoteDayInfoByCode: (goodscode: string) => {
+        // 通过 goodscode 获取盘面实时行情
+        getQuoteDayInfoByCode(goodscode: string) {
             return computed(() => this.state.quoteDayList.find((e) => e.goodscode.toUpperCase() === goodscode.toUpperCase()))
         },
-        /** 通过 goodscode 获取商品实时报价 */
-        getGoodsPriceByCode: (goodscode: string) => {
+        // 通过 goodscode 获取商品实时报价
+        getGoodsPriceByCode(goodscode: string) {
             return computed(() => {
                 const quote = this.actions.getQuoteDayInfoByCode(goodscode)
                 return quote.value?.last ?? 0
@@ -322,11 +119,187 @@ const store = new (class extends VueStore<StoreState>{
     }
 })
 
-export function useFuturesStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.getters,
-        ...store.actions,
-        ...store.methods,
+// 接收行情推送通知
+export const quotePushNotify = eventBus.$on('QuotePushNotify', (res) => {
+    const { quotes } = futuresStore.$mapState()
+    const data = res as Proto.Quote[]
+    data.forEach((item) => {
+        const index = quotes.value.findIndex((e) => e.goodscode === item.goodscode)
+        if (index > -1) {
+            quotes.value[index] = item
+        } else {
+            quotes.value.push(item)
+        }
+    })
+    handleQuote()
+})
+
+// 处理行情数据
+const handleQuote = timerInterceptor.setThrottle(() => {
+    const { quotes, goodsList, quoteDayList, } = futuresStore.$mapState()
+    quotes.value.forEach((item) => {
+        const goods = goodsList.value.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
+        const quote = quoteDayList.value.find((e) => e.goodscode.toUpperCase() === item.goodscode?.toUpperCase())
+        const lasttime = (item.date && item.time) ? moment(item.date + item.time, 'YYYYMMDDHHmmss').format('YYYY-MM-DD HH:mm:ss') : ''
+
+        // 处理报价小数位
+        const last = (() => {
+            const decimal = goods?.decimalplace ?? 0
+            const num = Math.pow(10, decimal)
+            if (item.last) {
+                return item.last / num
+            }
+            return 0
+        })()
+
+        if (quote) {
+            Object.entries(item).forEach(([key, value]) => {
+                // 只更新存在的属性
+                if (Reflect.has(quote, key)) {
+                    Object.defineProperty(quote, key, value)
+                }
+            })
+            quote.last = last
+            // 处理最高最低价
+            if (last) {
+                if (last > quote.highest) {
+                    quote.highest = last
+                }
+                if (last < quote.lowest) {
+                    quote.lowest = last
+                }
+            }
+            // 处理最新时间
+            if (lasttime) {
+                quote.lasttime = lasttime
+            }
+        } else {
+            console.warn('行情推送的商品 ' + item.goodscode + ' 缺少盘面信息')
+            quoteDayList.value.push({
+                ask: item.ask ?? 0,
+                ask2: item.ask2 ?? 0,
+                ask3: item.ask3 ?? 0,
+                ask4: item.ask4 ?? 0,
+                ask5: item.ask5 ?? 0,
+                ask6: 0,
+                ask7: 0,
+                ask8: 0,
+                ask9: 0,
+                ask10: 0,
+                askorderid: 0,
+                askorderid2: 0,
+                askorderid3: 0,
+                askorderid4: 0,
+                askorderid5: 0,
+                askordervolume: 0,
+                askordervolume2: 0,
+                askordervolume3: 0,
+                askordervolume4: 0,
+                askordervolume5: 0,
+                askordervolume6: 0,
+                askordervolume7: 0,
+                askordervolume8: 0,
+                askordervolume9: 0,
+                askordervolume10: 0,
+                askqueueinfo: "",
+                askvolume: item.askvolume ?? 0,
+                askvolume2: item.askvolume2 ?? 0,
+                askvolume3: item.askvolume3 ?? 0,
+                askvolume4: item.askvolume4 ?? 0,
+                askvolume5: item.askvolume5 ?? 0,
+                askvolume6: 0,
+                askvolume7: 0,
+                askvolume8: 0,
+                askvolume9: 0,
+                askvolume10: 0,
+                averageprice: 0,
+                bid: item.bid ?? 0,
+                bid2: item.bid2 ?? 0,
+                bid3: item.bid3 ?? 0,
+                bid4: item.bid4 ?? 0,
+                bid5: item.bid5 ?? 0,
+                bid6: 0,
+                bid7: 0,
+                bid8: 0,
+                bid9: 0,
+                bid10: 0,
+                bidorderid: 0,
+                bidorderid2: 0,
+                bidorderid3: 0,
+                bidorderid4: 0,
+                bidorderid5: 0,
+                bidordervolume: 0,
+                bidordervolume2: 0,
+                bidordervolume3: 0,
+                bidordervolume4: 0,
+                bidordervolume5: 0,
+                bidordervolume6: 0,
+                bidordervolume7: 0,
+                bidordervolume8: 0,
+                bidordervolume9: 0,
+                bidordervolume10: 0,
+                bidqueueinfo: "",
+                bidvolume: item.bidvolume ?? 0,
+                bidvolume2: item.bidvolume2 ?? 0,
+                bidvolume3: item.bidvolume3 ?? 0,
+                bidvolume4: item.bidvolume4 ?? 0,
+                bidvolume5: item.bidvolume5 ?? 0,
+                bidvolume6: 0,
+                bidvolume7: 0,
+                bidvolume8: 0,
+                bidvolume9: 0,
+                bidvolume10: 0,
+                calloptionpremiums: item.calloptionpremiums ?? 0,
+                calloptionpremiums2: item.calloptionpremiums2 ?? 0,
+                calloptionpremiums3: item.calloptionpremiums3 ?? 0,
+                calloptionpremiums4: item.calloptionpremiums4 ?? 0,
+                calloptionpremiums5: item.calloptionpremiums5 ?? 0,
+                cleartime: 0,
+                exchangecode: item.exchangecode ?? 0,
+                exchangedate: item.exchangedate ?? 0,
+                goodscode: item.goodscode ?? '',
+                grepmarketprice: 0,
+                highest: item.highest ?? 0,
+                holdincrement: 0,
+                holdvolume: item.holdvolume ?? 0,
+                iep: 0,
+                iev: 0,
+                inventory: item.inventory ?? 0,
+                iscleared: 0,
+                issettled: 0,
+                last,
+                lastlot: 0,
+                lasttime,
+                Lastturnover: 0,
+                lastvolume: item.lastvolume ?? 0,
+                limitdown: item.limitlow ?? 0,
+                limitup: item.limithigh ?? 0,
+                lowest: item.lowest ?? 0,
+                nontotalholdervolume: 0,
+                nontotallot: 0,
+                nontotalturnover: 0,
+                nontotalvolume: 0,
+                opened: item.opened ?? 0,
+                opentime: '',
+                orderid: 0,
+                preclose: item.preclose ?? 0,
+                preholdvolume: item.preholdvolume ?? 0,
+                presettle: item.presettle ?? 0,
+                publictradetype: '',
+                putoptionpremiums: item.putoptionpremiums ?? 0,
+                putoptionpremiums2: item.putoptionpremiums2 ?? 0,
+                putoptionpremiums3: item.putoptionpremiums3 ?? 0,
+                putoptionpremiums4: item.putoptionpremiums4 ?? 0,
+                putoptionpremiums5: item.putoptionpremiums5 ?? 0,
+                settle: item.settle ?? 0,
+                strikeprice: 0,
+                totalaskvolume: 0,
+                totalbidvolume: 0,
+                totallot: 0,
+                totalturnover: item.totalturnover ?? 0,
+                totalvolume: item.totalvolume ?? 0,
+                utclasttime: ''
+            })
+        }
     })
-}
+}, 200)

+ 16 - 33
src/stores/modules/language.ts

@@ -1,52 +1,35 @@
-import { toRefs, shallowReadonly, ShallowRef } from 'vue'
 import axios from 'axios'
 import { createI18n } from 'vue-i18n'
 import { Language } from '@/constants/language'
-import { VueStore } from '../base'
-import WebStorage from '@/utils/storage/base'
+import { createStore } from '../base'
+import { localData } from '../storage'
 
-interface StoreState {
-    lang: ShallowRef<Language>;
-}
+export const i18n = createI18n({})
 
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const storage = new WebStorage<Language>(localStorage, 'language', Language.ZhCN)
-        const state: StoreState = {
-            lang: storage.getRef()
+export const languageStore = createStore({
+    state() {
+        return {
+            lang: localData.getRef('appLanguage'),
         }
-
-        super(state)
-        const lang = this.state.lang
-        this.actions.setLanguage(lang)
-    }
-
-    i18n = createI18n({})
-
-    actions = {
-        /** 设置语言 */
-        setLanguage: async (lang: Language) => {
-            const locale = this.i18n.global.getLocaleMessage(lang)
+    },
+    actions: {
+        // 设置语言
+        async setLanguage(lang: Language) {
+            const locale = i18n.global.getLocaleMessage(lang)
 
             if (!Object.keys(locale).length) {
                 await axios(`./language/${lang}.json`).then((res) => {
-                    this.i18n.global.setLocaleMessage(lang, res.data)
+                    i18n.global.setLocaleMessage(lang, res.data)
                 }).catch(() => {
                     // 默认语言
                 })
             }
 
-            this.i18n.global.locale = lang
+            i18n.global.locale = lang
             this.state.lang = lang
         }
     }
 })
 
-export function useLanguageStore() {
-    return shallowReadonly({
-        i18n: store.i18n,
-        ...toRefs(store.state),
-        ...store.actions,
-        ...store.methods,
-    })
-}
+const { actions, state } = languageStore
+actions.setLanguage(state.lang)

+ 37 - 68
src/stores/modules/login.ts

@@ -1,47 +1,41 @@
-import { toRefs, shallowReadonly, ShallowRef } from 'vue'
 import { v4 } from 'uuid'
-import { login, queryLoginId } from '@/services/api/account'
-import { VueStore } from '../base'
+import { login, queryLoginId } from '@/services/api/account' // 引入可能会引起 Cannot access 'loginStore' before initialization
+import { createStore } from '../base'
+import { sessionData } from '../storage'
 import cryptojs from 'crypto-js'
-import WebStorage from '@/utils/storage/base'
-
-interface StoreState {
-    loading: boolean;
-    autoLogin: boolean;
-    loginInfo: ShallowRef<Proto.LoginRsp>;
-}
-
-function getInitData(): Proto.LoginRsp {
-    return {
-        AccountIDs: [],
-        LoginCode: '',
-        LoginID: 0,
-        LoginUserType: 0,
-        AccountStatus: 0,
-        UserID: 0,
-        ClientID: 0,
-        MemberUserID: 0,
-        Token: '',
-    }
-}
 
 /**
- * 登录存储
+ * 登录存储对象
  */
-const store = new (class extends VueStore<StoreState> {
-    constructor() {
-        const storage = new WebStorage(sessionStorage, 'loginInfo', getInitData())
-        const state: StoreState = {
+export const loginStore = createStore({
+    state() {
+        return {
             loading: false,
-            autoLogin: false,
-            loginInfo: storage.getRef(),
+            loginInfo: sessionData.getRef('loginInfo'),
         }
-        super(state)
-    }
-
-    actions = {
-        /** 用户登录 */
-        userLogin: (param: Proto.LoginReq) => {
+    },
+    getters: {
+        // 登录令牌
+        token() {
+            return this.state.loginInfo.Token
+        },
+        // 用户ID
+        userId() {
+            return this.state.loginInfo.UserID
+        },
+        // 登录ID
+        loginId() {
+            return this.state.loginInfo.LoginID
+        },
+        // 首个资金账户ID
+        firstAccountId() {
+            const accounts = this.state.loginInfo.AccountIDs
+            return accounts[0] ?? 0
+        },
+    },
+    actions: {
+        // 用户登录
+        userLogin(param: Proto.LoginReq) {
             this.state.loading = true
             return new Promise<Proto.LoginRsp>((resolve, reject) => {
                 queryLoginId({
@@ -75,38 +69,13 @@ const store = new (class extends VueStore<StoreState> {
                 })
             })
         },
-        /** 获取用户登录信息 */
-        getLoginInfo: <K extends keyof Proto.LoginRsp>(key: K) => {
+        // 获取用户登录信息
+        getLoginInfo<K extends keyof Proto.LoginRsp>(key: K) {
             return this.state.loginInfo[key]
         },
-        /** 获取登录令牌 */
-        getToken: () => {
-            return this.state.loginInfo.Token
-        },
-        /** 获取用户ID */
-        getUserId: () => {
-            return this.state.loginInfo.UserID
-        },
-        /** 获取登录ID */
-        getLoginId: () => {
-            return Number(this.state.loginInfo.LoginID)
-        },
-        /** 获取首个账户ID */
-        getFirstAccountId: () => {
-            const accounts = this.state.loginInfo.AccountIDs
-            return accounts[0] ?? 0
-        },
-        /** 重置数据 */
-        reset: () => {
-            this.state.loginInfo = getInitData()
+        // 重置数据
+        reset() {
+            sessionData.reset('loginInfo')
         }
     }
-})
-
-export function useLoginStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.actions,
-        ...store.methods,
-    })
-}
+})

+ 13 - 30
src/stores/modules/menu.ts

@@ -1,30 +1,21 @@
-import { toRefs, shallowReadonly, ShallowRef } from 'vue'
 import { queryAccountMenu } from '@/services/api/account'
-import { VueStore } from '../base'
-import WebStorage from '@/utils/storage/base'
+import { createStore } from '../base'
+import { sessionData } from '../storage'
 
-interface StoreState {
-    loading: boolean;
-    userMenus: ShallowRef<Model.UserMenu[]>;
-}
-
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const storage = new WebStorage<Model.UserMenu[]>(sessionStorage, 'userMenus', [])
-        const state: StoreState = {
+export const menuStore = createStore({
+    state() {
+        return {
             loading: false,
-            userMenus: storage.getRef()
+            userRoutes: sessionData.getRef('userRoutes'),
         }
-        super(state)
-    }
-
-    actions = {
+    },
+    actions: {
         /** 获取用户菜单列表 */
-        getUserMenuList: () => {
+        getUserMenuList() {
             this.state.loading = true
             return queryAccountMenu({
                 success: (res) => {
-                    this.state.userMenus = res.data
+                    this.state.userRoutes = res.data
                 },
                 complete: () => {
                     this.state.loading = false
@@ -32,16 +23,8 @@ const store = new (class extends VueStore<StoreState>{
             })
         },
         /** 重置数据 */
-        reset: () => {
-            this.state.userMenus = []
+        reset() {
+            this.state.userRoutes = []
         }
     }
-})
-
-export function useMenuStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.actions,
-        ...store.methods,
-    })
-}
+})

+ 33 - 54
src/stores/modules/theme.ts

@@ -1,66 +1,45 @@
-import { toRefs, shallowReadonly, ShallowRef } from 'vue'
 import { AppTheme } from '@/constants/theme'
-import { VueStore } from '../base'
-import WebStorage from '@/utils/storage/base'
+import { createStore } from '../base'
+import { localData } from '../storage'
 import plus from '@/utils/h5plus'
 
-interface StoreState {
-    appTheme: ShallowRef<AppTheme>;
-}
-
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const storage = new WebStorage<AppTheme>(localStorage, 'appTheme', AppTheme.Default)
-        const state: StoreState = {
-            appTheme: storage.getRef()
+export const themeStore = createStore({
+    state() {
+        return {
+            appTheme: localData.getRef('appTheme'),
         }
-
-        super(state)
-        document.addEventListener('DOMContentLoaded', this.loadTheme, false)
-    }
-
-    /**
-     * 加载主题
-     */
-    private loadTheme = () => {
-        const theme = this.state.appTheme
-        this.setStatusBarTheme(theme)
-        document.documentElement.setAttribute('theme', theme)
-        document.removeEventListener('DOMContentLoaded', this.loadTheme)
-    }
-
-    /**
-     * 设置状态栏主题色
-     * @param theme 
-     */
-    private setStatusBarTheme = (theme: AppTheme) => {
-        switch (theme) {
-            case AppTheme.Default:
-            case AppTheme.Dark: {
-                plus.setStatusBarStyle('light')
-                break
+    },
+    actions: {
+        // 设置状态栏主题色
+        setStatusBarTheme(theme: AppTheme) {
+            switch (theme) {
+                case AppTheme.Default:
+                case AppTheme.Dark: {
+                    plus.setStatusBarStyle('light')
+                    break
+                }
+                default: {
+                    plus.setStatusBarStyle('dark')
+                }
             }
-            default: {
-                plus.setStatusBarStyle('dark')
-            }
-        }
-    }
-
-    actions = {
-        /** 设置主题 */
-        setTheme: (key: keyof typeof AppTheme) => {
+        },
+        // 设置主题
+        setTheme(key: keyof typeof AppTheme) {
             const theme = AppTheme[key]
-            this.setStatusBarTheme(theme)
+            this.actions.setStatusBarTheme(theme)
             document.documentElement.setAttribute('theme', theme)
             this.state.appTheme = theme
         }
     }
 })
 
-export function useThemeStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.actions,
-        ...store.methods,
-    })
-}
+// 加载主题
+const loadTheme = () => {
+    const theme = themeStore.state.appTheme
+    themeStore.actions.setStatusBarTheme(theme)
+    document.documentElement.setAttribute('theme', theme)
+    document.removeEventListener('DOMContentLoaded', loadTheme)
+}
+
+// 等待 dom 加载完毕
+document.addEventListener('DOMContentLoaded', loadTheme, false)

+ 39 - 59
src/stores/modules/user.ts

@@ -1,22 +1,16 @@
-import { toRefs, shallowReadonly, computed } from 'vue'
 import { queryLoginData } from '@/services/api/account'
-import { useLoginStore } from './login'
-import { VueStore } from '../base'
-import eventBus from '@/services/bus';
-
-interface StoreState {
-    loading: boolean;
-    userData: Model.LoginQueryRsp;
-}
+import { loginStore } from './login'
+import { createStore } from '../base'
+import eventBus from '@/services/bus'
 
 /**
- * 用户存储
+ * 用户存储对象
  */
-const store = new (class extends VueStore<StoreState>{
-    constructor() {
-        const state: StoreState = {
+export const userStore = createStore({
+    state() {
+        return {
             loading: false,
-            userData: {
+            userData: <Model.LoginQueryRsp>{
                 arearole: [],
                 externalExchanges: [],
                 goodsgroups: [],
@@ -24,31 +18,31 @@ const store = new (class extends VueStore<StoreState>{
                 systemParams: []
             },
         }
-        super(state)
-
-        eventBus.$on('UserChangeNtf',()=>{
-            this.actions.getUserData()
-        })
-    }
-
-    /** 是否已实名认证 */
-    private hasAuth = computed(() => {
-        const { userAccount } = this.state.userData
-        return userAccount?.hasauth === 1
-    })
-
-    getters = {
-        hasAuth: this.hasAuth
-    }
-
-    actions = {
-        /** 获取用户数据 */
-        getUserData: () => {
-            const { getLoginId } = useLoginStore()
+    },
+    getters: {
+        // 用户信息
+        userInfo() {
+            const { userInfo } = this.state.userData
+            return userInfo
+        },
+        // 登录机构名称
+        accountName() {
+            const { userAccount } = this.state.userData
+            return userAccount?.accountname
+        },
+        // 是否已实名认证
+        hasAuth() {
+            const { userAccount } = this.state.userData
+            return userAccount?.hasauth === 1
+        }
+    },
+    actions: {
+        // 获取用户数据
+        getUserData() {
             this.state.loading = true
             return queryLoginData({
                 data: {
-                    loginID: getLoginId()
+                    loginID: loginStore.getters.loginId
                 },
                 success: (res) => {
                     this.state.userData = res.data
@@ -58,23 +52,13 @@ const store = new (class extends VueStore<StoreState>{
                 }
             })
         },
-        /** 获取用户数据 */
-        getUserDataInfo: <K extends keyof Model.LoginQueryRsp>(key: K) => {
+        // 获取用户数据
+        getUserDataInfo<K extends keyof Model.LoginQueryRsp>(key: K) {
             return this.state.userData[key]!
         },
-        /** 获取登录机构名称 */
-        getAccountName: () => {
-            const { userAccount } = this.state.userData
-            return userAccount?.accountname
-        },
-        /** 获取登录用户信息 */
-        getUserInfo: () => {
-            const { userInfo } = this.state.userData
-            return userInfo
-        },
-        /** 获取对应系统参数的对应值 */
-        getSystemParamValue: (paramcode: string) => {
-            const {systemParams} = this.state.userData
+        // 获取对应系统参数的对应值
+        getSystemParamValue(paramcode: string) {
+            const { systemParams } = this.state.userData
             return systemParams.find(obj => {
                 return obj.paramcode === paramcode
             })?.paramvalue
@@ -82,11 +66,7 @@ const store = new (class extends VueStore<StoreState>{
     }
 })
 
-export function useUserStore() {
-    return shallowReadonly({
-        ...toRefs(store.state),
-        ...store.getters,
-        ...store.actions,
-        ...store.methods,
-    })
-}
+// 接收账户变更通知
+export const userChangeNtf = eventBus.$on('UserChangeNtf', () => {
+    userStore.actions.getUserData()
+})

+ 32 - 0
src/stores/storage.ts

@@ -0,0 +1,32 @@
+import { Language } from '@/constants/language'
+import { AppTheme } from '@/constants/theme'
+import WebStorage from '@/utils/storage'
+
+function createLocalData() {
+    return {
+        appLanguage: Language.ZhCN,
+        appTheme: AppTheme.Default,
+    }
+}
+
+function createSessionData() {
+    return {
+        loginInfo: <Proto.LoginRsp>{
+            AccountIDs: [],
+            LoginCode: '',
+            LoginID: 0,
+            LoginUserType: 0,
+            AccountStatus: 0,
+            UserID: 0,
+            ClientID: 0,
+            MemberUserID: 0,
+            Token: '',
+        },
+        userRoutes: <Model.UserRoutes[]>[],
+        allEnums: <Model.EnumRsp[]>[], // 枚举信息
+        errorInfos: <Model.ErrorInfosRsp[]>[], // 错误信息
+    }
+}
+
+export const localData = new WebStorage(localStorage, createLocalData(), 'thj@')
+export const sessionData = new WebStorage(sessionStorage, createSessionData(), 'thj@')

+ 2 - 2
src/types/model/account.d.ts

@@ -271,7 +271,7 @@ declare global {
         }
 
         /** 用户菜单 */
-        interface UserMenu {
+        interface UserRoutes {
             id: number; // 自增ID
             authType: AuthType; // 权限类型
             title: string; // 标题
@@ -286,7 +286,7 @@ declare global {
             sort: number; // 排序
             hidden: boolean; // 是否隐藏
             remark: string; // 备注
-            children?: UserMenu[],
+            children?: UserRoutes[],
         }
 
         /** 用户角色 */

+ 5 - 3
src/utils/storage/index.ts

@@ -4,7 +4,8 @@ import { shallowRef, ShallowRef, watch } from 'vue'
  * 本地存储类
  */
 export default class <T extends object> {
-    constructor(storage: Storage, source: T) {
+    constructor(storage: Storage, source: T, prefix = '@') {
+        this.prefix = prefix
         this.storage = storage
         this.source = source
 
@@ -18,6 +19,7 @@ export default class <T extends object> {
 
     private readonly storage: Storage
     private readonly source // 初始数据
+    private readonly prefix // 防止命名冲突
     private state = {} as { [K in keyof T]: ShallowRef<T[K]> }
 
     /**
@@ -30,7 +32,7 @@ export default class <T extends object> {
                 this.reset(key)
             } else {
                 const strValue = JSON.stringify(value) // 注意数值长度过长会被自动转换为 String 类型
-                this.storage.setItem(key.toString(), strValue)
+                this.storage.setItem(this.prefix + key.toString(), strValue)
             }
         })
     }
@@ -41,7 +43,7 @@ export default class <T extends object> {
      * @returns 
      */
     getValue<K extends keyof T>(key: K) {
-        const storageValue = this.storage.getItem(key.toString())
+        const storageValue = this.storage.getItem(this.prefix + key.toString())
         if (storageValue !== 'undefined' && storageValue !== null) {
             return JSON.parse(storageValue) as T[K]
         } else {