setup.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { TabList } from '@/common/components/description/interface';
  2. import { initData } from '@/common/methods';
  3. import APP from '@/services';
  4. import { getQuoteDayInfoByCode } from '@/services/bus/goods';
  5. import { Ermcp3GoodsGroup, Goods } from '@/services/go/ermcp/goodsInfo/interface';
  6. import { QueryQuoteDayRsp } from '@/services/go/quote/interface';
  7. import { Externalexchange } from '@/services/go/useInfo/interface';
  8. import { ref } from 'vue';
  9. export function getColumnsList() {
  10. const columns = [
  11. { title: '序号', key: 'index', width: 80 },
  12. { title: '代码', key: 'goodscode' },
  13. { title: '名称', key: 'goodsname' },
  14. { title: '买价', key: 'bid' },
  15. { title: '买量', key: 'bidvolume' },
  16. { title: '卖价', key: 'ask' },
  17. { title: '卖量', key: 'askvolume' },
  18. { title: '当前价', key: 'last' },
  19. { title: '涨跌', key: 'change' }, // 最新价 - 昨结价
  20. { title: '幅度', key: 'amplitude' }, // (最新价 - 昨结价) / 100 %
  21. { title: '开盘', key: 'opened' },
  22. { title: '最高', key: 'highest' },
  23. { title: '最低', key: 'lowest' },
  24. { title: '结算', key: 'settle' },
  25. { title: '昨结算', key: 'presettle' },
  26. // { title: '振幅', key: 'vibration' }, // (最高价 - 最低价 ) / 最新价 * 100 %
  27. // { title: '总量', key: 'totalvolume' },
  28. // { title: '现量', key: 'lastvolume' },
  29. // { title: '持仓量', key: 'holdvolume' },
  30. // { title: '日增', key: 'holdincrement' },
  31. // { title: '金额', key: 'totalturnover' },
  32. ];
  33. return columns.map(el => {
  34. return { dataIndex: el.key, width: 100, align: 'center', slots: { customRender: el.key, }, ...el }
  35. })
  36. }
  37. // 外部交易所
  38. export const useExternalexchange = () => {
  39. const loading = ref<boolean>(false)
  40. const index = ref<string>('0');
  41. // 外部交易所 数据
  42. const externalexchangeList = ref<Externalexchange[]>([])
  43. const tabList = ref<TabList[]>([])
  44. // 盘面数据
  45. const tableList = ref<QueryQuoteDayRsp[]>([
  46. ])
  47. // 获取 商品数据
  48. const useGoodsList = (exchareaid: number) => {
  49. const goodsList = APP.get('Goods') as Goods[];
  50. const goodsGroups = APP.get('goodsgroups') as Ermcp3GoodsGroup[]
  51. // 商品组
  52. const selectedGoodsGroups = goodsGroups.filter(e => e.exexchangeid === exchareaid).map(el => el.goodsgroupid)
  53. return goodsList.filter(e => {
  54. return e.goodsstatus === 3 && selectedGoodsGroups.includes(e.goodsgroupid)
  55. })
  56. }
  57. initData(() => {
  58. externalexchangeList.value = APP.get('externalexchange')
  59. const list = externalexchangeList.value.map((e: Externalexchange) => {
  60. return { lable: e.exexchangename, code: e.exexchangecode };
  61. }) as TabList[]
  62. tabList.value = list
  63. if (list.length) {
  64. hanldeQuoteData(0)
  65. }
  66. })
  67. function hanldeQuoteData(index: number) {
  68. const id = getExternalId(index)
  69. // 找到 交易所 下的商品列表
  70. const goodsList = useGoodsList(id)
  71. // 找到 盘面数据
  72. getQuoteData(goodsList)
  73. }
  74. function getQuoteData(goodsList: Goods[]) {
  75. tableList.value.length = 0
  76. // 找到盘面数据
  77. goodsList.forEach(el => {
  78. const quote = getQuoteDayInfoByCode(el.goodscode);
  79. if (quote) {
  80. tableList.value.push(quote)
  81. }
  82. })
  83. }
  84. function getExternalId(index: number) {
  85. return externalexchangeList.value[index].autoid
  86. }
  87. return { index, loading, tabList, tableList, hanldeQuoteData }
  88. }