mirror of
https://gitee.com/dromara/go-view.git
synced 2026-04-23 00:00:12 +08:00
fix: 修改数据加密解密,新增登录校验,新增底部备案号
This commit is contained in:
@@ -30,7 +30,7 @@ export enum PageEnum {
|
||||
|
||||
// 我的项目
|
||||
BASE_HOME_ITEMS = '/project/items',
|
||||
BASE_HOME_ITEMS_NAME = 'Project-Ttems',
|
||||
BASE_HOME_ITEMS_NAME = 'Project-Items',
|
||||
|
||||
// 我的模板
|
||||
BASE_HOME_TEMPLATE = '/project/my-template',
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
<template>
|
||||
<div class="go-footer">
|
||||
<slot>
|
||||
<n-text depth="2">
|
||||
<n-a>{{ $t('global.doc_addr') }}: </n-a>
|
||||
<n-a italic :href="docPath">
|
||||
{{docPath}}
|
||||
</n-a>
|
||||
</n-text>
|
||||
<n-space :size="50">
|
||||
<n-text depth="2">
|
||||
<n-a>{{ $t('global.doc_addr') }}: </n-a>
|
||||
<n-a italic :href="docPath" target="_blank">
|
||||
{{ docPath }}
|
||||
</n-a>
|
||||
</n-text>
|
||||
<n-text depth="3">
|
||||
<n-a italic href="https://beian.miit.gov.cn/" target="_blank">
|
||||
京ICP备2021034585号-1
|
||||
</n-a>
|
||||
</n-text>
|
||||
</n-space>
|
||||
</slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router } from 'vue-router';
|
||||
import { PageEnum } from '@/enums/pageEnum'
|
||||
|
||||
import { loginCheck } from '@/utils'
|
||||
|
||||
export function createRouterGuards(router: Router) {
|
||||
// 前置
|
||||
@@ -11,6 +11,13 @@ export function createRouterGuards(router: Router) {
|
||||
if (isErrorPage === -1) {
|
||||
next({ name: PageEnum.ERROR_PAGE_NAME_404 })
|
||||
}
|
||||
|
||||
if (!loginCheck()) {
|
||||
if (to.name === PageEnum.BASE_LOGIN_NAME) {
|
||||
next()
|
||||
}
|
||||
next({ name: PageEnum.BASE_LOGIN_NAME })
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
|
||||
+24
-19
@@ -1,29 +1,34 @@
|
||||
import * as CryptoJS from 'crypto-ts'
|
||||
// 加密
|
||||
const AES_KEY = 'mt'
|
||||
import CryptoJS from 'crypto-js'
|
||||
import { isString } from './type'
|
||||
|
||||
const KEY = 'mt'
|
||||
|
||||
/**
|
||||
* * 加密
|
||||
* @param data { string }
|
||||
* @returns
|
||||
*/
|
||||
export const cryptoEncode = (data: string): string => {
|
||||
if (typeof data !== 'string') return ''
|
||||
if (!isString(data)) return ''
|
||||
// 加密
|
||||
const key = CryptoJS.enc.Utf8.parse(AES_KEY)
|
||||
const str = JSON.stringify(data)
|
||||
const encryptedData = CryptoJS.AES.encrypt(str, key, {
|
||||
const encryptedData = CryptoJS.AES.encrypt(data, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.PKCS7,
|
||||
iv: CryptoJS.enc.Utf8.parse(AES_KEY)
|
||||
})
|
||||
return encryptedData.toString()
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString()
|
||||
return encryptedData
|
||||
}
|
||||
// 解密
|
||||
|
||||
/**
|
||||
* * 解密
|
||||
* @param data { string }
|
||||
* @returns
|
||||
*/
|
||||
export const cryptoDecode = (data: string): string => {
|
||||
if (typeof data !== 'string') return ''
|
||||
const encryptedHexStr = CryptoJS.enc.Utf8.parse(data)
|
||||
const encryptedBase64Str = CryptoJS.enc.Utf8.stringify(encryptedHexStr)
|
||||
const key = CryptoJS.enc.Utf8.parse(AES_KEY)
|
||||
const decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
|
||||
if (!isString(data)) return ''
|
||||
// 解密
|
||||
const decryptedData = CryptoJS.AES.decrypt(data, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.PKCS7,
|
||||
iv: CryptoJS.enc.Utf8.parse(AES_KEY)
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
})
|
||||
return decryptedData.toString(CryptoJS.enc.Utf8)
|
||||
}
|
||||
|
||||
+27
-1
@@ -1,8 +1,11 @@
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ResultEnum } from '@/enums/httpEnum'
|
||||
import { ErrorPageNameMap, PageEnum } from '@/enums/pageEnum'
|
||||
import router from '@/router'
|
||||
import { docPath, giteeSourceCodePath } from '@/settings/pathConst'
|
||||
import { cryptoDecode } from './crypto'
|
||||
import { StorageEnum } from '@/enums/storageEnum'
|
||||
import { clearLocalStorage, getLocalStorage } from './storage'
|
||||
import router from '@/router'
|
||||
|
||||
/**
|
||||
* * 根据名字跳转路由
|
||||
@@ -101,6 +104,7 @@ export const reloadRoutePage = () => {
|
||||
* * 退出
|
||||
*/
|
||||
export const logout = () => {
|
||||
clearLocalStorage(StorageEnum.GO_LOGIN_INFO_STORE)
|
||||
routerTurnByName(PageEnum.BASE_LOGIN_NAME)
|
||||
}
|
||||
|
||||
@@ -128,6 +132,10 @@ export const openGiteeSourceCode = () => {
|
||||
openNewWindow(giteeSourceCodePath)
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断是否是预览页
|
||||
* @returns boolean
|
||||
*/
|
||||
export const isPreview = () => {
|
||||
return document.location.hash.includes('preview')
|
||||
}
|
||||
@@ -152,3 +160,21 @@ export const fetchRouteParams = () => {
|
||||
export const goHome = () => {
|
||||
routerTurnByName(PageEnum.BASE_HOME_NAME)
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断是否登录(现阶段是有 login 数据即可)
|
||||
* @return boolean
|
||||
*/
|
||||
export const loginCheck = () => {
|
||||
try {
|
||||
const info = getLocalStorage(StorageEnum.GO_LOGIN_INFO_STORE)
|
||||
if (!info) return false
|
||||
const decodeInfo = cryptoDecode(info)
|
||||
if (decodeInfo) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
+17
-1
@@ -18,7 +18,7 @@
|
||||
* @param k 键名
|
||||
* @returns any
|
||||
*/
|
||||
export const getLocalStorage = (k: string) => {
|
||||
export const getLocalStorage = (k: string) => {
|
||||
const item = window.localStorage.getItem(k)
|
||||
try {
|
||||
return item ? JSON.parse(item) : item
|
||||
@@ -27,6 +27,14 @@ export const getLocalStorage = (k: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * 清除本地会话数据
|
||||
* @param name
|
||||
*/
|
||||
export const clearLocalStorage = (name: string) => {
|
||||
window.localStorage.removeItem(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* * 存储临时会话数据
|
||||
* @param k 键名
|
||||
@@ -52,4 +60,12 @@ export const getSessionStorage: (k: string) => any = (k: string) => {
|
||||
} catch (err) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * 清除本地会话数据
|
||||
* @param name
|
||||
*/
|
||||
export const clearSessioStorage = (name: string) => {
|
||||
window.sessionStorage.removeItem(name)
|
||||
}
|
||||
@@ -116,11 +116,6 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref, onMounted } from 'vue'
|
||||
import {
|
||||
routerTurnByName,
|
||||
cryptoEncode,
|
||||
setLocalStorage
|
||||
} from '@/utils'
|
||||
import shuffle from 'lodash/shuffle'
|
||||
import { carouselInterval } from '@/settings/designSetting'
|
||||
import { useDesignStore } from '@/store/modules/designStore/designStore'
|
||||
@@ -131,7 +126,7 @@ import { LayoutFooter } from '@/layout/components/LayoutFooter'
|
||||
import { PageEnum } from '@/enums/pageEnum'
|
||||
import { icon } from '@/plugins'
|
||||
import { StorageEnum } from '@/enums/storageEnum'
|
||||
|
||||
import { routerTurnByName, cryptoEncode, setLocalStorage } from '@/utils'
|
||||
const { GO_LOGIN_INFO_STORE } = StorageEnum
|
||||
|
||||
const { PersonOutlineIcon, LockClosedOutlineIcon } = icon.ionicons5
|
||||
@@ -161,20 +156,20 @@ onMounted(() => {
|
||||
|
||||
const formInline = reactive({
|
||||
username: 'admin',
|
||||
password: '123456'
|
||||
password: '123456',
|
||||
})
|
||||
|
||||
const rules = {
|
||||
username: {
|
||||
required: true,
|
||||
message: t('global.form_account'),
|
||||
trigger: 'blur'
|
||||
trigger: 'blur',
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
message: t('global.form_password'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
trigger: 'blur',
|
||||
},
|
||||
}
|
||||
|
||||
// 定时器
|
||||
@@ -193,7 +188,7 @@ const bgList = ref([
|
||||
'heatmap',
|
||||
'map',
|
||||
'pie',
|
||||
'radar'
|
||||
'radar',
|
||||
])
|
||||
|
||||
// 处理url获取
|
||||
@@ -220,7 +215,7 @@ const handleSubmit = (e: Event) => {
|
||||
cryptoEncode(
|
||||
JSON.stringify({
|
||||
username,
|
||||
password
|
||||
password,
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user