- 移除秒合约页面及UI - 合约页Tab改为Position Held/Transaction Record - 存款/提款/转账页增加BTC/ETH - 资产页重构(用户信息+盈亏+多语言) - 注册页改版(匹配新设计稿) - 日文全面翻译+首页菜单多语言 - 代理专属注册链接支持(?code=) - 10个locale文件同步更新
335 lines
8.5 KiB
JavaScript
335 lines
8.5 KiB
JavaScript
import Vue from 'vue'
|
|
import App from './App'
|
|
//引入vuex
|
|
import store from './store'
|
|
import uView from "uview-ui";
|
|
Vue.use(uView);
|
|
|
|
import {
|
|
router
|
|
} from './router/index.js'
|
|
import {
|
|
req,
|
|
req1,
|
|
apiUrl
|
|
} from './api/index.js'
|
|
import toast from './api/tos.js'
|
|
|
|
import myNav from "@/components/my-navbar/index.vue"
|
|
Vue.component('myNav', myNav)
|
|
// import apploading from "@/components/apploading/apploading.vue"
|
|
// Vue.component('apploading', apploading)
|
|
// 考虑规范性,使用 module.exports 导出,应该使用 require 引用
|
|
let Chinese = require('./static/locales/zh-CN.js')
|
|
let English = require('./static/locales/en-US.js')
|
|
let mn = require('./static/locales/mn.js')
|
|
let ms = require('./static/locales/ms.js')
|
|
let kr = require('./static/locales/kr.js')
|
|
let fre = require('./static/locales/fre.js')
|
|
let ger = require('./static/locales/ger.js')
|
|
let ily = require('./static/locales/ily.js')
|
|
let jp = require('./static/locales/jp.js')
|
|
|
|
const isWhiteRoute = (url) => {
|
|
if (!url) return true
|
|
let path = url
|
|
const qIndex = path.indexOf('?')
|
|
if (qIndex >= 0) path = path.slice(0, qIndex)
|
|
const hashIndex = path.indexOf('#')
|
|
if (hashIndex >= 0) path = path.slice(0, hashIndex)
|
|
const whiteList = [
|
|
'/pages/startup/startup',
|
|
'/pages/index/index',
|
|
'/pages/login/index',
|
|
'/pages/login/register',
|
|
'/pages/login/forget',
|
|
'/pages/lang/lang'
|
|
]
|
|
return whiteList.includes(path)
|
|
}
|
|
|
|
const interceptToLogin = (method) => {
|
|
uni.addInterceptor(method, {
|
|
invoke(args) {
|
|
const url = args && args.url
|
|
if (isWhiteRoute(url)) return args
|
|
if (uni.getStorageSync('token')) return args
|
|
uni.reLaunch({
|
|
url: '/pages/login/index'
|
|
})
|
|
return false
|
|
}
|
|
})
|
|
}
|
|
|
|
interceptToLogin('navigateTo')
|
|
interceptToLogin('redirectTo')
|
|
interceptToLogin('reLaunch')
|
|
interceptToLogin('switchTab')
|
|
|
|
Vue.mixin({
|
|
onShow() {
|
|
// 全局弃用深色主题:强制持久化为浅色
|
|
uni.setStorageSync('theme', 'light')
|
|
|
|
// 强制使用浅色主题
|
|
if (this.$store && this.$store.state && this.$store.state.lightTheme) {
|
|
this.theme = this.$store.state.lightTheme
|
|
|
|
// 设置tabBar样式为浅色主题
|
|
if (typeof uni.setTabBarStyle === 'function') {
|
|
uni.setTabBarStyle({
|
|
color: this.theme.fu_text || '#909090',
|
|
selectedColor: '#007AFF',
|
|
backgroundColor: this.theme.backgroundColor,
|
|
borderStyle: 'white',
|
|
borderColor: 'rgb(238, 238, 238)'
|
|
})
|
|
}
|
|
if (typeof uni.setTabBarItem === 'function' && this.$t) {
|
|
const i18n = this.$t('message')
|
|
if (i18n && i18n.tabBar) {
|
|
uni.setTabBarItem({
|
|
index: 0,
|
|
text: i18n.tabBar.home
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 1,
|
|
text: i18n.tabBar.market
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 2,
|
|
text: i18n.tabBar.cycle
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 3,
|
|
text: i18n.tabBar.lever
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 4,
|
|
text: i18n.tabBar.assets
|
|
})
|
|
}
|
|
}
|
|
|
|
// 设置状态栏样式
|
|
// #ifdef APP-PLUS
|
|
if (typeof plus !== 'undefined' && typeof plus.navigator === 'object') {
|
|
plus.navigator.setStatusBarStyle('dark')
|
|
}
|
|
// #endif
|
|
}
|
|
|
|
const token = uni.getStorageSync('token')
|
|
if (token) return
|
|
const pages = getCurrentPages()
|
|
if (!pages || !pages.length) return
|
|
const current = pages[pages.length - 1]
|
|
const path = '/' + (current.route || '')
|
|
const whiteList = [
|
|
'/pages/startup/startup',
|
|
'/pages/index/index',
|
|
'/pages/login/index',
|
|
'/pages/login/register',
|
|
'/pages/login/forget',
|
|
'/pages/lang/lang'
|
|
]
|
|
if (!whiteList.includes(path)) {
|
|
uni.reLaunch({
|
|
url: '/pages/login/index'
|
|
})
|
|
}
|
|
|
|
}
|
|
})
|
|
// VueI18n
|
|
import VueI18n from 'vue-i18n'
|
|
|
|
// VueI18n
|
|
Vue.use(VueI18n)
|
|
|
|
Vue.config.productionTip = false
|
|
|
|
// VueI18n
|
|
// 注意下述代码务必放在代码 "Vue.prototype._i18n = i18n" 上方
|
|
const i18n = new VueI18n({
|
|
// 默认语言
|
|
locale: 'jp',
|
|
// 引入语言文件
|
|
messages: {
|
|
'zh-cn': Chinese,
|
|
'en-us': English,
|
|
'mn': mn,
|
|
'ms': ms,
|
|
'kr': kr,
|
|
'fre': fre,
|
|
'ger': ger,
|
|
'ily': ily,
|
|
'jp': jp
|
|
}
|
|
})
|
|
|
|
Vue.prototype._goback = function() {
|
|
uni.navigateBack()
|
|
}
|
|
Vue.prototype.$store = store
|
|
Vue.prototype._i18n = i18n
|
|
Vue.prototype.router = router
|
|
Vue.prototype.post = req
|
|
Vue.prototype.get = req1
|
|
Vue.prototype.tos = toast
|
|
Vue.prototype.upload = apiUrl
|
|
|
|
Vue.prototype.connectWS = function() {
|
|
console.log("websocket开始链接")
|
|
var that = this
|
|
uni.connectSocket({
|
|
url: 'wss://jyshd.pp1008.top:17878',
|
|
})
|
|
uni.onSocketOpen(function(res) {
|
|
console.log('WebSocket连接已打开!');
|
|
getApp().globalData.socket = true
|
|
if (getApp().globalData.period) {
|
|
console.log(getApp().globalData.period, "时段重新链接")
|
|
that.sendSocketMessage({
|
|
'subs': 'tradenow',
|
|
"user_id": uni.getStorageSync("user_id"),
|
|
"sub": "market." + getApp().globalData.symbol + ".kline." + getApp().globalData
|
|
.period,
|
|
"id": "BTC",
|
|
})
|
|
that.sendSocketMessage({
|
|
'subs': 'depth',
|
|
"user_id": uni.getStorageSync("user_id"),
|
|
"sub": "market." + getApp().globalData.symbol + ".depth.step0",
|
|
"id": "BTC",
|
|
})
|
|
uni.$emit("reConnect")
|
|
} else if (getApp().globalData.symbol) {
|
|
console.log(getApp().globalData.symbol, "重新链接")
|
|
that.sendSocketMessage({
|
|
'subs': 'tradenow',
|
|
"user_id": uni.getStorageSync("user_id"),
|
|
"sub": "market." + getApp().globalData.symbol + ".kline.1min",
|
|
"id": "BTC",
|
|
})
|
|
that.sendSocketMessage({
|
|
'subs': 'depth',
|
|
"user_id": uni.getStorageSync("user_id"),
|
|
"sub": "market." + getApp().globalData.symbol + ".depth.step0",
|
|
"id": "BTC",
|
|
})
|
|
uni.$emit("reConnect")
|
|
} else {
|
|
that.onSocketMessage()
|
|
}
|
|
});
|
|
uni.onSocketError(function(res) {
|
|
console.log('WebSocket连接打开失败,请检查!');
|
|
getApp().globalData.socket = false
|
|
clearInterval(getApp().globalData.reConnect)
|
|
getApp().globalData.reConnect = setInterval(function() {
|
|
if (getApp().globalData.socket == false) {
|
|
that.connectWS()
|
|
} else {
|
|
clearInterval(getApp().globalData.reConnect)
|
|
}
|
|
}, 2000)
|
|
});
|
|
uni.onSocketClose(function(res) {
|
|
console.log('WebSocket 已关闭!');
|
|
getApp().globalData.socket = false
|
|
clearInterval(getApp().globalData.reConnect)
|
|
getApp().globalData.reConnect = setInterval(function() {
|
|
if (getApp().globalData.socket == false) {
|
|
that.connectWS()
|
|
} else {
|
|
clearInterval(getApp().globalData.reConnect)
|
|
}
|
|
}, 2000)
|
|
});
|
|
}
|
|
|
|
Vue.prototype.onSocketMessage = function() {
|
|
var that = this
|
|
uni.onSocketMessage(function(res) {
|
|
var msg = JSON.parse(res.data)
|
|
// console.log(msg)
|
|
if (msg.ping) {
|
|
that.sendSocketMessage({
|
|
"pong": msg.ping
|
|
})
|
|
} else if (msg.tick) {
|
|
// console.log('链接的币种',msg.ch.split(".")[1])
|
|
if (msg.subs == "depth") {
|
|
// console.log('深度',msg)
|
|
if (msg.ch && that.coinInfo && that.coinInfo.symbol && msg.ch == "market." + that.coinInfo.symbol + ".depth.step0") {
|
|
// console.log('深度',msg.tick)
|
|
that.tick = msg.tick
|
|
}
|
|
} else {
|
|
// console.log(msg.tick)
|
|
if (msg.ch && that.coinInfo && that.coinInfo.symbol && msg.ch == "market." + that.coinInfo.symbol + ".kline.1min") {
|
|
// console.log('最后一分钟数据',msg.tick)
|
|
that.lastData = msg.tick
|
|
}
|
|
if (msg.ch && that.coinInfo && that.coinInfo.symbol && msg.ch == "market." + that.coinInfo.symbol + ".kline.1day") {
|
|
// console.log('一天内数据',msg.tick)
|
|
that.dayData = msg.tick
|
|
}
|
|
}
|
|
} else if (msg.data) {
|
|
// 所有历史数据
|
|
// console.log('所有历史数据',msg.data)
|
|
that.lastData = msg.data[msg.data.length - 1]
|
|
} else {
|
|
// console.log(msg)
|
|
}
|
|
});
|
|
}
|
|
|
|
Vue.prototype.changeExchange = function() {
|
|
var that = this
|
|
uni.closeSocket({
|
|
fail: function() {
|
|
that.connectWS()
|
|
}
|
|
})
|
|
},
|
|
|
|
//发送消息
|
|
Vue.prototype.sendSocketMessage = function(msg) {
|
|
// console.log(msg)
|
|
uni.sendSocketMessage({
|
|
data: JSON.stringify(msg),
|
|
success: function(res) {
|
|
|
|
},
|
|
complete: function(res) {
|
|
|
|
}
|
|
});
|
|
},
|
|
|
|
Vue.prototype._formatDate = function(thisData) {
|
|
var date = new Date(thisData);
|
|
var YY = date.getFullYear() + '-';
|
|
var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
|
|
var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
|
|
var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
|
|
var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
|
|
var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
|
|
// return YY + MM + DD + " " + hh + mm + ss;
|
|
return MM + DD + " " + hh + mm + ss;
|
|
}
|
|
|
|
App.mpType = 'app'
|
|
|
|
const app = new Vue({
|
|
i18n,
|
|
...App,
|
|
//挂载
|
|
store
|
|
})
|
|
app.$mount()
|