protoHeader.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {TradeMode} from "@/common/constants/enumCommon";
  2. import {getSelectedAccountId, getUserId} from "@/services/bus/account";
  3. import {getMarketByTradeMode} from "@/services/bus/market";
  4. import {funCode} from "@/services/funcode";
  5. import {v4 as uuidv4} from 'uuid';
  6. import {IMessageHead} from "./proto";
  7. export enum HeadEnum {
  8. common, // funcode uuid userID
  9. AccountID, // funcode uuid userID AccountID
  10. MarketID18_GoodsID0, // funcode uuid userID, MarketID:18, GoodsID: 0
  11. MarketID15101,
  12. MarketID69201,
  13. MarketID45201,
  14. tradeMode17,
  15. tradeMode45
  16. }
  17. /**
  18. * // 站在 用户角度
  19. *
  20. * 设置 proto header 参数
  21. * @param funCodeName funCodeName
  22. * @param type HeadEnum
  23. */
  24. export function getProtoHeadParam(funCodeName: string, type: HeadEnum = 0): IMessageHead {
  25. const code = funCode[funCodeName];
  26. if (!code) console.error('没有找到对应的funCode值,请配置');
  27. let result: IMessageHead = {
  28. FunCode: code,
  29. UUID: uuidv4(),
  30. UserID: getUserId(),
  31. }
  32. switch (type) {
  33. case HeadEnum.common:
  34. break
  35. case HeadEnum.AccountID:
  36. result = Object.assign(result, {AccountID: getSelectedAccountId()})
  37. break
  38. case HeadEnum.MarketID18_GoodsID0:
  39. result = Object.assign(result, {
  40. MarketID: 18,
  41. GoodsID: 0,
  42. })
  43. break
  44. case HeadEnum.MarketID15101:
  45. result = Object.assign(result, {MarketID: 15101})
  46. break;
  47. case HeadEnum.MarketID69201:
  48. result = Object.assign(result, {MarketID: getMarketByTradeMode(TradeMode.Platinum)?.marketid,})
  49. break;
  50. case HeadEnum.tradeMode17:
  51. result = Object.assign(result, {MarketID: getMarketByTradeMode(TradeMode.WarehouseReceiptTrade)?.marketid,})
  52. break;
  53. case HeadEnum.tradeMode45:
  54. result = Object.assign(result, {MarketID: getMarketByTradeMode(TradeMode.Wrtrade)?.marketid,})
  55. break;
  56. case HeadEnum.MarketID45201:
  57. result = Object.assign(result, {MarketID: 45201})
  58. break;
  59. }
  60. return result
  61. }