优化
This commit is contained in:
parent
c6c6df9c57
commit
4cc94e2132
@ -28,9 +28,10 @@ export const addDemand = async (demandData) => {
|
|||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
...demandData,
|
...demandData,
|
||||||
content: demandData.sendcontent // 确保 content 与 sendcontent 一致
|
content: demandData.content // 直接使用传入的 content
|
||||||
};
|
};
|
||||||
const response = await axiosInstance.post('/demands/add', payload);
|
const response = await axiosInstance.post('/demands/add', payload);
|
||||||
|
console.log('添加需求的数据:', payload);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('添加需求失败:', error);
|
console.error('添加需求失败:', error);
|
||||||
@ -50,13 +51,13 @@ export const updateDemand = async (id, dataToUpdate) => {
|
|||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
sendcontent: dataToUpdate.sendcontent,
|
sendcontent: dataToUpdate.sendcontent,
|
||||||
// 根据 DemandModel,补齐其他必填或可选字段,即使它们不被后端 update 逻辑使用
|
|
||||||
requester: dataToUpdate.requester || '',
|
requester: dataToUpdate.requester || '',
|
||||||
qq_code: dataToUpdate.qq_code || '',
|
qq_code: dataToUpdate.qq_code || '',
|
||||||
content: dataToUpdate.sendcontent, // 保持一致
|
content: dataToUpdate.content || '', // 直接使用传入的 content,如果为空则使用空字符串
|
||||||
reward: dataToUpdate.reward || '',
|
reward: dataToUpdate.reward || '',
|
||||||
date: dataToUpdate.date || new Date().toISOString().slice(0, 19).replace('T', ' ') // 确保有日期
|
date: dataToUpdate.date || new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||||
};
|
};
|
||||||
|
console.log('更新需求的数据:', payload);
|
||||||
const response = await axiosInstance.put(`/demands/update/${id}`, payload);
|
const response = await axiosInstance.put(`/demands/update/${id}`, payload);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
<td>{{ demand.reward || '无赏金' }}</td>
|
<td>{{ demand.reward || '无赏金' }}</td>
|
||||||
<td>{{ formatDate(demand.date) }}</td>
|
<td>{{ formatDate(demand.date) }}</td>
|
||||||
<td>
|
<td>
|
||||||
<!-- <button @click="editDemand(demand)" class="action-button edit">编辑</button>-->
|
<button @click="editDemand(demand)" class="action-button edit">编辑</button>
|
||||||
<!-- <button @click="confirmDeleteDemand(demand.id)" class="action-button delete">删除</button>-->
|
<button @click="confirmDeleteDemand(demand.id)" class="action-button delete">删除</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -62,7 +62,7 @@ export const logoutUser = () => { // 不再是 async,因为它不执行异步
|
|||||||
// console.log('jwt.js: logoutUser called. Clearing local storage.');
|
// console.log('jwt.js: logoutUser called. Clearing local storage.');
|
||||||
localStorage.removeItem('access_token');
|
localStorage.removeItem('access_token');
|
||||||
localStorage.removeItem('user_id');
|
localStorage.removeItem('user_id');
|
||||||
sessionStorage.removeItem('currentUser'); // 同时清除sessionStorage中的用户信息
|
//sessionStorage.removeItem('currentUser'); // 同时清除sessionStorage中的用户信息
|
||||||
// 导航将由调用者(如路由守卫)处理
|
// 导航将由调用者(如路由守卫)处理
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,9 +172,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<span class="label">QQ号:</span>
|
<span class="label">QQ号:</span>
|
||||||
<input v-model="addForm.qq_code" class="input" placeholder="可选" />
|
<input
|
||||||
|
v-model="addForm.qq_code"
|
||||||
|
class="input"
|
||||||
|
placeholder="可选"
|
||||||
|
@input="validateQQ"
|
||||||
|
type="text"
|
||||||
|
pattern="[0-9]*"
|
||||||
|
inputmode="numeric"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<span class="label">需求内容:</span>
|
<span class="label">需求内容:</span>
|
||||||
<textarea
|
<textarea
|
||||||
@ -303,8 +310,18 @@ const closeModal = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
const openAddModal = (demand) => {
|
const openAddModal = () => {
|
||||||
reply.value = demand;
|
// 重置表单数据
|
||||||
|
addForm.value = {
|
||||||
|
requester: '',
|
||||||
|
content: '',
|
||||||
|
reward: '',
|
||||||
|
qq_code: '',
|
||||||
|
sendcontent: '',
|
||||||
|
author: '',
|
||||||
|
author_contact: ''
|
||||||
|
};
|
||||||
|
addError.value = '';
|
||||||
showAddModal.value = true;
|
showAddModal.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,12 +331,25 @@ function closeAddModal() {
|
|||||||
addError.value = ''
|
addError.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
//提交表单
|
// 在 script setup 部分添加验证函数
|
||||||
|
const validateQQ = (event) => {
|
||||||
|
// 只保留数字
|
||||||
|
addForm.value.qq_code = event.target.value.replace(/[^\d]/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改 submitAddForm 函数,添加 QQ 号验证
|
||||||
async function submitAddForm() {
|
async function submitAddForm() {
|
||||||
if (!addForm.value.content?.trim()) {
|
if (!addForm.value.content?.trim()) {
|
||||||
addError.value = '需求内容不能为空';
|
addError.value = '需求内容不能为空';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果填写了QQ号,验证是否为纯数字
|
||||||
|
if (addForm.value.qq_code && !/^\d+$/.test(addForm.value.qq_code)) {
|
||||||
|
addError.value = 'QQ号必须为纯数字';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
addLoading.value = true;
|
addLoading.value = true;
|
||||||
addError.value = '';
|
addError.value = '';
|
||||||
try {
|
try {
|
||||||
|
@ -301,7 +301,16 @@ const changePage = (page) => {
|
|||||||
|
|
||||||
// 跳转到地图详情
|
// 跳转到地图详情
|
||||||
const goToMapDetail = (id) => {
|
const goToMapDetail = (id) => {
|
||||||
sessionStorage.setItem('maps_view_mode', viewMode.value)
|
// 保存当前状态
|
||||||
|
const state = {
|
||||||
|
viewMode: viewMode.value,
|
||||||
|
currentPage: currentPage.value,
|
||||||
|
searchValue: searchValue.value,
|
||||||
|
playerCountFilter: playerCountFilter.value,
|
||||||
|
tagFilter: tagFilter.value,
|
||||||
|
selectedOrder: selectedOrder.value
|
||||||
|
}
|
||||||
|
sessionStorage.setItem('maps_state', JSON.stringify(state))
|
||||||
router.push(`/map/${id}`)
|
router.push(`/map/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,13 +333,26 @@ const scrollToTop = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const savedMode = sessionStorage.getItem('maps_view_mode')
|
// 恢复保存的状态
|
||||||
if (savedMode) {
|
const savedState = sessionStorage.getItem('maps_state')
|
||||||
viewMode.value = savedMode
|
if (savedState) {
|
||||||
} else if (window.innerWidth <= 700) {
|
const state = JSON.parse(savedState)
|
||||||
viewMode.value = 'card'
|
viewMode.value = state.viewMode
|
||||||
|
currentPage.value = state.currentPage
|
||||||
|
searchValue.value = state.searchValue
|
||||||
|
playerCountFilter.value = state.playerCountFilter
|
||||||
|
tagFilter.value = state.tagFilter
|
||||||
|
selectedOrder.value = state.selectedOrder
|
||||||
|
// 使用保存的状态重新获取数据
|
||||||
|
fetchMaps(currentPage.value)
|
||||||
|
} else {
|
||||||
|
// 如果没有保存的状态,根据屏幕宽度设置视图模式
|
||||||
|
if (window.innerWidth <= 700) {
|
||||||
|
viewMode.value = 'card'
|
||||||
|
}
|
||||||
|
fetchMaps(1)
|
||||||
}
|
}
|
||||||
fetchMaps(1)
|
|
||||||
getAllTags().then(tags => {
|
getAllTags().then(tags => {
|
||||||
tagOptions.value = tags
|
tagOptions.value = tags
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user