优化部分代码

This commit is contained in:
Kunagisa 2025-06-14 00:40:50 +08:00
parent c21fd11637
commit 8c69f3c29f
2 changed files with 133 additions and 36 deletions

View File

@ -1,7 +1,3 @@
import { ref } from 'vue'; import { ref } from 'vue';
// This flag is used by the router guard to know if a navigation
// is occurring immediately after a successful login.
// If true, the guard can choose to bypass an immediate session check (e.g., getUserInfo)
// for that first navigation, assuming the new token is valid.
export const justLoggedIn = ref(false); export const justLoggedIn = ref(false);

View File

@ -42,6 +42,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<!-- 回复查看表单联系方式昵称相关建议--> <!-- 回复查看表单联系方式昵称相关建议-->
<div v-if="replyModal" class="modal-overlay" @click="closeReplyModal"> <div v-if="replyModal" class="modal-overlay" @click="closeReplyModal">
<div class="modal-content" @click.stop> <div class="modal-content" @click.stop>
@ -51,6 +52,24 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form class="add-modal-form" @submit.prevent="submitReply"> <form class="add-modal-form" @submit.prevent="submitReply">
<div class="form-row">
<span class="label">昵称</span>
<input
v-model="addForm.author"
class="input"
placeholder="请输入您的昵称"
required
/>
</div>
<div class="form-row">
<span class="label">QQ号</span>
<input
v-model="addForm.author_contact"
class="input"
placeholder="请输入您的QQ号"
required
/>
</div>
<div class="form-row"> <div class="form-row">
<span class="label">相关建议</span> <span class="label">相关建议</span>
<textarea <textarea
@ -60,6 +79,7 @@
rows="3" rows="3"
ref="autoTextarea" ref="autoTextarea"
@input="autoResize" @input="autoResize"
required
></textarea> ></textarea>
</div> </div>
<div v-if="addError" class="error">{{ addError }}</div> <div v-if="addError" class="error">{{ addError }}</div>
@ -118,7 +138,14 @@
</div> </div>
<div v-else class="no-reply"> <div v-else class="no-reply">
<div v-if="selectedDemand?.sendcontent"> <div v-if="selectedDemand?.sendcontent">
<div class="reply-content">{{ selectedDemand.sendcontent }}</div> <div v-for="(reply, index) in selectedDemand.sendcontent.split('|')" :key="index" class="reply-content">
<div class="reply-with-avatar">
<img :src="`https://q1.qlogo.cn/g?b=qq&nk=${reply.match(/\((\d+)\)/)?.[1] || ''}&s=40`" alt="User Avatar" class="reply-avatar" />
<div class="reply-text">
<b>{{ reply.split(')')[0] + '' }}</b>{{ reply.split(')')[1] }}
</div>
</div>
</div>
</div> </div>
<div v-else> <div v-else>
暂无回复 暂无回复
@ -193,7 +220,9 @@ const addForm = ref({
content: '', content: '',
reward: '', reward: '',
qq_code: '', qq_code: '',
sendcontent: '' sendcontent: '',
author: '',
author_contact: ''
}) })
const addLoading = ref(false) const addLoading = ref(false)
const autoTextarea = ref(null) const autoTextarea = ref(null)
@ -239,9 +268,25 @@ const showReply = (demand) => {
reply.value = demand reply.value = demand
replyModal.value = true replyModal.value = true
} }
// //
const closeReplyModal = () => { const closeReplyModal = () => {
replyModal.value = false replyModal.value = false;
resetReplyForm();
}
//
const resetReplyForm = () => {
addForm.value = {
sendcontent: '',
author: '',
author_contact: ''
};
addError.value = '';
//
if (autoTextarea.value) {
autoTextarea.value.style.height = 'auto';
}
} }
// //
@ -257,16 +302,10 @@ const closeModal = () => {
} }
// //
function openAddModal() { const openAddModal = (demand) => {
addForm.value = { reply.value = demand;
requester: '', replyModal.value = true;
content: '', resetReplyForm();
reward: '',
qq_code: '',
sendcontent: ''
}
addError.value = ''
showAddModal.value = true
} }
// //
@ -313,27 +352,47 @@ const submitReply = async () => {
addError.value = '回复内容不能为空'; addError.value = '回复内容不能为空';
return; return;
} }
if (!addForm.value.author?.trim()) {
addError.value = '昵称不能为空';
return;
}
if (!addForm.value.author_contact?.trim()) {
addError.value = 'QQ号不能为空';
return;
}
// QQ
if (!/^\d+$/.test(addForm.value.author_contact)) {
addError.value = 'QQ号必须为纯数字';
return;
}
addLoading.value = true; addLoading.value = true;
addError.value = ''; addError.value = '';
try { try {
const now = new Date(); const now = new Date();
const dateStr = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2,'0')}-${now.getDate().toString().padStart(2,'0')} ${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}:${now.getSeconds().toString().padStart(2,'0')}`; const dateStr = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2,'0')}-${now.getDate().toString().padStart(2,'0')} ${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}:${now.getSeconds().toString().padStart(2,'0')}`;
//
const newReply = `${addForm.value.author}(${addForm.value.author_contact})${addForm.value.sendcontent}`;
const formattedContent = reply.value.sendcontent
? `${reply.value.sendcontent}|${newReply}`
: newReply;
const payload = { const payload = {
requester: reply.value.requester || '', requester: reply.value.requester || '',
sendcontent: addForm.value.sendcontent, sendcontent: formattedContent,
content: reply.value.content, content: reply.value.content,
reward: reply.value.reward || '', reward: reply.value.reward || '',
date: dateStr, date: dateStr,
qq_code: reply.value.qq_code || '' qq_code: reply.value.qq_code || '',
author: addForm.value.author,
author_contact: addForm.value.author_contact
}; };
console.log('提交的回复数据:', payload); console.log('提交的回复数据:', payload);
await updateDemand(reply.value.id, payload); await updateDemand(reply.value.id, payload);
replyModal.value = false; replyModal.value = false;
addForm.value.sendcontent = ''; resetReplyForm();
if (autoTextarea.value) {
autoTextarea.value.style.height = 'auto';
}
fetchDemands(); // fetchDemands(); //
} catch (e) { } catch (e) {
console.error('提交回复失败:', e); console.error('提交回复失败:', e);
@ -641,15 +700,15 @@ function autoResize() {
} }
.reply-list { .reply-list {
max-height: 300px; background: none;
overflow-y: auto; border-radius: 0;
padding: 0 0 0 0;
} }
.reply-item { .reply-item {
background: #f7faff; background: none;
border-radius: 8px; border-radius: 0;
padding: 15px; padding: 0 0 0 0;
margin-bottom: 15px;
} }
.reply-header { .reply-header {
@ -693,4 +752,46 @@ function autoResize() {
background: transparent; background: transparent;
box-shadow: none; box-shadow: none;
} }
.reply-with-avatar {
display: flex;
align-items: flex-start;
gap: 8px;
margin-bottom: 16px;
}
.reply-with-avatar:last-child {
margin-bottom: 0;
}
.reply-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
border: none;
object-fit: cover;
flex-shrink: 0;
background: #f3f6fa;
}
.reply-text {
flex: 1;
display: flex;
align-items: center;
min-height: 40px;
font-size: 15px;
color: #222;
line-height: 1.7;
padding-left: 14px;
background: none;
border-radius: 0;
box-shadow: none;
}
.reply-text b {
font-weight: 600;
margin-right: 6px;
color: #2563eb;
font-size: 15px;
}
</style> </style>