currency-market.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import {
  2. Api_getQuotationNew
  3. } from "@/api/index.js"
  4. export const gerCurrencyMarket = (callback) => {
  5. const rq = (callback) => {
  6. Api_getQuotationNew().then(res => {
  7. // if (res && res.length > 0) {
  8. // let newArr = res.find((item) => item.name == 'USDT').quotation || [];
  9. // if (!state.currencyVal || !state.currencyVal?.currency_id) {
  10. // state.currencyVal = newArr[0];
  11. // }
  12. // // 首页推荐
  13. // if (newArr && newArr.length > 0) {
  14. // const nums = newArr.length > 3 ? 3 : newArr.length;
  15. // state.usdtList = newArr.slice(0, nums);
  16. // } else {
  17. // state.usdtList = []
  18. // }
  19. // // 自选
  20. // state.optional = newArr.slice(0, 6)
  21. // // 全部
  22. // state.marketAll = newArr
  23. // }
  24. callback(new Date())
  25. }).catch(err => {
  26. // if (state.currencySuspend && data?.noRefresh) {
  27. // console.log(11111 , state.currencySuspend , data?.noRefresh)
  28. // rq()
  29. // }
  30. }).finally(() => {
  31. setTimeout(() => {
  32. rq()
  33. // noRefresh : 是否不刷新,true 不会继续调用
  34. // if (state.currencySuspend && !data?.noRefresh) {
  35. // console.log(22222 , state.currencySuspend , data?.noRefresh)
  36. // rq()
  37. // }
  38. }, 3000)
  39. })
  40. }
  41. rq(callback)
  42. }
  43. // export default class currencyMarket {
  44. // ​
  45. // constructor() {
  46. // ​
  47. // this.socket = null;​
  48. // this.typeName = null;​
  49. // this.onopen = (() => {
  50. // ​
  51. // console.log(`open ${this.typeName} websocket`);​​
  52. // })​ this.onmessage = (e => {
  53. // ​ //处理各种推送消息
  54. // ​​})​ this.onerror = (e => {
  55. // ​
  56. // console.warn(`${this.typeName}websocket服务已断开,正在重连`);​
  57. // console.error("error " + e);​​
  58. // })​ this.onclose = (() => {
  59. // ​
  60. // console.warn("close websocket");​
  61. // console.warn(`${this.typeName}websocket服务已断开,正在重连`);​​
  62. // })​ this.initWs();​
  63. // }
  64. // ​ initWs() {
  65. // ​
  66. // console.warn(`初始化${this.typeName}websocket连接`);​
  67. // this.socket = new WebSocket(this.url); // 创建连接并注册响应函数
  68. // ​
  69. // this.socket.onopen = () => {
  70. // ​
  71. // this.onopen();​
  72. // };​
  73. // this.socket.onclose = () => {
  74. // ​
  75. // this.onclose();​
  76. // this.socket = null; // 清理
  77. // ​
  78. // stopWebsocket();​
  79. // };​
  80. // this.socket.onerror = (e) => {
  81. // ​
  82. // this.onerror(e);​
  83. // stopWebsocket();​
  84. // }​
  85. // this.socket.onmessage = (e) => {
  86. // ​
  87. // this.onmessage(e);​
  88. // };​
  89. // }
  90. // ​ reConnect(that) {
  91. // ​
  92. // if (that.isReconnect) return;​
  93. // that.isReconnect = true;​ //没连接上会一直重连,设置延迟避免请求过多
  94. // ​
  95. // setTimeout(() => {
  96. // ​
  97. // that.initWs();​
  98. // that.isReconnect = false;​
  99. // }, 2000);​
  100. // }
  101. // }