Adapt to mobile devices
This commit is contained in:
113
src/utils/gm.js
Normal file
113
src/utils/gm.js
Normal file
@@ -0,0 +1,113 @@
|
||||
export default {
|
||||
$notice(val) {
|
||||
let div = document.createElement('div')
|
||||
div.classList.add('global-notice')
|
||||
div.textContent = val
|
||||
document.body.append(div)
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(div)
|
||||
}, 1000)
|
||||
},
|
||||
$no() {
|
||||
this.$notice('未实现')
|
||||
},
|
||||
$back() {
|
||||
this.$router.back()
|
||||
// window.history.back()
|
||||
},
|
||||
$stopPropagation(e) {
|
||||
e.stopImmediatePropagation()
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
},
|
||||
$getCss(curEle, attr) {
|
||||
let val = null, reg = null
|
||||
if ("getComputedStyle" in window) {
|
||||
val = window.getComputedStyle(curEle, null)[attr]
|
||||
} else { //ie6~8不支持上面属性
|
||||
//不兼容
|
||||
if (attr === "opacity") {
|
||||
val = curEle.currentStyle["filter"] //'alpha(opacity=12,345)'
|
||||
reg = /^alphaopacity=(\d+(?:\.\d+)?)opacity=(\d+(?:\.\d+)?)$/i
|
||||
val = reg.test(val) ? reg.exec(val)[1] / 100 : 1
|
||||
} else {
|
||||
val = curEle.currentStyle[attr]
|
||||
}
|
||||
}
|
||||
// reg = /^(-?\d+(\.\d)?)(px|pt|em|rem)?$/i
|
||||
// return reg.test(val) ? parseFloat(val) : val
|
||||
return parseFloat(val)
|
||||
},
|
||||
$getCss2(curEle, attr) {
|
||||
let val = null, reg = null
|
||||
if ("getComputedStyle" in window) {
|
||||
val = window.getComputedStyle(curEle, null)[attr]
|
||||
} else { //ie6~8不支持上面属性
|
||||
//不兼容
|
||||
if (attr === "opacity") {
|
||||
val = curEle.currentStyle["filter"] //'alpha(opacity=12,345)'
|
||||
reg = /^alphaopacity=(\d+(?:\.\d+)?)opacity=(\d+(?:\.\d+)?)$/i
|
||||
val = reg.test(val) ? reg.exec(val)[1] / 100 : 1
|
||||
} else {
|
||||
val = curEle.currentStyle[attr]
|
||||
}
|
||||
}
|
||||
// reg = /^(-?\d+(\.\d)?)(px|pt|em|rem)?$/i
|
||||
// return reg.test(val) ? parseFloat(val) : val
|
||||
return val
|
||||
},
|
||||
$setCss(el, key, value) {
|
||||
// console.log(value)
|
||||
if (key === 'transform') {
|
||||
//直接设置不生效
|
||||
el.style.webkitTransform = el.style.MsTransform = el.style.msTransform = el.style.MozTransform = el.style.OTransform = el.style.transform = value;
|
||||
} else {
|
||||
el.style[key] = value
|
||||
}
|
||||
},
|
||||
$nav(path, query = {}) {
|
||||
this.$router.push({path, query})
|
||||
},
|
||||
$clone(v) {
|
||||
return JSON.parse(JSON.stringify(v))
|
||||
},
|
||||
$console(v) {
|
||||
return console.log(JSON.stringify(v, null, 4))
|
||||
},
|
||||
$sleep(duration) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(resolve, duration)
|
||||
})
|
||||
},
|
||||
$getTransform(el) {
|
||||
let transform = el.style.transform
|
||||
if (!transform) return 0
|
||||
// console.log('transform',transform)
|
||||
let transformY = transform.substring(transform.indexOf('0px') + 5, transform.lastIndexOf('0px') - 4)
|
||||
// console.log('transformY',transformY)
|
||||
//当前的transformY
|
||||
transformY = parseInt(transformY)
|
||||
return transformY
|
||||
},
|
||||
getCenter(a, b) {
|
||||
const x = (a.x + b.x) / 2;
|
||||
const y = (a.y + b.y) / 2;
|
||||
return {x, y}
|
||||
},
|
||||
// 获取坐标之间的举例
|
||||
getDistance(start, stop) {
|
||||
return Math.hypot(stop.x - start.x, stop.y - start.y);
|
||||
},
|
||||
copy(val) {
|
||||
const input = document.createElement('input');
|
||||
input.setAttribute('readonly', 'readonly');
|
||||
input.setAttribute('value', val);
|
||||
document.body.appendChild(input);
|
||||
input.setSelectionRange(0, 9999);
|
||||
if (document.execCommand('copy')) {
|
||||
document.execCommand('copy');
|
||||
this.$notice('已复制')
|
||||
}
|
||||
document.body.removeChild(input);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user