1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

后台管理 登陆权限问题解决

This commit is contained in:
程序员小墨 2023-03-28 14:01:13 +08:00
parent 614e04ed1b
commit 880e4f8941
13 changed files with 498 additions and 386 deletions

View File

@ -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

View File

@ -1,5 +1,5 @@
// Generated by 'unplugin-auto-import'
export {}
declare global {
const ElMessage: typeof import('element-plus/es')['ElMessage']
}

View File

@ -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",

View File

@ -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",

17
frontend/src/api/user.js Normal file
View File

@ -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,
}
});
};

View File

@ -1,47 +1,47 @@
<template>
<div class="header">
<!-- 折叠按钮 -->
<div class="collapse-btn" @click="collapseChage">
<el-icon v-if="sidebar.collapse">
<Expand />
</el-icon>
<el-icon v-else>
<Fold />
</el-icon>
</div>
<div class="logo">{{ settings.siteFullTitle }}</div>
<div class="header-right">
<div class="header-user-con">
<!-- 消息中心 -->
<div class="btn-bell" @click="router.push('/tabs')">
<el-tooltip effect="dark" :content="message ? `有${message}条未读消息` : `消息中心`" placement="bottom">
<i class="el-icon-lx-notice"></i>
</el-tooltip>
<span class="btn-bell-badge" v-if="message"></span>
</div>
<!-- 用户头像 -->
<el-avatar class="user-avator" :size="30" :src="imgurl" />
<!-- 用户名下拉菜单 -->
<el-dropdown class="user-name" trigger="click" @command="handleCommand">
<span class="el-dropdown-link">
{{ username }}
<el-icon class="el-icon--right">
<arrow-down />
</el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
<el-dropdown-item>项目仓库</el-dropdown-item>
</a>
<el-dropdown-item command="user">个人中心</el-dropdown-item>
<el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</div>
<div class="header">
<!-- 折叠按钮 -->
<div class="collapse-btn" @click="collapseChage">
<el-icon v-if="sidebar.collapse">
<Expand />
</el-icon>
<el-icon v-else>
<Fold />
</el-icon>
</div>
<div class="logo">{{ settings.siteFullTitle }}</div>
<div class="header-right">
<div class="header-user-con">
<!-- 消息中心 -->
<div class="btn-bell" @click="router.push('/tabs')">
<el-tooltip effect="dark" :content="message ? `有${message}条未读消息` : `消息中心`" placement="bottom">
<i class="el-icon-lx-notice"></i>
</el-tooltip>
<span class="btn-bell-badge" v-if="message"></span>
</div>
<!-- 用户头像 -->
<el-avatar class="user-avator" :size="30" :src="imgurl" />
<!-- 用户名下拉菜单 -->
<el-dropdown class="user-name" trigger="click" @command="handleCommand">
<span class="el-dropdown-link">
{{ username }}
<el-icon class="el-icon--right">
<arrow-down />
</el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
<el-dropdown-item>项目仓库</el-dropdown-item>
</a>
<el-dropdown-item command="user">个人中心</el-dropdown-item>
<el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { onMounted } from 'vue';
@ -59,131 +59,131 @@ const message: number = 2;
const sidebar = useSidebarStore();
//
const collapseChage = () => {
sidebar.handleCollapse();
sidebar.handleCollapse();
};
onMounted(() => {
//
// if (document.body.clientWidth < 1500) {
// collapseChage();
// }
//
// if (document.body.clientWidth < 1500) {
// collapseChage();
// }
});
//
const router = useRouter();
const handleCommand = (command: string) => {
if (command == 'loginout') {
// 退
send_request('v1/user/logout', "POST");
// ()
const tags = useTagsStore();
tags.clearTags();
// localStorage
localStorage.clear();
// localStorage.removeItem('ms_username');
// localStorage.removeItem('ms_user_id');
// localStorage.removeItem('ms_role_id');
//
router.push({
path: '/login',
query: {
redirectTo: router.currentRoute.value.path // window.location.href
},
});
ElMessage.success('已退出登录');
} else if (command == 'user') {
router.push('/user');
}
if (command == 'loginout') {
// 退
send_request({
url: 'v1/user/logout',
method: "POST",
} as any);
// ()
const tags = useTagsStore();
tags.clearTags();
// localStorage
localStorage.clear();
//
router.push({
path: '/login',
query: {
redirectTo: router.currentRoute.value.path // window.location.href
},
});
ElMessage.success('已退出登录');
} else if (command == 'user') {
router.push('/user');
}
};
</script>
<style scoped>
.header {
position: relative;
box-sizing: border-box;
width: 100%;
height: 70px;
font-size: 22px;
color: #fff;
position: relative;
box-sizing: border-box;
width: 100%;
height: 70px;
font-size: 22px;
color: #fff;
}
.collapse-btn {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
float: left;
padding: 0 21px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
float: left;
padding: 0 21px;
cursor: pointer;
}
.header .logo {
float: left;
/* width: 250px; */
line-height: 70px;
/* 系统名称不换行 */
white-space: nowrap;
float: left;
/* width: 250px; */
line-height: 70px;
/* 系统名称不换行 */
white-space: nowrap;
}
.header-right {
float: right;
padding-right: 50px;
float: right;
padding-right: 50px;
}
.header-user-con {
display: flex;
height: 70px;
align-items: center;
display: flex;
height: 70px;
align-items: center;
}
.btn-fullscreen {
transform: rotate(45deg);
margin-right: 5px;
font-size: 24px;
transform: rotate(45deg);
margin-right: 5px;
font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
position: relative;
width: 30px;
height: 30px;
text-align: center;
border-radius: 15px;
cursor: pointer;
display: flex;
align-items: center;
position: relative;
width: 30px;
height: 30px;
text-align: center;
border-radius: 15px;
cursor: pointer;
display: flex;
align-items: center;
}
.btn-bell-badge {
position: absolute;
right: 4px;
top: 0px;
width: 8px;
height: 8px;
border-radius: 4px;
background: #f56c6c;
color: #fff;
position: absolute;
right: 4px;
top: 0px;
width: 8px;
height: 8px;
border-radius: 4px;
background: #f56c6c;
color: #fff;
}
.btn-bell .el-icon-lx-notice {
color: #fff;
color: #fff;
}
.user-name {
margin-left: 10px;
margin-left: 10px;
}
.user-avator {
margin-left: 20px;
margin-left: 20px;
}
.el-dropdown-link {
color: #fff;
cursor: pointer;
display: flex;
align-items: center;
color: #fff;
cursor: pointer;
display: flex;
align-items: center;
}
.el-dropdown-menu__item {
text-align: center;
text-align: center;
}
</style>

