🎨 optimized code

This commit is contained in:
2024-11-27 18:59:11 +08:00
parent a3e15bbc86
commit 46e6b49c02
14 changed files with 74 additions and 50 deletions

View File

@@ -54,14 +54,14 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.15.0", "@eslint/js": "^9.15.0",
"@vitejs/plugin-vue": "^5.2.0", "@vitejs/plugin-vue": "^5.2.1",
"eslint-plugin-vue": "^9.31.0", "eslint-plugin-vue": "^9.31.0",
"globals": "^15.12.0", "globals": "^15.12.0",
"sass": "^1.81.0", "sass": "^1.81.0",
"typescript": "^5.7.2", "typescript": "^5.7.2",
"typescript-eslint": "^8.15.0", "typescript-eslint": "^8.15.0",
"unplugin-vue-components": "^0.27.4", "unplugin-vue-components": "^0.27.4",
"vite": "^6.0.0", "vite": "^6.0.1",
"vite-plugin-bundle-obfuscator": "1.3.1", "vite-plugin-bundle-obfuscator": "1.3.1",
"vite-plugin-chunk-split": "^0.5.0", "vite-plugin-chunk-split": "^0.5.0",
"vue-tsc": "^2.1.10" "vue-tsc": "^2.1.10"

View File

@@ -168,7 +168,7 @@ async function commentSubmit(point: any) {
images: comment.imageList, images: comment.imageList,
author: user.user.uid, author: user.user.uid,
point: [point.x, point.y], point: [point.x, point.y],
key: comment.slideCaptchaData.key, key: comment.slideCaptchaData.captKey,
}; };
const result: any = await commentSubmitApi(commentParams); const result: any = await commentSubmitApi(commentParams);
if (result.code === 200) { if (result.code === 200) {
@@ -182,8 +182,8 @@ async function commentSubmit(point: any) {
created_time: result.data.created_time, created_time: result.data.created_time,
browser: result.data.browser, browser: result.data.browser,
operating_system: result.data.operating_system, operating_system: result.data.operating_system,
reply_count: result.data.reply_count, reply_count: 0,
likes: result.data.likes, likes: 0,
author: result.data.author, author: result.data.author,
location: result.data.location, location: result.data.location,
is_liked: false, is_liked: false,
@@ -193,13 +193,15 @@ async function commentSubmit(point: any) {
comment.commentList.comments = []; // 初始化 comments 数组 comment.commentList.comments = []; // 初始化 comments 数组
} }
comment.commentList.comments.unshift(tmpData); comment.commentList.comments.unshift(tmpData);
comment.commentMap[result.data.id] = tmpData;
commentContent.value = ""; commentContent.value = "";
await comment.clearFileList(); await comment.clearFileList();
showSubmitCaptcha.value = false; showSubmitCaptcha.value = false;
message.success(t('comment.commentSuccess')); message.success(t('comment.commentSuccess'));
} else { } else {
await comment.getSlideCaptchaData(); await comment.getSlideCaptchaData();
message.error(result.message || t('comment.commentError')); message.warning(result.message || t('comment.commentError'));
} }
} }
@@ -215,7 +217,7 @@ async function showSlideCaptcha() {
return; return;
} }
if (comment.imageList.length > 3) { if (comment.imageList.length > 3) {
message.error(t('comment.maxImageCount')); message.warning(t('comment.maxImageCount'));
return; return;
} }
const res = await comment.getSlideCaptchaData(); const res = await comment.getSlideCaptchaData();

View File

