提交 d6e4fb65 编写于 作者: guangjun.yang's avatar guangjun.yang

代码优化

上级 8bad3dc8
<template>
<div class="img-handle-container">
<div class="img-box">
<img :src="imgUrl" :style="{width: imgData.newW + 'px', height: imgData.newH + 'px' }"/>
</div>
</div>
</template>
<script>
export default {
name: 'imgSize',
props: {
imgUrl: {
type: String,
default: ''
},
imgData: {
type: Object,
default: {}
},
index: {
type: Number,
default: 0
}
},
data() {
return {
imgWidth: 0,
imgHeight: 0,
imgProportion: 0,
lw: 0,
lh: 0,
newW: 0,
newH: 0,
}
},
mounted() {
let {lw, lh, newW, newH} = this;
if(typeof this.imgData.content == 'string') {
this.imgWidth = this.imgData.width || JSON.parse(this.imgData.content).w;
this.imgHeight = this.imgData.height || JSON.parse(this.imgData.content).h;
}else {
this.imgWidth = this.imgData.width || this.imgData.content.w;
this.imgHeight = this.imgData.height || this.imgData.content.h;
}
this.imgProportion = (this.imgWidth / this.imgHeight).toFixed(1);
if(this.imgProportion > 0.6) {
if(this.imgWidth > 192) {
lw = 192;
lh = (this.imgHeight * lw) / this.imgWidth;
} else if(this.imgWidth <= 192) {
lw = this.imgWidth;
lh = this.imgHeight;
}
} else if(this.imgProportion == 0.6) {
if(this.imgHeight > 320) {
lh = 320;
}else {
lh = this.imgHeight;
}
lw = lh * 0.6;
}else {
if(this.imgHeight > 320) {
lh = 320;
lw = (this.imgWidth * lh) / this.imgHeight;
}else if(this.imgHeight <= 320) {
lh = this.imgHeight;
lw = this.imgWidth;
}
}
if((lh < 32) && (lh < lw)) {
newH = 32;
newW = (lw * 32) / lh;
}else if((lw < 32) && (lw < lh)) {
newW = 32;
newH = (lh * 32) / lw;
}else {
newH = lh;
newW = lw;
}
this.$emit('imgHandle', {width: newW, height: newH, index: this.index});
},
methods: {
}
}
</script>
<style lang="scss" scoped>
.img-handle-container {
.img-box {
max-width: 192px;
max-height: 320px;
overflow: hidden;
}
}
</style>
\ No newline at end of file
......@@ -38,14 +38,12 @@
</template>
<script>
import BreadCrumb from "@/components/breadcrumb.vue";
import ImgSize from "@/components/IM/img-size.vue";
import { doUpload, getFilePath } from "@/utils/qiniu-util";
import { openLoading, closeLoading, betaHandle } from "@/utils/utils";
import * as commonUtil from "@/utils/utils";
export default {
components: {
BreadCrumb,
ImgSize
},
data() {
return {
......@@ -90,10 +88,6 @@ export default {
}
});
},
imgHandle(data) {
this.$set(this.detailData.contentModelList[data.index], 'newW', data.width)
this.$set(this.detailData.contentModelList[data.index], 'newH', data.height)
},
// 下载目标文件
downFile() {
......
......@@ -210,7 +210,6 @@
<script>
import { mapGetters, mapMutations } from "vuex";
import BreadCrumb from "@/components/breadcrumb.vue";
import ImgSize from "@/components/IM/img-size.vue";
import { doUpload, getFilePath } from "@/utils/qiniu-util";
import { validateWord } from "@/utils/validate.js";
import { openLoading, closeLoading, betaHandle } from "@/utils/utils";
......@@ -228,7 +227,6 @@ export default {
components: {
BreadCrumb,
UserInfo,
ImgSize
},
data() {
return {
......@@ -272,7 +270,8 @@ export default {
},
imgWidth: 0,
imgHeight: 0,
imgProportion: 0
imgProportion: 0,
hasNoHistoryData: false,
};
},
......@@ -446,7 +445,7 @@ export default {
// 查询医生和居民的消息历史(下拉刷新时调用)
getOldMSGHistory() {
// if(this.hasNoHistory) return;
if(this.hasNoHistoryData) return;
let session = this.currentSession;
let params = {
doctorAccId: this.currentToAccId,
......@@ -461,7 +460,11 @@ export default {
this.POST("/im/msg/history", params).then(res => {
if (res.code === "000000") {
// 将新消息合并到之前的消息中, 并且重置最后一条消息
this.convertMessageList(res.data, 3);
if(res.data && res.data.length > 0) {
this.convertMessageList(res.data, 3);
} else {
this.hasNoHistoryData = true;
}
} else {
this.$message({
message: res.message,
......@@ -592,12 +595,6 @@ export default {
msg.url = url;
msg.sessionFlag = false;
cMessageList.push(msg);
// if (
// msg.type.toLowerCase() == "image" ||
// msg.type.toLowerCase() == "picture"
// ) {
// this.imgSizeHandle(msg);
// }
});
if (directFlag === 1) {
......@@ -1057,54 +1054,6 @@ export default {
return betaHandle(val);
},
// imgHandle(data) {
// this.$set(this.messageList[data.index], "newW", data.width);
// this.$set(this.messageList[data.index], "newH", data.height);
// },
// 图片处理
imgSizeHandle(item) {
let lw, lh, newW, newH;
this.imgWidth = JSON.parse(item.content).w;
this.imgHeight = JSON.parse(item.content).h;
this.imgProportion = (this.imgWidth / this.imgHeight).toFixed(1);
if (this.imgProportion > 0.6) {
if (this.imgWidth > 192) {
lw = 192;
lh = (this.imgHeight * lw) / this.imgWidth;
} else if (this.imgWidth <= 192) {
lw = this.imgWidth;
lh = this.imgHeight;
}
} else if (this.imgProportion == 0.6) {
if (this.imgHeight > 320) {
lh = 320;
} else {
lh = this.imgHeight;
}
lw = lh * 0.6;
} else {
if (this.imgHeight > 320) {
lh = 320;
lw = (this.imgWidth * lh) / this.imgHeight;
} else if (this.imgHeight <= 320) {
lh = this.imgHeight;
lw = this.imgWidth;
}
}
if (lh < 32 && lh < lw) {
newH = 32;
newW = (lw * 32) / lh;
} else if (lw < 32 && lw < lh) {
newW = 32;
newH = (lh * 32) / lw;
} else {
newH = lh;
newW = lw;
}
this.$set(item, "newW", newW);
this.$set(item, "newH", newH);
},
},
beforeDestroy() {
......
......@@ -54,14 +54,12 @@
</template>
<script>
import BreadCrumb from "@/components/breadcrumb.vue";
import ImgSize from "@/components/IM/img-size.vue";
import { doUpload, getFilePath } from "@/utils/qiniu-util";
import { openLoading, closeLoading, betaHandle, timeHandle } from "@/utils/utils";
import { getPicaKFAccid } from "@/utils";
export default {
components: {
BreadCrumb,
ImgSize
},
data() {
return {
......@@ -201,10 +199,6 @@ export default {
}
})
},
imgHandle(data) {
this.$set(this.detailData[data.index], 'newW', data.width)
this.$set(this.detailData[data.index], 'newH', data.height)
},
// 按照时间大小排序
timeSort(arrList) {
arrList.sort((a, b) => {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册