古人言 温故而知新 多温习才能变成自己的东西呀
1. dingo兼容vue模版字符串语法
const app = new Vue({
delimiters: ["[[", "]]"],
el: '#app',
})
2. img标签 onload方法
<img :src="`data:image/jpeg;base64,${distinguishList.imageBase64}`"
@onload="imgLoadFn" alt=""
ref="imgSize"
v-if="imageBase64"
@click="handlePictureView(imageBase64)">
imgLoadFn () {
if (this.$refs.imgSize) {
let _o = this.$refs.imgSize;
this.radio.area = this.distinguishList.div_width / _o.width;
let ratio =
Math.floor(this.distinguishList.div_width) / Math.floor(_o.width) / 1.6;
this.ratio = Number(parseFloat(ratio).toFixed(1));
}
},
3. 绝对定位absolute 定位每一个字的位置 (表格错位 需要打补丁)
- 通过position定位每一个字的位置 需彻底理解绝对定位是如何定位的
- 绝对定位 做一个隔层 -top -left
- 绝对定位 做两个循环 都相对于A定位
- 两个循环 把数据处理成平级 有个div空循环♻️
- 计算差距离 i.top-text.top 打补丁
<div v-if="active==0&¶ms.table" style="margin-right: 10px">
<div
:style="`position:relative;width:distinguishList.div_width;height:distinguishList.div_height;`">
<div v-for="results in distinguishList.box_divs">
<div
v-for="i in results"
:style="`position:absolute;left: ${ i.x/ratio }px;top: ${ i.y/ratio}px;width: ${ i.width/ratio }px;height: ${ i.height/ratio }px; border: 1px black solid;`"
:position="`(${ i.x/ratio },${ i.y/ratio },${ i.width/ratio },${ i.height/ratio })`">
<div
:style="`position: relative; width: 100%;height:100%;left: ${ -i.x/ratio }px;top: ${ -i.y/ratio}px;`">
<span
v-for="text in i.text"
:style="`position:absolute;left: ${ text.x/ratio }px;top: ${ text.y/ratio}px;
white-space:nowrap;font-size: ${i.height/ratio}px;font-size: ${text.height/ratio}px; border: 0px solid gold;`">
{{text.text}}
</span>
</div>
</div>
</div>
<div v-for="results in distinguishList.divs">
<div v-for="i in results">
<span
:style="`position:absolute;left:${ i.x/ratio }px;top: ${ i.y/ratio}px;
font-size: ${i.height/ratio}px; white-space:nowrap;
margin-bottom:10px; width: ${ i.width/ratio }px; ${ i.height/ratio }px`">
{{i.text }}
</span>
</div>
</div>
</div>
</div>
4. 通过form表单的方式传参
let res = await axios.post('http://1.202.22.126:8284/', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
});
let formData = new FormData();
formData.append('img', item.file);
formData.append('type', this.active);
5. base64转码word excel
- 通过FileReader.readAsDataURL(file)可以获取一段data:base64的字符串
- 通过URL.createObjectURL(blob)可以获取当前文件的一个内存URL
- charCodeAt() 方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 - 65535 之间的整数。
- btoa 和 atob 是window对象的两个函数,其中:
- btoa :是binary to ascii,用于将binary的数据用ascii码表示,即Base64的编码过程
- atob:是ascii to binary,用于将ascii码解析成binary数据,即Base64的解码过程。
downloadFile (url, name = "影像识别结果") {
let a = document.createElement("a");
a.setAttribute("href", url);
a.setAttribute("download", name);
a.setAttribute("target", "_blank");
let clickEvent = document.createEvent("MouseEvents");
clickEvent.initEvent("click", true, true);
a.dispatchEvent(clickEvent);
},
dataURLtoBlob (dataurl) {
let arr = dataurl.split(","),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
},
downloadFn (base64, name) {
let myBlob = this.dataURLtoBlob(base64);
let myUrl = URL.createObjectURL(myBlob);
let convert_file_type = this.params.convert_file_type == 'excel' ? 'xlsx' || 'xls' : 'docx' || 'doc';
let ocr_name = '影像识别结果.' + convert_file_type
this.downloadFile(myUrl, ocr_name);
},
getBase64Type (type) {
switch (type) {
case 'doc': return 'data:application/msword;base64,';
case 'docx': return 'data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,';
case 'xls': return 'data:application/vnd.ms-excel;base64,';
case 'xlsx': return 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,';
case 'pdf': return 'data:application/pdf;base64,';
}
},
getType (file) {
let convert_file_type = this.params.convert_file_type == 'excel' ? 'xlsx' || 'xls' : 'docx' || 'doc';
let filename = file + '.' + convert_file_type;
let index1 = filename.lastIndexOf(".");
let index2 = filename.length;
let type = filename.substring(index1 + 1, index2);
return type;
},
6. this.$nextTick(function () { }) 方法
- 将回调延迟到下次DOM更新循环之后执行。在修改数据之后立即使用它,然后等待DOM更新。
- 在修改数据之后立即使用它,
然后等待 DOM 更新。
它跟全局方法 Vue.nextTick 一样,
不同的是回调的 this 自动绑定到调用它的实例上。