feat:财务和合同

This commit is contained in:
李伊帆
2026-11-05 13:50:25 +08:00
parent b0a711f70a
commit 31fcd273f1
173 changed files with 11040 additions and 1067 deletions

View File

@@ -1,22 +1,56 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { FEEDBACK_DESCRIPTION_MAX_LENGTH } from '@/constants/feedback'
import { submitFeedback } from '@/api/feedback'
import { uploadRequirementAttachment } from '@/api/requirement'
import { getOssListByIds } from '@/api/oss'
import {
FEEDBACK_ATTACHMENT_MAX_COUNT,
FEEDBACK_DESCRIPTION_MAX_LENGTH,
} from '@/constants/feedback'
import deleteIcon from '@/static/icons/X.png'
import pdfIcon from '@/static/icons/PDF.png'
import pngIcon from '@/static/icons/PNG.png'
import { ensureLoggedIn } from '@/utils/auth-guard'
import { chooseLocalFiles } from '@/utils/choose-local-files'
import { navigateBackWithFallback } from '@/utils/navigate-back'
interface FeedbackAttachmentItem {
id: string
name: string
icon: string
url: string
}
const title = ref('')
const description = ref('')
const attachments = ref([
{ id: '1', name: '需求文档.pdf', icon: pdfIcon },
{ id: '2', name: '系统....pdf', icon: pdfIcon },
{ id: '3', name: '参考图.png', icon: pngIcon },
])
const attachments = ref<FeedbackAttachmentItem[]>([])
const uploadingAttachment = ref(false)
const submitting = ref(false)
const descLength = computed(() => description.value.length)
function resolveAttachmentIcon(name: string) {
const ext = name.split('.').pop()?.toLowerCase() || ''
if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'].includes(ext))
return pngIcon
return pdfIcon
}
async function resolveUploadUrl(
uploaded: { url?: string, ossId?: string | number, id?: string | number },
) {
const direct = uploaded.url?.trim()
if (direct)
return direct
const ossId = uploaded.ossId ?? uploaded.id
if (ossId === undefined || ossId === null || ossId === '')
return ''
const files = await getOssListByIds([ossId])
return files[0]?.url?.trim() || ''
}
function handleBack() {
navigateBackWithFallback('/pages/personal-center/index')
}
@@ -25,21 +59,68 @@ function handleRemoveAttachment(id: string) {
attachments.value = attachments.value.filter(item => item.id !== id)
}
function handleAddAttachment() {
uni.showToast({ title: '附件上传开发中', icon: 'none' })
async function handleAddAttachment() {
if (!ensureLoggedIn())
return
if (uploadingAttachment.value)
return
const remain = FEEDBACK_ATTACHMENT_MAX_COUNT - attachments.value.length
if (remain <= 0) {
uni.showToast({ title: `最多上传${FEEDBACK_ATTACHMENT_MAX_COUNT}个附件`, icon: 'none' })
return
}
try {
const files = await chooseLocalFiles(remain)
if (!files.length)
return
uploadingAttachment.value = true
uni.showLoading({ title: '上传中...', mask: true })
for (const file of files) {
const uploaded = await uploadRequirementAttachment(file.path)
const url = await resolveUploadUrl(uploaded)
if (!url) {
uni.showToast({ title: '上传失败,未返回附件地址', icon: 'none' })
continue
}
const name = uploaded.fileName || file.name
attachments.value.push({
id: String(uploaded.ossId ?? uploaded.id ?? `${Date.now()}-${attachments.value.length}`),
name,
icon: resolveAttachmentIcon(name),
url,
})
}
}
catch (error) {
const message = error instanceof Error ? error.message : '上传失败'
if (!/cancel/i.test(message))
uni.showToast({ title: message, icon: 'none' })
}
finally {
uploadingAttachment.value = false
uni.hideLoading()
}
}
function handleReset() {
title.value = ''
description.value = ''
attachments.value = [
{ id: '1', name: '需求文档.pdf', icon: pdfIcon },
{ id: '2', name: '系统....pdf', icon: pdfIcon },
{ id: '3', name: '参考图.png', icon: pngIcon },
]
attachments.value = []
}
function handleSubmit() {
async function handleSubmit() {
if (submitting.value || uploadingAttachment.value)
return
if (!ensureLoggedIn())
return
if (!title.value.trim()) {
uni.showToast({ title: '请输入反馈标题', icon: 'none' })
return
@@ -49,10 +130,29 @@ function handleSubmit() {
return
}
uni.showToast({ title: '提交成功', icon: 'none' })
setTimeout(() => {
uni.navigateBack()
}, 1500)
submitting.value = true
uni.showLoading({ title: '提交中...', mask: true })
try {
const urls = attachments.value.map(item => item.url).filter(Boolean)
await submitFeedback({
title: title.value.trim(),
content: description.value.trim(),
// OpenAPI 定义为 string,不能直接传数组,否则会 400「请求参数格式错误」
attachments: urls.length ? JSON.stringify(urls) : undefined,
})
uni.showToast({ title: '提交成功', icon: 'success' })
setTimeout(() => {
uni.navigateBack()
}, 1200)
}
catch {
// 错误提示由 request 统一处理
}
finally {
submitting.value = false
uni.hideLoading()
}
}
</script>
@@ -107,7 +207,7 @@ function handleSubmit() {
附件上传
</text>
<text class="feedback__hint">
支持图片/文档/压缩包
支持图片/文档/压缩包,最多{{ FEEDBACK_ATTACHMENT_MAX_COUNT }}个
</text>
</view>
<view class="feedback__attachment-row">
@@ -136,6 +236,7 @@ function handleSubmit() {
</text>
</view>
<view
v-if="attachments.length < FEEDBACK_ATTACHMENT_MAX_COUNT"
class="feedback__attachment-add"
@tap="handleAddAttachment"
>