Skip to content

Commit

Permalink
优化:sonar 代码(质量)规范化
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyuchuixue committed Jan 28, 2025
1 parent 993666f commit 6ed0905
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 171 deletions.
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class RequestHttp {
return this.service.get(url, { params, ..._object, responseType: 'blob' });
}

upload<T>(url: string, params = {}, _object: AxiosRequestConfig<{}> | undefined): Promise<IResultData<T>> {
upload<T>(url: string, params: any = {}, _object: AxiosRequestConfig<{}> | undefined): Promise<IResultData<T>> {
return this.service.post(url, params, {
..._object,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/api/interface/system/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export namespace ICaptcha {
posY: number;
secretKey: string;
}
export interface verifyImageParams {
export interface VerifyImageParams {
requestId: string;
moveEncrypted: string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/interface/system/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 登录模块
export namespace ICommon {
export interface templateDown {
export interface TemplateDown {
templateName: string;
}
}
2 changes: 1 addition & 1 deletion src/api/modules/system/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const getImageCodeApi = () => {
return http.post<ICaptcha.Info>(ADMIN_MODULE + `/captcha/get`, {}, { loading: false });
};
// 校验滑块拼图验证码
export const verifyImageCodeApi = (params: ICaptcha.verifyImageParams) => {
export const verifyImageCodeApi = (params: ICaptcha.VerifyImageParams) => {
return http.post(ADMIN_MODULE + `/captcha/check`, params, { loading: false });
};
2 changes: 1 addition & 1 deletion src/api/modules/system/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import type { ICommon } from '@/api/interface/system/common';
/**
* 模版下载
*/
export const downloadTemplate = (params: ICommon.templateDown) => {
export const downloadTemplate = (params: ICommon.TemplateDown) => {
return http.template(ADMIN_MODULE + `/common/download/templates`, params);
};
20 changes: 14 additions & 6 deletions src/components/Captcha/SliderCaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
<div class="sliderBox">
<div class="sliderBox_content">
<!-- 大图显示 -->
<img v-show="slideData.big" :src="'data:image/png;base64,' + slideData.big" class="bigImg" />
<img v-show="slideData.big" :src="'data:image/png;base64,' + slideData.big" class="bigImg" alt="验证码主图" />
<span class="sliderBox_refresh" @click="refreshSlider">
<el-icon class="el-input__icon"><refresh /></el-icon>
</span>
<!-- 小图显示 -->
<img v-show="slideData.small" :src="'data:image/png;base64,' + slideData.small" class="smallImg" ref="imgK" />
<img
v-show="slideData.small"
:src="'data:image/png;base64,' + slideData.small"
class="smallImg"
ref="imgK"
alt="验证码拼图"
/>
<!-- 验证结果提示 -->
<div v-if="overlayVisible" class="overlay" :class="{ success: slideData.isSuccess, failure: !slideData.isSuccess }">
<span>{{ overlayMessage }}</span>
Expand Down Expand Up @@ -151,15 +157,17 @@ const initializeSlider = () => {
moveSlider(clientX);
};
const handleEnd = () => {
const handleEnd = async () => {
document.removeEventListener('mousemove', handleMove);
document.removeEventListener('mouseup', handleEnd);
document.removeEventListener('touchmove', handleMove);
document.removeEventListener('touchend', handleEnd);
verifyImageCode({
const { iv, encryptedData } = await aesEncrypt(offsetX + '', slideData.secretKey);
await verifyImageCode({
requestId: slideData.requestId,
startTime,
moveEncrypted: aesEncrypt(offsetX + '', slideData.secretKey)
moveEncrypted: encryptedData,
iv: iv
});
};
Expand Down Expand Up @@ -191,7 +199,7 @@ const initializeSlider = () => {
};
// 验证滑动结果
const verifyImageCode = async (params: { requestId: string; startTime: number; moveEncrypted: string }) => {
const verifyImageCode = async (params: { requestId: string; startTime: number; moveEncrypted: string; iv: string }) => {
if (isVerifying.value) return; // 防止重复验证
isVerifying.value = true;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Grid/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const findIndex = () => {
if (Number(prev) > props.collapsedRows * (gridCols.value as number) - suffixCols) {
hiddenIndex.value = index;
find = true;
throw 'find it';
throw new Error('find it');
}
return prev;
}, 0);
Expand Down
1 change: 0 additions & 1 deletion src/components/HighCode/code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
display: flex;
flex-direction: column;
width: max-content;
// padding: 30px 1em 0 0;
overflow-x: hidden;
font-size: 14px;
line-height: 24px;
Expand Down
4 changes: 1 addition & 3 deletions src/components/HighCode/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,4 @@ const handleCopy = async () => {
};
</script>

<style lang="scss" scoped>
// @import './index.scss';
</style>
<style lang="scss" scoped></style>
2 changes: 1 addition & 1 deletion src/components/IconChoose/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const elementIcons = Object.keys(Icons).map(key => {
const svgIcons: string[] = [];
const svgIconsFiles = import.meta.glob('@/assets/icons/**/*.svg');
for (const key in svgIconsFiles) {
const matchArray = key.match(/.*\/assets\/icons\/(.*)\.svg/);
const matchArray = key.match(/\/assets\/icons\/([^/]+)\.svg$/);
if (matchArray && matchArray.length >= 2) {
svgIcons.push(`svg-${matchArray[1]}`);
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Upload/Img.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:accept="fileType.join(',')"
>
<template v-if="imageUrl">
<img :src="imageUrl" class="upload-image" />
<img :src="imageUrl" class="upload-image" alt="图片预览" />
<div class="upload-handle" @click.stop>
<div v-if="!self_disabled" class="handle-icon" @click="editImg">
<el-icon><Edit /></el-icon>
Expand All @@ -35,7 +35,6 @@
<div class="upload-empty">
<slot name="empty">
<el-icon><Plus /></el-icon>
<!-- <span>请上传图片</span> -->
</slot>
</div>
</template>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Upload/Imgs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
<div class="upload-empty">
<slot name="empty">
<el-icon><Plus /></el-icon>
<!-- <span>请上传图片</span> -->
</slot>
</div>
<template #file="{ file }">
<img :src="file.url" class="upload-image" />
<img :src="file.url" class="upload-image" alt="预览图片" />
<div class="upload-handle" @click.stop>
<div class="handle-icon" @click="handlePictureCardPreview(file)">
<el-icon><ZoomIn /></el-icon>
Expand Down
9 changes: 3 additions & 6 deletions src/config/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export const dictBusinessType: Options[] = [

export const dictBusinessTypeLabel = (value: string): string => {
const item = dictBusinessType.find(item => item.value === value);

return item?.label || '';
return item?.label ?? '';
};

/**
Expand All @@ -61,8 +60,7 @@ export const dictBusinessTypeLabel = (value: string): string => {
*/
export const yesNoOptionsLabel = (value: string): string => {
const item = yesNoOptions.find(item => item.value === value);

return item?.label || '';
return item?.label ?? '';
};

/**
Expand Down Expand Up @@ -104,6 +102,5 @@ export const tagsTypeOptions: Options[] = [
*/
export const tagsTypeOptionsLabel = (value: string): string => {
const item = tagsTypeOptions.find(item => item.value === value);

return item?.label || '';
return item?.label ?? '';
};
14 changes: 10 additions & 4 deletions src/layouts/LayoutColumns/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ watch(
const menuItem = menuList.value.filter(item => {
return route.path === item.path || `/${route.path.split('/')[1]}` === item.path;
});
if (menuItem[0] && menuItem[0].children?.length) return (subMenuList.value = menuItem[0].children);
subMenuList.value = [];
if (menuItem[0] && menuItem[0].children?.length) {
subMenuList.value = menuItem[0].children;
} else {
subMenuList.value = [];
}
},
{
deep: true,
Expand All @@ -99,8 +102,11 @@ watch(
// change SubMenu
const changeSubMenu = (item: Menu.MenuOptions) => {
splitActive.value = item.path;
if (item.children?.length) return (subMenuList.value = item.children);
subMenuList.value = [];
if (item.children?.length) {
subMenuList.value = item.children;
} else {
subMenuList.value = [];
}
router.push(item.path);
};
</script>
Expand Down
3 changes: 2 additions & 1 deletion src/stores/modules/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { ElMessageBox } from 'element-plus';
import { useAuthStore } from '@/stores/modules/auth';

// 是否使用socket 当 import.meta.env.VITE_SOCKET_URL 不为空时,启用websocket
const useSocket = Object.prototype.hasOwnProperty.call(import.meta.env, 'VITE_SOCKET_URL');
//const useSocket = Object.prototype.hasOwnProperty.call(import.meta.env, 'VITE_SOCKET_URL');
const useSocket = Object.hasOwn(import.meta.env, 'VITE_SOCKET_URL');
const socketUrl = new URL(import.meta.env.VITE_SOCKET_URL, window.location.origin);
socketUrl.protocol = socketUrl.protocol === 'https:' ? 'wss:' : 'ws:';
const MAX_RECONNECT_COUNT = 10;
Expand Down
128 changes: 0 additions & 128 deletions src/styles/reset.scss
Original file line number Diff line number Diff line change
@@ -1,132 +1,4 @@
/* Reset style sheet */

/* 目前项目中使用富文本编辑器需要注释,如果你项目中没有使用富文本编辑器,可以取消注释 */
// html,
// body,
// div,
// span,
// applet,
// object,
// iframe,
// h1,
// h2,
// h3,
// h4,
// h5,
// h6,
// p,
// blockquote,
// pre,
// a,
// abbr,
// acronym,
// address,
// big,
// cite,
// code,
// del,
// dfn,
// em,
// img,
// ins,
// kbd,
// q,
// s,
// samp,
// small,
// strike,
// strong,
// sub,
// sup,
// tt,
// var,
// b,
// u,
// i,
// center,
// dl,
// dt,
// dd,
// ol,
// ul,
// li,
// fieldset,
// form,
// label,
// legend,
// table,
// caption,
// tbody,
// tfoot,
// thead,
// tr,
// th,
// td,
// article,
// aside,
// canvas,
// details,
// embed,
// figure,
// figcaption,
// footer,
// header,
// hgroup,
// menu,
// nav,
// output,
// ruby,
// section,
// summary,
// time,
// mark,
// audio,
// video {
// padding: 0;
// margin: 0;
// font: inherit;
// font-size: 100%;
// vertical-align: baseline;
// border: 0;
// }

// /* HTML5 display-role reset for older browsers */
// article,
// aside,
// details,
// figcaption,
// figure,
// footer,
// header,
// hgroup,
// menu,
// nav,
// section {
// display: block;
// }
// body {
// padding: 0;
// margin: 0;
// }
// ol,
// ul {
// list-style: none;
// }
// blockquote,
// q {
// quotes: none;
// }
// blockquote::before,
// blockquote::after,
// q::before,
// q::after {
// content: "";
// content: none;
// }
// table {
// border-spacing: 0;
// border-collapse: collapse;
// }
html,
body,
#app {
Expand Down
31 changes: 22 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isArray } from '@/utils/is';
import CryptoJS from 'crypto-js';

/**
* @description 获取localStorage
Expand Down Expand Up @@ -346,13 +345,27 @@ export function isLocalEnv() {
}

/**
* AES 加密
* @param message
* @param secretKey
* 使用 AES-GCM 模式加密消息
* @param {string} message - 待加密的消息
* @param {string} secretKey - 加密密钥(16 字节)
* @returns {Promise<{ iv: string, encryptedData: string }>} - 返回加密后的数据和 IV
*/
export function aesEncrypt(message: string, secretKey: string) {
const key = CryptoJS.enc.Utf8.parse(secretKey);
const msg = CryptoJS.enc.Utf8.parse(message);
const encrypted = CryptoJS.AES.encrypt(msg, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
return encrypted.toString();
export async function aesEncrypt(message: string, secretKey: string) {
const encoder = new TextEncoder();
const key = await crypto.subtle.importKey('raw', encoder.encode(secretKey), { name: 'AES-GCM' }, false, ['encrypt']);

const iv = crypto.getRandomValues(new Uint8Array(12)); // 生成随机 IV (12 字节)
const encrypted = await crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv: iv
},
key,
encoder.encode(message)
);

return {
iv: btoa(String.fromCharCode(...iv)), // 将 IV 转换为 Base64 编码的字符串
encryptedData: btoa(String.fromCharCode(...new Uint8Array(encrypted))) // 将加密数据转换为 Base64 编码的字符串
};
}
Loading

0 comments on commit 6ed0905

Please sign in to comment.