protoHeader.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. }
  14. /**
  15. * // 站在 用户角度
  16. *
  17. * 设置 proto header 参数
  18. * @param funCodeName funCodeName
  19. * @param type HeadEnum
  20. */
  21. export function getProtoHeadParam(funCodeName: string, type: HeadEnum = 0): IMessageHead {
  22. const code = funCode[funCodeName];
  23. if (!code) console.error('没有找到对应的funCode值,请配置');
  24. let result: IMessageHead = {
  25. FunCode: code,
  26. UUID: uuidv4(),
  27. UserID: getUserId(),
  28. }
  29. switch (type) {
  30. case HeadEnum.common:
  31. break
  32. case HeadEnum.AccountID:
  33. result = Object.assign(result, { AccountID: getSelectedAccountId() })
  34. break
  35. case HeadEnum.MarketID18_GoodsID0:
  36. result = Object.assign(result, {
  37. MarketID: 18,
  38. GoodsID: 0,
  39. })
  40. break
  41. case HeadEnum.MarketID15101:
  42. result = Object.assign(result, { MarketID: 15101})
  43. break;
  44. case HeadEnum.MarketID69201:
  45. result = Object.assign(result, { MarketID: getMarketByTradeMode(TradeMode.Platinum), })
  46. break;
  47. }
  48. return result
  49. }