From 696e6398cb8ba619a751ff8c7eaee1f772e1dec1 Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 19 Apr 2022 11:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BB=9F=E8=AE=A1=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ src/js/utools.js | 3 ++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index ce8ada5..ec77a78 100644 --- a/src/App.vue +++ b/src/App.vue @@ -53,6 +53,8 @@ export default defineComponent({ return true; }, startUp() { + // 处理旧版本数据 + this.v2DataHandler(); // 读取用户配置 let userProfile = this.utools.getDB( this.utools.DBPRE.CFG + "preferences" @@ -76,6 +78,8 @@ export default defineComponent({ this.setCssVar("primary", this.profile.primaryColor); }, enterPlugin(enter) { + // 使用情况统计 + this.usageStatistics(enter.code, this.parseDate(new Date())); this.$q.dark.set(utools.isDarkColors()); quickcommand.enterData = enter; quickcommand.payload = enter.payload; @@ -117,6 +121,66 @@ export default defineComponent({ window.runCodeFile(command.cmd, option, false, () => {}); } }, + usageStatistics(featureCode, runTime) { + let statisticsData = this.utools.getDB( + this.utools.DBPRE.CFG + "statisticsData" + ); + let thisYear = runTime.year; + if (!statisticsData[thisYear]) statisticsData[thisYear] = []; + statisticsData[thisYear].push({ + code: featureCode, + time: { + month: runTime.month, + day: runTime.day, + hour: runTime.hour, + minute: runTime.minute, + }, + }); + this.utools.putDB( + statisticsData, + this.utools.DBPRE.CFG + "statisticsData" + ); + }, + parseDate: (dateString) => { + return { + year: dateString.getFullYear(), + month: dateString.getMonth() + 1, + day: dateString.getDate(), + hour: dateString.getHours(), + minute: dateString.getMinutes(), + second: dateString.getSeconds(), + }; + }, + v2DataHandler() { + let v2DataHandled = this.utools.whole.dbStorage.getItem( + this.utools.DBPRE.STATUS + "v2DataHandled" + ); + if (v2DataHandled) return; + // 处理统计数据 + let statisticsData = this.utools.getDB( + this.utools.DBPRE.CFG + "statisticsData" + ); + _.forIn(statisticsData, (data, year) => { + statisticsData[year] = data.map((x) => { + let code = + x.command.code === "options" ? "configuration" : x.command.code; + return { + code: code, + time: x.time, + }; + }); + }); + this.utools.putDB( + statisticsData, + this.utools.DBPRE.CFG + "statisticsData" + ); + // 处理历史代码 + // ... + this.utools.whole.dbStorage.setItem( + this.utools.DBPRE.STATUS + "v2DataHandled", + true + ); + }, }, }); diff --git a/src/js/utools.js b/src/js/utools.js index a8cc88e..eda7580 100644 --- a/src/js/utools.js +++ b/src/js/utools.js @@ -10,7 +10,8 @@ let whole = window.utools const DBPRE = { QC: 'qc_', CFG: 'cfg_', - PAN: 'pan_' + PAN: 'pan_', + STATUS: 'st_' } // 数据库函数封装