主题
图片上传并压缩
jsx
<uni-file-picker v-model="pageData.cardForntValue" class="my-upload" file-mediatype="all"
fileMediatype="image" :sizeType="['compressed']" ref="files" mode="grid" :auto-upload="false"
@select="changeImg(1, $event)" :limit="1"
:imageStyles="{border: false, width: '320rpx', height: '210rpx'}">
<view
class="w-100 h-100 bd-photo-dashed border-radius-12 flex flex-column flex-align-center flex-justify-center">
<u-icon name="photo" size="60"></u-icon>
<text class="mgt-10 c-text-4">身份证正面</text>
</view>
</uni-file-picker>
const pageData = reactive({
cardForntValue: [],
cardBackValue: []
})
const changeImg = async (type, e) => {
const {
tempFiles,
tempFilePaths
} = e;
let file = tempFiles[0].file;
let img = await proxy.Pub.compressImg(file);
let res = await proxy.$http.postFile(img);
if (res.code == 200) {
if (type == 1) {
formData.front_id_card = res.data.path;
} else {
formData.after_id_card = res.data.path;
}
}
}