var langues = { zh_CN: { title: '首页', help: '帮助中心', recharge: "充值", withdrawal: "提现", favorites: "自选", top: '涨跌榜', more:'更多' }, zh_HK: { title: '首頁', help: '幫助中心', recharge: "充值", withdrawal: "提現", favorites: " 自選", top: '漲跌榜', more:'更多' }, en_US: { title: 'Home', help: 'Help Center', recharge: "Recharge", withdrawal: "Withdrawal", favorites: "Favorites", top: 'Top', more:'More' } }; //2、页面上所有需要国际化的文字,包括提示,都通过Vue去引用,例子: var langueKey = app.getLanguageLocalStorage(); //获取国际化语种 var langue = langues[langueKey]; // 获取国际化语种数据 var dataInfo = new Vue({ el: "#js-data-info", data: { langue: langue } }) //3、每个页面都需要加上以下的方法: window.addEventListener('switchLangueData', function(e) { //dataInfo为Vue对象的名称 dataInfo.langue = langues[e.detail]; }); var currencysObj = null; var homeMarketPairObj = {}; mui.plusReady(function() { initData(); listener(); mui("#js-data-info").pullToRefresh({ down: { callback: function() { getNews(); listAdSlider(); var self = this; setTimeout(function() { self.endPullDownToRefresh(); }, 1000); } } }); }); function initData() { initHomeMarket(); initTopMarket(); getNews(); listAdSlider(); } function listener() { var marketPage = app.preloadWin('../../market/market.html', 'html/market/market.html', null, null, null, true); // 更多点击事件 document.getElementById('more').addEventListener('tap', function() { marketPage.show(); }); // 帮助中心点击事件 document.getElementById('helpCenter').addEventListener('tap', function() { mui.openWindow({ url: '../../../mine/html/my/my_help_center.html', }); }); // 自选点击事件 document.getElementById('choice').addEventListener('tap', function() { var url = 'html/market/market.html'; var data = { url: url }; var marketView = plus.webview.getWebviewById(url); mui.fire(marketView, "choiceTab", null); var indexView = plus.webview.getWebviewById(plus.runtime.appid); mui.fire(indexView, "viewTab", data); marketPage.show(); }); // 提现点击事件 document.getElementById('withdraw').addEventListener('tap', function() { if(JSON.stringify(app.getUserLocalStorage()) != "{}") { // app.openWin('../../wallet/html/withdraw.html', 'withdraw.html'); var url = 'html/wallet/html/wallet.html'; var data = { url: url }; var marketView = plus.webview.getWebviewById(url); mui.fire(marketView, "choiceTab", null); var indexView = plus.webview.getWebviewById(plus.runtime.appid); mui.fire(indexView, "viewTab", data); } else { app.openWin('../../../mine/html/wallet_login.html', 'wallet_login.html'); } }); // 充值点击事件 document.getElementById('recharge').addEventListener('tap', function() { if(JSON.stringify(app.getUserLocalStorage()) != "{}") { // app.openWin('../../wallet/html/recharge.html', 'recharge.html'); var url = 'html/wallet/html/wallet.html'; var data = { url: url }; var marketView = plus.webview.getWebviewById(url); mui.fire(marketView, "choiceTab", null); var indexView = plus.webview.getWebviewById(plus.runtime.appid); mui.fire(indexView, "viewTab", data); } else { app.openWin('../../../mine/html/wallet_login.html', 'wallet_login.html'); } }); /** * 监听获取行情列表 */ window.addEventListener("marketList", function(event) { currencysObj = event.detail; }); /** * 监听行情改变事件 */ window.addEventListener("marketChange", function(event) { marketChange(event.detail); }); /** * 汇率改变事件 */ window.addEventListener("exchangeRate", function(event) { initData(); }); } function marketChange(changeMarketObj) { var percent = (changeMarketObj.percent * 100).toFixed(2) + "%"; var className; var topClassName; if(changeMarketObj.percent < 0) { className = 'app-market-down'; topClassName = 'app-coin-percent-down'; } else { percent = "+" + percent; className = 'app-market-up'; topClassName = 'app-coin-percent-up'; } //涨跌榜中的 var topEl = document.getElementById("top-total-" + changeMarketObj.currencyPair); if(topEl) { topEl.innerHTML = '24H ' + app.formatValue(changeMarketObj.total); document.getElementById("top-amount-" + changeMarketObj.currencyPair).innerHTML = app.formatValue(changeMarketObj.amount); document.getElementById("top-money-" + changeMarketObj.currencyPair).innerHTML = app.formatValue(changeMarketObj[app.getExchangeRateLocalStorage().toLowerCase() + 'Amount'] * changeMarketObj.amount) + ' ' + app.getExchangeRateLocalStorage(); var topPercentEl = document.getElementById("top-percent-" + changeMarketObj.currencyPair); topPercentEl.innerHTML = percent; topPercentEl.classList.remove('app-coin-percent-down'); topPercentEl.classList.remove('app-coin-percent-up'); topPercentEl.classList.add(topClassName); } //头部的 if(homeMarketPairObj[changeMarketObj.currencyPair]) { var i = homeMarketPairObj[changeMarketObj.currencyPair]; document.getElementById("currency-amount-" + i).innerText = app.formatValue(changeMarketObj.amount); document.getElementById("currency-percent-" + i).innerText = percent; document.getElementById("currency-rate-" + i).innerText = app.formatValue(changeMarketObj[app.getExchangeRateLocalStorage().toLowerCase() + 'Amount']) + app.getExchangeRateLocalStorage(); document.getElementById("currency-amount-" + i).classList.remove('app-market-up'); document.getElementById("currency-amount-" + i).classList.remove('app-market-down'); document.getElementById("currency-amount-" + i).classList.add(className); document.getElementById("currency-percent-" + i).classList.remove('app-market-up'); document.getElementById("currency-percent-" + i).classList.remove('app-market-down'); document.getElementById("currency-percent-" + i).classList.add(className); } } function initHomeMarket() { var url = app.currencyBaseUrl + "market/getHomeList"; mui.ajax(url, { type: "GET", timeout: 5000, dataType: "json", success: function(j) { if(j.code == 200) { var markets = j.data; app.setLocalStorage("market/getHomeList",markets); renderHomeMarket(markets); } else { var markets = app.getLocalStorage("market/getHomeList"); renderHomeMarket(markets); } }, error: function(xhr, type, errorThrown) { console.log("===market/getHomeList=== error type:"+type) var markets = app.getLocalStorage("market/getHomeList"); renderHomeMarket(markets); } }); } function renderHomeMarket(markets){ for(var i in markets) { var percent = (markets[i].percent * 100).toFixed(2) + "%"; if(markets[i].percent < 0) { document.getElementById("currency-amount-" + i).classList.add('app-market-down'); document.getElementById("currency-percent-" + i).classList.add('app-market-down'); } else { percent = "+" + percent; document.getElementById("currency-amount-" + i).classList.add('app-market-up'); document.getElementById("currency-percent-" + i).classList.add('app-market-up'); } var currencys = markets[i].currencyPair.split("-"); homeMarketPairObj[markets[i].currencyPair] = i; document.getElementById("currency-pair-" + i).innerText = currencys[0] + '/' + currencys[1]; document.getElementById("currency-amount-" + i).innerText = app.formatValue(markets[i].amount); document.getElementById("currency-percent-" + i).innerText = percent; document.getElementById("currency-rate-" + i).innerText = app.formatValue(markets[i][app.getExchangeRateLocalStorage().toLowerCase() + 'Amount'] * markets[i].amount) + app.getExchangeRateLocalStorage(); var currencyObj = { 'marketObj': markets[i], 'title': currencys[0] + '/' + currencys[1], 'basecoin': currencys[1], 'coin': currencys[0] } liListener(document.getElementById("currency-market-" + i), markets[i].currencyPair) } } function initTopMarket() { var url = app.currencyBaseUrl + "market/getTopList"; mui.ajax(url, { type: "GET", timeout: 5000, dataType: "json", success: function(j) { if(j.code == 200) { var markets = j.data; app.setLocalStorage("market/getTopList",markets); renderTopMarket(markets); // var sliderItem = document.createElement('li'); // sliderItem.className = "gain-item-list mui-table-view-cell"; // sliderItem.innerHTML = '