fix: multi-table countdown freeze + selection not persisted after refresh
1. Countdown freeze: all_table API doesn't return count_down field, Vue 2 can't track it reactively. Fixed by initializing count_down=0 on each table object when data is loaded. 2. Selection persistence: choselist was only in Vuex memory, lost on refresh. Now saves selected table IDs to localStorage and restores on next load. 3. Added error-report.js for frontend error logging.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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) : ''
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user