setup.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import { TabList } from '@/common/components/description/interface';
  2. import { initData } from '@/common/methods';
  3. import APP from '@/services';
  4. import { GoodsQuote } from '@/services/go/ermcp/goodsInfo/interface';
  5. import { Externalexchange } from '@/services/go/useInfo/interface';
  6. import { ref } from 'vue';
  7. import { quoteChange, quoteAmplitude } from '@/common/setup/table/tableQuote';
  8. import { getGoodsQuoteList } from '@/services/bus/goods';
  9. import { subcriteGoodsQuote } from '@/common/setup/table/tableQuote';
  10. import { changeUnit } from '@/utils/qt/common'
  11. /**
  12. * 处理空数据
  13. */
  14. function formatValue<Key extends keyof GoodsQuote>(value: GoodsQuote[Key]) {
  15. return value > 0 ? value : '--';
  16. }
  17. /**
  18. * 处理行情价格颜色
  19. */
  20. function handleQuotePriceColor<T, Key extends keyof GoodsQuote>(text: T, value: GoodsQuote[Key], presettle: GoodsQuote['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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  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: GoodsQuote }) => {
  106. return formatValue(record.totalvolume);
  107. }
  108. },
  109. {
  110. title: '现量',
  111. key: 'lastvolume',
  112. customRender: ({ record }: { record: GoodsQuote }) => {
  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: GoodsQuote }) => {
  121. return formatValue(record.holdvolume);
  122. }
  123. },
  124. {
  125. title: '日增',
  126. key: 'holdincrement',
  127. customRender: ({ record }: { record: GoodsQuote }) => {
  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: GoodsQuote }) => {
  136. return formatValue(record.presettle);
  137. }
  138. },
  139. {
  140. title: '金额',
  141. key: 'totalturnover',
  142. customRender: ({ record }: { record: GoodsQuote }) => {
  143. if (record.totalturnover > 0) {
  144. return changeUnit(record.totalturnover);
  145. }
  146. return formatValue(record.totalturnover);
  147. }
  148. },
  149. {
  150. title: '开盘',
  151. key: 'opened',
  152. customRender: ({ record }: { record: GoodsQuote }) => {
  153. const text = formatValue(record.opened);
  154. return handleQuotePriceColor(text, record.opened, record.presettle);
  155. }
  156. },
  157. {
  158. title: '最高',
  159. key: 'highest',
  160. customRender: ({ record }: { record: GoodsQuote }) => {
  161. const text = formatValue(record.highest);
  162. return handleQuotePriceColor(text, record.highest, record.presettle);
  163. }
  164. },
  165. {
  166. title: '最低',
  167. key: 'lowest',
  168. customRender: ({ record }: { record: GoodsQuote }) => {
  169. const text = formatValue(record.lowest);
  170. return handleQuotePriceColor(text, record.lowest, record.presettle);
  171. }
  172. },
  173. ];
  174. return columns.map(el => {
  175. return {
  176. dataIndex: el.key,
  177. width: 100,
  178. align: 'center',
  179. slots: { customRender: el.key, },
  180. ...el
  181. }
  182. })
  183. }
  184. // 外部交易所
  185. export const useExternalexchange = () => {
  186. let stopSubcribe: () => void;
  187. const loading = ref(false)
  188. // 交易所ID
  189. const exchangeId = ref(0);
  190. // 表格数据
  191. const tableList = ref<GoodsQuote[]>([]);
  192. // 外部交易所 数据
  193. const externalexchangeList = ref<Externalexchange[]>([])
  194. // 交易所标签
  195. const tabList = ref<TabList[]>([]);
  196. function hanldeQuoteData(index: number) {
  197. exchangeId.value = externalexchangeList.value[index].autoid;
  198. tableList.value = getGoodsQuoteList(exchangeId.value);
  199. const codes = tableList.value.map((el) => el.goodscode);
  200. // 行情按需订阅
  201. stopSubcribe = subcriteGoodsQuote(codes);
  202. }
  203. // 切换交易所标签
  204. function changeTab(index: number, current: TabList) {
  205. // 停止上次订阅
  206. stopSubcribe();
  207. hanldeQuoteData(index);
  208. console.log(index, current);
  209. }
  210. initData(() => {
  211. externalexchangeList.value = APP.get('externalexchange')
  212. const list = externalexchangeList.value.map((e: Externalexchange) => {
  213. return { lable: e.exexchangename, code: e.exexchangecode };
  214. }) as TabList[]
  215. tabList.value = list
  216. if (list.length) {
  217. hanldeQuoteData(0)
  218. }
  219. })
  220. return { loading, exchangeId, tabList, tableList, changeTab, }
  221. }