diff --git a/src/components/multiple/multiple.vue b/src/components/multiple/multiple.vue index 5f7b8718..8f9e5c37 100644 --- a/src/components/multiple/multiple.vue +++ b/src/components/multiple/multiple.vue @@ -103,8 +103,17 @@ export default { this.Multipledata=MultipleData; if(this.choselist.length==0){ - - this.$store.commit('multipleData',MultipleData.slice(0,4)) + var savedIds = this.$store.state._savedChoseIds || []; + if(savedIds.length > 0){ + var restored = MultipleData.filter(function(t){ return savedIds.indexOf(t.id) !== -1; }); + if(restored.length > 0){ + this.$store.commit('multipleData', restored); + } else { + this.$store.commit('multipleData', MultipleData.slice(0,4)); + } + } else { + this.$store.commit('multipleData', MultipleData.slice(0,4)); + } } } }, diff --git a/src/main.js b/src/main.js index aef7684c..554d8513 100644 --- a/src/main.js +++ b/src/main.js @@ -8,6 +8,8 @@ import store from './store' import common from './common/js/common' import './common/css/reset.css' import './common/css/animate.css' +import { setupErrorReporting } from './plugins/error-report' +setupErrorReporting(Vue) Vue.config.productionTip = false /* eslint-disable no-new */ diff --git a/src/plugins/error-report.js b/src/plugins/error-report.js new file mode 100644 index 00000000..5f574420 --- /dev/null +++ b/src/plugins/error-report.js @@ -0,0 +1,64 @@ +var queue = [] +var sending = false + +function getReportUrl() { + var api = localStorage.getItem('ApiUrl') + if (api) { + try { api = JSON.parse(api) } catch(e) { api = '' } + } + return (api || '') + '/log/report' +} + +function send(data) { + if (queue.length >= 10) return + data.source = 'pc' + data.time = new Date().toISOString() + data.url = location.href + queue.push(data) + flush() +} + +function flush() { + if (sending || queue.length === 0) return + sending = true + var item = queue.shift() + var xhr = new XMLHttpRequest() + xhr.open('POST', getReportUrl()) + xhr.setRequestHeader('Content-Type', 'application/json') + xhr.onloadend = function() { sending = false; flush() } + xhr.onerror = function() { sending = false } + xhr.timeout = 3000 + xhr.send(JSON.stringify(item)) +} + +export function setupErrorReporting(Vue) { + Vue.config.errorHandler = function(err, vm, info) { + send({ + type: 'vue_error', + message: err.message, + stack: err.stack ? err.stack.substring(0, 2000) : '', + info: info + }) + console.error(err) + } + + window.onerror = function(message, source, lineno, colno, error) { + send({ + type: 'error', + message: String(message), + stack: error && error.stack ? error.stack.substring(0, 2000) : '', + file: source, + line: lineno, + col: colno + }) + } + + window.addEventListener('unhandledrejection', function(event) { + var reason = event.reason + send({ + type: 'unhandledrejection', + message: reason && reason.message ? reason.message : String(reason), + stack: reason && reason.stack ? reason.stack.substring(0, 2000) : '' + }) + }) +} diff --git a/src/store/index.js b/src/store/index.js index 3a7c1a8b..77f65373 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -38,6 +38,7 @@ const state = { backClearBet: false, isTablist: false, choselist: [], + _savedChoseIds: JSON.parse(localStorage.getItem("multiChoseIds") || "[]"), isaudio: true, mainPop: { type: "", @@ -88,6 +89,7 @@ const mutations = { .post(ApiUrl + "/all_table", { encryptData: secret }) .then((response) => { var data = JSON.parse(decrypt(response.data.Data)); + data.forEach(function(t) { if (t.count_down === undefined) t.count_down = 0; }); state.tabData = data; }) .catch((error) => { @@ -133,6 +135,7 @@ const mutations = { }, // 获取所有游戏台 taballData(state, data) { + data.forEach(function(t) { if (t.count_down === undefined) t.count_down = 0; }); state.tabData = data; }, // 选择筹码 @@ -174,6 +177,7 @@ const mutations = { }, multipleData(state, data) { state.choselist = data; + localStorage.setItem("multiChoseIds", JSON.stringify(data.map(function(t) { return t.id; }))); }, // 刷新视频 refresh(state) {