@@ -158,7 +158,7 @@ async function replySubmit(point: any) {
return; return;
} }
if (comment.imageList.length > 3) { if (comment.imageList.length > 3) {
message.error(t('comment.maxImageCount')); message.warning(t('comment.maxImageCount'));
return; return;
} }
const content = replyContent.value.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); const content = replyContent.value.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
@@ -183,7 +183,7 @@ async function replySubmit(point: any) {
reply_id: props.item.id, reply_id: props.item.id,
reply_user: props.item.user_id, reply_user: props.item.user_id,
point: [point.x, point.y], point: [point.x, point.y],
key: comment.slideCaptchaData.key, key: comment.slideCaptchaData.captKey,
}; };
const result: any = await replySubmitApi(replyParams); const result: any = await replySubmitApi(replyParams);
if (result.code === 200) { if (result.code === 200) {
@@ -198,8 +198,8 @@ async function replySubmit(point: any) {
browser: result.data.browser, browser: result.data.browser,
operating_system: result.data.operating_system, operating_system: result.data.operating_system,
location: result.data.location, location: result.data.location,
likes: result.data.likes, reply_count: 0,
reply_count: result.data.reply_count, likes: 0,
reply_user: result.data.reply_user, reply_user: result.data.reply_user,
nickname: user.user.nickname, nickname: user.user.nickname,
avatar: user.user.avatar, avatar: user.user.avatar,
@@ -218,7 +218,7 @@ async function replySubmit(point: any) {
message.success(t('comment.replySuccess')); message.success(t('comment.replySuccess'));
} else { } else {
await comment.getSlideCaptchaData(); await comment.getSlideCaptchaData();
message.error(t('comment.replyError')); message.warning(t('comment.replyError'));
} }
} }
@@ -229,11 +229,11 @@ const getSlideCaptchaDataThrottled = useThrottleFn(comment.getSlideCaptchaData,
*/ */
async function showSlideCaptcha() { async function showSlideCaptcha() {
if (replyContent.value.trim() === "") { if (replyContent.value.trim() === "") {
message.error(t('comment.commentContentNotEmpty')); message.warning(t('comment.commentContentNotEmpty'));
return; return;
} }
if (comment.imageList.length > 3) { if (comment.imageList.length > 3) {
message.error(t('comment.maxImageCount')); message.warning(t('comment.maxImageCount'));
return; return;
} }
const res = await comment.getSlideCaptchaData(); const res = await comment.getSlideCaptchaData();

View File

@@ -169,7 +169,7 @@ async function replyReplySubmit(point: any) {
return; return;
} }
if (comment.imageList.length > 3) { if (comment.imageList.length > 3) {
message.error(t('comment.maxImageCount')); message.warning(t('comment.maxImageCount'));
return; return;
} }
const content = replyReplyContent.value.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); const content = replyReplyContent.value.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
@@ -186,7 +186,7 @@ async function replyReplySubmit(point: any) {
reply_id: props.item.id, reply_id: props.item.id,
reply_user: props.child.user_id, reply_user: props.child.user_id,
point: [point.x, point.y], point: [point.x, point.y],
key: comment.slideCaptchaData.key, key: comment.slideCaptchaData.captKey,
}; };
const result: any = await replyReplySubmitApi(replyParams); const result: any = await replyReplySubmitApi(replyParams);
if (result.code === 200) { if (result.code === 200) {
@@ -201,8 +201,8 @@ async function replyReplySubmit(point: any) {
browser: result.data.browser, browser: result.data.browser,
operating_system: result.data.operating_system, operating_system: result.data.operating_system,
location: result.data.location, location: result.data.location,
likes: result.data.likes, reply_count: 0,
reply_count: result.data.reply_count, likes: 0,
reply_user: result.data.reply_user, reply_user: result.data.reply_user,
nickname: user.user.nickname, nickname: user.user.nickname,
avatar: user.user.avatar, avatar: user.user.avatar,
@@ -224,7 +224,7 @@ async function replyReplySubmit(point: any) {
message.success(t('comment.replySuccess')); message.success(t('comment.replySuccess'));
} else { } else {
await comment.getSlideCaptchaData(); await comment.getSlideCaptchaData();
message.error(t('comment.replyError')); message.warning(t('comment.replyError'));
} }
} }
@@ -235,11 +235,11 @@ const getSlideCaptchaDataThrottled = useThrottleFn(comment.getSlideCaptchaData,
*/ */
async function showSlideCaptcha() { async function showSlideCaptcha() {
if (replyReplyContent.value.trim() === "") { if (replyReplyContent.value.trim() === "") {
message.error(t('comment.commentContentNotEmpty')); message.warning(t('comment.commentContentNotEmpty'));
return; return;
} }
if (comment.imageList.length > 3) { if (comment.imageList.length > 3) {
message.error(t('comment.maxImageCount')); message.warning(t('comment.maxImageCount'));
return; return;
} }
const res = await comment.getSlideCaptchaData(); const res = await comment.getSlideCaptchaData();

View File

@@ -13,7 +13,7 @@
</div> </div>
<div class="landing-footer-content-right"> <div class="landing-footer-content-right">
<div class="landing-footer-content-right-left"> <div class="landing-footer-content-right-left">
<AQrcode :value="'https://git.landaiqing.cn'" :size="120" :bordered="false" <AQrcode :value="'3517283258'" :size="120" :bordered="false"
:icon="qq" :icon="qq"
:iconSize="20" :iconSize="20"
/> />

View File

@@ -2,8 +2,8 @@
<header class="header-main"> <header class="header-main">
<div class="header-container"> <div class="header-container">
<AFlex :vertical="false" align="center" justify="flex-end" class="header-logo-container"> <AFlex :vertical="false" align="center" justify="flex-end" class="header-logo-container">
<AAvatar :size="50" :src="logo"/> <AAvatar :size="50" shape="square" :src="logo" @click="router.push('/')"/>
<img style="width: 200px;" src="@/assets/images/logo.png" alt="logo"> <span class="header-logo-text" @click="router.push('/')">S.Album</span>
</AFlex> </AFlex>
<AFlex :vertical="false" align="center" justify="flex-end" class="header-menu-container"> <AFlex :vertical="false" align="center" justify="flex-end" class="header-menu-container">
<AFlex :vertical="false" align="center" justify="flex-start" class="header-menu-item"> <AFlex :vertical="false" align="center" justify="flex-start" class="header-menu-item">
@@ -34,7 +34,7 @@
</header> </header>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import logo from "@/assets/svgs/logo-schisandra.svg"; import logo from "@/assets/svgs/logo-album.svg";
import useStore from "@/store"; import useStore from "@/store";
import {BellOutlined, TranslationOutlined} from "@ant-design/icons-vue"; import {BellOutlined, TranslationOutlined} from "@ant-design/icons-vue";
import {h} from "vue"; import {h} from "vue";
@@ -43,6 +43,7 @@ import {useI18n} from "vue-i18n";
const user = useStore().user; const user = useStore().user;
const {t, locale} = useI18n(); const {t, locale} = useI18n();
const lang = useStore().lang; const lang = useStore().lang;
const router = useRouter();
/** /**
* 切换语言 * 切换语言

View File

@@ -23,6 +23,13 @@
justify-content: space-between; justify-content: space-between;
width: 1200px; width: 1200px;
max-width: 1200px; max-width: 1200px;
.header-logo-text {
margin-left: 10px;
font-size: 25px;
font-family: "Comic Sans MS", cursive;
font-weight: bolder;
}
} }
.header-logo-container { .header-logo-container {

View File

@@ -20,7 +20,7 @@ export const useCommentStore = defineStore(
const replyList = ref<Comment>({} as Comment); const replyList = ref<Comment>({} as Comment);
const commentMap = reactive<any>({}); const commentMap = reactive<any>({});
const slideCaptchaData = reactive({ const slideCaptchaData = reactive({
key: "", captKey: "",
image: "", image: "",
thumb: "", thumb: "",
thumbWidth: 0, thumbWidth: 0,
@@ -55,9 +55,11 @@ export const useCommentStore = defineStore(
if (result.code === 200 && result.data) { if (result.code === 200 && result.data) {
commentList.value = result.data; commentList.value = result.data;
commentLoading.value = false; commentLoading.value = false;
commentList.value.comments.forEach((item: any) => { if (Array.isArray(commentList.value.comments)) {
commentMap[item.id] = item; commentList.value.comments.map((item: any) => {
}); commentMap[item.id] = item;
});
}
} else { } else {
commentLoading.value = false; commentLoading.value = false;
} }
@@ -147,7 +149,7 @@ export const useCommentStore = defineStore(
const res: any = await getSlideCaptchaDataApi(); const res: any = await getSlideCaptchaDataApi();
if (res.code == 200 && res.data) { if (res.code == 200 && res.data) {
const {key, image, thumb, thumb_width, thumb_height, thumb_x, thumb_y} = res.data; const {key, image, thumb, thumb_width, thumb_height, thumb_x, thumb_y} = res.data;
slideCaptchaData.key = key; slideCaptchaData.captKey = key;
slideCaptchaData.image = image; slideCaptchaData.image = image;
slideCaptchaData.thumb = thumb; slideCaptchaData.thumb = thumb;
slideCaptchaData.thumbWidth = thumb_width; slideCaptchaData.thumbWidth = thumb_width;

View File

@@ -94,6 +94,7 @@
title: t('login.rotateCaptchaTitle'), title: t('login.rotateCaptchaTitle'),
}" }"
:events="resetPasswordRotateEvent" :events="resetPasswordRotateEvent"
:ref="resetPasswordRotate"
/> />
</AModal> </AModal>
<div class="area"> <div class="area">
@@ -127,10 +128,11 @@ import {useDebounceFn} from "@vueuse/core";
const router = useRouter(); const router = useRouter();
const {t} = useI18n(); const {t} = useI18n();
const resetPasswordRef = ref(); const resetPasswordRef = ref();
const captchaData = reactive({angle: 0, image: "", thumb: "", key: ""}); const captchaData = reactive({image: "", thumb: "", captKey: ""});
const showRotateCaptcha = ref<boolean>(false); const showRotateCaptcha = ref<boolean>(false);
const resetPasswordRotate = ref<any>(null);
const resetPasswordRotateEvent = { const resetPasswordRotateEvent = {
confirm: (angle: number) => { confirm: (angle: number, _reset: () => void) => {
checkPhoneLoginCaptcha(angle); checkPhoneLoginCaptcha(angle);
}, },
close: () => { close: () => {
@@ -176,7 +178,7 @@ const rules: Record<string, Rule[]> = {
}, },
], ],
repassword: [ repassword: [
{required: true,validator: validateRepassword, trigger: 'blur'} {required: true, validator: validateRepassword, trigger: 'blur'}
], ],
phone: [ phone: [
{required: true, message: t('login.phoneValidate'), trigger: 'blur'}, {required: true, message: t('login.phoneValidate'), trigger: 'blur'},
@@ -263,7 +265,7 @@ async function resetPasswordSubmit() {
const res: any = await resetPasswordApi(ResetPasswordForm); const res: any = await resetPasswordApi(ResetPasswordForm);
if (res.code === 200 && res.data) { if (res.code === 200 && res.data) {
message.success(t('login.resetPasswordSuccess')); message.success(t('login.resetPasswordSuccess'));
await router.push('/login'); router.push('/login');
} else { } else {
message.error(t('login.resetPasswordError')); message.error(t('login.resetPasswordError'));
} }
@@ -284,11 +286,10 @@ const refreshCaptcha = useDebounceFn(getRotateCaptcha, 3000);
async function getRotateCaptcha() { async function getRotateCaptcha() {
const data: any = await getRotatedCaptchaData(); const data: any = await getRotatedCaptchaData();
if (data.code === 200 && data.data) { if (data.code === 200 && data.data) {
const {angle, image, thumb, key} = data.data; const {image, thumb, key} = data.data;
captchaData.angle = angle;
captchaData.image = image; captchaData.image = image;
captchaData.thumb = thumb; captchaData.thumb = thumb;
captchaData.key = key; captchaData.captKey = key;
} else { } else {
message.error(t('login.systemError')); message.error(t('login.systemError'));
} }
@@ -314,7 +315,7 @@ async function sendMessageByPhone(param: any): Promise<boolean> {
*/ */
async function checkPhoneLoginCaptcha(angle: number) { async function checkPhoneLoginCaptcha(angle: number) {
const param = { const param = {
key: captchaData.key, key: captchaData.captKey,
angle: angle, angle: angle,
phone: ResetPasswordForm.phone, phone: ResetPasswordForm.phone,
}; };

View File

@@ -5,13 +5,13 @@
<AButton href="/qrlogin" class="login-form-bottom-button" :icon="h(QrcodeOutlined)">{{ t("login.qrLogin") }} <AButton href="/qrlogin" class="login-form-bottom-button" :icon="h(QrcodeOutlined)">{{ t("login.qrLogin") }}
</AButton> </AButton>
<AButton @click="userStore.openQQUrl" class="login-form-bottom-button" :icon="h(QqOutlined)"></AButton> <AButton @click="userStore.openQQUrl" class="login-form-bottom-button" :icon="h(QqOutlined)"></AButton>
<AButton @click="userStore.openGithubUrl" class="login-form-bottom-button" <AButton @click="userStore.openGiteeUrl" class="login-form-bottom-button"
style="display: flex; align-items: center;justify-content: center;"> style="display: flex; align-items: center;justify-content: center;">
<template #icon> <template #icon>
<img :src=gitee alt="gitee" class="gitee-icon" style="width: 16px; height: 16px;"/> <img :src=gitee alt="gitee" class="gitee-icon" style="width: 16px; height: 16px;"/>
</template> </template>
</AButton> </AButton>
<AButton @click="userStore.openGiteeUrl" class="login-form-bottom-button" :icon="h(GithubOutlined)"></AButton> <AButton @click="userStore.openGithubUrl" class="login-form-bottom-button" :icon="h(GithubOutlined)"></AButton>
</AFlex> </AFlex>
</div> </div>
</template> </template>

View File

@@ -153,6 +153,8 @@
title: t('login.rotateCaptchaTitle'), title: t('login.rotateCaptchaTitle'),
}" }"
:events="phoneLoginRotateEvent" :events="phoneLoginRotateEvent"
:ref="phoneLoginRotateRef"
/> />
</AModal> </AModal>
<AModal v-model:open="showAccountRotateCaptcha" :footer="null" :closable="false" width="375" :centered="true" <AModal v-model:open="showAccountRotateCaptcha" :footer="null" :closable="false" width="375" :centered="true"
@@ -166,6 +168,7 @@
title: t('login.rotateCaptchaTitle'), title: t('login.rotateCaptchaTitle'),
}" }"
:events="accountLoginRotateEvent" :events="accountLoginRotateEvent"
:ref="accountLoginRotateRef"
/> />
</AModal> </AModal>
@@ -206,11 +209,14 @@ const accountLoginFormRef = ref<any>();
const phoneLoginFormRef = ref<any>(); const phoneLoginFormRef = ref<any>();
const showPhoneRotateCaptcha = ref<boolean>(false); const showPhoneRotateCaptcha = ref<boolean>(false);
const showAccountRotateCaptcha = ref<boolean>(false); const showAccountRotateCaptcha = ref<boolean>(false);
const captchaData = reactive({angle: 0, image: "", thumb: "", key: ""}); const captchaData = reactive({image: "", thumb: "", captKey: ""});
const loginLoading = ref<boolean>(false); const loginLoading = ref<boolean>(false);
const userStore = useStore().user; const userStore = useStore().user;
const phoneLoginRotateRef = ref<any>(null);
const accountLoginRotateRef = ref<any>(null);
const phoneLoginRotateEvent = { const phoneLoginRotateEvent = {
confirm: (angle: number) => { confirm: (angle: number, _reset: () => void) => {
checkPhoneLoginCaptchaDebounce(angle); checkPhoneLoginCaptchaDebounce(angle);
}, },
close: () => { close: () => {
@@ -410,13 +416,18 @@ const refreshCaptcha = useThrottleFn(getRotateCaptcha, 3000);
* 获取旋转验证码数据 * 获取旋转验证码数据
*/ */
async function getRotateCaptcha() { async function getRotateCaptcha() {
if (phoneLoginRotateRef.value) {
phoneLoginRotateRef.value?.clear();
}
if (accountLoginRotateRef.value) {
accountLoginRotateRef.value?.clear();
}
const data: any = await getRotatedCaptchaData(); const data: any = await getRotatedCaptchaData();
if (data.code === 200 && data.data) { if (data.code === 200 && data.data) {
const {angle, image, thumb, key} = data.data; const {image, thumb, key} = data.data;
captchaData.angle = angle;
captchaData.image = image; captchaData.image = image;
captchaData.thumb = thumb; captchaData.thumb = thumb;
captchaData.key = key; captchaData.captKey = key;
} else { } else {
message.error(t('login.systemError')); message.error(t('login.systemError'));
} }
@@ -435,7 +446,7 @@ async function checkPhoneLoginCaptcha(angle: number) {
const params = { const params = {
phone: phoneLoginForm.phone, phone: phoneLoginForm.phone,
angle: angle, angle: angle,
key: captchaData.key, key: captchaData.captKey,
}; };
const result: boolean = await sendMessageByPhone(params); const result: boolean = await sendMessageByPhone(params);
if (result) { if (result) {
@@ -457,7 +468,7 @@ async function checkAccountLoginCaptcha(angle: number) {
const params = { const params = {
...accountLoginForm, ...accountLoginForm,
angle: angle, angle: angle,
key: captchaData.key, key: captchaData.captKey,
}; };
loginLoading.value = true; loginLoading.value = true;
const res: any = await accountLoginApi(params); const res: any = await accountLoginApi(params);

View File

@@ -61,7 +61,7 @@ import QRLoginFooter from "@/views/QRLogin/QRLoginFooter.vue";
import {useRouter} from 'vue-router'; import {useRouter} from 'vue-router';
import {generateQrCode} from "@/api/oauth/wechat.ts"; import {generateQrCode} from "@/api/oauth/wechat.ts";
import {onBeforeUnmount, onMounted, ref} from "vue"; import {onBeforeUnmount, onMounted, ref} from "vue";
import logo from "@/assets/svgs/logo-schisandra.svg"; import logo from "@/assets/svgs/logo-album.svg";
import useStore from "@/store"; import useStore from "@/store";
import {message} from "ant-design-vue"; import {message} from "ant-design-vue";

View File

@@ -77,7 +77,7 @@
margin-bottom: 24px; margin-bottom: 24px;
.qrlogin-card-wechat { .qrlogin-card-wechat {
color: #7acc35; color: rgba(77, 167, 255, 0.89);
margin-left: 4px; margin-left: 4px;
margin-right: 4px; margin-right: 4px;
cursor: pointer; cursor: pointer;

View File

@@ -61,7 +61,7 @@ export default defineConfig(({mode}: { mode: string }): object => {
} }
}, },
optimizeDeps: { optimizeDeps: {
exclude: ["vite", ".vite"], exclude: [".vite","node_modules/.vite/deps"],
force: true, force: true,
}, },
plugins: [ plugins: [