setup.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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, toRefs } from 'vue';
  9. import { quoteChange, quoteAmplitude } from '@/common/setup/table/tableQuote';
  10. import { TableQuote } from '@/common/setup/table/interface';
  11. /**
  12. * 处理空数据
  13. */
  14. function formatValue<Key extends keyof TableQuote>(value: TableQuote[Key]) {
  15. return value > 0 ? value : '--';
  16. }
  17. /**
  18. * 处理行情价格颜色
  19. */
  20. function handleQuotePriceColor<T, Key extends keyof TableQuote>(text: T, value: TableQuote[Key], presettle: TableQuote['presettle']) {
  21. let className = ''
  22. if (presettle && value !== presettle) {
  23. if (value > presettle) {
  24. className = 'up-quote-color'
  25. } else {
  26. className = 'down-quote-color'
  27. }
  28. }
  29. return <span class={className}>{text}</span>;
  30. }
  31. export function getColumnsList() {
  32. const columns = [
  33. {
  34. title: '序号',
  35. key: 'index',
  36. width: 80
  37. },
  38. {
  39. title: '代码',
  40. key: 'goodscode',
  41. },
  42. {
  43. title: '名称',
  44. key: 'goodsname'
  45. },
  46. {
  47. title: '最新价',
  48. key: 'last',
  49. customRender: ({ record }: { record: TableQuote }) => {
  50. const text = formatValue(record.last);
  51. return handleQuotePriceColor(text, record.last, record.presettle);
  52. }
  53. },
  54. {
  55. title: '涨跌幅%',
  56. key: 'amplitude',
  57. customRender: ({ record }: { record: TableQuote }) => {
  58. const text = quoteAmplitude(record);
  59. return handleQuotePriceColor(text, record.last, record.presettle);
  60. }
  61. },
  62. {
  63. title: '涨跌额',
  64. key: 'change',
  65. customRender: ({ record }: { record: TableQuote }) => {
  66. const text = quoteChange(record, record.decimalplace);
  67. return handleQuotePriceColor(text, record.last, record.presettle);
  68. }
  69. },
  70. {
  71. title: '买价',
  72. key: 'bid',
  73. customRender: ({ record }: { record: TableQuote }) => {
  74. const text = formatValue(record.bid);
  75. return handleQuotePriceColor(text, record.bid, record.presettle);
  76. }
  77. },
  78. {
  79. title: '卖价',
  80. key: 'ask',
  81. customRender: ({ record }: { record: TableQuote }) => {
  82. const text = formatValue(record.ask);
  83. return handleQuotePriceColor(text, record.ask, record.presettle);
  84. }
  85. },
  86. {
  87. title: '买量',
  88. key: 'bidvolume',
  89. customRender: ({ record }: { record: TableQuote }) => {
  90. const text = formatValue(record.bidvolume);
  91. return handleQuotePriceColor(text, record.bidvolume, record.presettle);
  92. }
  93. },
  94. {
  95. title: '卖量',
  96. key: 'askvolume',
  97. customRender: ({ record }: { record: TableQuote }) => {
  98. const text = formatValue(record.askvolume);
  99. return handleQuotePriceColor(text, record.askvolume, record.presettle);
  100. }
  101. },
  102. {
  103. title: '总量',
  104. key: 'totalvolume',
  105. customRender: ({ record }: { record: TableQuote }) => {
  106. return formatValue(record.totalvolume);
  107. }
  108. },
  109. {
  110. title: '现量',
  111. key: 'lastvolume',
  112. customRender: ({ record }: { record: TableQuote }) => {
  113. const text = formatValue(record.lastvolume);
  114. return handleQuotePriceColor(text, record.lastvolume, record.presettle);
  115. }
  116. },
  117. {
  118. title: '持仓量',
  119. key: 'holdvolume',
  120. customRender: ({ record }: { record: TableQuote }) => {
  121. return formatValue(record.holdvolume);
  122. }
  123. },
  124. {
  125. title: '日增',
  126. key: 'holdincrement',
  127. customRender: ({ record }: { record: TableQuote }) => {
  128. const text = formatValue(record.holdincrement);
  129. return handleQuotePriceColor(text, record.holdincrement, record.presettle);
  130. }
  131. },
  132. {
  133. title: '昨结价',
  134. key: 'presettle',
  135. customRender: ({ record }: { record: TableQuote }) => {
  136. return formatValue(record.presettle);
  137. }
  138. },
  139. {
  140. title: '金额',
  141. key: 'totalturnover',
  142. customRender: ({ record }: { record: TableQuote }) => {
  143. return formatValue(record.totalturnover);
  144. }
  145. },
  146. {
  147. title: '开盘',
  148. key: 'opened',
  149. customRender: ({ record }: { record: TableQuote }) => {
  150. const text = formatValue(record.opened);
  151. return handleQuotePriceColor(text, record.opened, record.presettle);
  152. }
  153. },
  154. {
  155. title: '最高',
  156. key: 'highest',
  157. customRender: ({ record }: { record: TableQuote }) => {
  158. const text = formatValue(record.highest);
  159. return handleQuotePriceColor(text, record.highest, record.presettle);
  160. }
  161. },
  162. {
  163. title: '最低',
  164. key: 'lowest',
  165. customRender: ({ record }: { record: TableQuote }) => {
  166. const text = formatValue(record.lowest);
  167. return handleQuotePriceColor(text, record.lowest, record.presettle);
  168. }
  169. },
  170. ];
  171. return columns.map(el => {
  172. return {
  173. dataIndex: el.key,
  174. width: 100,
  175. align: 'center',
  176. slots: { customRender: el.key, },
  177. ...el
  178. }
  179. })
  180. }
  181. // 外部交易所
  182. export const useExternalexchange = () => {
  183. const loading = ref<boolean>(false)
  184. const index = ref<string>('0');
  185. // 盘面数据
  186. const quoteList = ref<QueryQuoteDayRsp[]>([]);
  187. // 表格数据
  188. const tableList = ref<TableQuote[]>([]);
  189. // 外部交易所 数据
  190. const externalexchangeList = ref<Externalexchange[]>([])
  191. const tabList = ref<TabList[]>([])
  192. // 获取 商品数据
  193. const useGoodsList = (exchareaid: number) => {
  194. // 商品列表
  195. const goodsList = APP.get('Goods') as Goods[];
  196. const goodsGroups = APP.get('goodsgroups') as Ermcp3GoodsGroup[]
  197. // 商品组
  198. const selectedGoodsGroups = goodsGroups.filter(e => e.exexchangeid === exchareaid).map(el => el.goodsgroupid)
  199. return goodsList.filter(e => {
  200. return e.goodsstatus === 3 && selectedGoodsGroups.includes(e.goodsgroupid)
  201. })
  202. }
  203. initData(() => {
  204. externalexchangeList.value = APP.get('externalexchange')
  205. const list = externalexchangeList.value.map((e: Externalexchange) => {
  206. return { lable: e.exexchangename, code: e.exexchangecode };
  207. }) as TabList[]
  208. tabList.value = list
  209. if (list.length) {
  210. hanldeQuoteData(0)
  211. }
  212. })
  213. function hanldeQuoteData(index: number) {
  214. const id = getExternalId(index)
  215. // 找到 交易所 下的商品列表
  216. const goodsList = useGoodsList(id)
  217. // 重置表格数据
  218. tableList.value = goodsList.map((el) => {
  219. return {
  220. goodsid: el.goodsid,
  221. goodscode: el.goodscode,
  222. goodsname: el.goodsname,
  223. decimalplace: el.decimalplace,
  224. marketid: el.marketid,
  225. }
  226. })
  227. // 找到 盘面数据
  228. getQuoteData(goodsList)
  229. }
  230. function getQuoteData(goodsList: Goods[]) {
  231. quoteList.value.length = 0
  232. // 找到盘面数据
  233. goodsList.forEach(el => {
  234. const quote = getQuoteDayInfoByCode(el.goodscode);
  235. if (quote) {
  236. quoteList.value.push(quote)
  237. }
  238. })
  239. }
  240. // 处理表格行情数据
  241. function hanldeTableData() {
  242. quoteList.value.forEach((quote) => {
  243. const refs = toRefs(quote);
  244. const index = tableList.value.findIndex((e) => e.goodscode === quote.goodscode);
  245. if (index > -1) {
  246. const item = tableList.value[index];
  247. item.last = refs.last; // 最新价
  248. item.bid = refs.bid; // 买价
  249. item.ask = refs.ask; // 卖价
  250. item.bidvolume = refs.bidvolume; // 买量
  251. item.askvolume = refs.askvolume; // 卖量
  252. item.totalvolume = refs.totalvolume; // 总量
  253. item.lastvolume = refs.lastvolume; // 现量
  254. item.holdvolume = refs.holdvolume; // 持仓量
  255. item.holdincrement = refs.holdincrement; // 日增
  256. item.presettle = refs.presettle; // 昨结价
  257. item.totalturnover = refs.totalturnover; // 金额
  258. item.opened = refs.opened; // 开盘
  259. item.highest = refs.highest; // 最高
  260. item.lowest = refs.lowest; // 最低
  261. }
  262. });
  263. }
  264. function getExternalId(index: number) {
  265. return externalexchangeList.value[index].autoid
  266. }
  267. return { index, loading, tabList, tableList, quoteList, hanldeQuoteData, hanldeTableData }
  268. }