From 342807749b5df25f111f4d9488f60a4a70c52be7 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Sat, 31 Oct 2026 12:38:22 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 8 +- src/pages/human-face/apply.vue | 13 +- src/pages/integrated/feedback/index.vue | 16 +- src/pages/integrated/repair/index.vue | 17 +- src/pages/prosperity-shop/categary-manage.vue | 5 +- src/pages/prosperity-shop/goods-form.vue | 15 +- src/pages/refund/apply.vue | 9 +- .../rich-text-editor/rich-text-editor.vue | 7 +- src/sheep/utils/file-access-core.ts | 22 +- src/sheep/utils/file-access.ts | 14 +- src/sheep/utils/file-upload.ts | 67 ++++ .../tm-upload-photo/tm-upload-photo.vue | 12 +- .../tm-upload-video/tm-upload-video.vue | 11 +- tests/file-upload-flow.test.cjs | 300 ++++++++++++++++++ 14 files changed, 455 insertions(+), 61 deletions(-) create mode 100644 src/sheep/utils/file-upload.ts create mode 100644 tests/file-upload-flow.test.cjs diff --git a/.env b/.env index c647c59..0ed20e9 100644 --- a/.env +++ b/.env @@ -25,16 +25,16 @@ VITE_OAUTH2_APP_CLIENT='mini:mini' # VITE_ZZD_CORP_ID= # --------------------------- 开发环境 api地址 ---------------------------------- -# VITE_APP_DEV_SERVICE = https://www.pjzhhq.cn/api # 域名线上 +VITE_APP_DEV_SERVICE = https://www.pjzhhq.cn/api # 域名线上 #VITE_APP_DEV_SERVICE = http://59.202.170.152:81/api # 信创线上 - VITE_APP_DEV_SERVICE = https://dzc-test-1.fy.takin.cc # 邓-本地 +# VITE_APP_DEV_SERVICE = https://dzc-test-1.fy.takin.cc # 邓-本地 # VITE_APP_DEV_SERVICE = http://127.0.0.1:9999 # 邓-本地 # VITE_APP_DEV_SERVICE = http://123.157.250.162:8089/api # 测试线上 # --------------------------- 开发环境 图片访问基础地址 --------------------------- -# VITE_IMAGE_DEV_PATH = https://www.pjzhhq.cn/api # 域名线上 +VITE_IMAGE_DEV_PATH = https://www.pjzhhq.cn/api # 域名线上 #VITE_IMAGE_DEV_PATH = http://59.202.170.152:81/api # 信创线上 -VITE_IMAGE_DEV_PATH = https://dzc-test-1.fy.takin.cc # 邓-本地 +# VITE_IMAGE_DEV_PATH = https://dzc-test-1.fy.takin.cc # 邓-本地 # VITE_IMAGE_DEV_PATH = http://127.0.0.1:9999 # VITE_IMAGE_DEV_PATH = http://123.157.250.162:8089/api # 测试线上 diff --git a/src/pages/human-face/apply.vue b/src/pages/human-face/apply.vue index 0c8d72d..389a7b3 100644 --- a/src/pages/human-face/apply.vue +++ b/src/pages/human-face/apply.vue @@ -7,6 +7,7 @@ import { hooks, router } from "@@/index" import { faceApi } from "@@/api" import { filePath } from "@@/utils/file" +import { uploadedFileUrl } from "@@/utils/file-upload" const state = reactive({ detailType: "add", @@ -45,13 +46,8 @@ const getDetail = async () => { } const beforeComplete = (uploadFile: any) => { - if (JSON.parse(uploadFile.data).code == 0) { - uploadFileUrl.value = JSON.parse(uploadFile.data).data.url - return true - } else { - uploadFileUrl.value = "" - return false - } + uploadFileUrl.value = uploadedFileUrl({ response: uploadFile.data }) + return !!uploadFileUrl.value } const applyFormRef = ref(null) @@ -59,6 +55,9 @@ const doSubmit = async () => { applyFormRef.value.submit() const { isPass } = applyFormRef.value.validate() if (!isPass || !uploadFileUrl.value) return + if (applyForm.faceImg.some((item: any) => item?.status !== undefined && item.status !== 2)) { + return uni.showToast({ title: "请先完成人脸图片上传", icon: "none" }) + } try { uni.showLoading({ title: "提交中...", mask: false }) const { data, code }: any = diff --git a/src/pages/integrated/feedback/index.vue b/src/pages/integrated/feedback/index.vue index 083855d..12c4953 100644 --- a/src/pages/integrated/feedback/index.vue +++ b/src/pages/integrated/feedback/index.vue @@ -95,6 +95,7 @@ import feedbackApi from '@/sheep/api/feedback' import { onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app' import { filePath } from '@/sheep/utils/file' import { useDefaultHeader } from '@/sheep/hooks/use-token' +import { uploadedFileUrl } from '@/sheep/utils/file-upload' const typeOptions = ref<{ value: string; label: string }[]>([]) const typeOptionsLoaded = ref(false) @@ -180,20 +181,13 @@ async function submitFeedback() { uni.showToast({ title: '请填写完整信息', icon: 'none' }) return } + if (uploadList.value.some(item => !uploadedFileUrl(item))) { + return uni.showToast({ title: '请完成图片上传或移除失败图片', icon: 'none' }) + } try { uni.showLoading({ title: '提交中...' }) - let picUrlArr: any[] = [] - uploadList.value.forEach(item => { - if (item.response) { - try { - const res = JSON.parse(item.response) - if (res.code === 0 && res.data && res.data.url) { - picUrlArr.push(res.data.url) - } - } catch {} - } - }) + const picUrlArr = uploadList.value.map(uploadedFileUrl) const data = { title: title.value.trim(), type: typeOptions.value[typeIndex.value].value, diff --git a/src/pages/integrated/repair/index.vue b/src/pages/integrated/repair/index.vue index 07ce3fd..0731631 100644 --- a/src/pages/integrated/repair/index.vue +++ b/src/pages/integrated/repair/index.vue @@ -105,6 +105,7 @@ import { onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app' import maintenanceApi from '@/sheep/api/maintenance' import { hooks } from '@@/index' import { filePath } from '@/sheep/utils/file' +import { uploadedFileUrl } from '@/sheep/utils/file-upload' const typeOptions = ref([]) const typeOptionsLoaded = ref(false) @@ -240,20 +241,10 @@ async function submitRepair() { return } - // 收集所有上传成功图片的 url - let picUrl: string[] = [] - if (uploadFileUrl.value.length > 0) { - uploadFileUrl.value.forEach(item => { - if (item.response) { - try { - const res = JSON.parse(item.response) - if (res.code === 0 && res.data && res.data.url) { - picUrl.push(res.data.url) - } - } catch {} - } - }) + if (uploadFileUrl.value.some(item => !uploadedFileUrl(item))) { + return uni.showToast({ title: '请完成图片上传或移除失败图片', icon: 'none' }) } + const picUrl = uploadFileUrl.value.map(uploadedFileUrl) try { uni.showLoading({ title: '提交中...' }) diff --git a/src/pages/prosperity-shop/categary-manage.vue b/src/pages/prosperity-shop/categary-manage.vue index d8249b7..dac4e7e 100644 --- a/src/pages/prosperity-shop/categary-manage.vue +++ b/src/pages/prosperity-shop/categary-manage.vue @@ -79,6 +79,7 @@ import NodeTree from "@/sheep/components/node-tree.vue" import { useCategaryManage } from "./use-categary-manage" import { hooks } from "@@/index" import { filePath } from "@/sheep/utils/file" +import { uploadedFileUrl } from "@/sheep/utils/file-upload" const categaryFormDrawer = ref(false) const form = reactive({ @@ -130,11 +131,13 @@ const editCategary = (item) => { const saveCategary = async () => { if (!form.name) return uni.showToast({ title: "请填写分类名称", icon: "none" }) if (selectedNodeId.value === form.id) return uni.showToast({ title: "父级分类不能是自己", icon: "none" }) + const picUrl = form.picUrl?.length ? uploadedFileUrl(form.picUrl[0]) : "" + if (form.picUrl?.length && !picUrl) return uni.showToast({ title: "请完成分类图片上传或移除失败图片", icon: "none" }) try { const params = { ...form, parentId: selectedNodeId.value, - picUrl: form.picUrl?.length ? JSON.parse(form.picUrl[0].response).data.url : "", + picUrl, } uni.showLoading({ title: "保存中..." }) const { code, msg } = await (form.id ? prosperityShopApi.editCategary(params) : prosperityShopApi.addCategary(params)) diff --git a/src/pages/prosperity-shop/goods-form.vue b/src/pages/prosperity-shop/goods-form.vue index 25e3c10..325a0a6 100644 --- a/src/pages/prosperity-shop/goods-form.vue +++ b/src/pages/prosperity-shop/goods-form.vue @@ -192,6 +192,7 @@ import { prosperityShopApi } from "@/sheep/api" import ShopCategaryPicker from "@/sheep/components/shop-categary-picker.vue" import { onLoad } from "@dcloudio/uni-app" import { filePath } from "@/sheep/utils/file" +import { uploadedFileUrl } from "@/sheep/utils/file-upload" import { displayPrice, storePrice } from "@/sheep/utils/formatMoney" const form = reactive({ @@ -322,17 +323,9 @@ const addSkuListItem = () => { // 保存 const onsubmit = async (evt: TM.FORM_SUBMIT_RESULT) => { - // console.log("校验结果:", evt) - console.log(form.carouselImages) - - const submitData = { - ...form, - coverImage: JSON.parse(form.coverImage[0].response).data.url, - // carouselImages: form.carouselImages.map((item: any) => JSON.parse(item.response).data.url).join(","), - } - console.log("提交的数据:", submitData) - if (!evt.isPass) return + const coverImage = uploadedFileUrl(form.coverImage[0]) + if (!coverImage) return uni.showToast({ title: "请先完成商品主图上传", icon: "none" }) if (form.priceType == 1) { for (let i = 0; i < form.skuList.length; i++) { @@ -358,7 +351,7 @@ const onsubmit = async (evt: TM.FORM_SUBMIT_RESULT) => { price: storePrice(item.price), } }), - coverImage: JSON.parse(form.coverImage[0].response).data.url, + coverImage, // carouselImages: form.carouselImages.map((item: any) => JSON.parse(item.response).data.url).join(","), } uni.showLoading({ title: "提交中..." }) diff --git a/src/pages/refund/apply.vue b/src/pages/refund/apply.vue index a72b7d9..d1332b7 100644 --- a/src/pages/refund/apply.vue +++ b/src/pages/refund/apply.vue @@ -7,6 +7,7 @@ import { hooks, router } from "@@/index" import { orderApi, refundApi, commonApi } from "@@/api" import { filePath } from "@@/utils/file" +import { uploadedFileUrl } from "@@/utils/file-upload" const data = { payType: [ @@ -20,10 +21,10 @@ const state = reactive({ shopCarList: [], setting: {}, selectList: [], - header: "", + header: {}, }) const uploadApplyPicUrls = ref | string>>([]) // 补充凭证图片 -const applyPicUrls = computed(() => uploadApplyPicUrls.value.map((item: any) => JSON.parse(item.response).data.url).join(",")) +const applyPicUrls = computed(() => uploadApplyPicUrls.value.map(uploadedFileUrl).filter(Boolean).join(",")) const applyForm = reactive({ way: data.payType[0].type, @@ -94,6 +95,7 @@ const radioChange = (e: any) => { const doSubmit = async () => { if (isEmpty(applyForm.reasonStr)) return uni.showToast({ title: "请选择申请原因", icon: "none" }) if (!applyPicUrls.value.length) return uni.showToast({ title: "请补充凭证图片", icon: "none" }) + if (uploadApplyPicUrls.value.some(item => !uploadedFileUrl(item))) return uni.showToast({ title: "请完成图片上传或移除失败图片", icon: "none" }) if (isEmpty(applyForm.remark.trim())) return uni.showToast({ title: "请填写相关描述", icon: "none" }) const _pa = { way: applyForm.way, @@ -125,7 +127,8 @@ const doSubmit = async () => { - + {{ v.productName }} ¥ {{ hooks.useMoney(v.productPrice) }} diff --git a/src/sheep/components/rich-text-editor/rich-text-editor.vue b/src/sheep/components/rich-text-editor/rich-text-editor.vue index abdd451..857388b 100644 --- a/src/sheep/components/rich-text-editor/rich-text-editor.vue +++ b/src/sheep/components/rich-text-editor/rich-text-editor.vue @@ -111,6 +111,7 @@