From 5fb85d260530b3d84a3b6d33586c78bb7138464b Mon Sep 17 00:00:00 2001 From: vee Date: Sun, 28 Aug 2022 17:21:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?k=E7=BA=BF=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 2 +- pages/markets/kLine.vue | 841 +++++++++++++++++++++------------------- 2 files changed, 447 insertions(+), 396 deletions(-) diff --git a/main.js b/main.js index 87176b5..7286c68 100644 --- a/main.js +++ b/main.js @@ -16,7 +16,7 @@ Vue.prototype.$api = api // 自定义底部导航栏 import tabBar from 'components/tabBar/tabBar.vue' Vue.component('tab-bar', tabBar) - +window.wx = {} Vue.use(uView); uni.$u.config.unit = 'rpx' diff --git a/pages/markets/kLine.vue b/pages/markets/kLine.vue index 191396b..61ea66a 100644 --- a/pages/markets/kLine.vue +++ b/pages/markets/kLine.vue @@ -24,10 +24,22 @@ 28394893.30943094 + + + 1M + + 30M + + 60M + + 1D + + 30D + + style="height:500rpx;width: 100%;position: relative; padding: 0px; margin: 0px; border-width: 0px; cursor: default;"> @@ -79,72 +91,88 @@ + } + From 685619c8a62cf0b9648915c991996ec37c3c5cc5 Mon Sep 17 00:00:00 2001 From: vee <897831508@qq.com> Date: Mon, 29 Aug 2022 19:07:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=88=E7=BA=A6?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 10 +- pages/markets/.DS_Store | Bin 0 -> 6148 bytes pages/markets/index.vue | 402 +++++++++++++++----------- pages/markets/kLine.vue | 3 +- pages/markets/trade.vue | 624 ++++++++++++++++++++++++---------------- utils/axios.js | 15 +- utils/websocket.js | 184 ++++++++++++ 7 files changed, 816 insertions(+), 422 deletions(-) create mode 100644 pages/markets/.DS_Store create mode 100644 utils/websocket.js diff --git a/main.js b/main.js index 873820a..f5bd8d8 100644 --- a/main.js +++ b/main.js @@ -12,16 +12,22 @@ import ZH from './utils/language/zh_TW.js' import VI from './utils/language/vi_VN.js' import api from './utils/api.js' +import constant from './utils/constant.js' +import websocket from './utils/websocket.js' Vue.prototype.$api = api +Vue.prototype.$constant = constant +Vue.prototype.$websocket = websocket // 自定义底部导航栏 import tabBar from 'components/tabBar/tabBar.vue' Vue.component('tab-bar', tabBar) -window.wx = {} + Vue.use(uView); uni.$u.config.unit = 'rpx' Vue.use(VueI18n); - +// #ifdef H5 +window.wx = {} +// #endif const i18n = new VueI18n({ locale: store.state.language, // 默认选择的语言 // locale: 'en_US', // 默认选择的语言 diff --git a/pages/markets/.DS_Store b/pages/markets/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 - - - - {{ i18n.TrandingPair }} - {{ i18n.LatestPrice }} - {{ i18n.RiseAndfall }} - - - - - - - - BTC/USDT - {{ 5145 * index * index * index }} - 500.30% - - - - - - - - - - diff --git a/pages/markets/kLine.vue b/pages/markets/kLine.vue index 61ea66a..af6e4c2 100644 --- a/pages/markets/kLine.vue +++ b/pages/markets/kLine.vue @@ -342,7 +342,8 @@ top: '8%', left: '50rpx', right: '10rpx', - height: '60%', + height: '60%', + backgroundColor: 'transparent', }, { diff --git a/pages/markets/trade.vue b/pages/markets/trade.vue index 4a6ac4d..693919d 100644 --- a/pages/markets/trade.vue +++ b/pages/markets/trade.vue @@ -1,245 +1,381 @@ - - - - - diff --git a/utils/axios.js b/utils/axios.js index ebaa520..c557e0f 100644 --- a/utils/axios.js +++ b/utils/axios.js @@ -28,10 +28,11 @@ service.interceptors.request.use( title: 'loading', mask: true }) - } + } + if (config.url.indexOf('market') > -1) { // #ifdef H5 - baseURL = constant.H5_MARKET_URL; + config.baseURL = constant.H5_MARKET_URL; // #endif // #ifdef APP-PLUS config.baseURL = Vue.prototype.MARKET_URL; @@ -138,19 +139,16 @@ service.interceptors.response.use(res => { // console.log(res) // console.log(res.data) // console.log(res.data.data[0].nameAlias) - if (res.success || res.errCode === 'USER.0017') { + if (res.code===0||res.success) { return res.data; } - if(res.errMsg=='No customer service is online'&&res.errCode=='SYS.0012'){ - return res; - } - else { + uni.showToast({ title: res.errMsg, icon: 'none', duration: 1500 }) - if (res.errCode === 'USER.0010') { + if (res.errCode === 'SYS.0006') { uni.setStorageSync('ticket',null); uni.removeStorage({ key: 'logInfo', @@ -178,7 +176,6 @@ service.interceptors.response.use(res => { } uni.$emit('refreshQrCode') return Promise.reject(res.errMsg); - } }, error => { uni.hideLoading(); return Promise.reject(error) diff --git a/utils/websocket.js b/utils/websocket.js new file mode 100644 index 0000000..9d55568 --- /dev/null +++ b/utils/websocket.js @@ -0,0 +1,184 @@ +class WebSocketClass { + constructor(url) { + this.lockReconnect = false; // 是否开始重连 + this.wsUrl = ""; // ws 地址 + this.globalCallback = null; // 回调方法 + this.userClose = false; // 是否主动关闭 + this.createWebSocket(url); + } + + createWebSocket(url) { + // #ifdef H5 + if (typeof(WebSocket) === 'undefined') { + this.writeToScreen("您的浏览器不支持WebSocket,无法获取数据"); + return false + } + // #endif + + // #ifdef APP-PLUS + if (typeof(uni.connectSocket) === 'undefined') { + this.writeToScreen("您的浏览器不支持WebSocket,无法获取数据"); + return false + } + // #endif + + this.wsUrl = url; + try { + // 创建一个this.ws对象【发送、接收、关闭socket都由这个对象操作】 + + // #ifdef H5 + this.ws = new WebSocket(this.wsUrl); + this.initEventHandle(); + // #endif + + // #ifdef APP-PLUS + let that = this + this.ws = uni.connectSocket({ + url: this.wsUrl, + success(data) { + console.log("websocket连接成功"); + + that.initEventHandle(); + }, + }); + // #endif + } catch (e) { + this.reconnect(url); + } + } + + // 初始化 + initEventHandle() { + /** + * 监听WebSocket连接打开成功 + */ + + // #ifdef H5 + this.ws.onopen = (event) => { + console.log("WebSocket连接打开"); + }; + // #endif + + // #ifdef APP-PLUS + this.ws.onOpen(res => { + console.log('WebSocket连接打开'); + }); + // #endif + + + /** + * 连接关闭后的回调函数 + */ + + // #ifdef H5 + this.ws.onclose = (event) => { + if (!this.userClose) { + this.reconnect(this.wsUrl); //重连 + } + }; + // #endif + + // #ifdef APP-PLUS + this.ws.onClose(() => { + if (!this.userClose) { + this.reconnect(this.wsUrl); //重连 + } + }); + // #endif + + + /** + * 报错时的回调函数 + */ + + // #ifdef H5 + this.ws.onerror = (event) => { + if (!this.userClose) { + this.reconnect(this.wsUrl); //重连 + } + }; + // #endif + + // #ifdef APP-PLUS + this.ws.onError(() => { + if (!this.userClose) { + this.reconnect(this.wsUrl); //重连 + } + }); + // #endif + + + /** + * 收到服务器数据后的回调函数 + */ + + // #ifdef H5 + this.ws.onmessage = (event) => { + + this.globalCallback(JSON.parse(event.data)) + }; + // #endif + + // #ifdef APP-PLUS + this.ws.onMessage(event => { + this.globalCallback(JSON.parse(event.data)) + }); + // #endif + } + + // 关闭ws连接回调 + reconnect(url) { + if (this.lockReconnect) return; + this.ws.close(); + this.lockReconnect = true; // 关闭重连,没连接上会一直重连,设置延迟避免请求过多 + setTimeout(() => { + this.createWebSocket(url); + this.lockReconnect = false; + }, 1000); + } + + // 发送信息方法 + webSocketSendMsg(msg) { + // #ifdef H5 + this.ws && this.ws.send(JSON.stringify(msg)); + // #endif + + // #ifdef APP-PLUS + this.ws && this.ws.send({ + data: JSON.stringify(msg), + success() { + console.log("消息发送成功"); + }, + fail(err) { + console.log("关闭失败", err) + } + }); + // #endif + + } + + // 获取ws返回的数据方法 + getWebSocketMsg(callback) { + this.globalCallback = callback + } + + // 关闭ws方法 + closeSocket() { + if (this.ws) { + this.userClose = true; + this.ws.close({ + success(res) { + console.log("关闭成功", res) + }, + fail(err) { + console.log("关闭失败", err) + } + }); + } + } + + writeToScreen(massage) { + console.log(massage); + } +} +export default WebSocketClass;