This commit is contained in:
kuaifan 2022-05-22 10:02:55 +08:00
parent 7033f00a0e
commit b469069e92
7 changed files with 97 additions and 23 deletions

10
public/js/vconsole.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,7 @@ export default {
},
computed: {
...mapState(['userId', 'userToken']),
...mapState(['ws', 'userId', 'userToken']),
},
watch: {
@ -83,16 +83,36 @@ export default {
handler() {
this.$store.dispatch("websocketConnection");
//
if (this.$isEEUiApp && this.userId > 0) {
setTimeout(_ => {
const webview = requireModuleJs("webview");
webview && webview.sendMessage({
action: 'setUmengAlias',
userid: this.userId,
token: this.userToken,
url: $A.apiUrl('users/umeng/alias')
if (this.userId > 0) {
if (this.$isEEUiApp) {
setTimeout(_ => {
const webview = requireModuleJs("webview");
webview && webview.sendMessage({
action: 'setUmengAlias',
userid: this.userId,
token: this.userToken,
url: $A.apiUrl('users/umeng/alias')
});
}, 6000)
}
//
if (this.openVlog) {
$A.loadScript('js/vconsole.min.js', (e) => {
if (e !== null || typeof window.VConsole !== 'function') {
$A.modalAlert("vConsole 组件加载失败!");
return;
}
window.vConsole = new window.VConsole({
onReady: () => {
console.log('vConsole: onReady');
},
onClearLog: () => {
console.log('vConsole: onClearLog');
}
});
console.info('vConsole: Welcome');
});
}, 6000)
}
}
},
immediate: true
@ -229,12 +249,22 @@ export default {
}
//
window.__onPagePause = () => {
if (this.openVlog) {
console.log('onPagePause');
}
}
//
window.__onPageResume = (num) => {
if (this.openVlog) {
console.log('onPageResume', num);
console.log('ws', this.ws);
console.log('ws.readyState', this.ws ? this.ws.readyState : null);
}
if (num > 0) {
this.$store.state.ws === null && this.$store.dispatch("websocketConnection");
if (this.ws === null || this.ws.readyState === WebSocket.CLOSED) {
this.$store.dispatch("websocketConnection");
}
this.$store.dispatch("getBasicData", 5000)
}
}
}

View File

@ -110,6 +110,7 @@ Vue.prototype.$isMainElectron = false;
Vue.prototype.$isSubElectron = false;
Vue.prototype.$isEEUiApp = isEEUiApp;
Vue.prototype.$isDesktop = $A.isDesktop();
Vue.prototype.$openVlog = $A.getStorageString("vlog::open") === "open";
if (isElectron) {
Vue.prototype.$Electron = electron;
Vue.prototype.$Platform = /macintosh|mac os x/i.test(navigator.userAgent) ? "mac" : "win";
@ -143,6 +144,7 @@ $A.isMainElectron = app.$isMainElectron;
$A.isSubElectron = app.$isSubElectron;
$A.isEEUiApp = app.$isEEUiApp;
$A.isDesktop = app.$isDesktop;
$A.openVlog = app.$openVlog;
$A.execMainDispatch = (action, data) => {
if ($A.isSubElectron) {
$A.Electron.sendMessage('sendForwardMain', {

View File

@ -679,11 +679,7 @@ export default {
wsOpenNum(num) {
if (num <= 1) return
this.wsOpenTimeout && clearTimeout(this.wsOpenTimeout)
this.wsOpenTimeout = setTimeout(() => {
this.$store.dispatch("getBasicData")
this.getReportUnread()
}, 5000)
this.$store.dispatch("getBasicData", 5000).then(this.getReportUnread)
},
workReportShow(show) {

View File

@ -258,6 +258,20 @@ export default {
},
watch: {
dialogKey(val) {
switch (val) {
case 'vlog.open':
case 'vlog:open':
$A.setStorage("vlog::open", "open");
$A.reloadUrl();
break;
case 'vlog.close':
case 'vlog:close':
$A.setStorage("vlog::open", "close");
$A.reloadUrl();
break;
}
},
contactsKey(val) {
setTimeout(() => {
if (this.contactsKey == val) {

View File

@ -252,8 +252,19 @@ export default {
/**
* 获取基本数据项目对话仪表盘任务
* @param dispatch
* @param timeout
* @returns {Promise<unknown>}
*/
getBasicData({dispatch}) {
getBasicData({dispatch}, timeout) {
if (typeof timeout === "number") {
return new Promise(resolve => {
window.__getBasicData && clearTimeout(window.__getBasicData)
window.__getBasicData = setTimeout(() => {
dispatch("getBasicData", null)
resolve()
}, timeout)
});
}
dispatch("getProjects").catch(() => {});
dispatch("getDialogs").catch(() => {});
dispatch("getTaskForDashboard");
@ -2214,16 +2225,17 @@ export default {
url = url.replace("http://", "ws://");
url += "?action=web&token=" + state.userToken;
//
const wgLog = $A.openVlog;
const wsRandom = $A.randomString(16);
state.wsRandom = wsRandom;
//
state.ws = new WebSocket(url);
state.ws.onopen = (e) => {
// console.log("[WS] Open", $A.formatDate())
wgLog && console.log("[WS] Open", e, $A.formatDate())
state.wsOpenNum++;
};
state.ws.onclose = (e) => {
// console.log("[WS] Close", $A.formatDate())
wgLog && console.log("[WS] Close", e, $A.formatDate())
state.ws = null;
//
clearTimeout(state.wsTimeout);
@ -2232,7 +2244,7 @@ export default {
}, 3000);
};
state.ws.onerror = (e) => {
// console.log("[WS] Error", $A.formatDate())
wgLog && console.log("[WS] Error", e, $A.formatDate())
state.ws = null;
//
clearTimeout(state.wsTimeout);
@ -2241,7 +2253,7 @@ export default {
}, 3000);
};
state.ws.onmessage = (e) => {
// console.log("[WS] Message", e);
wgLog && console.log("[WS] Message", e);
const msgDetail = $A.formatWebsocketMessageDetail($A.jsonParse(e.data));
const {type, msgId} = msgDetail;
switch (type) {
@ -2266,7 +2278,7 @@ export default {
try {
call(msgDetail);
} catch (err) {
// console.log("[WS] Callerr", err);
wgLog && console.log("[WS] Callerr", err);
}
}
});

File diff suppressed because one or more lines are too long