Ver código fonte

fix: 优化权限控制,将权限控制获取放在登录之后

yanglzh 1 ano atrás
pai
commit
6594f5ca82

+ 0 - 16
README rule.md

@@ -1,17 +1 @@
 # 前端开发规范
-
-1. rules 校验用 change 不用 blur
-2. upload 重新选择文件不生效
-3. setup
-4. 页面撑满
-5. 表格高度
-6. 文件上传,图片上传 增加 source 字段
-7. 地图ak和地图中心电从参数中获取
-8. 多选反选
-9. 弹窗页面有table的用小table
-10. build 方式
-11. 本地启动说明 .local
-12. 部署说
-13. 图形显示
-多余log
-大页面分组件

+ 1 - 3
src/App.vue

@@ -24,13 +24,11 @@ sessionStorage.setItem('comeTime', Date.now().toString())
 export default defineComponent({
 	name: 'app',
 	components: { LockScreen, Setings, CloseFull },
-	created() {
+	async created() {
 		api.sysinfo().then((res: any) => {
 			// 安全开关是否开启 按钮权限,列表权限,rsa权限在开启安全权限下才使用
 			const isSecurityControlEnabled = res.isSecurityControlEnabled
 			localStorage.setItem('sysinfo', JSON.stringify(res));
-			sessionStorage.setItem('btnNoAuth', (isSecurityControlEnabled && res.sysButtonSwitch) ? '' : '1');
-			sessionStorage.setItem('colNoAuth', (isSecurityControlEnabled && res.sysColumnSwitch) ? '' : '1');
 			sessionStorage.setItem('isSecurityControlEnabled', isSecurityControlEnabled ? '1' : '');
 			sessionStorage.setItem('isRsaEnabled', (isSecurityControlEnabled && res.isRsaEnabled) ? '1' : '');
 		});

+ 1 - 1
src/api/system/index.ts

@@ -187,5 +187,5 @@ export default {
     down: (params: object) => file('/system/monitor/downloadLog', params),
     delete: (params: object) => del('/system/monitor/lastLinesLog/delete', params),
   },
-  getInfoByKey: (params: object) => get('/common/config/getInfoByKey', params)
+  getInfoByKey: (ConfigKey: string) => get('/common/config/getInfoByKey', { ConfigKey })
 }

+ 1 - 1
src/components/upload-wrapper/index.vue

@@ -13,7 +13,7 @@ import getOrigin from '/@/utils/origin'
 
 const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + '/common/singleImg');
 
-const source = JSON.parse(localStorage.sysinfo || '{"uploadFileWay": 0}').uploadFileWay;
+const source = localStorage.uploadFileWay
 
 const headers = {
   Authorization: 'Bearer ' + localStorage.token,

+ 1 - 1
src/components/upload/index.vue

@@ -38,7 +38,7 @@ const headers = {
 
 const emit = defineEmits(['setImg', 'setImgs'])
 
-const source = JSON.parse(localStorage.sysinfo || '{"uploadFileWay": 0}').uploadFileWay;
+const source = localStorage.uploadFileWay
 
 const props = defineProps({
 	multiple: {

+ 1 - 1
src/components/upload/uploadFile.vue

@@ -13,7 +13,7 @@ import { ElMessage } from 'element-plus';
 import type { UploadProps } from 'element-plus';
 import getOrigin from '/@/utils/origin';
 
-const source = JSON.parse(localStorage.sysinfo || '{"uploadFileWay": 0}').uploadFileWay;
+const source = localStorage.uploadFileWay
 
 const headers = {
 	Authorization: 'Bearer ' + localStorage.token,

+ 3 - 3
src/utils/authDirective.ts

@@ -13,7 +13,7 @@ export function authDirective(app: App) {
 	// 单个权限验证(v-auth="xxx")
 	app.directive('auth', {
 		mounted(el, binding) {
-			if (sessionStorage.btnNoAuth) return
+			if (localStorage.btnNoAuth) return
 			const buttons = <string[]>router.currentRoute.value.meta.buttons
 			if (buttons.includes(allPermissions)) return
 
@@ -32,7 +32,7 @@ export function authDirective(app: App) {
 	// 多个权限验证,满足一个则显示(v-auths="[xxx,xxx]")
 	app.directive('auths', {
 		mounted(el, binding) {
-			if (sessionStorage.btnNoAuth) return
+			if (localStorage.btnNoAuth) return
 			const buttons = <string[]>router.currentRoute.value.meta.buttons
 			if (buttons.includes(allPermissions)) return
 			let flag = false;
@@ -48,7 +48,7 @@ export function authDirective(app: App) {
 	// 多个权限验证,全部满足则显示(v-auth-all="[xxx,xxx]")
 	app.directive('auth-all', {
 		mounted(el, binding) {
-			if (sessionStorage.btnNoAuth) return
+			if (localStorage.btnNoAuth) return
 			const buttons = <string[]>router.currentRoute.value.meta.buttons
 			if (buttons.includes(allPermissions)) return
 			!smallInBig(buttons, binding.value) && el.parentNode.removeChild(el)

+ 3 - 3
src/utils/colDirective.ts

@@ -13,7 +13,7 @@ export function colDirective(app: App) {
 	// 单个权限验证(v-col="xxx")
 	app.directive('col', {
 		mounted(el, binding) {
-			if (sessionStorage.colNoAuth) return
+			if (localStorage.colNoAuth) return
 			const columns = <string[]>router.currentRoute.value.meta.columns
 			if (columns.includes(allPermissions)) return
 			if (!columns.includes(binding.value)) el.parentNode.removeChild(el)
@@ -22,7 +22,7 @@ export function colDirective(app: App) {
 	// 多个权限验证,满足一个则显示(v-cols="[xxx,xxx]")
 	app.directive('cols', {
 		mounted(el, binding) {
-			if (sessionStorage.colNoAuth) return
+			if (localStorage.colNoAuth) return
 			const columns = <string[]>router.currentRoute.value.meta.columns
 			if (columns.includes(allPermissions)) return
 			let flag = false;
@@ -37,7 +37,7 @@ export function colDirective(app: App) {
 	// 多个权限验证,全部满足则显示(v-col-all="[xxx,xxx]")
 	app.directive('col-all', {
 		mounted(el, binding) {
-			if (sessionStorage.colNoAuth) return
+			if (localStorage.colNoAuth) return
 			const columns = <string[]>router.currentRoute.value.meta.columns
 			if (columns.includes(allPermissions)) return
 			!smallInBig(columns, binding.value) && el.parentNode.removeChild(el)

+ 1 - 1
src/utils/map.ts

@@ -11,7 +11,7 @@ export function initMap(): any {
       return resolve({ BMapGL: window.BMapGL, centerPoint })
     }
 
-    Promise.all([apiSystem.getInfoByKey({ ConfigKey: 'sys.map.access.key' }), apiSystem.getInfoByKey({ ConfigKey: 'sys.map.lngAndLat' })]).then(([res1, res2]) => {
+    Promise.all([apiSystem.getInfoByKey('sys.map.access.key'), apiSystem.getInfoByKey('sys.map.lngAndLat')]).then(([res1, res2]) => {
       const ak = res1.data.configValue
       const centerStr = res2.data.configValue
 

+ 2 - 2
src/views/iot/device/instance/component/edit.vue

@@ -306,10 +306,10 @@ export default defineComponent({
     }
 
     onMounted(() => {
-      apiSystem.getInfoByKey({ ConfigKey: 'sys.device.phone.limit' }).then((res: any) => {
+      apiSystem.getInfoByKey('sys.device.phone.limit').then((res: any) => {
         state.deviceImgLimit = parseInt(res.data.configValue);
       });
-      apiSystem.getInfoByKey({ ConfigKey: 'sys.device.certificate.limit' }).then((res: any) => {
+      apiSystem.getInfoByKey('sys.device.certificate.limit').then((res: any) => {
         state.certificateLimit = parseInt(res.data.configValue);
       });
     })

+ 2 - 2
src/views/iot/ota-update/update/component/edit.vue

@@ -125,7 +125,7 @@ export default defineComponent({
   setup(prop, { emit }) {
     const formRef = ref<HTMLElement | null>(null);
     const headers = { Authorization: 'Bearer ' + localStorage.token, };
-    const source = JSON.parse(localStorage.sysinfo || '{"uploadFileWay": 0}').uploadFileWay;
+    const source = localStorage.uploadFileWay
     const editDicRef = ref();
     const areType = ref([
       {
@@ -198,7 +198,7 @@ export default defineComponent({
       state.isShowDialog = true;
 
       // 获取上传格式
-      apiSystem.getInfoByKey({ ConfigKey: 'sys.uploadFile.fileType' }).then((res: any) => {
+      apiSystem.getInfoByKey('sys.uploadFile.fileType').then((res: any) => {
         let fileType = res.data.configValue.split(",");
         for (let i = 0; i < fileType.length; i++) {
           fileType[i] = '.' + fileType[i];

+ 11 - 2
src/views/login/component/account.vue

@@ -118,7 +118,6 @@ export default defineComponent({
 					if (valid) {
 						state.loading.signIn = true;
 						let password: string
-						console.log(sessionStorage.isRsaEnabled)
 						if (sessionStorage.isRsaEnabled) {
 							password = await encrypt(state.ruleForm.password)
 						} else {
@@ -142,13 +141,23 @@ export default defineComponent({
 									})
 								}
 
+								localStorage.setItem('token', res.token);
 								const userInfos = res.userInfo;
 								userInfos.avatar = proxy.getUpFileUrl(userInfos.avatar);
 								// 存储 token 到浏览器缓存
-								localStorage.setItem('token', res.token);
 								Local.set('userInfo', userInfos);
 								// 存储用户信息到浏览器缓存
 								Session.set('userInfo', userInfos);
+
+
+								// 获取权限配置,上传文件类型等
+								const [columnRes, buttonRes, uploadFileRes] = await Promise.all([api.getInfoByKey('sys.column.switch'), api.getInfoByKey('sys.button.switch'), api.getInfoByKey('sys.uploadFile.way')])
+
+								const isSecurityControlEnabled = sessionStorage.isSecurityControlEnabled
+								localStorage.setItem('btnNoAuth', (isSecurityControlEnabled && Number(buttonRes.data.configValue)) ? '' : '1');
+								localStorage.setItem('colNoAuth', (isSecurityControlEnabled && Number(columnRes.data.configValue)) ? '' : '1');
+								localStorage.setItem('uploadFileWay', uploadFileRes.data.configValue);
+
 								await store.dispatch('userInfos/setUserInfos', userInfos);
 
 								currentUser();