能效诊断
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<!-- :after-read="afterRead" -->
|
||||
<!-- :after-read="afterRead" -->
|
||||
<van-uploader
|
||||
v-model="fileList"
|
||||
multiple
|
||||
:max-count="1"
|
||||
:afterRead="afterRead"
|
||||
:before-delete="delImg"
|
||||
@click-upload="onUpload"
|
||||
>
|
||||
<div class="uploader">
|
||||
<van-icon name="plus" class="uploader-icon" />
|
||||
</div>
|
||||
</van-uploader>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { uploadFile } from '@/api/api.js'
|
||||
import { chooseAlbumAndTakePhoto } from '@/utils/dsbridge'
|
||||
import { downloadUrl } from '@/settings'
|
||||
export default {
|
||||
props: {
|
||||
type: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
value: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
fileList: this.value,
|
||||
activTimer: null,
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.activTimer = setTimeout(() => {
|
||||
this.fileList = this.value
|
||||
}, 200)
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearTimeout(this.activTimer)
|
||||
this.fileList = []
|
||||
},
|
||||
methods: {
|
||||
base64ToFile(data, fileName) {
|
||||
const dataArr = data.split(",");
|
||||
const byteString = window.atob(dataArr[1]);
|
||||
const options = {
|
||||
type: "image/jpeg",
|
||||
endings: "native"
|
||||
};
|
||||
const u8Arr = new Uint8Array(byteString.length);
|
||||
for (let i = 0; i < byteString.length; i++) {
|
||||
u8Arr[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
let formData = new FormData();
|
||||
let fileOfBlob = new File([u8Arr], fileName + ".jpg", options);//返回文件流
|
||||
formData.append("file", fileOfBlob);
|
||||
return formData
|
||||
},
|
||||
// 上传图片调用原生的方法 获取到绝对路径调用getImageFileFromUrl
|
||||
onUpload () {
|
||||
chooseAlbumAndTakePhoto(async (data) => {
|
||||
let d = 'data:image/jpeg;base64,' + data
|
||||
this.fileIamge = d
|
||||
let params = this.base64ToFile(d,new Date().getTime().toString())
|
||||
const res = await uploadFile(params)
|
||||
if (res.code == 0) {
|
||||
this.fileList.push({
|
||||
url:`${downloadUrl}${res.data.attach_id}`
|
||||
})
|
||||
this.$emit('onUpload', this.fileList, this.type)
|
||||
}
|
||||
})
|
||||
},
|
||||
async afterRead(file) {
|
||||
let params = new FormData()
|
||||
params.append('file', file.file)
|
||||
console.log(file.file);
|
||||
console.log(params);
|
||||
// console.log(decryptParseToJSON(a),77777777);
|
||||
const res = await uploadFile(params)
|
||||
if (res.code == 0) {
|
||||
this.$emit('afterRead', res.data, this.type)
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
delImg(file, detail) {
|
||||
this.fileList.splice(detail.index, 1)
|
||||
this.$emit('delImg', file, detail, this.type)
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style lang='less' scoped>
|
||||
/deep/ .van-uploader__preview-image {
|
||||
padding: 10px;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||
border-radius: 10px;
|
||||
margin-left: 20px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/deep/ .van-uploader__preview-delete {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
|
||||
.uploader {
|
||||
width: 2.133333rem;
|
||||
height: 2.133333rem;
|
||||
background: #f7f7f7;
|
||||
border-radius: 5px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: 10px 0 10px 20px;
|
||||
.uploader-icon {
|
||||
font-size: 30px;
|
||||
color: #ababab;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user