WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2024-07-31 0e1bdf804b76b896f4e38606f1ed33558b3cab14
Merge branch 'master_dev'
2 files modified
78 ■■■■ changed files
forms/imagePicker/CImageCompressor.vue 69 ●●●● patch | view | raw | blame | history
forms/imagePicker/CImagePicker.vue 9 ●●●● patch | view | raw | blame | history
forms/imagePicker/CImageCompressor.vue
@@ -64,14 +64,40 @@
                src: tempPath,
                success: res => {
                    const size = this._limitSize(res);
                    const drawSet = this._creatDrawSet(res, size);
                    this._drawImage(tempPath, drawSet, compress => {
                        this.imgBlobs.push({
                            source: tempPath,
                            compress,
                    // 网页图片压缩
                    if (process.env.TARO_ENV === 'h5') {
                        const drawSet = this._creatDrawSet(res, size);
                        this._drawImage(tempPath, drawSet, compress => {
                            this.imgBlobs.push({
                                source: tempPath,
                                compress,
                            });
                            callback();
                        });
                        callback();
                    });
                    }
                    // 小程序图片压缩
                    else if (process.env.TARO_ENV === 'weapp') {
                        Taro.compressImage({
                            src: tempPath,
                            quality: 60,
                            compressedWidth: size[0],
                            compressHeight: size[1],
                            success: cps => {
                                this.imgBlobs.push({
                                    source: tempPath,
                                    compress: cps.tempFilePath,
                                });
                                callback();
                            },
                            fail: err => {
                                this.imgBlobs.push({
                                    source: tempPath,
                                    compress: tempPath,
                                });
                                callback();
                            },
                        });
                    }
                },
            });
        },
@@ -93,13 +119,10 @@
        _setCanvasSize(width, height) {
            this.cavWidth = width;
            this.cavHeight = height;
            if (process.env.TARO_ENV === 'h5') {
                $(this.$refs.canvas.$el)
                    .find('canvas')
                    .attr('width', width)
                    .attr('height', height);
            }
            // TODO: 小程序中的 canvas 重设
            $(this.$refs.canvas.$el)
                .find('canvas')
                .attr('width', width)
                .attr('height', height);
        },
        _creatDrawSet(res, [width, height]) {
            const orientation = res.orientation || 'up';
@@ -140,7 +163,23 @@
                const [key, params] = step;
                if (key === 'drawImage') {
                    // 使用图片
                    const img = new Image();
                    const img = (() => {
                        if (typeof Image === 'undefined') {
                            console.log(this.$refs.canvas);
                            console.log($('canvas[canvas-id=' + this.cavId + ']'));
                            const query = Taro.createSelectorQuery();
                            query
                                .select('canvas[canvas-id=' + this.cavId + ']')
                                .boundingClientRect()
                                .exec(res => {
                                    console.log(res);
                                });
                            return this.$refs.canvas.createImage();
                        } else {
                            return new Image();
                        }
                    })();
                    img.src = tempPath;
                    this.canvasContext.drawImage(img, ...params);
                } else {
forms/imagePicker/CImagePicker.vue
@@ -138,8 +138,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 的图片