WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2025-03-27 0396d398bea811f5650d04ce5b55a232b4f58b98
forms/imagePicker/CImagePicker.vue
@@ -1,5 +1,8 @@
/**
 * CImagePicker
 * 图片选择器组件,用于在表单中上传和管理图片
 * 支持单张和多张图片上传,并提供压缩、预览等功能
 * 可限制上传图片的数量和来源(相册/相机)
 * @author Tevin
 */
@@ -73,6 +76,11 @@
            type: Boolean,
            default: false,
        },
        // 上传地址来源
        uploadUrlSource: {
            type: String,
            default: '',
        },
    },
    data() {
        return {
@@ -138,8 +146,13 @@
                const needs = nextFiles
                    .map((file, needIndex) => {
                        const fileInfo = file.file;
                        // 没有 file 信息对象,或者不是 blob 类型
                        if (!fileInfo || fileInfo.path.indexOf('blob') < 0) {
                        // 没有 file 信息对象,或者不是 blob、wxfile、tmp 类型
                        if (
                            !fileInfo ||
                            (fileInfo.path.indexOf('blob') < 0 &&
                                fileInfo.path.indexOf('wxfile') < 0 &&
                                fileInfo.path.indexOf('http://tmp/') < 0)
                        ) {
                            return false;
                        }
                        // 尺寸小于 1M 的图片
@@ -218,7 +231,11 @@
                        callback(state, res);
                    }
                },
                this.params,
                $fetchCommon.transKeyName('underline', {
                    ...this.params,
                    needThumb: this.needThumb ? 1 : 0,
                }),
                this.uploadUrlSource,
            );
        },
    },
@@ -238,12 +255,12 @@
// 图片上传节流
const _readyUpload = {};
export const uploadImage = (files, callback, params) => {
export const uploadImage = (files, callback, formData = {}, uploadUrlSource) => {
    if (!files || files.length === 0) {
        callback('success', []);
        return;
    }
    let url = $fetchCommon.getUploadImgURL();
    let url = uploadUrlSource ? uploadUrlSource : $fetchCommon.getUploadImgURL();
    if (url.indexOf('http') < 0) {
        url = $hostBoot.getHost() + url;
    }
@@ -282,10 +299,7 @@
                        ...requestFile,
                        header,
                        name: 'file',
                        formData: $fetchCommon.transKeyName('underline', {
                            ...params,
                            needThumb: this.needThumb ? 1 : 0,
                        }),
                        formData,
                        timeout: 30 * 1000,
                        success(res) {
                            let res2;