zhangwei
2024-08-20 ef1114c22614762e54e49bc7c600d2a2cd460791
src/common/utils/uploadHelper.js
@@ -167,3 +167,54 @@
    });
};
// 上传身份证
export const uploadIdCord = (PageName, callback) => {
    // 获取用户token
    let userToken = db.get("userToken");
    if (!userToken) {
        this.$store.commit('showLoginTip', true);
        return false;
    };
    uni.chooseImage({
        success: (res) => {
            uni.showLoading({
                title: '上传中...'
            });
            let tempFilePaths = res.tempFilePaths;
            for (var i = 0; i < tempFilePaths.length; i++) {
                uni.uploadFile({
                    url: apiBaseUrl + `api/UpFile/UploadIdCord?PageName=${PageName}`,
                    filePath: tempFilePaths[i],
                    fileType: 'image',
                    name: 'file',
                    header: {
                        'Accept': 'application/json',
                        'Content-Type': 'multipart/form-data',
                        'Authorization': 'Bearer ' + userToken
                    },
                    formData: {
                        'method': 'images.upload',
                        'upfile': tempFilePaths[i]
                    },
                    success: (uploadFileRes) => {
                        callback(JSON.parse(uploadFileRes.data));
                    },
                    fail: (error) => {
                        if (error && error.response) {
                            showError(error.response);
                        }
                    },
                    complete: () => {
                        setTimeout(function () {
                            uni.hideLoading();
                        },
                            250);
                    },
                });
            }
        }
    });
};