From c27e413f71c4beb1318237fedf585770702fe3a4 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Thu, 13 Mar 2025 10:13:57 +0800 Subject: [PATCH] 知识库文档,添加表单组件文档 --- forms/userSignature/CUserSignature.vue | 58 +++++++++++----------------------------------------------- 1 files changed, 11 insertions(+), 47 deletions(-) diff --git a/forms/userSignature/CUserSignature.vue b/forms/userSignature/CUserSignature.vue index ba66a1f..71a7882 100644 --- a/forms/userSignature/CUserSignature.vue +++ b/forms/userSignature/CUserSignature.vue @@ -48,6 +48,7 @@ import { $bridge } from '@components/common/Bridge'; import { $hostBoot } from '@components/bases/HostBoot'; import CSignatureLayer from '@components/forms/userSignature/CSignatureLayer'; +import { uploadImage } from '@components/forms/imagePicker'; import project from '@project'; import './cUserSignature.scss'; @@ -112,57 +113,20 @@ url: this.itemRes.formData[this.itemRes.name], fileName: 'file-' + Date.now() + '.png', }; - // 没有上传内容,视为上传成功 + // 没有上传内容,视为无需上传 if (!file.url) { callback('success'); return; } - // 不是临时文件,视为上传成功 - if ( - file.url.indexOf('blob') < 0 && - file.url.indexOf('wxfile') < 0 && - file.url.indexOf('http://tmp/') < 0 - ) { - callback('success'); - return; - } - // 开始上传 - let header = {}; - if (process.env.TARO_ENV === 'weapp') { - const localCookies = JSON.parse(Taro.getStorageSync('cookies') || '{}'); - const cookiesArr = []; - Object.keys(localCookies).forEach(key => { - cookiesArr.push(key + '=' + localCookies[key]); - }); - header['Cookie'] = cookiesArr.join('; '); - } - Taro.uploadFile({ - url: $hostBoot.getHost() + $fetchCommon.getUploadImgURL(), - header, - filePath: file.url, - fileName: file.fileName, - name: 'file', - formData: {}, - success: res => { - const res2 = - typeof res.data === 'string' ? JSON.parse(res.data) : res.data; - if (res2.state.code === 2000) { - const serverUrl = $fetchCommon.transImgPath( - 'fix', - res2.data.src || res2.data.file || res2.data.url, - ); - this.itemRes.onChange(serverUrl); - callback('success'); - } else { - callback('error', res2.state.msg); - } - }, - cancel() { - callback('error', '上传图片已取消!'); - }, - fail() { - callback('error', '上传图片失败!'); - }, + uploadImage([file], (state, res) => { + if (state === 'success') { + this.itemRes.onChange(res[0]); + setTimeout(() => { + callback(state); + }, 10); + } else if (state === 'error') { + callback(state, res); + } }); }, }, -- Gitblit v1.9.1