|
@@ -24,35 +24,16 @@ import { defineComponent } from 'vue';
|
|
import CommonService from './../../services/common.service';
|
|
import CommonService from './../../services/common.service';
|
|
const commonService: CommonService = CommonService.getInstance();
|
|
const commonService: CommonService = CommonService.getInstance();
|
|
|
|
|
|
-const logsDatas: ConsoleLogVo[] = [];
|
|
|
|
-let timer: any = null;
|
|
|
|
-
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: 'SgcConsole',
|
|
name: 'SgcConsole',
|
|
components: {
|
|
components: {
|
|
IonIcon,
|
|
IonIcon,
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- window.setTimeout(() => {
|
|
|
|
- commonService.setLogger(this);
|
|
|
|
- timer = window.setInterval(() => {
|
|
|
|
- if (logsDatas.length > 0) {
|
|
|
|
- let log = logsDatas.shift();
|
|
|
|
- while (log) {
|
|
|
|
- this.dataList.push(log);
|
|
|
|
- log = logsDatas.shift();
|
|
|
|
- }
|
|
|
|
- logsDatas.length = 0;
|
|
|
|
- if (this.dataList.length > 30) {
|
|
|
|
- this.dataList.shift();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }, 500);
|
|
|
|
- }, 1000);
|
|
|
|
|
|
+ commonService.setLogger(this);
|
|
},
|
|
},
|
|
unmounted() {
|
|
unmounted() {
|
|
commonService.setLogger(null);
|
|
commonService.setLogger(null);
|
|
- window.clearInterval(timer);
|
|
|
|
},
|
|
},
|
|
setup() {
|
|
setup() {
|
|
return {
|
|
return {
|
|
@@ -70,8 +51,55 @@ export default defineComponent({
|
|
commonService.openToast('MSG_SERVER_ERROR');
|
|
commonService.openToast('MSG_SERVER_ERROR');
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- consoleLog(type: ConsoleLogType, title: string, ...obj: any[]) {
|
|
|
|
- logsDatas.push({ type: type, title: title, datas: obj, showDetail: false });
|
|
|
|
|
|
+ _getLogObject(obj: any) {
|
|
|
|
+ switch (typeof obj) {
|
|
|
|
+ case 'number':
|
|
|
|
+ case 'string':
|
|
|
|
+ case 'boolean':
|
|
|
|
+ return obj;
|
|
|
|
+ case 'object':
|
|
|
|
+ if (Array.isArray(obj)) {
|
|
|
|
+ return 'Array[' + obj.length + ']';
|
|
|
|
+ } else if (obj.toString) {
|
|
|
|
+ return obj.toString();
|
|
|
|
+ } else {
|
|
|
|
+ return 'object';
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ return 'unknown';
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ consoleLog(type: ConsoleLogType, title: string, ...objs: any[]) {
|
|
|
|
+ const datas: any[] = [];
|
|
|
|
+ if (objs !== null && objs !== undefined && objs.length > 0) {
|
|
|
|
+ objs.forEach(obj => {
|
|
|
|
+ switch (typeof obj) {
|
|
|
|
+ case 'number':
|
|
|
|
+ case 'string':
|
|
|
|
+ case 'boolean':
|
|
|
|
+ datas.push(obj);
|
|
|
|
+ break;
|
|
|
|
+ case 'object':
|
|
|
|
+ if (Array.isArray(obj)) {
|
|
|
|
+ const arrayItem: any[] = [];
|
|
|
|
+ obj.forEach(item => {
|
|
|
|
+ arrayItem.push(this._getLogObject(item));
|
|
|
|
+ });
|
|
|
|
+ datas.push(arrayItem);
|
|
|
|
+ } else {
|
|
|
|
+ datas.push(this._getLogObject(obj));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ datas.push(typeof obj);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ this.dataList.push({ type: type, title: title, datas: datas, showDetail: false });
|
|
|
|
+ if (this.dataList.length > 30) {
|
|
|
|
+ this.dataList.shift();
|
|
|
|
+ }
|
|
},
|
|
},
|
|
toggleLog(log: ConsoleLogVo) {
|
|
toggleLog(log: ConsoleLogVo) {
|
|
log.showDetail = !log.showDetail;
|
|
log.showDetail = !log.showDetail;
|