180 lines
5.0 KiB
Vue
180 lines
5.0 KiB
Vue
<template>
|
||
<view style="width: 100%;">
|
||
<web-view :src="url" style="width: 100%;"></web-view>
|
||
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
url: null, //要打开的外部链接
|
||
viewerUrl: '/hybrid/html/web/viewer.html',
|
||
webviewStyles: {
|
||
width: '750px',
|
||
height: '100%',
|
||
},
|
||
|
||
}
|
||
},
|
||
onReady() {
|
||
uni.setNavigationBarTitle({
|
||
title:'预览'
|
||
})
|
||
// #ifdef APP-PLUS
|
||
console.log('App plus2')
|
||
var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
|
||
setTimeout(function() {
|
||
wv = currentWebview.children()[0]
|
||
wv.setStyle({
|
||
scalable: true
|
||
})
|
||
}, 1000); //如果是页面初始化调用时,需要延时一下
|
||
// #endif
|
||
},
|
||
onLoad: function(option) {
|
||
|
||
|
||
this.asdcccc(1212,5)
|
||
this.kuyuiy(1212.5)
|
||
this.ryrtyj(1212,5)
|
||
this.hgddh(1212,5)
|
||
this.asdaghds(1212,5)
|
||
this.url = option.url
|
||
// this.url="https://jiaoyu.xianmxkj.com/file/uploadPath/2023/03/08/b6c0dd4821cc9ce70c897adca3ad22c2.pdf"
|
||
// h5,使用h5访问的时候记得跨域
|
||
// #ifdef H5
|
||
// this.url="https://jiaoyu.xianmxkj.com/file/uploadPath/2023/03/08/b6c0dd4821cc9ce70c897adca3ad22c2.pdf"
|
||
// this.url = `${this.viewerUrl}?file=${encodeURIComponent(option.url)}`;
|
||
// this.url = `${this.viewerUrl}?file=${'https://jiaoyu.xianmxkj.com/file/uploadPath/2023/03/08/b6c0dd4821cc9ce70c897adca3ad22c2.pdf'}`;
|
||
// #endif
|
||
|
||
// 在安卓和ios手机上
|
||
// 判断是手机系统:安卓,使用pdf.js
|
||
// #ifdef APP-PLUS
|
||
// if(plus.os.name === 'Android') {
|
||
// this.url = `${this.viewerUrl}?file=${encodeURIComponent(option.url)}`;
|
||
// }
|
||
// // ios,直接访问pdf所在路径
|
||
// else {
|
||
// this.url = encodeURIComponent(option.url);
|
||
// }
|
||
// #endif
|
||
|
||
},
|
||
methods:{
|
||
//乘法函数,用来得到精确的乘法结果
|
||
//说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
|
||
//调用:mul(arg1,arg2)
|
||
//返回值:arg1乘以arg2的精确结果
|
||
//
|
||
ryrtyj(arg1, arg2) {
|
||
var m = 0,
|
||
s1 = arg1.toString(),
|
||
s2 = arg2.toString();
|
||
try {
|
||
m += s1.split(".")[1].length;
|
||
} catch (e) {
|
||
m = 0;
|
||
}
|
||
try {
|
||
m += s2.split(".")[1].length;
|
||
} catch (e) {
|
||
m = m || 0;
|
||
}
|
||
return (
|
||
(Number(s1.replace(".", "")) * Number(s2.replace(".", ""))) /
|
||
Math.pow(10, m)
|
||
);
|
||
}, //除法函数,用来得到精确的除法结果
|
||
//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
|
||
//调用:div(arg1,arg2)
|
||
//返回值:arg1除以arg2的精确结果
|
||
asdcccc(arg1, arg2) {
|
||
var r1, r2, m, n;
|
||
try {
|
||
r1 = arg1.toString().split(".")[1].length;
|
||
} catch (e) {
|
||
r1 = 0;
|
||
}
|
||
try {
|
||
r2 = arg2.toString().split(".")[1].length;
|
||
} catch (e) {
|
||
r2 = 0;
|
||
}
|
||
m = Math.pow(10, Math.max(r1, r2));
|
||
//动态控制精度长度
|
||
n = r1 >= r2 ? r1 : r2;
|
||
return ((arg1 * m - arg2 * m) / m).toFixed(n);
|
||
},
|
||
hgddh(arg1, arg2) {
|
||
var r1, r2, m, n;
|
||
try {
|
||
r1 = arg1.toString().split(".")[1].length;
|
||
} catch (e) {
|
||
r1 = 0;
|
||
}
|
||
try {
|
||
r2 = arg2.toString().split(".")[1].length;
|
||
} catch (e) {
|
||
r2 = 0;
|
||
}
|
||
m = Math.pow(10, Math.max(r1, r2));
|
||
n = r1 >= r2 ? r1 : r2;
|
||
return ((arg1 * m + arg2 * m) / m).toFixed(n);
|
||
},
|
||
asdaghds(arg1, arg2) {
|
||
var t1 = 0,
|
||
t2 = 0,
|
||
r1,
|
||
r2;
|
||
try {
|
||
t1 = arg1.toString().split(".")[1].length;
|
||
} catch (e) {
|
||
t1 = 0;
|
||
}
|
||
try {
|
||
t2 = arg2.toString().split(".")[1].length;
|
||
} catch (e) {
|
||
t2 = 0;
|
||
}
|
||
r1 = Number(arg1.toString().replace(".", ""));
|
||
r2 = Number(arg2.toString().replace(".", ""));
|
||
|
||
},
|
||
/**
|
||
* 保留小数n位,不进行四舍五入
|
||
* num你传递过来的数字,
|
||
* decimal你保留的几位,默认保留小数后两位
|
||
* isInt 是否保留0。如:12.20 是否保留0
|
||
*/
|
||
kuyuiy(num, decimal = 2, isInt = false) {
|
||
num = num.toFixed(3).toString();
|
||
const index = num.indexOf(".");
|
||
if (index !== -1) {
|
||
num = num.substring(0, decimal + index + 1);
|
||
} else {
|
||
num = num.substring(0);
|
||
}
|
||
//截取后保留两位小数
|
||
if (isInt) {
|
||
return parseFloat(num);
|
||
} else {
|
||
return parseFloat(num).toFixed(decimal);
|
||
}
|
||
},
|
||
|
||
//乘法函数,用来得到精确的乘法结果
|
||
//说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
|
||
//调用:mul(arg1,arg2)
|
||
//返回值:arg1乘以arg2的精确结果
|
||
}
|
||
}
|
||
</script>
|
||
<style lang="scss">
|
||
.webview {
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
</style> |