修改提交任务

This commit is contained in:
WindowBird 2025-11-05 15:56:46 +08:00
parent 62d84fcc38
commit 3d0ea8cc69
2 changed files with 128 additions and 28 deletions

View File

@ -13,7 +13,7 @@
<view class="form-item">
<view class="form-icon"></view>
<textarea
v-model="formData.description"
v-model="formData.description"
class="description-input"
placeholder="输入提交说明"
placeholder-style="color: #999;"
@ -112,7 +112,7 @@
:disabled="!canSubmit"
@click="handleSubmit"
>
确认提交
{{ isEditMode ? '确认更新' : '确认提交' }}
</uv-button>
</view>
</view>
@ -132,6 +132,10 @@ const formData = ref({
// ID
const taskId = ref(null);
//
const isEditMode = ref(false);
const editRecordIndex = ref(-1);
const editRecordData = ref(null);
//
const showProgressPicker = ref(false);
@ -156,6 +160,42 @@ const canSubmit = computed(() => {
//
onLoad((options) => {
taskId.value = options.taskId || options.id;
//
if (options.mode === 'edit' || options.recordIndex !== undefined) {
isEditMode.value = true;
editRecordIndex.value = parseInt(options.recordIndex || -1);
//
const editData = uni.getStorageSync('editSubmitRecord');
if (editData && editData.record) {
editRecordData.value = editData.record;
//
formData.value.description = editData.record.content || '';
formData.value.progress = editData.record.progress !== null && editData.record.progress !== undefined
? editData.record.progress
: null;
//
if (editData.record.attachments && editData.record.attachments.length > 0) {
editData.record.attachments.forEach(attachment => {
if (attachment.type === 'image' && attachment.path) {
formData.value.images.push(attachment.path);
} else if (attachment.type === 'file') {
formData.value.files.push({
name: attachment.name || '文件',
path: attachment.path || '',
size: attachment.size || 0
});
}
});
}
//
uni.removeStorageSync('editSubmitRecord');
}
}
});
//
@ -374,7 +414,7 @@ const handleSubmit = () => {
}
uni.showLoading({
title: '提交中...'
title: isEditMode.value ? '更新中...' : '提交中...'
});
//
@ -393,8 +433,8 @@ const handleSubmit = () => {
// TODO:
// 使API
// uni.request({
// url: '/api/task/submit',
// method: 'POST',
// url: isEditMode.value ? '/api/task/submit/update' : '/api/task/submit',
// method: isEditMode.value ? 'PUT' : 'POST',
// data: submitData,
// success: (res) => {
// //
@ -408,27 +448,54 @@ const handleSubmit = () => {
setTimeout(() => {
uni.hideLoading();
//
const submitRecord = {
userName: '当前用户', // TODO:
time: formatTimeToChinese(new Date()),
content: submitData.description || '',
progress: submitData.progress,
attachments: [
...submitData.images.map(img => ({ type: 'image', path: img })),
...submitData.files.map(file => ({ type: 'file', name: file.name, path: file.path }))
],
canEdit: true,
showDelayBtn: false
};
if (isEditMode.value) {
//
const updatedRecord = {
userName: editRecordData.value?.userName || '当前用户', //
time: formatTimeToChinese(new Date()), //
content: submitData.description || '',
progress: submitData.progress,
attachments: [
...submitData.images.map(img => ({ type: 'image', path: img })),
...submitData.files.map(file => ({ type: 'file', name: file.name, path: file.path }))
],
canEdit: true, //
showDelayBtn: editRecordData.value?.showDelayBtn || false
};
// 使
uni.setStorageSync('newSubmitRecord', submitRecord);
// 使
uni.setStorageSync('updatedSubmitRecord', {
recordIndex: editRecordIndex.value,
record: updatedRecord
});
uni.showToast({
title: '提交成功',
icon: 'success'
});
uni.showToast({
title: '更新成功',
icon: 'success'
});
} else {
//
const submitRecord = {
userName: '当前用户', // TODO:
time: formatTimeToChinese(new Date()),
content: submitData.description || '',
progress: submitData.progress,
attachments: [
...submitData.images.map(img => ({ type: 'image', path: img })),
...submitData.files.map(file => ({ type: 'file', name: file.name, path: file.path }))
],
canEdit: true,
showDelayBtn: false
};
// 使
uni.setStorageSync('newSubmitRecord', submitRecord);
uni.showToast({
title: '提交成功',
icon: 'success'
});
}
//
setTimeout(() => {

View File

@ -225,10 +225,28 @@ const closeMenu = () => {
//
const editRecord = (index) => {
uni.showToast({
title: '编辑记录',
icon: 'none'
const record = task.value.submitRecords[index];
if (!record) {
uni.showToast({
title: '记录不存在',
icon: 'none'
});
showMenuIndex.value = -1;
return;
}
// 使
uni.setStorageSync('editSubmitRecord', {
recordIndex: index,
record: record,
taskId: task.value.id
});
//
uni.navigateTo({
url: `/pages/submit-task/index?taskId=${task.value.id}&mode=edit&recordIndex=${index}`
});
showMenuIndex.value = -1;
};
@ -353,8 +371,9 @@ onLoad((options) => {
}
});
//
//
onShow(() => {
//
const newSubmitRecord = uni.getStorageSync('newSubmitRecord');
if (newSubmitRecord) {
//
@ -364,6 +383,20 @@ onShow(() => {
//
uni.removeStorageSync('newSubmitRecord');
}
//
const updatedSubmitRecord = uni.getStorageSync('updatedSubmitRecord');
if (updatedSubmitRecord) {
const { recordIndex, record } = updatedSubmitRecord;
if (recordIndex !== undefined && recordIndex >= 0 && recordIndex < task.value.submitRecords.length) {
//
task.value.submitRecords[recordIndex] = record;
//
activeTab.value = 'records';
}
//
uni.removeStorageSync('updatedSubmitRecord');
}
});
</script>