WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2024-03-22 36f9b3bec3f8df0da0d8d1e1cc63eb7f53765be3
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);
                }
            });
        },
    },