1.m2pool断网重连 60秒内重连机制 所有页面添加
2.优化响应错误提示 3秒内同一种错误只提示一次
This commit is contained in:
61
mining-pool/src/mixins/networkRecoveryMixin.js
Normal file
61
mining-pool/src/mixins/networkRecoveryMixin.js
Normal file
@@ -0,0 +1,61 @@
|
||||
//处理断网重连后数据刷新的混入
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 注册需要在网络恢复时调用的方法名
|
||||
recoveryMethods: [],
|
||||
// 上次调用这些方法时的参数
|
||||
methodParams: {}
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
/**
|
||||
* 注册需要在网络恢复时自动重新调用的方法
|
||||
* @param {String} methodName - 方法名
|
||||
* @param {*} params - 调用方法时需要的参数
|
||||
*/
|
||||
registerRecoveryMethod(methodName, params) {
|
||||
if (typeof this[methodName] === 'function' && !this.recoveryMethods.includes(methodName)) {
|
||||
this.recoveryMethods.push(methodName);
|
||||
this.methodParams[methodName] = params;
|
||||
console.log(`[NetworkRecovery] 注册方法: ${methodName}`);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新方法的参数
|
||||
* @param {String} methodName - 方法名
|
||||
* @param {*} params - 新的参数
|
||||
*/
|
||||
updateMethodParams(methodName, params) {
|
||||
if (this.recoveryMethods.includes(methodName)) {
|
||||
this.methodParams[methodName] = params;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 网络恢复后调用所有注册的方法
|
||||
*/
|
||||
handleNetworkRecovery() {
|
||||
console.log('[NetworkRecovery] 网络已恢复,正在刷新数据...');
|
||||
this.recoveryMethods.forEach(methodName => {
|
||||
if (typeof this[methodName] === 'function') {
|
||||
const params = this.methodParams[methodName];
|
||||
console.log(`[NetworkRecovery] 重新调用方法: ${methodName}`);
|
||||
this[methodName](params);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
// 监听网络恢复事件
|
||||
window.addEventListener('network-retry-complete', this.handleNetworkRecovery);
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
// 清理事件监听
|
||||
window.removeEventListener('network-retry-complete', this.handleNetworkRecovery);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user