This commit is contained in:
jiangyinzhi
2024-09-03 15:28:55 +08:00
parent 0095c6ecba
commit be8a167fd0
13 changed files with 392 additions and 28 deletions
@@ -0,0 +1,215 @@
<template>
<!-- :after-read="afterRead" -->
<!-- :after-read="afterRead" -->
<van-uploader
v-model="fileList"
:disabled="disableImg"
multiple
:deletable="deletable"
:max-count="1"
:before-read="beforeRead"
:afterRead="afterRead"
:before-delete="delImg"
@click-upload="onUpload"
accept="image/*"
>
<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'
import { addWaterMarker } from '@/utils/marker'
import { Base64ToFile } from '@/utils/base64'
export default {
props: {
type: {
type: String,
default: '',
},
value: {
type: Array,
default: () => [],
},
deletable: {
type: Boolean,
default: true,
},
},
data() {
return {
disableImg: false,
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() {
this.fileList= []
console.log('--------chooseAlbumAndTakePhoto---', 'onUpload')
chooseAlbumAndTakePhoto(async (data) => {
console.log('--------onUpload---', data)
let d = 'data:image/jpeg;base64,' + data
this.fileIamge = d
// let params = this.base64ToFile(d, new Date().getTime().toString())
// console.log('--------params---', params)
let img = Base64ToFile(d,'image/jpeg',new Date().getTime().toString() + ".jpg")
console.log('-------------------------onUpload---', img);
let blob = await addWaterMarker(img, 'image')
console.log('-------------------------blob---', blob);
let params = new FormData()
let file = new File([blob], img.name)
params.append('file', file)
console.log('-------------------------file---', file);
const res = await uploadFile(params)
console.log('--------res---', res)
if (res.code == 0) {
this.fileList.push({
fileName: res.data.original_name,
fileId: res.data.attach_id,
url: `${downloadUrl}${res.data.attach_id}`,
})
this.$emit('onUpload', this.fileList, this.type)
}
})
},
async afterRead(file) {
this.fileList= []
this.disableImg = true
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.disableImg = false
this.fileList.push({
fileName: res.data.original_name,
fileId: res.data.attach_id,
url: `${downloadUrl}${res.data.attach_id}`,
})
this.$emit('onUpload', this.fileList, this.type)
// this.$emit('afterRead', res.data, this.type)
}else{
this.disableImg = false
}
return true
},
beforeRead(img) {
if(!img){
return
}
return new Promise(async(resolve, reject) => {
let blob = await addWaterMarker(img, 'blob')
blob.name = img.name
let file = new File([blob], img.name)
resolve(file)
})
}, //压缩图片
compressFiles(fileObj) {
let type = fileObj.type
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.readAsDataURL(fileObj)
reader.onload = function (e) {
let image = new Image() //新建一个img标签(不嵌入DOM节点,仅做canvas操作)
image.src = e.target.result //让该标签加载base64格式的原图
image.onload = function () {
//图片加载完毕后再通过canvas压缩图片,否则图片还没加载完就压缩,结果图片是全黑的
let canvas = document.createElement('canvas'), //创建一个canvas元素
context = canvas.getContext('2d'), //context相当于画笔,里面有各种可以进行绘图的API
imageWidth = image.width / 2, //压缩后图片的宽度,这里设置为缩小一半
imageHeight = image.height / 2, //压缩后图片的高度,这里设置为缩小一半
data = '' //存储压缩后的图片
canvas.width = imageWidth //设置绘图的宽度
canvas.height = imageHeight //设置绘图的高度
//使用drawImage重新设置img标签中的图片大小,实现压缩。drawImage方法的参数可以自行查阅W3C
context.drawImage(image, 0, 0, imageWidth, imageHeight)
//使用toDataURL将canvas上的图片转换为base64格式
data = canvas.toDataURL(type)
canvas.toBlob(function (blob) {
const f = new File([blob], fileObj.name, { type })
resolve(f)
}, type)
}
}
})
},
delImg(file, detail) {
this.fileList.splice(detail.index, 1)
this.$emit('delImg', file, detail, this.type)
},
checkImgisUpload(list) {
if (this.fileList && list && this.fileList.length == list.length) {
return false
} else {
return true
}
},
},
}
</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>
@@ -4,18 +4,20 @@
<div class="focusItem">
<van-cell-group>
<van-field v-model="formColumns.heatModeName" required :rules="[{ required: true }]" label="采暖方式" input-align="right" is-link placeholder="请选择" readonly @click="handelHeatModeShow = !showForm" />
<van-field v-model="formColumns.heatTypeName" required :rules="[{ required: true }]" label="采暖设备类型" input-align="right" is-link placeholder="请选择" readonly @click="heatTypeShow = !showForm" />
<van-field v-model="formColumns.heatTypeListName" :rules="[{ required: false, message:'请选择并填写采暖机组' }]" label="采暖机组" input-align="right" is-link placeholder="" @click-input="handleClickInput(3)" readonly />
<van-field v-model="form.pumpNum" v-input.numNo0 required :rules="[{ required: true}]" label="输送泵组采暖泵台数" type="number" label-width="140" input-align="right" placeholder="请输入" @input="handelInput('pumpNum', form.pumpNum)" />
<van-field v-model="form.pumpNum" v-input.num :required="form.heatMode!='1'" :rules="[{ required: form.heatMode!='1',
validator:validateisData}]" label="输送泵组采暖泵台数" type="number" label-width="140" input-align="right" placeholder="请输入" @input="handelInput('pumpNum', form.pumpNum)" />
<van-field v-model="form.pumpTotalPower" v-input.floatNo0 required :rules="[{ required: true}]" label="输送泵组总功率(kW)" type="number" label-width="140" input-align="right" placeholder="请输入" @input="handelInput('pumpTotalPower', form.pumpTotalPower)" />
<van-field v-model="form.pumpTotalPower" v-input.float :required="form.heatMode!='1'" :rules="[{ required: form.heatMode!='1',
validator:validateisData}]" label="输送泵组总功率(kW)" type="number" label-width="140" input-align="right" placeholder="请输入" @input="handelInput('pumpTotalPower', form.pumpTotalPower)" />
<van-field v-model="form.pumpYear" required :rules="[{ required: true}]" label="输送泵组设备年份" label-width="140" input-align="right" placeholder="请选择" is-link readonly @click="handelClickYear('pumpYear', 'SET_HEAT_YEAR')" />
<van-field v-model="form.pumpYear" :required="form.heatMode!='1'" :rules="[{ required: form.heatMode!='1'}]" label="输送泵组设备年份" label-width="140" input-align="right" placeholder="请选择" is-link readonly @click="handelClickYear('pumpYear', 'SET_HEAT_YEAR')" />
<!-- 是否进行过设备改造 -->
@@ -177,7 +179,17 @@ export default {
mixins: [mixin],
data() {
let validateisData = (value, rule) => {
if(!rule.required){
return true
}else if (!value|| value <= 0) {
return false
} else{
return true
}
}
return {
validateisData,
typeId: this.$route.query.typeId,
tidCid: null,
//页面名称
@@ -319,7 +331,7 @@ export default {
//修改覆写数据
async editData() {
console.log(this.$store.getters.heatingUnitList);
// console.log(this.$store.getters.heatingUnitList);
this.mouSetTimer = setTimeout(async () => {
//查询机组
this.searchHeatType()
@@ -333,7 +345,7 @@ export default {
//问询问题
const searchInfo = this.$store.getters.searchInfo
if (searchInfo) {
console.log(this.$store.getters.searchInfo);
// console.log(this.$store.getters.searchInfo);
const res = dataMode(searchInfo['sbcn'])
this.searchList = res
//运营类
@@ -797,14 +809,13 @@ export default {
this.form.modifyMode = data.id.join(',')
},
handelInput(type, num) {
if(type == 'pumpNum' && !num) {
if(!num) {
num = 0
}
const data = {
type,
data: num,
}
console.log(type,num);
this.$store.commit('search/SET_NUM', data)
},
handleClickInput(val) {
@@ -482,22 +482,22 @@ export default {
ifType(data, type, num) {
if(num == 1) {
if (type == 'exteriorImage') {
this.exteriorImage.push(data.attach_id)
// this.exteriorImage.push(data.attach_id)
// const list = this.ifObj(this.exteriorImage)
this.form.exteriorImage = this.exteriorImage
this.form.exteriorImage.pop()
this.form.exteriorImage = this.exteriorImage = data
// this.form.exteriorImage.pop()
}
if (type == 'tagImage') {
this.tagImage.push(data.attach_id)
// this.tagImage.push(data.attach_id)
// const list = this.tagImage.join(',')
this.form.tagImage = this.tagImage
this.form.tagImage.pop()
this.form.tagImage = this.tagImage = data
// this.form.tagImage.pop()
}
if (type == 'markImage') {
this.markImage.push(data.attach_id)
// this.markImage.push(data.attach_id)
// const list = this.ifObj(this.markImage)
this.form.markImage = this.markImage
this.form.markImage.pop()
this.form.markImage = this.markImage = data
// this.form.markImage.pop()
}
} else {
if (type == 'exteriorImage') {
+2 -2
View File
@@ -476,9 +476,9 @@ export default {
this.commonForm.nxzdUseEnergyEquipDTO.heatMode = store.heatMode
this.commonForm.nxzdUseEnergyEquipDTO.pumpTotalPower = store.pumpTotalPower
this.commonForm.nxzdUseEnergyEquipDTO.pumpTotalPower = store.pumpTotalPower||0
this.commonForm.nxzdUseEnergyEquipDTO.pumpNum = store.pumpNum
this.commonForm.nxzdUseEnergyEquipDTO.pumpNum = store.pumpNum||0
this.commonForm.nxzdHeatSystemDTO = this.$store.getters.heatingUnitList
/**
*集中式空调