diff --git a/src/apis/index.js b/src/apis/index.js new file mode 100644 index 0000000000000000000000000000000000000000..e50c1f0fd843e3b9b8607f4fda6ea87468979ffe --- /dev/null +++ b/src/apis/index.js @@ -0,0 +1,84 @@ +import Axios from "axios" +import storeSaver from "./storeSaver.js"; +import isTimeFinished from "../utils/calc.js"; + +let { ipcRenderer } = window.require('electron'); + +export async function checkToken(con) { + let res = Axios.post("/user/info") + if (res.data.type != "SUCCESS") { + await logout(); + } +} + +export async function logout() { + let res = await Axios.post("/user/logout"); + con.$store.commit("draweritems", [ + { title: '登录', to: '/login', icon: 'mdi-account-circle' }, + { title: "反馈错误", to: "/report", icon: "mdi-alert" }, + { title: "关于我们", to: "/about", icon: "mdi-help-circle" }, + ]); + 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(() => { }); + return res; +} + +export async function fetchClassList(callback) { + let res = await Axios.get("/class/list"); + return res.data.class; +} + +export async function fetchStudentList(classid, callback) { + let res = await Axios.get("/class/stulist/" + classid); + + for (stu in res.data.student) { + stu.finished = isTimeFinished(stu.id, stu.time) ? "是" : "否"; + } + callback(stus) +} + +export async function fetchClassVolunter(classid, callback) { + let url = classid ? "/class/volunteer/" + classid : "/volunteer/list/"; + let res = await Axios.get(url) + callback(res.data.volunteer); +} + +export async function fetchAllVolunter(callback) { + let res = await Axios.get("/volunteer/list") + callback(res.data.volunteer); +} + +export async function openPictures(callback) { + ipcRenderer.once("open-picture-recv", (_, data) => { + callback(data) + }) + ipcRenderer.send("open-picture") +} + +export async function openCSV(callback) { + ipcRenderer.once("open-csv-recv", (_, data) => { + callback(data) + }) + + ipcRenderer.send("open-csv") +} + +export async function fetchNotices(callback) { + callback((await Axios.get("/user/notices").catch((err) => { console.error(err) })).data); +} + +export async function sendNotice(target, title, deadtime, message, callback) => { + let res = await Axios.post("/user/sendNotice", { + target, + title, + deadtime, + message + }) + callback(res.data); +} + diff --git a/src/utils/calc.js b/src/utils/calc.js new file mode 100644 index 0000000000000000000000000000000000000000..3a187c5f0cbb36d5e80e1a98754503da680feda2 --- /dev/null +++ b/src/utils/calc.js @@ -0,0 +1,20 @@ + +export function isTimeFinished(id, time) { + // 义工时间上限;2021届以后有变动 + let vim = 24, vom = 20, vlm = 16; + if (id > 20210000) { vim = 30; vom = 16; vlm = 18; } + + let inside = stus[i].inside / 60.0; + let outside = stus[i].outside / 60.0; + let large = stus[i].large / 60.0; + let result = true; + if (outside < vom) { // 溢出判满机制:校内除二当校外 + inside = inside - (vom - outside) * 2; + outside = vom; + } + if (large < vlm || inside < vim || outside < vom || inside + outside < vim + vom) { + result = false; + } + return result; +} + diff --git a/src/utils/permissions.js b/src/utils/permissions.js index 4ddb15ad150b18b233523c4d06687d0f73ecfc6c..f92e412b3cf2202a23d0490cfed86598002f213f 100644 --- a/src/utils/permissions.js +++ b/src/utils/permissions.js @@ -1,7 +1,15 @@ -export default { +const permissionTypes = { secretary: 0, teacher: 1, admin: 2, _super: 4, system: 3 } + +const permissionNames = { + [permissionTypes.secretary]: "团支书", + [permissionTypes.teacher]: "教师", + [permissionTypes.admin]: "管理员", + [permissionTypes.system]: "系统", + [permissionTypes._super]: "超管", +} \ No newline at end of file diff --git a/src/utils/validation.js b/src/utils/validation.js index dc329eaf70201bbb516d706456aa4d725d725b4e..0b4ccbf475215976cb7a1b3040703169c46539c7 100644 --- a/src/utils/validation.js +++ b/src/utils/validation.js @@ -1 +1 @@ -export const NOTEMPTY = () => v => !!v || '此处不能为空' \ No newline at end of file +//export const NOTEMPTY = () => v => !!v || '此处不能为空' \ No newline at end of file diff --git a/src/utils/zutils.js b/src/utils/zutils.js index 8e9c8bfbf2d83f0e949a6fbb915244d998ca9d5b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/src/utils/zutils.js +++ b/src/utils/zutils.js @@ -1,126 +0,0 @@ -import Axios from "axios" -import storeSaver from "./storeSaver.js"; - -let { ipcRenderer } = window.require('electron'); - -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" }, - { title: "关于我们", to: "/about", icon: "mdi-help-circle" }, - ]); - 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(()=>{}); - }) - } - }) - }, - - fetchClassList: async (callback) => { - await Axios - .get("/class/list") - .then((response) => { - callback(response.data.class) - }) - .catch((err) => { - console.error(err) - }) - }, - - fetchStudentList: async (classid, callback) => { - await Axios - .get("/class/stulist/" + classid) - .then((response) => { - console.log(response.data) - let stus = response.data.student - if (stus) - for (var i = 0; i < stus.length; i++) { - // 义工时间上限;2021届以后有变动 - var vim=24,vom=20,vlm=16; - if(stus[i]["id"]>20210000){ vim=30;vom=16;vlm=18; } - - var inside = stus[i]["inside"]/60.0; - var outside = stus[i]["outside"]/60.0; - var large = stus[i]["large"]/60.0; - var result = true; - if (outside < vom) { // 溢出判满机制:校内除二当校外 - inside = inside - (vom - outside) * 2; - outside = vom; - } - if (large < vlm || inside < vim || outside < vom || inside + outside < vim+vom) { - result = false; - } - result ? stus[i].finished = "是" : stus[i].finished = "否" - } - callback(stus) - }) - .catch((err) => { - console.error(err) - }) - }, - - fetchClassVolunter: async (classid, callback) => { - let url = classid ? "/class/volunteer/"+classid : "/volunteer/list/"; - await Axios - .get(url).then((response) => { - console.log(response.data); - callback(response.data.volunteer); - }) - .catch((err) => { console.error(err) }) - }, - - fetchAllVolunter: async (callback) => { - await Axios - .get("/volunteer/list").then((response) => { - console.log(response.data); - callback(response.data.volunteer); - }) - .catch((err) => { console.error(err) }) - }, - - openPictures: (callback) => { - ipcRenderer.once("open-picture-recv", (_, data) => { - callback(data) - }) - - ipcRenderer.send("open-picture") - }, - - openCSV: (callback) => { - ipcRenderer.once("open-csv-recv", (_, data) => { - callback(data) - }) - - ipcRenderer.send("open-csv") - }, - - fetchNotices: async (callback) => { - callback((await Axios.get("/user/notices").catch((err) => { console.error(err) })).data); - }, - - sendNotice: async (target, title, deadtime, message, callback) => { - callback(( - await Axios - .post("/user/sendNotice", { - target, - title, - deadtime, - message - }) - .catch((err) => { - console.log(err); - }) - ).data); - } -}