一、在app.js利用官方方法获取设备信息,将获取到的screenHeight、windowHeight度量单位统一由rpx换算为px
注:官方文档给出 【rpx换算px (屏幕宽度/750) 】【 px换算rpx (750/屏幕宽度)】
[crayon-67423159dc299[……]
一、在app.js利用官方方法获取设备信息,将获取到的screenHeight、windowHeight度量单位统一由rpx换算为px
注:官方文档给出 【rpx换算px (屏幕宽度/750) 】【 px换算rpx (750/屏幕宽度)】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
<template> <audio src="./static/music.mp3" id="bgMusic" preload="auto" loop></audio> <div class="bgMusicBtn" @click="bgMusicPlayOrPause('bgMusic')"> <img :src="playFlag ? playImg : pauseImg" :class="{rotate: playFlag}"> </div> </template> export default { data() { return { playFlag: true, playImg: require('../../static/play.png'), pauseImg: require('../../static/pause.png'), clickMusicBtn: false } }, mounted() { this.audioAutoPlay('bgMusic'); document.addEventListener("visibilitychange", (e) => { // 兼容ios微信手Q if (this.clickMusicBtn) { // 点击了关闭音乐按钮 if (this.playFlag) { this.audioAutoPlay('bgMusic'); this.playFlag = true; } else { this.audioPause('bgMusic'); this.playFlag = false; } text.innerHTML = e.hidden; if (e.hidden) { // 网页被挂起 this.audioAutoPlay('bgMusic'); this.playFlag = true; } else { // 网页被呼起 this.audioPause('bgMusic'); this.playFlag = false; } } else { // 未点击关闭音乐按钮 if (this.playFlag) { this.audioPause('bgMusic'); this.playFlag = false; } else { this.audioAutoPlay('bgMusic'); this.playFlag = true; } text.innerHTML = e.hidden; if (e.hidden) { // 网页被挂起 this.audioPause('bgMusic'); this.playFlag = false; } else { // 网页被呼起 this.audioAutoPlay('bgMusic'); this.playFlag = true; } } }); }, methods: { bgMusicPlayOrPause(id) { this.clickMusicBtn = !this.clickMusicBtn; if (this.playFlag) { this.audioPause(id); this.playFlag = false; } else { this.audioAutoPlay(id); this.playFlag = true; } }, audioPause(id) { var audio = document.getElementById(id); audio.pause(); document.addEventListener("WeixinJSBridgeReady", function () { audio.pause(); }, false); document.addEventListener('YixinJSBridgeReady', function () { audio.pause(); }, false); }, audioAutoPlay(id) { var audio = document.getElementById(id); audio.play(); document.addEventListener("WeixinJSBridgeReady", function () { audio.play(); }, false); document.addEventListener('YixinJSBridgeReady', function () { audio.play(); }, false); } } } |
webpack打包报错,原因是windows不支持 cross-env,安装模块即可:
npm install -g cross-env
首先新建一个directives.js文件,自定义一个指令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
export const clickOutSide = { // 初始化指令 bind(el, binding, vnode) { function documentHandler(e) { // 这里判断点击的元素是否是本身,是本身,则返回 if (el.contains(e.target)) { return false; } // 判断指令中是否绑定了函数 if (binding.expression) { // 如果绑定了函数 则调用那个函数,此处binding.value就是handleClose方法 binding.value(e); } } // 给当前元素绑定个私有变量,方便在unbind中可以解除事件监听 el.__vueClickOutside__ = documentHandler; document.addEventListener('click', documentHandler); }, update() {}, unbind(el, binding) { // 解除事件监听 document.removeEventListener('click', el.__vueClickOutside__); delete el.__vueClickOutside__; }, }; |
然后在组件内:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<template> <div class="" v-if="closeFlag" v-clickOutSide="handlerClick"> 确认过眼神,不是我的八哥 </div> </template> <script> import {clickOutSide} from './directives' export default { data() { return { closeFlag: true } }, directives: { clickOutSide } </script> |
效果图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
(function rotate(){ var orientation=window.orientation; var pd = null; function createPd(){ if(document.getElementById('preventTran') === null){ var imgData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABaCAYAA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aOiUF2A/slJKTpHkVMnJRkRPmqY5VdbrxqYfwuX2z1kA4Az0P/DzMgCwzzTN424c8CIjpdxd/MCC4zjbLMt6wosNz4R1Xb9ZCMHbydkaX+TxmzpcZ/xjpRSXzwdqfX19S3K5HG8ACrf5IIRYOzg4+KoXw54Jc+HysWPHuH74EpdA25VSW13Kziim6zqXy3OEC20slUq1eX2mxjNhRpNSmlxR64LEHk3THojFYjzkAzUp5e8AoLjs/kdKqQe9GvVLmNON+cGS2dpzjuNsmmnX4sVRXdc7hBA7i3R4hfiYUur3XuywrC/C/CBBOBzm93RC5QCJ6MWxsbGNe/fu9fxhUGovGo1e3tDQcAQRLy78jYieNU2z+EkN17x9Ec4P6xcAgJenaY2IDk5MTNyVTCYnXHsxgyB3bCgUehkRbywim7Ft+4ZEIvGWH/u+Ceu6/pAQ4ntlQF87ffr03UFL5Xt7ey+1bXsfP4ZSjOE4zqOWZfH7A76ab8JdXV1XhUKht2cY0qOO48gdO3bs9+OVYRh3AkAcES8r0edSHM7e5yMcX8034fyw/jMAXAMAXFNYehTETvFE83Wl1F/ceNfd3X2dEOJr+Sdqpj1CRkSHJyYmbg/6UwlE2DAMPuyLZLPZezVNiyFi6ZtazJOJ8+0F54Mdymazbx0/fnwyU2758uWtoVDoI7Ztr+WTRSJaW67eiSfBTCazeefOne+56bjZZAIRzhtmG8Q7mba2tu8AwBcrWKTFnfX4yMjIowcOHMgFJcv6lSA8zQ8p5a0AwJPZqiAOEtEb/AigZVkHg9gp1a04YQaIRCINzc3N9yHil4honYeIF4b/9/Pf374np5k6aU4IF4NJKT8EAO355E5+NelyACjcBvJ7WKMAwLusV3K53L5EIsH/nrP2PzAJNfmP9znfAAAAAElFTkSuQmCC'; pd = document.createElement('div'); pd.setAttribute('id','preventTran'); pd.style.position = 'fixed'; pd.style.left = '0'; pd.style.top = '0'; pd.style.width = '100%'; pd.style.height = '100%'; pd.style.overflow = 'hidden'; pd.style.backgroundColor = '#2e2e2e'; pd.style.textAlign = 'center'; pd.style.zIndex = '99999'; document.getElementsByTagName('body')[0].appendChild(pd); var img = document.createElement('img'); img.src = imgData; pd.appendChild(img); img.style.margin = '60px auto 30px' var br = document.createElement('br'); var p = document.createElement('p'); p.style.width = '100%'; p.style.height = 'auto'; p.style.fontSize = '22px'; p.style.color = '#626262'; p.style.lineHeight = '34px'; p.style.textAlign = 'center'; p.innerHTML = '为了您的良好体验'; p.appendChild(br); p.innerHTML += '请将手机/平板竖屏操作'; pd.appendChild(p); } } if(orientation==90||orientation==-90){ if(pd == null && document.getElementById('preventTran') === null) createPd(); document.getElementById('preventTran').style.display = 'block'; } window.onorientationchange=function(){ if(pd == null && document.getElementById('preventTran') == null) createPd(); document.getElementById('preventTran').style.display='none'; rotate(); }; })(); |
1.vue-easytable (基于vue2.x )
https://github.com/huangshuwei/vue-easytable
http://doc.huangsw.com/vue-easytable/app.html#/table
[crayon-67423159dca[……]
GitHub: https://github.com/skillnull/Get-Device-Info
在线实例:http://skillnull.com/others/GetDeviceInfo/index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
var DeviceInfo = (function () { var root = typeof self !== 'undefined' ? self : this var _window = root || {} // 变量库 var VariableLibrary = { navigator: typeof root.navigator != 'undefined' ? root.navigator : {}, // 信息map infoMap: { engine: ['WebKit', 'Trident', 'Gecko', 'Presto'], browser: ['Safari', 'Chrome', 'Edge', 'IE', 'Firefox', 'Firefox Focus', 'Chromium', 'Opera', 'Vivaldi', 'Yandex', 'Arora', 'Lunascape', 'QupZilla', 'Coc Coc', 'Kindle', 'Iceweasel', 'Konqueror', 'Iceape', 'SeaMonkey', 'Epiphany', '360', '360SE', '360EE', 'UC', 'QQBrowser', 'QQ', 'Baidu', 'Maxthon', 'Sogou', 'LBBROWSER', '2345Explorer', 'TheWorld', 'XiaoMi', 'Quark', 'Qiyu', 'Wechat', 'Taobao', 'Alipay', 'Weibo', 'Douban', 'Suning', 'iQiYi'], os: ['Windows', 'Linux', 'Mac OS', 'Android', 'Ubuntu', 'FreeBSD', 'Debian', 'iOS', 'Windows Phone', 'BlackBerry', 'MeeGo', 'Symbian', 'Chrome OS', 'WebOS'], device: ['Mobile', 'Tablet', 'iPad'] } } // 方法库 var MethodLibrary = (function () { return { // 获取匹配库 getMatchMap: function (u) { return { // 内核 'Trident': u.indexOf('Trident') > -1 || u.indexOf('NET CLR') > -1, 'Presto': u.indexOf('Presto') > -1, 'WebKit': u.indexOf('AppleWebKit') > -1, 'Gecko': u.indexOf('Gecko/') > -1, // 浏览器 'Safari': u.indexOf('Safari') > -1, 'Chrome': u.indexOf('Chrome') > -1 || u.indexOf('CriOS') > -1, 'IE': u.indexOf('MSIE') > -1 || u.indexOf('Trident') > -1, 'Edge': u.indexOf('Edge') > -1, 'Firefox': u.indexOf('Firefox') > -1 || u.indexOf('FxiOS') > -1, 'Firefox Focus': u.indexOf('Focus') > -1, 'Chromium': u.indexOf('Chromium') > -1, 'Opera': u.indexOf('Opera') > -1 || u.indexOf('OPR') > -1, 'Vivaldi': u.indexOf('Vivaldi') > -1, 'Yandex': u.indexOf('YaBrowser') > -1, 'Arora': u.indexOf('Arora') > -1, 'Lunascape': u.indexOf('Lunascape') > -1, 'QupZilla': u.indexOf('QupZilla') > -1, 'Coc Coc': u.indexOf('coc_coc_browser') > -1, 'Kindle': u.indexOf('Kindle') > -1 || u.indexOf('Silk/') > -1, 'Iceweasel': u.indexOf('Iceweasel') > -1, 'Konqueror': u.indexOf('Konqueror') > -1, 'Iceape': u.indexOf('Iceape') > -1, 'SeaMonkey': u.indexOf('SeaMonkey') > -1, 'Epiphany': u.indexOf('Epiphany') > -1, '360': u.indexOf('QihooBrowser') > -1 || u.indexOf('QHBrowser') > -1, '360EE': u.indexOf('360EE') > -1, '360SE': u.indexOf('360SE') > -1, 'UC': u.indexOf('UC') > -1 || u.indexOf(' UBrowser') > -1, 'QQBrowser': u.indexOf('QQBrowser') > -1, 'QQ': u.indexOf('QQ/') > -1, 'Baidu': u.indexOf('Baidu') > -1 || u.indexOf('BIDUBrowser') > -1, 'Maxthon': u.indexOf('Maxthon') > -1, 'Sogou': u.indexOf('MetaSr') > -1 || u.indexOf('Sogou') > -1, 'LBBROWSER': u.indexOf('LBBROWSER') > -1, '2345Explorer': u.indexOf('2345Explorer') > -1, 'TheWorld': u.indexOf('TheWorld') > -1, 'XiaoMi': u.indexOf('MiuiBrowser') > -1, 'Quark': u.indexOf('Quark') > -1, 'Qiyu': u.indexOf('Qiyu') > -1, 'Wechat': u.indexOf('MicroMessenger') > -1, 'Taobao': u.indexOf('AliApp(TB') > -1, 'Alipay': u.indexOf('AliApp(AP') > -1, 'Weibo': u.indexOf('Weibo') > -1, 'Douban': u.indexOf('com.douban.frodo') > -1, 'Suning': u.indexOf('SNEBUY-APP') > -1, 'iQiYi': u.indexOf('IqiyiApp') > -1, // 系统或平台 'Windows': u.indexOf('Windows') > -1, 'Linux': u.indexOf('Linux') > -1 || u.indexOf('X11') > -1, 'Mac OS': u.indexOf('Macintosh') > -1, 'Android': u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, 'Ubuntu': u.indexOf('Ubuntu') > -1, 'FreeBSD': u.indexOf('FreeBSD') > -1, 'Debian': u.indexOf('Debian') > -1, 'Windows Phone': u.indexOf('IEMobile') > -1 || u.indexOf('Windows Phone') > -1, 'BlackBerry': u.indexOf('BlackBerry') > -1 || u.indexOf('RIM') > -1, 'MeeGo': u.indexOf('MeeGo') > -1, 'Symbian': u.indexOf('Symbian') > -1, 'iOS': u.indexOf('like Mac OS X') > -1, 'Chrome OS': u.indexOf('CrOS') > -1, 'WebOS': u.indexOf('hpwOS') > -1, // 设备 'Mobile': u.indexOf('Mobi') > -1 || u.indexOf('iPh') > -1 || u.indexOf('480') > -1, 'Tablet': u.indexOf('Tablet') > -1 || u.indexOf('Nexus 7') > -1, 'iPad': u.indexOf('iPad') > -1 } }, // 在信息map和匹配库中进行匹配 matchInfoMap: function (_this) { var u = VariableLibrary.navigator.userAgent || {} var match = MethodLibrary.getMatchMap(u) for (var s in VariableLibrary.infoMap) { for (var i = 0; i < VariableLibrary.infoMap[s].length; i++) { var value = VariableLibrary.infoMap[s][i] if (match[value]) { _this[s] = value } } } }, // 获取当前操作系统 getOS: function () { var _this = this MethodLibrary.matchInfoMap(_this) return _this.os }, // 获取操作系统版本 getOSVersion: function () { var _this = this var u = VariableLibrary.navigator.userAgent || {} _this.osVersion = '' // 系统版本信息 var osVersion = { 'Windows': function () { var v = u.replace(/^.*Windows NT ([\d.]+);.*$/, '$1') var oldWindowsVersionMap = { '6.4': '10', '6.3': '8.1', '6.2': '8', '6.1': '7', '6.0': 'Vista', '5.2': 'XP', '5.1': 'XP', '5.0': '2000' } return oldWindowsVersionMap[v] || v }, 'Android': function () { return u.replace(/^.*Android ([\d.]+);.*$/, '$1') }, 'iOS': function () { return u.replace(/^.*OS ([\d_]+) like.*$/, '$1').replace(/_/g, '.') }, 'Debian': function () { return u.replace(/^.*Debian\/([\d.]+).*$/, '$1') }, 'Windows Phone': function () { return u.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/, '$2') }, 'Mac OS': function () { return u.replace(/^.*Mac OS X ([\d_]+).*$/, '$1').replace(/_/g, '.') }, 'WebOS': function () { return u.replace(/^.*hpwOS\/([\d.]+);.*$/, '$1') } } if (osVersion[_this.os]) { _this.osVersion = osVersion[_this.os]() if (_this.osVersion == u) { _this.osVersion = '' } } return _this.osVersion }, // 获取横竖屏状态 getOrientationStatu: function () { var orientationStatus = '' var orientation = window.matchMedia("(orientation: portrait)") if (orientation.matches) { orientationStatus = "竖屏" } else { orientationStatus = "横屏" } return orientationStatus }, // 获取设备类型 getDeviceType: function () { var _this = this _this.device = 'PC' MethodLibrary.matchInfoMap(_this) return _this.device }, // 获取网络状态 getNetwork: function () { var netWork = navigator && navigator.connection && navigator.connection.effectiveType return netWork }, // 获取当前语言 getLanguage: function () { var _this = this _this.language = (function () { var language = (VariableLibrary.navigator.browserLanguage || VariableLibrary.navigator.language) var arr = language.split('-') if (arr[1]) { arr[1] = arr[1].toUpperCase() } return arr.join('_') })() return _this.language }, // 生成浏览器指纹 createFingerprint: function (domain) { var fingerprint function bin2hex (s) { var i, l, n, o = '' s += '' for (i = 0, l = s.length; i < l; i++) { n = s.charCodeAt(i) .toString(16) o += n.length < 2 ? '0' + n : n } return o } var canvas = document.createElement('canvas') var ctx = canvas.getContext('2d') var txt = domain || window.location.host ctx.textBaseline = "top" ctx.font = "14px 'Arial'" ctx.textBaseline = "tencent" ctx.fillStyle = "#f60" ctx.fillRect(125, 1, 62, 20) ctx.fillStyle = "#069" ctx.fillText(txt, 2, 15) ctx.fillStyle = "rgba(102, 204, 0, 0.7)" ctx.fillText(txt, 4, 17) var b64 = canvas.toDataURL().replace("data:image/png;base64,", "") var bin = atob(b64) var crc = bin2hex(bin.slice(-16, -12)) fingerprint = crc return fingerprint }, // 浏览器信息 getBrowserInfo: function () { var _this = this MethodLibrary.matchInfoMap(_this) var u = VariableLibrary.navigator.userAgent || {} var _mime = function (option, value) { var mimeTypes = VariableLibrary.navigator.mimeTypes for (var key in mimeTypes) { if (mimeTypes[key][option] == value) { return true } } return false } var match = MethodLibrary.getMatchMap(u) var is360 = false if (_window.chrome) { var chrome_vision = u.replace(/^.*Chrome\/([\d]+).*$/, '$1') if (chrome_vision > 36 && _window.showModalDialog) { is360 = true } else if (chrome_vision > 45) { is360 = _mime("type", "application/vnd.chromium.remoting-viewer") } } if (match['Baidu'] && match['Opera']) { match['Baidu'] = false } if (match['Mobile']) { match['Mobile'] = !(u.indexOf('iPad') > -1) } if (is360) { if (_mime("type", "application/gameplugin")) { match['360SE'] = true } else if (VariableLibrary.navigator && typeof VariableLibrary.navigator['connection']['saveData'] == 'undefined') { match['360SE'] = true } else { match['360EE'] = true } } if (match['IE'] || match['Edge']) { var navigator_top = window.screenTop - window.screenY switch (navigator_top) { case 71: // 无收藏栏,贴边 break case 74: // 无收藏栏,非贴边 break case 99: // 有收藏栏,贴边 break case 102: // 有收藏栏,非贴边 match['360EE'] = true break; case 75: // 无收藏栏,贴边 break case 74: // 无收藏栏,非贴边 break case 105: // 有收藏栏,贴边 break case 104: // 有收藏栏,非贴边 match['360SE'] = true break default: break } } var browerVersionMap = { 'Safari': function () { return u.replace(/^.*Version\/([\d.]+).*$/, '$1') }, 'Chrome': function () { return u.replace(/^.*Chrome\/([\d.]+).*$/, '$1').replace(/^.*CriOS\/([\d.]+).*$/, '$1') }, 'IE': function () { return u.replace(/^.*MSIE ([\d.]+).*$/, '$1').replace(/^.*rv:([\d.]+).*$/, '$1') }, 'Edge': function () { return u.replace(/^.*Edge\/([\d.]+).*$/, '$1') }, 'Firefox': function () { return u.replace(/^.*Firefox\/([\d.]+).*$/, '$1').replace(/^.*FxiOS\/([\d.]+).*$/, '$1') }, 'Firefox Focus': function () { return u.replace(/^.*Focus\/([\d.]+).*$/, '$1') }, 'Chromium': function () { return u.replace(/^.*Chromium\/([\d.]+).*$/, '$1') }, 'Opera': function () { return u.replace(/^.*Opera\/([\d.]+).*$/, '$1').replace(/^.*OPR\/([\d.]+).*$/, '$1') }, 'Vivaldi': function () { return u.replace(/^.*Vivaldi\/([\d.]+).*$/, '$1') }, 'Yandex': function () { return u.replace(/^.*YaBrowser\/([\d.]+).*$/, '$1') }, 'Arora': function () { return u.replace(/^.*Arora\/([\d.]+).*$/, '$1') }, 'Lunascape': function () { return u.replace(/^.*Lunascape[\/\s]([\d.]+).*$/, '$1') }, 'QupZilla': function () { return u.replace(/^.*QupZilla[\/\s]([\d.]+).*$/, '$1') }, 'Coc Coc': function () { return u.replace(/^.*coc_coc_browser\/([\d.]+).*$/, '$1') }, 'Kindle': function () { return u.replace(/^.*Version\/([\d.]+).*$/, '$1') }, 'Iceweasel': function () { return u.replace(/^.*Iceweasel\/([\d.]+).*$/, '$1') }, 'Konqueror': function () { return u.replace(/^.*Konqueror\/([\d.]+).*$/, '$1') }, 'Iceape': function () { return u.replace(/^.*Iceape\/([\d.]+).*$/, '$1') }, 'SeaMonkey': function () { return u.replace(/^.*SeaMonkey\/([\d.]+).*$/, '$1') }, 'Epiphany': function () { return u.replace(/^.*Epiphany\/([\d.]+).*$/, '$1') }, '360': function () { return u.replace(/^.*QihooBrowser\/([\d.]+).*$/, '$1') }, '360SE': function () { var hash = {'63': '10.0', '55': '9.1', '45': '8.1', '42': '8.0', '31': '7.0', '21': '6.3'} var chrome_vision = u.replace(/^.*Chrome\/([\d]+).*$/, '$1') return hash[chrome_vision] || '' }, '360EE': function () { var hash = {'69': '11.0', '63': '9.5', '55': '9.0', '50': '8.7', '30': '7.5'}; var chrome_vision = u.replace(/^.*Chrome\/([\d]+).*$/, '$1') return hash[chrome_vision] || '' }, 'Maxthon': function () { return u.replace(/^.*Maxthon\/([\d.]+).*$/, '$1') }, 'QQBrowser': function () { return u.replace(/^.*QQBrowser\/([\d.]+).*$/, '$1') }, 'QQ': function () { return u.replace(/^.*QQ\/([\d.]+).*$/, '$1') }, 'Baidu': function () { return u.replace(/^.*BIDUBrowser[\s\/]([\d.]+).*$/, '$1') }, 'UC': function () { return u.replace(/^.*UC?Browser\/([\d.]+).*$/, '$1') }, 'Sogou': function () { return u.replace(/^.*SE ([\d.X]+).*$/, '$1').replace(/^.*SogouMobileBrowser\/([\d.]+).*$/, '$1') }, 'LBBROWSER': function () { var hash = {'57': '6.5', '49': '6.0', '46': '5.9', '42': '5.3', '39': '5.2', '34': '5.0', '29': '4.5', '21': '4.0'}; var chrome_vision = navigator.userAgent.replace(/^.*Chrome\/([\d]+).*$/, '$1'); return hash[chrome_vision] || ''; }, '2345Explorer': function () { return u.replace(/^.*2345Explorer\/([\d.]+).*$/, '$1') }, 'TheWorld': function () { return u.replace(/^.*TheWorld ([\d.]+).*$/, '$1') }, 'XiaoMi': function () { return u.replace(/^.*MiuiBrowser\/([\d.]+).*$/, '$1') }, 'Quark': function () { return u.replace(/^.*Quark\/([\d.]+).*$/, '$1') }, 'Qiyu': function () { return u.replace(/^.*Qiyu\/([\d.]+).*$/, '$1') }, 'Wechat': function () { return u.replace(/^.*MicroMessenger\/([\d.]+).*$/, '$1') }, 'Taobao': function () { return u.replace(/^.*AliApp\(TB\/([\d.]+).*$/, '$1') }, 'Alipay': function () { return u.replace(/^.*AliApp\(AP\/([\d.]+).*$/, '$1') }, 'Weibo': function () { return u.replace(/^.*weibo__([\d.]+).*$/, '$1') }, 'Douban': function () { return u.replace(/^.*com.douban.frodo\/([\d.]+).*$/, '$1') }, 'Suning': function () { return u.replace(/^.*SNEBUY-APP([\d.]+).*$/, '$1') }, 'iQiYi': function () { return u.replace(/^.*IqiyiVersion\/([\d.]+).*$/, '$1') } } _this.browserVersion = '' if (browerVersionMap[_this.browser]) { _this.browserVersion = browerVersionMap[_this.browser]() if (_this.browserVersion == u) { _this.browserVersion = '' } } if (_this.browser == 'Edge') { _this.engine = 'EdgeHTML' } if (_this.browser == 'Chrome' && parseInt(_this.browserVersion) > 27) { _this.engine = 'Blink' } if (_this.browser == 'Opera' && parseInt(_this.browserVersion) > 12) { _this.engine = 'Blink' } if (_this.browser == 'Yandex') { _this.engine = 'Blink' } return _this.browser + '(版本: ' + _this.browserVersion + ' 内核: ' + _this.engine + ')' } } })() // 逻辑层 var LogicLibrary = (function () { return { DeviceInfoObj: function (params) { var info = { deviceType: MethodLibrary.getDeviceType(), // 设备类型 OS: MethodLibrary.getOS(), // 操作系统 OSVersion: MethodLibrary.getOSVersion(), // 操作系统版本 screenHeight: _window.screen.height, // 屏幕高 screenWidth: _window.screen.width, // 屏幕宽 language: MethodLibrary.getLanguage(), // 当前使用的语言-国家 netWork: MethodLibrary.getNetwork(), // 联网类型 orientation: MethodLibrary.getOrientationStatu(), // 横竖屏 browserInfo: MethodLibrary.getBrowserInfo(), // 浏览器信息 fingerprint: MethodLibrary.createFingerprint(params.domain), // 浏览器指纹 userAgent: VariableLibrary.navigator.userAgent // 包含 appCodeName,appName,appVersion,language,platform 等 } if (!params.info || params.info.length == 0) { return info } else { var infoTemp = {} for (var i in info) { params.info.forEach(function (item) { if (item.toLowerCase() == i.toLowerCase()) { item = i infoTemp[item] = info[item] } }) } return infoTemp } } } })() // 对外暴露方法 return { getDeviceInfo: function (params) { return LogicLibrary.DeviceInfoObj(params) } } })() |
&[……]
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * @function Determine if the image has been loaded. * @param img,callback */ function imgIsLoaded(img, callback) { var timer = setInterval(function () { if (img.complete) { callback(img) clearInterval(timer) } }, 50) } |
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * 如果target(也就是FirstOBJ[key])存在, * 且是对象的话再去调用deepObjectMerge, * 否则就是FirstOBJ[key]里面没这个对象,需要与SecondOBJ[key]合并 */ function deepObjectMerge(FirstOBJ, SecondOBJ) { // 深度合并对象 for (var key in SecondOBJ) { FirstOBJ[key] = FirstOBJ[key] && FirstOBJ[key].toString() === "[object Object]" ? deepObjectMerge(FirstOBJ[key], SecondOBJ[key]) : FirstOBJ[key] = SecondOBJ[key]; } return FirstOBJ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/** * @function Monitor whether the document tree is loaded. * @param fn */ function domReady(fn) { if (document.addEventListener) { // 标准浏览器 document.addEventListener('DOMContentLoaded', function () { //注销时间,避免重复触发 document.removeEventListener('DOMContentLoaded', arguments.callee, false); fn(); // 运行函数 }, false); } else if (document.attachEvent) { // IE浏览器 document.attachEvent('onreadystatechange', function () { if (document.readyState == 'complete') { document.detachEvent('onreadystatechange', arguments.callee); fn(); // 函数运行 } }); } } domReady(loadStart); |