futures.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { ref, computed } from 'vue'
  2. import { queryGoodsList } from '@/services/api/goods'
  3. import storageData from './storage'
  4. /**
  5. * 商品存储类
  6. */
  7. export default new (class {
  8. loading = ref(false)
  9. goodsList = ref<Ermcp.GoodsRsp[]>([]) // 商品列表
  10. quoteDayList = ref<Ermcp.QuoteDay[]>([]) // 盘面列表
  11. /**
  12. * 期货行情列表
  13. */
  14. quoteList = computed(() => {
  15. return this.goodsList.value.reduce((res, cur) => {
  16. const { goodscode, goodsname } = cur
  17. const quote = this.getQuoteDayInfoByCode(goodscode).value
  18. const item: Store.Quotation = {
  19. goodscode,
  20. goodsname,
  21. last: quote?.last ?? 0,
  22. amplitude: 0,
  23. change: 0,
  24. bid: quote?.bid ?? 0,
  25. ask: quote?.ask ?? 0,
  26. bidvolume: quote?.bidvolume ?? 0,
  27. askvolume: quote?.askvolume ?? 0,
  28. totalvolume: quote?.totalvolume ?? 0,
  29. lastvolume: quote?.lastvolume ?? 0,
  30. holdvolume: quote?.holdvolume ?? 0,
  31. holdincrement: quote?.holdincrement ?? 0,
  32. presettle: quote?.presettle ?? 0,
  33. totalturnover: quote?.totalturnover ?? 0,
  34. opened: quote?.opened ?? 0,
  35. highest: quote?.highest ?? 0,
  36. lowest: quote?.lowest ?? 0,
  37. }
  38. res.push(item)
  39. return res
  40. }, [] as Store.Quotation[])
  41. })
  42. /**
  43. * 获取商品列表
  44. */
  45. getGoodsList = () => {
  46. this.loading.value = true
  47. return queryGoodsList({
  48. data: {
  49. userid: storageData.getLoginInfo('UserID')
  50. },
  51. success: (res) => {
  52. this.goodsList.value = res.data
  53. },
  54. complete: () => {
  55. this.loading.value = false
  56. }
  57. })
  58. }
  59. /**
  60. * 通过 goodscode 获取盘面实时行情
  61. * @param goodscode
  62. * @returns
  63. */
  64. getQuoteDayInfoByCode = (goodscode: string) => {
  65. return computed(() => this.quoteDayList.value.find((e) => e.goodscode.toUpperCase() === goodscode.toUpperCase()))
  66. }
  67. /**
  68. * 通过 goodscode 获取商品实时报价
  69. * @param goodscode
  70. * @returns
  71. */
  72. getGoodsPriceByCode = (goodscode: string) => {
  73. return computed(() => {
  74. const quote = this.getQuoteDayInfoByCode(goodscode)
  75. return quote.value?.last ?? 0
  76. })
  77. }
  78. })