View File

@ -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;
}
},

View File

@ -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();
}

View File

@ -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) : <string[]>[],
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;
// }
// }
});

View File

@ -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;
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;

View File

@ -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/",
};

View File

@ -1,163 +1,136 @@
<template>
<div class="login-wrap">
<div class="login-container">
<div class="ms-login">
<div class="ms-title">{{ settings.siteFullTitle }}</div>
<el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
<el-form-item prop="username">
<el-input v-model="param.username" placeholder="用户名">
<template #prepend>
<el-button :icon="User"></el-button>
</template>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" placeholder="密码" v-model="param.password"
@keyup.enter="submitForm(login)">
<template #prepend>
<el-button :icon="Lock"></el-button>
</template>
</el-input>
</el-form-item>
<div class="login-btn">
<el-button type="primary" @click="submitForm(login)">
<!-- <el-icon><UserFilled /></el-icon>-->
&nbsp;<el-icon>
<Right />
</el-icon>
</el-button>
</div>
</el-form>
</div>
</div>
<div class="company-info" v-if="settings.companyName">
{{ settings.companyName }}
</div>
</div>
<div class="login-wrap">
<div class="login-container">
<div class="ms-login">
<div class="ms-title">{{ settings.siteFullTitle }}</div>
<el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
<el-form-item prop="username">
<el-input v-model="param.username" placeholder="用户名">
<template #prepend>
<el-button :icon="User"></el-button>
</template>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" placeholder="密码" v-model="param.password"
@keyup.enter="submitForm(login)">
<template #prepend>
<el-button :icon="Lock"></el-button>
</template>
</el-input>
</el-form-item>
<div class="login-btn">
<el-button type="primary" @click="submitForm(login)">
<!-- <el-icon><UserFilled /></el-icon>-->
&nbsp;<el-icon>
<Right />
</el-icon>
</el-button>
</div>
</el-form>
</div>
</div>
<div class="company-info" v-if="settings.companyName">
{{ settings.companyName }}
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue';
import { useTagsStore } from '../store/tags';
import { usePermissStore } from '../store/permiss';
import { useRouter } from 'vue-router';
import { ElMessage, ElLoading } from 'element-plus';
import { ElMessage } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { Lock, User } from '@element-plus/icons-vue';
import send_request from '../utils/send_request';
import settings from '../utils/settings';
import * as userApi from '../api/user';
interface LoginInfo {
username: string;
password: string;
}
interface UserInfo {
username: string;
id: string;
roleId: string;
username: string;
password: string;
}
interface PrivilegeInfo {
"id": Number,
"roleId": Number,
"privilegeName": string,
"module": string
"id": Number,
"roleId": Number,
"privilegeName": string,
"module": string
}
interface RoleInfo {
id: Number,
roleName: string,
comment: any,
privileges: Array<PrivilegeInfo>;
id: Number,
roleName: string,
comment: any,
privileges: Array<PrivilegeInfo>;
}
const router = useRouter();
const param = reactive<LoginInfo>({
username: 'admin',
password: '123123'
username: 'root',
password: 'root'
});
const rules: FormRules = {
username: [
{
required: true,
message: '请输入用户名',
trigger: 'blur'
}
],
password: [
{
required: true,
message: '请输入密码',
trigger: 'blur'
}
]
username: [
{
required: true,
message: '请输入用户名',
trigger: 'blur'
}
],
password: [
{
required: true,
message: '请输入密码',
trigger: 'blur'
}
]
};
const permiss: any = usePermissStore();
const login = ref<FormInstance>();
const submitForm = (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid: boolean, invalidFields: any) => {
if (!valid) {
// ElMessage.error('');
if (!formEl) return;
formEl.validate(async (valid: boolean, invalidFields: any) => {
if (!valid) {
// ElMessage.error('');
console.log("invalidFields", invalidFields);
//
Object.values(invalidFields).forEach((input: any) => {
// console.log("input", input)
//
input.forEach((element: any) => {
// console.log("element", element)
ElMessage.error({ message: element.message, grouping: true });
});
});
return;
}
console.log("invalidFields", invalidFields);
//
Object.values(invalidFields).forEach((input: any) => {
// console.log("input", input)
//
input.forEach((element: any) => {
// console.log("element", element)
ElMessage.error({ message: element.message, grouping: true });
});
});
return;
}
const loading = ElLoading.service({
lock: true,
text: '请稍候',
background: 'rgba(0, 0, 0, 0.7)',
});
userApi.userLogin({
username: param.username,
password: param.password
}).then(async (data: any) => {
//
if (!data) return;
console.log("login data", data, data.userInfo);
await send_request('v1/user/login', "POST", {
userName: param.username,
passWord: param.password
}, async (data: UserInfo) => {
//
if (!data) {
ElMessage.error("用户名或密码错误");
return;
}
ElMessage.success('登录成功');
localStorage.setItem('ms_username', data.username);
localStorage.setItem('ms_user_id', data.id);
localStorage.setItem('ms_role_id', data.roleId);
ElMessage.success('登录成功');
localStorage.setItem('ms_username', data.userInfo?.username);
localStorage.setItem('ms_realname', data.userInfo?.realname);
localStorage.setItem('ms_user_id', data.userInfo?.id);
localStorage.setItem('ms_role_id', data.userInfo?.role);
let defaultList = {};
await send_request('v1/role/list', "GET", {}, (roleList: Array<RoleInfo>) => {
for (let role of roleList) {
defaultList[role.id.toString()] = role.privileges.map((i: any) => i.module)
}
});
permiss.defaultList = defaultList;
permiss.key = defaultList[data.roleId];
if (typeof (permiss.key) === "undefined") return;
localStorage.setItem('ms_keys', JSON.stringify(permiss.key));
localStorage.setItem('ms_default_list', JSON.stringify(defaultList));
let targetRoute: any = router.currentRoute?.value?.query?.redirectTo
if (targetRoute && !targetRoute.includes('/login')) {
router.push(targetRoute);
} else {
router.push('/');
}
});
loading.close();
});
let targetRoute: any = router.currentRoute?.value?.query?.redirectTo
if (targetRoute && !targetRoute.includes('/login')) {
router.push(targetRoute);
} else {
router.push('/');
}
})
});
};
const tags = useTagsStore();
@ -166,57 +139,57 @@ tags.clearTags();
<style scoped>
.login-wrap {
width: 100%;
height: 100%;
width: 100%;
height: 100%;
}
.login-container {
width: 100%;
height: 100%;
display: grid;
place-items: center;
width: 100%;
height: 100%;
display: grid;
place-items: center;
}
.ms-title {
width: 100%;
padding: 18px 24px;
box-sizing: border-box;
text-align: center;
font-size: 20px;
color: #fff;
border-bottom: 1px solid #ddd;
width: 100%;
padding: 18px 24px;
box-sizing: border-box;
text-align: center;
font-size: 20px;
color: #fff;
border-bottom: 1px solid #ddd;
}
.ms-login {
width: min(380px, 95vw);
padding: 5px 10px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.3);
overflow: hidden;
width: min(380px, 95vw);
padding: 5px 10px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.3);
overflow: hidden;
}
.ms-content {
padding: 30px 30px;
padding: 30px 30px;
}
.login-btn {
text-align: center;
text-align: center;
}
.login-btn button {
width: 100%;
height: 36px;
margin-bottom: 10px;
width: 100%;
height: 36px;
margin-bottom: 10px;
}
.company-info {
color: #7589b6;
text-align: center;
position: absolute;
left: 0;
right: 0;
bottom: 10px;
font-size: 13px;
letter-spacing: 1px;
color: #7589b6;
text-align: center;
position: absolute;
left: 0;
right: 0;
bottom: 10px;
font-size: 13px;
letter-spacing: 1px;
}
</style>

View File

@ -114,20 +114,16 @@ Page({
let result = d.data;
if (result.success) {
// 登录成功
if (result.data.userInfo.role != 2) {
if ([3, 4, 5, 6].includes(result.data.userInfo.role)) {
wx.showModal({
title: '你不是社区居民',
content: '请前往网页版登录',
content: '管理员请前往网页版登录',
showCancel: false,
complete: (res) => {
if (res.cancel) {
}
if (res.confirm) {
}
//
}
})
return
}
wx.setStorageSync("userInfo", result.data.userInfo);
console.log("userInfo", wx.getStorageSync("userInfo"))