diff --git a/config.json b/config.json new file mode 100644 index 0000000000000000000000000000000000000000..7271b732352774d56da211b981badc41e0f22d11 --- /dev/null +++ b/config.json @@ -0,0 +1 @@ +{"isLogined":true,"isLoading":false,"token":"eyJhbGciOiJIUzUxMiIsImlhdCI6MTYzNzgzMzY3OCwiZXhwIjoxNjczODMzNjc4fQ.eyJ1c2VyaWQiOiIyMDIwMDciLCJ1c2VybmFtZSI6IumrmOS6jDfnj60iLCJjbGFzcyI6MjAyMDA3LCJwZXJtaXNzaW9uIjoxfQ.YbU09lVwnBTgTWazoHUc274MXxUm2v1wYeylmlsniDEdMic288ktmePTSHh7h22qaesFaJHKkmvXn5qblqRfeg","info":{"username":"高二7班","permission":1,"class":202007,"classname":"高二7班"},"lastSeenVol":[{"id":1,"name":"测试义工","date":"2021-11-14","time":"12:00","description":"测试义工,大家可以随意报名并提交感想。(还有,近日的义工统计请不要使用“假期义工”)","status":0,"stuMax":1000}],"draweritems":[{"title":"我的","to":"/me","icon":"mdi-account-circle"},{"title":"修改密码","to":"/modifyPwd","icon":"mdi-account-circle"},{"title":"学生列表","to":"/class/stulist/202007","icon":"mdi-view-list"},{"title":"义工列表","to":"/volunteer/list","icon":"mdi-view-list"},{"title":"假期义工","to":"/volunteer/holiday","icon":"mdi-view-list"},{"title":"感想提交","to":"/volunteer/thought","icon":"mdi-view-list"},{"title":"登出","to":"/logout","icon":"mdi-exit-to-app"},{"title":"反馈错误","to":"/report","icon":"mdi-alert"}]} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index cf12e1890c81923dfca05f5a2d5bbf65992fc921..a38ae175e61fda0766e5ad28555f3f08a8729421 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "zvms-electron", - "version": "1.2.1.20211113", + "version": "1.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 17ac88bf0e89e5340724f7fb5a1d4bf5c98d2148..b272a8699621a0492595d0f10ad5f779db589a57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zvms-electron", - "version": "1.2.1.20211113", + "version": "1.2.3", "private": true, "scripts": { "serve": "vue-cli-service serve", diff --git a/src/App.vue b/src/App.vue index f566bf20d910cba909abae7e270348018c423ddc..4733608654608cc5e2ab1c9d9464d2c95c487dae 100644 --- a/src/App.vue +++ b/src/App.vue @@ -125,6 +125,7 @@ import zutils from "./utils/zutils.js" import dialogs from "./utils/dialogs.js"; import permissions from "./utils/permissions.js"; +import storeSaver from "./utils/storeSaver.js"; let { ipcRenderer } = window.require('electron') export default { @@ -136,9 +137,12 @@ export default { currentVol: undefined }), mounted: async function () { + // storeSaver.loadState(this); + // this.$router.push("/me"); + // await zutils.checkToken(this); await zutils.fetchAllVolunter((volworks) => { this.vol = volworks; }); - setInterval(this.listen, 300000, this); - console.log("mounted"); + setInterval(this.listen, 60000, this); + // console.log("mounted"); }, methods: { granted: function () { @@ -174,16 +178,21 @@ export default { }, async listen(t) { console.log("listen"); - if (!t.$store.isLogined){ + if (!t.$store.state.isLogined){ + console.log(t.$store.state); + console.error("!login"); ipcRenderer.send('flash'); return; } + storeSaver.saveState(this); zutils.checkToken(t); - await zutils.fetchVol(); + t.fetchVol(); let flag = false; - let last = t.$store.lastSeenVol; + let last = t.$store.state.lastSeenVol; let vol = t.currentVol; - if (last && vol) { + // console.log(last,vol); + if (last!=null && last!=undefined && vol!=null && vol!=undefined) { + // console.log(last,vol); if (vol.length != last.length) flag = true; else { for (var i = 0; i < vol.length; i++) diff --git a/src/background.js b/src/background.js index 3e6d9afac767880b493d2b9be9af09fdf4fcf422..37e422ecd60b7c67044cc02a3db2e3b2daa5d8a5 100644 --- a/src/background.js +++ b/src/background.js @@ -10,6 +10,7 @@ const isDevelopment = process.env.NODE_ENV !== 'production' const electron = require('electron') const Menu = electron.Menu const Tray = electron.Tray +const fs = require('fs') // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. @@ -121,6 +122,16 @@ function createWindow() { timericon = undefined; tray.setImage(path.join(__static,'logo.ico')); }) + ipcMain.on('file-read-req', (event, arg) => { + fs.readFile(arg, 'utf-8', (err, data) => { + event.sender.send('file-read-complete', {"err": err, "data": data}) + }) + }) + ipcMain.on('file-write-req', (event, arg) => { + fs.writeFile(arg.path, arg.data, (err) => { + event.sender.send('file-write-complete', {"err": err}) + }) + }) } // Quit when all windows are closed. diff --git a/src/components/signerlist.vue b/src/components/signerlist.vue index f4d2bdf0d68a01834320d8444c4a2468578237e3..0a8fbd7e1de56c6ac460976818e86a8dcd330d8b 100644 --- a/src/components/signerlist.vue +++ b/src/components/signerlist.vue @@ -75,9 +75,12 @@ export default { methods: { timeToHint: function (a){ let hr = parseInt(a / 60); - let mi = a % 60; + let mi = parseInt(a % 60); if (hr != 0) - return hr + " 小时 " + mi + " 分钟"; + if (mi != 0) + return hr + " 小时 " + mi + " 分钟"; + else + return hr + " 小时 "; else return mi + "分钟"; }, diff --git a/src/components/stuvolist.vue b/src/components/stuvolist.vue index c719953b36bd5a3462301200930432721b083a4f..998f460629883d9a95bbaf9f33b115d4a3f35594 100644 --- a/src/components/stuvolist.vue +++ b/src/components/stuvolist.vue @@ -68,9 +68,12 @@ export default { methods: { timeToHint: function (a){ let hr = parseInt(a / 60); - let mi = a % 60; + let mi = parseInt(a % 60); if (hr != 0) - return hr + " 小时 " + mi + " 分钟"; + if (mi != 0) + return hr + " 小时 " + mi + " 分钟"; + else + return hr + " 小时 "; else return mi + "分钟"; }, diff --git a/src/components/volinfo.vue b/src/components/volinfo.vue index 0d86fb76510d238f87a001ae690488c99cc22bd0..3577403a7ca6dbbc39df2d80e3e09bc97b3c830a 100644 --- a/src/components/volinfo.vue +++ b/src/components/volinfo.vue @@ -73,14 +73,17 @@ export default { this.init(); }, methods: { - timeToHint: function (a){ - let hr = parseInt(a / 60); - let mi = a % 60; - if (hr != 0) - return hr + " 小时 " + mi + " 分钟"; - else - return mi + "分钟"; - }, + timeToHint: function (a){ + let hr = parseInt(a / 60); + let mi = parseInt(a % 60); + if (hr != 0) + if (mi != 0) + return hr + " 小时 " + mi + " 分钟"; + else + return hr + " 小时 "; + else + return mi + "分钟"; + }, init: function () { if (this.volid != 0 && this.volid != undefined) { this.$store.commit("loading", true); diff --git a/src/main.js b/src/main.js index 9a041b3fe5c9e65a53600f3b252382e068fd49d3..866f56a778c0c81738c7b6e3e91967dfa559a8a1 100644 --- a/src/main.js +++ b/src/main.js @@ -37,6 +37,10 @@ router.beforeEach((to, from, next) => { NProgress.start(); if (to.path == '/report') next(); else if (to.path != '/login') { + console.log(233); + console.log(to,from,next); + console.log(store.state.token); + console.log(233); if (store.state.token) { next(); } else { diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index 5aea99aef182769128bc5280415d3384f303f2b2..86abc41536547f46dbff398a05e8f0fab185cb6f 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -14,7 +14,7 @@ const opts = { }, theme: { themes: { - "light": { "primary": "#F48FB1" }, + "light": { "primary": "#92BAEE" }, "dark": { "primary": "#424242" } }, }, diff --git a/src/utils/store.js b/src/utils/store.js index 8799ff5357142f3cae5632ef65feae845b4fecbc..d0489e5fe2b007718b412653cbd2c36dac3958e7 100644 --- a/src/utils/store.js +++ b/src/utils/store.js @@ -39,6 +39,9 @@ export default new Vuex.Store({ }, token: (state, payload) => { state.token = payload + }, + lastSeenVol: (state, payload) => { + state.lastSeenVol = payload } }, plugins: [createPersistedState()] diff --git a/src/utils/storeSaver.js b/src/utils/storeSaver.js new file mode 100644 index 0000000000000000000000000000000000000000..aff1bd9b1045f5e506f342cffc3fc84116367508 --- /dev/null +++ b/src/utils/storeSaver.js @@ -0,0 +1,38 @@ +const configPath = "./config.json"; + +let { ipcRenderer } = window.require('electron'); + +export default { + saveState: async (con) => { + // console.log("SADFdsjfhsdjsdhjfdshjfdshfjhd"); + ipcRenderer.once('file-write-complete', (event, arg) => { + // console.log(arg); + if (arg.err){ + console.error(arg.err); + return undefined; + } + }) + ipcRenderer.send('file-write-req', { + "path": configPath, + "data": JSON.stringify(con.$store.state) + }); + }, + loadState: async (con, f) => { + ipcRenderer.once('file-read-complete', (event, arg) => { + // console.log(arg); + if (arg.err){ + console.error(arg.err); + return undefined; + } + con.$store.commit("token", JSON.parse(arg.data).token); + con.$store.commit("info", JSON.parse(arg.data).info); + con.$store.commit("login", JSON.parse(arg.data).isLogined); + con.$store.commit("draweritems", JSON.parse(arg.data).draweritems); + con.$store.commit("lastSeenVol", JSON.parse(arg.data).lastSeenVol); + f(con); + // console.log(con.$store); + // console.log(arg.data); + }) + ipcRenderer.send('file-read-req', configPath); + } +} \ No newline at end of file diff --git a/src/utils/zutils.js b/src/utils/zutils.js index 9050465322ffbf324b3a216d0c3e934ee0243bd3..26f154f923d0691d91b0d5177d21103297c21d67 100644 --- a/src/utils/zutils.js +++ b/src/utils/zutils.js @@ -1,4 +1,5 @@ import Axios from "axios" +import storeSaver from "./storeSaver.js"; let { ipcRenderer } = window.require('electron'); @@ -6,15 +7,19 @@ export default { checkToken: async (con) => { await Axios .post("/user/info").then((msg) => { + console.log(con.$store); if (msg["data"]["type"] != "SUCCESS") { Axios.post("/user/logout").finally(() => { con.$store.commit("draweritems", [ { title: '登录', to: '/login', icon: 'mdi-account-circle' }, { title: "反馈错误", to: "/report", icon: "mdi-alert" } ]); - con.$store.state.token = undefined; ipcRenderer.send('flash'); + con.$store.commit("token",undefined); + con.$store.commit("login", false); con.$store.commit("loading", false); + con.$store.commit("lastSeenVol", []); + storeSaver.saveState(con); con.$router.push("/login").catch(()=>{}); }) } diff --git a/src/views/class/stulist.vue b/src/views/class/stulist.vue index c8dfdfaeb59c5b7e0e5cdd3a142257519a66a866..9c39ddbfc8cbcad9bbea9a6ae6ae61553bd50e06 100644 --- a/src/views/class/stulist.vue +++ b/src/views/class/stulist.vue @@ -97,9 +97,12 @@ export default { methods: { timeToHint: function (a){ let hr = parseInt(a / 60); - let mi = a % 60; + let mi = parseInt(a % 60); if (hr != 0) - return hr + " 小时 " + mi + " 分钟"; + if (mi != 0) + return hr + " 小时 " + mi + " 分钟"; + else + return hr + " 小时 "; else return mi + "分钟"; }, diff --git a/src/views/login.vue b/src/views/login.vue index 918760b5eb7af85298c10ea5ca78464b921de7ac..115f8230dd5fcf20f0610067a508b67ee508ca43 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -44,15 +44,17 @@