From 880e4f8941b15f67597522eb60f5655b1f900bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Tue, 28 Mar 2023 14:01:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E7=99=BB=E9=99=86=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/epp.sql | 50 ++-- frontend/auto-imports.d.ts | 2 +- frontend/package-lock.json | 58 ++++- frontend/package.json | 1 + frontend/src/api/user.js | 17 ++ frontend/src/components/header.vue | 240 ++++++++++---------- frontend/src/main.ts | 6 +- frontend/src/router/index.ts | 14 +- frontend/src/store/permiss.ts | 68 ++++-- frontend/src/utils/send_request.js | 119 +++++----- frontend/src/utils/settings.js | 6 +- frontend/src/views/login.vue | 289 +++++++++++------------- weixin-miniprogram/pages/index/login.js | 14 +- 13 files changed, 498 insertions(+), 386 deletions(-) create mode 100644 frontend/src/api/user.js diff --git a/database/epp.sql b/database/epp.sql index 089fc51..8d4d63d 100644 --- a/database/epp.sql +++ b/database/epp.sql @@ -11,7 +11,7 @@ Target Server Version : 80012 File Encoding : 65001 - Date: 22/03/2023 16:41:32 + Date: 28/03/2023 13:51:00 */ SET NAMES utf8mb4; @@ -49,10 +49,10 @@ INSERT INTO `apply1` VALUES (11, 2, '1', '飞机', '1', '2022-10-23 16:17:00', ' INSERT INTO `apply1` VALUES (12, 13, '1', '飞机', '1', '2022-10-26 19:25:00', '2022-10-26 21:25:00', 1, ''); -- ---------------------------- --- Table structure for community_gate +-- Table structure for community_gate1 -- ---------------------------- -DROP TABLE IF EXISTS `community_gate`; -CREATE TABLE `community_gate` ( +DROP TABLE IF EXISTS `community_gate1`; +CREATE TABLE `community_gate1` ( `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '雪花id', `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '大门显示名称', `open` tinyint(1) NOT NULL DEFAULT 1 COMMENT '大门是否开放 1为开放 2为关闭', @@ -60,7 +60,7 @@ CREATE TABLE `community_gate` ( ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '社区大门' ROW_FORMAT = DYNAMIC; -- ---------------------------- --- Records of community_gate +-- Records of community_gate1 -- ---------------------------- -- ---------------------------- @@ -281,10 +281,13 @@ CREATE TABLE `order` ( -- ---------------------------- -- Records of order -- ---------------------------- -INSERT INTO `order` VALUES (1748800678865801225, 1, '2023-03-21 15:50:19', 'Pending', 21.99, NULL); -INSERT INTO `order` VALUES (1749495597129404427, 1, '2023-03-21 16:30:54', 'Pending', 5.99, NULL); -INSERT INTO `order` VALUES (1749495896040673288, 1, '2023-03-21 16:32:06', 'Pending', 5.99, NULL); -INSERT INTO `order` VALUES (1749496012575215624, 1, '2023-03-21 16:32:33', 'Pending', 17.97, NULL); +INSERT INTO `order` VALUES (1748800678865801225, 3, '2023-03-21 15:50:19', 'Pending', 21.99, NULL); +INSERT INTO `order` VALUES (1749495597129404427, 3, '2023-03-21 16:30:54', 'Pending', 5.99, NULL); +INSERT INTO `order` VALUES (1749495896040673288, 3, '2023-03-21 16:32:06', 'Pending', 5.99, NULL); +INSERT INTO `order` VALUES (1749496012575215624, 3, '2023-03-21 16:32:33', 'Pending', 17.97, NULL); +INSERT INTO `order` VALUES (1750312359831932932, 3, '2023-03-23 22:36:26', 'Cancelled', 87.50, NULL); +INSERT INTO `order` VALUES (1750312445567700999, 3, '2023-03-23 22:36:46', 'Processing', 87.50, NULL); +INSERT INTO `order` VALUES (1750313361633054722, 3, '2023-03-23 22:40:25', 'Processing', 2.50, NULL); -- ---------------------------- -- Table structure for order_detail @@ -301,7 +304,7 @@ CREATE TABLE `order_detail` ( INDEX `good_id`(`good_id`) USING BTREE, CONSTRAINT `order_detail_ibfk_1` FOREIGN KEY (`good_id`) REFERENCES `goods` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT `order_detail_ibfk_2` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE = InnoDB AUTO_INCREMENT = 43 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 46 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of order_detail @@ -316,6 +319,9 @@ INSERT INTO `order_detail` VALUES (39, 1748800678865801225, 19, 1, 21.99); INSERT INTO `order_detail` VALUES (40, 1749495597129404427, 16, 1, 5.99); INSERT INTO `order_detail` VALUES (41, 1749495896040673288, 16, 1, 5.99); INSERT INTO `order_detail` VALUES (42, 1749496012575215624, 16, 3, 5.99); +INSERT INTO `order_detail` VALUES (43, 1750312359831932932, 55, 25, 3.50); +INSERT INTO `order_detail` VALUES (44, 1750312445567700999, 55, 25, 3.50); +INSERT INTO `order_detail` VALUES (45, 1750313361633054722, 56, 1, 2.50); -- ---------------------------- -- Table structure for report @@ -329,17 +335,18 @@ CREATE TABLE `report` ( `temperature` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '体温是否正常', `address` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '地址', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 61 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 62 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of report -- ---------------------------- -INSERT INTO `report` VALUES (53, 1, '管理员 密码root', '2022-12-26 20:35:38', '1', '湖北省武汉市洪山区文治街南湖雅园(洪山区信访局对面)'); -INSERT INTO `report` VALUES (55, 1, '管理员 密码root', '2022-12-27 21:03:24', '0', '湖北省武汉市洪山区文治街508号南湖雅园F栋2-104号'); -INSERT INTO `report` VALUES (57, 1, '管理员 密码root', '2022-12-28 21:47:57', '0', '湖北省武汉市洪山区文治街南湖雅园(洪山区信访局对面)'); -INSERT INTO `report` VALUES (58, 1, '管理员 密码root', '2022-12-29 18:20:00', '1', '湖北省武汉市洪山区鲁磨路209号'); -INSERT INTO `report` VALUES (59, 1, '管理员 密码root', '2023-03-17 00:27:21', '0', '湖北省武汉市洪山区雄楚大道珞狮南路南湖雅园F-4-106'); -INSERT INTO `report` VALUES (60, 1, '管理员 密码root', '2023-03-20 00:47:22', '0', '湖北省武汉市武昌区武车路'); +INSERT INTO `report` VALUES (53, 3, '用户 密码user', '2022-12-26 20:35:38', '1', '湖北省武汉市洪山区文治街南湖雅园(洪山区信访局对面)'); +INSERT INTO `report` VALUES (55, 3, '用户 密码user', '2022-12-27 21:03:24', '0', '湖北省武汉市洪山区文治街508号南湖雅园F栋2-104号'); +INSERT INTO `report` VALUES (57, 3, '用户 密码user', '2022-12-28 21:47:57', '0', '湖北省武汉市洪山区文治街南湖雅园(洪山区信访局对面)'); +INSERT INTO `report` VALUES (58, 3, '用户 密码user', '2022-12-29 18:20:00', '1', '湖北省武汉市洪山区鲁磨路209号'); +INSERT INTO `report` VALUES (59, 3, '用户 密码user', '2023-03-17 00:27:21', '0', '湖北省武汉市洪山区雄楚大道珞狮南路南湖雅园F-4-106'); +INSERT INTO `report` VALUES (60, 3, '用户 密码user', '2023-03-20 00:47:22', '0', '湖北省武汉市武昌区武车路'); +INSERT INTO `report` VALUES (61, 3, '用户 密码user', '2023-03-23 22:24:14', '0', '湖北省武汉市武昌区修远路'); -- ---------------------------- -- Table structure for setting @@ -355,7 +362,7 @@ CREATE TABLE `setting` ( -- ---------------------------- -- Records of setting -- ---------------------------- -INSERT INTO `setting` VALUES ('wechat_access_token', '66_k4e3ae12hwRMq2XLW5mW5rOBsLawIcKPsFjNC4ILQS6rYJi4RJN8tYXtwCJLxqimgAHrZ-MV0LqsFn7u_9OVjEOj7b-d3V4tirO3mxLTj59U87V5WhV0XNp1fFULMRhAJASTY', '2023-03-21 00:34:18'); +INSERT INTO `setting` VALUES ('wechat_access_token', '66_qSxbHTU4lcXa4l8JgZisZm_2gXUmQH_vVSybGHP229Nv9QeacmXuYeQxpZQ-JNnLWI-HpJ9Zlf18B4Lnif5fR1EvGukoLFZmGWADlcobLsY-JlKZX7lXRzk6tAoRWTiACAZEB', '2023-03-24 00:26:42'); -- ---------------------------- -- Table structure for user @@ -368,19 +375,20 @@ CREATE TABLE `user` ( `realname` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '真实姓名', `id_number` varchar(18) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '身份证号', `phone_number` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '手机号', - `role` int(11) NOT NULL COMMENT '角色 (0-超级管理员 1-工作人员 2-社区居民_房主 3-社区居民_家庭成员 4-社区居民_租客 5-访客)', + `role` int(11) NOT NULL COMMENT '角色 (1-超级管理员 2-工作人员 3-社区居民_房主 4-社区居民_家庭成员 5-社区居民_租客 6-访客)', `building_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '门栋号+单元号', `doorplate` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '门牌号', `permission` int(11) NOT NULL DEFAULT 0 COMMENT '进出权限 (0-无 1-继承(普通居民) 2-永久 3-限时)', `permission_time` datetime NULL DEFAULT NULL COMMENT '进出权限失效时间', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 22 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO `user` VALUES (1, 'root', '99adc231b045331e514a516b4b7680f588e3823213abe901738bc3ad67b2f6fcb3c64efb93d18002588d3ccc1a49efbae1ce20cb43df36b38651f11fa75678e8', '管理员 密码root', '420111111111111111', NULL, 1, NULL, NULL, 0, NULL); -INSERT INTO `user` VALUES (2, 'user', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户 密码user', '420111111111111111', NULL, 2, NULL, NULL, 0, NULL); +INSERT INTO `user` VALUES (2, 'admin', 'c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec', '社区管理员 密码admin', '420111111111111111', NULL, 2, NULL, NULL, 0, NULL); +INSERT INTO `user` VALUES (3, 'user', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户 密码user', '420111111111111111', NULL, 3, NULL, NULL, 0, NULL); -- ---------------------------- -- Table structure for visitor1 diff --git a/frontend/auto-imports.d.ts b/frontend/auto-imports.d.ts index 8139ac9..08908ed 100644 --- a/frontend/auto-imports.d.ts +++ b/frontend/auto-imports.d.ts @@ -1,5 +1,5 @@ // Generated by 'unplugin-auto-import' export {} declare global { - const ElMessage: typeof import('element-plus/es')['ElMessage'] + } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f5d7f8c..d844119 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -14,6 +14,7 @@ "element-plus": "^2.2.14", "md-editor-v3": "^2.2.1", "pinia": "^2.0.20", + "qs": "^6.11.1", "vue": "^3.2.37", "vue-cropperjs": "^5.0.0", "vue-router": "^4.1.3", @@ -709,6 +710,15 @@ "node": ">=8" } }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, "node_modules/cesium": { "version": "1.102.0", "resolved": "https://registry.npmmirror.com/cesium/-/cesium-1.102.0.tgz", @@ -1427,8 +1437,17 @@ "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "node_modules/get-intrinsic": { + "version": "1.2.0", + "resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.2.0.tgz", + "integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==", + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + } }, "node_modules/glob-parent": { "version": "5.1.2", @@ -1459,7 +1478,6 @@ "version": "1.0.3", "resolved": "https://registry.npmmirror.com/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, "dependencies": { "function-bind": "^1.1.1" }, @@ -1467,6 +1485,14 @@ "node": ">= 0.4.0" } }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmmirror.com/http-errors/-/http-errors-2.0.0.tgz", @@ -1784,6 +1810,11 @@ "dev": true, "peer": true }, + "node_modules/object-inspect": { + "version": "1.12.3", + "resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==" + }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmmirror.com/on-finished/-/on-finished-2.4.1.tgz", @@ -1931,6 +1962,17 @@ "node": ">=12.0.0" } }, + "node_modules/qs": { + "version": "6.11.1", + "resolved": "https://registry.npmmirror.com/qs/-/qs-6.11.1.tgz", + "integrity": "sha512-0wsrzgTz/kAVIeuxSjnpGC56rzYtr6JT/2BwEvMaPhFIoYa1aGO8LbzuU1R0uUYQkLpWBTOj0l/CLAJB64J6nQ==", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -2133,6 +2175,16 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "dev": true }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmmirror.com/source-map/-/source-map-0.6.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 34ad67c..18010ce 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,6 +14,7 @@ "element-plus": "^2.2.14", "md-editor-v3": "^2.2.1", "pinia": "^2.0.20", + "qs": "^6.11.1", "vue": "^3.2.37", "vue-cropperjs": "^5.0.0", "vue-router": "^4.1.3", diff --git a/frontend/src/api/user.js b/frontend/src/api/user.js new file mode 100644 index 0000000..fcdd613 --- /dev/null +++ b/frontend/src/api/user.js @@ -0,0 +1,17 @@ +import send_request from '../utils/send_request'; + +/** + * 用户登录 + * @returns + */ +export function userLogin({ username, password }) { + return send_request({ + url: '/user/login', + method: 'POST', + useQS: true, + params: { + "username": username, + "password": password, + } + }); +}; diff --git a/frontend/src/components/header.vue b/frontend/src/components/header.vue index a3474a9..5cd228e 100644 --- a/frontend/src/components/header.vue +++ b/frontend/src/components/header.vue @@ -1,47 +1,47 @@ diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 43ae5c7..79a66ff 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -15,11 +15,13 @@ app.use(router); for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component); } + // 自定义权限指令 const permiss = usePermissStore(); -app.directive('permiss', { +app.directive('permiss', { // 元素级权限控制 mounted(el, binding) { - if (!permiss.key.includes(String(binding.value))) { + const role = localStorage.getItem('ms_role_id'); + if (!permiss[role as string] || !permiss[role as string].includes(binding.value as string)) { el['hidden'] = true; } }, diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 951d38a..8bc74b6 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -198,18 +198,26 @@ const router = createRouter({ router.beforeEach((to, from, next) => { document.title = `${to.meta.title} | ${settings.siteTitle}`; - const role = localStorage.getItem('ms_username'); + const username = localStorage.getItem('ms_username'); + const role = localStorage.getItem('ms_role_id'); const permiss = usePermissStore(); - if (!role && to.path !== '/login') { + const currentUserPermiss = permiss[role as string]; + // console.log("currentUserPermiss", currentUserPermiss) + if (!username && to.path !== '/login') { next({ path: '/login', query: { redirectTo: router.currentRoute.value.path // window.location.href }, }); - } else if (to.meta.permiss && !permiss.key.includes(to.meta.permiss)) { + return + } else if ( + to.meta.permiss && + !(currentUserPermiss && currentUserPermiss.includes(to.meta.permiss as string)) + ) { // 如果没有权限,则进入403 next('/403'); + return } else { next(); } diff --git a/frontend/src/store/permiss.ts b/frontend/src/store/permiss.ts index 6a9baec..eb7f90e 100644 --- a/frontend/src/store/permiss.ts +++ b/frontend/src/store/permiss.ts @@ -2,21 +2,61 @@ import { defineStore } from 'pinia'; import send_request from '../utils/send_request'; interface ObjectList { - [key: string]: string[]; + [key: string]: string[]; } +// 不同 role 的用户分别有哪些权限 export const usePermissStore = defineStore('permiss', { - state: () => { - const keys = localStorage.getItem('ms_keys'); - const defaultList = localStorage.getItem('ms_default_list'); - return { - key: keys ? JSON.parse(keys) : [], - defaultList: JSON.stringify(defaultList) - }; - }, - actions: { - handleSet(val: string[]) { - this.key = val; - } - } + state: () => { + return { + "1": [ + "dashboard", + "data-integration", + "default", + "equipment", + "equipment-setting", + "equipment-setting-manage", + "equipment-view", + "monitor-data", + "monitor-data-statistics", + "monitor-data-view", + "privilege", + "privilege-role-setting", + "privilege-user-setting", + "report", + "report-upload", + "resource", + "resource-staff-setting", + "resource-vehicle-setting", + "site-info", + "warning", + "warning-log", + "warning-setting", + "warning-view" + ], + "2": [ + "dashboard", + "data-integration", + "default", + "equipment", + "equipment-setting", + "equipment-view", + "monitor-data", + "monitor-data-statistics", + "monitor-data-view", + "report", + "report-upload", + "site-info", + "warning", + "warning-log", + "warning-setting", + "warning-view" + ] + }; + }, + // actions: { + // handleSet(val: string[]) { + // this.key = val; + // } + // } }); diff --git a/frontend/src/utils/send_request.js b/frontend/src/utils/send_request.js index 95f5144..08ef91f 100644 --- a/frontend/src/utils/send_request.js +++ b/frontend/src/utils/send_request.js @@ -1,52 +1,67 @@ -import request from './request'; -import settings from './settings'; - -async function send_request(url, method = "POST", params, callback) { - if (!url) { - return false; - } - - let returnData = await request({ - baseURL: settings.backendHost, - url: url, - method: method, - withCredentials: true, - // POST 请求参数 - data: method.toUpperCase() == "POST" ? params : null, - // GET 请求参数 - params: method.toUpperCase() == "GET" ? params : null, - }).then((response) => { - let result = response.data; - // 判断后端是否处理成功 - if (!result.isSuccess) { - // 用户未登录情况 - if (result.data && result.data.errCode == 20003) { - ElMessage.error(result?.data?.errMsg || "用户未登录"); - localStorage.clear(); - // window.location.reload(); - // 如果同时发出多个请求,可能会多次进来,第二次及之后进入时,hash已经变成 #/login 了 - if (!window.location.hash.includes("/login")) { - let newUrl = '/#/login?redirectTo=' + encodeURIComponent(window.location.hash.substring(1).split('?')[0]) - console.log("newUrl", newUrl) - window.location.href = newUrl; - } - } else { - ElMessage.error(result?.data?.errMsg || "服务器错误"); - } - return false; - } - let data = result.data; - if (typeof (callback) === "function") { - callback(data); - } - return true; - }).catch((err) => { - console.error(err); - ElMessage.error(err.message); - // ElMessage.error('请求超时,请检查网络连接'); - return false; - }) - return returnData; -} - -export default send_request; \ No newline at end of file +import request from './request'; +import settings from './settings'; +import { ElMessage, ElLoading } from 'element-plus'; +import qs from 'qs'; + +async function send_request({ url, method = "POST", params, useQS = false, callback }) { + if (!url) { + return false; + } + + const loading = ElLoading.service({ + lock: true, + text: '请稍候', + background: 'rgba(0, 0, 0, 0.7)', + }); + + let opt = { + baseURL: settings.backendHost, + url: url, + method: method, + withCredentials: true, + } + + if (method.toUpperCase() == "POST") { + // POST 请求参数 + opt.headers = { 'content-type': 'application/x-www-form-urlencoded' } + opt.data = useQS ? qs.stringify(params) : params + } else if (method.toUpperCase() == "GET") { + // GET 请求参数 + opt.params = params + } + + return request(opt).then((response) => { + let result = response.data; + // 判断后端是否处理成功 + if (!result.success) { + // 用户未登录情况 + // if (result.data && result.data.errCode == 20003) { + // ElMessage.error(result?.data?.msg || "用户未登录"); + // localStorage.clear(); + // // window.location.reload(); + // // 如果同时发出多个请求,可能会多次进来,第二次及之后进入时,hash已经变成 #/login 了 + // if (!window.location.hash.includes("/login")) { + // let newUrl = '/#/login?redirectTo=' + encodeURIComponent(window.location.hash.substring(1).split('?')[0]) + // console.log("newUrl", newUrl) + // window.location.href = newUrl; + // } + // } else { + ElMessage.error(result?.data?.msg || "服务器错误"); + // } + return null; + } + let data = result.data; + if (typeof (callback) === "function") { + callback(data); + } + return data; + }).catch((err) => { + console.error(err); + ElMessage.error(err.message); + return false; + }).finally(() => { + loading.close(); + }) +} + +export default send_request; diff --git a/frontend/src/utils/settings.js b/frontend/src/utils/settings.js index 3a94b1b..f0fb695 100644 --- a/frontend/src/utils/settings.js +++ b/frontend/src/utils/settings.js @@ -11,7 +11,7 @@ export default { * (网页标题 / 登录页显示) */ siteTitle: "社区疫情防控系统", - siteFullTitle: "社区疫情防控系统 - 后台管理系统(社区管理员)", + siteFullTitle: "社区疫情防控系统 - 后台管理系统", /** * 开发公司名称 @@ -21,7 +21,7 @@ export default { /** * 后端接口请求地址 - * (以 / 结尾) + * (结尾加不加 / 都可) */ - backendHost: "http://epp.only4.work/", + backendHost: "https://epp.only4.work/", }; diff --git a/frontend/src/views/login.vue b/frontend/src/views/login.vue index 98ff56c..1549221 100644 --- a/frontend/src/views/login.vue +++ b/frontend/src/views/login.vue @@ -1,163 +1,136 @@