Files
supplier-dispatch-h5/src/utils/myMixins.js
T

123 lines
3.6 KiB
JavaScript

import { getLog } from "@/api/order"
let _setLogTimer = null
export const myMixins = {
data() {
return {
}
},
methods: {
setLogHandler(data) {
if (_setLogTimer) return
_setLogTimer = setTimeout(() => { _setLogTimer = null }, 1000)
getLog(data)
},
showFun() {
if( localStorage.getItem('infoVerify') == 8 || localStorage.getItem('infoVerify') == 12 ) {
return false
}
return true
},
goPage(page, query) {
this.$router.push({
name: page,
query: query
})
},
copyText(){//复制订单编号
const copyText = document.getElementById('copyText');
const range = document.createRange();
range.selectNode(copyText);
window.getSelection().removeAllRanges(); // 清除当前页面的选择内容
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges(); // 清除选择内容的高亮状态
this.$toast('复制成功')
},
goBack(){//h5返回APP
let data = {"action":"goBack","params":""}
var u = navigator.userAgent;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
// var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
if(isiOS){
window.webkit.messageHandlers.nativeObject.postMessage(data);
}else {
window.android.sendMessage("goBack");
}
},
goH5Detail(item,type){//h5传参到app文档资料,培训文档
// console.log("type",type)
let data = {
"action": "goTraining",
"params": {
"id":type == '培训文档' ? Number(1000000+item.id) : item.id,
}
};
let u = navigator.userAgent;
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if(isiOS){
// console.log("data",data)
window.webkit.messageHandlers.nativeObject.postMessage(data);
}else {
if(type == '培训文档'){
window.android.sendMessage("articleId=" +'q'+ item.id);
}else{
window.android.sendMessage("articleId=" + item.id);
}
}
},
h5GoBack(){
this.$router.back();
},
noMultipleClicks(methods, info) {
// methods是需要点击后需要执行的函数, info是点击需要传的参数
let that = this;
if (that.noClick) {
// 第一次点击
that.noClick = false;
if (info && info !== '') {
//info是执行函数需要传的参数
methods(info)
} else {
methods();
}
setTimeout(() => {
that.noClick = true;
}, 3000)
} else {
// 这里是重复点击的判断
}
},
formatNumber(num) {
if (num < 10000) {
// 小于 5 位数,显示为 0.x 万
return `${(num / 10000).toFixed(1)}`;
} else {
// 大于或等于 5 位数,显示为 x 万,四舍五入到小数点后一位
return `${Math.round(num / 1000) / 10}`;
}
},
isWebFunc(){
let res=false
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
console.log('isMobile',isMobile)
if (!isMobile) {// 是移动端不变
res=true
}
return res
},
closeParentDialog() {
if (window.parent) {
const hasListener = window.parent.dispatchEvent(new Event('checkCloseDialog'));
if (hasListener) {
window.parent.postMessage('closeDialog', '*');
} else {
window.history.back();
}
}
},
}
}