mirror of
https://gitee.com/dromara/go-view.git
synced 2026-04-23 00:00:12 +08:00
fix: 修改数据加密解密,新增登录校验,新增底部备案号
This commit is contained in:
+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)
|
||||
}
|
||||
Reference in New Issue
Block a user