diff --git a/main.js b/main.js index d398530..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) - + 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 0000000..5008ddf Binary files /dev/null and b/pages/markets/.DS_Store differ diff --git a/pages/markets/index.vue b/pages/markets/index.vue index babbebd..1225c06 100644 --- a/pages/markets/index.vue +++ b/pages/markets/index.vue @@ -1,167 +1,237 @@ - - - - - diff --git a/pages/markets/kLine.vue b/pages/markets/kLine.vue index 191396b..af6e4c2 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 @@ + } + 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;