From eb23a7c7faefe86330a88f9118b8211f6b86e75b Mon Sep 17 00:00:00 2001 From: loulijun2021 <1694218219@qq.com> Date: 星期二, 20 九月 2022 19:00:58 +0800 Subject: [PATCH] 1.点检项目开发( 除提交功能外完成) --- js/common.js | 473 +++++++++++++++++++++++++++++++---------------------------- 1 files changed, 248 insertions(+), 225 deletions(-) diff --git a/js/common.js b/js/common.js index 2a5c880..ac4a291 100644 --- a/js/common.js +++ b/js/common.js @@ -1,178 +1,189 @@ -(function(w){ -// 绌哄嚱鏁� -function shield(){ - return false; -} -document.addEventListener('touchstart', shield, false);//鍙栨秷娴忚鍣ㄧ殑鎵�鏈変簨浠讹紝浣垮緱active鐨勬牱寮忓湪鎵嬫満涓婃甯哥敓鏁� -document.oncontextmenu=shield;//灞忚斀閫夋嫨鍑芥暟 -// H5 plus浜嬩欢澶勭悊 -var ws=null,as='pop-in'; -function plusReady(){ - ws=plus.webview.currentWebview(); - plus.key.addEventListener('backbutton', function(){ - back(); - },false); -} -if(w.plus){ - plusReady(); -}else{ - document.addEventListener('plusready', plusReady, false); -} -// DOMContentLoaded浜嬩欢澶勭悊 -document.addEventListener('DOMContentLoaded', function(){ - gInit(); - document.body.onselectstart=shield; -},false); -// 杩斿洖 -w.back=function(hide){ - if(w.plus){ - ws||(ws=plus.webview.currentWebview()); - (hide||ws.preate)?ws.hide('auto'):ws.close('auto'); - }else if(history.length>1){ - history.back(); - }else{ - w.close(); +(function(w) { + // 绌哄嚱鏁� + function shield() { + return false; } -}; -// 澶勭悊鐐瑰嚮浜嬩欢 -var openw=null; -/** - * 鎵撳紑鏂扮獥鍙� - * @param {URIString} id : 瑕佹墦寮�椤甸潰url - * @param {String} t : 椤甸潰鏍囬鍚嶇О - * @param {JSON} ws : Webview绐楀彛灞炴�� - */ -w.clicked=function(id, t, ws){ - if(openw){//閬垮厤澶氭鎵撳紑鍚屼竴涓〉闈� - return null; - } - if(w.plus){ - ws=ws||{}; - ws.scrollIndicator||(ws.scrollIndicator='none'); - ws.scalable||(ws.scalable=false); - ws.backButtonAutoControl||(ws.backButtonAutoControl='close'); - ws.titleNView=ws.titleNView||{autoBackButton:true}; - ws.titleNView.backgroundColor = '#D74B28'; - ws.titleNView.titleColor = '#CCCCCC'; - ws.doc&&(ws.titleNView.buttons=ws.titleNView.buttons||[],ws.titleNView.buttons.push({fontSrc:'_www/helloh5.ttf',text:'\ue301',fontSize:'20px',onclick:'javascript:openDoc()'})); - t&&(ws.titleNView.titleText=t); - openw = plus.webview.create(id, id, ws); - openw.addEventListener('loaded', function(){ - openw.show(as); + document.addEventListener('touchstart', shield, false); //鍙栨秷娴忚鍣ㄧ殑鎵�鏈変簨浠讹紝浣垮緱active鐨勬牱寮忓湪鎵嬫満涓婃甯哥敓鏁� + document.oncontextmenu = shield; //灞忚斀閫夋嫨鍑芥暟 + // H5 plus浜嬩欢澶勭悊 + var ws = null, + as = 'pop-in'; + + function plusReady() { + ws = plus.webview.currentWebview(); + plus.key.addEventListener('backbutton', function() { + back(); }, false); - openw.addEventListener('close', function(){ - openw=null; - }, false); - return openw; - }else{ - w.open(id); } - return null; -}; -/** - * 鍒涘缓鏂扮獥鍙o紙鏃犲師濮嬫爣棰樻爮锛夛紝 - * @param {URIString} id : 瑕佹墦寮�椤甸潰url - * @param {JSON} ws : Webview绐楀彛灞炴�� - */ -w.createWithoutTitle=function(id, ws){ - if(openw){//閬垮厤澶氭鎵撳紑鍚屼竴涓〉闈� - return null; + if (w.plus) { + plusReady(); + } else { + document.addEventListener('plusready', plusReady, false); } - if(w.plus){ - ws=ws||{}; - ws.scrollIndicator||(ws.scrollIndicator='none'); - ws.scalable||(ws.scalable=false); - ws.backButtonAutoControl||(ws.backButtonAutoControl='close'); - openw = plus.webview.create(id, id, ws); - openw.addEventListener('close', function(){ - openw=null; - }, false); - return openw; - }else{ - w.open(id); - } - return null; -}; -/** - * 鎵撳紑鏂囨。椤甸潰 - * @param {URIString} c : 瑕佹墦寮�椤甸潰url - */ -w.openDoc=function(c){ - plus.webview.create(c, 'document', { - titleNView:{ - autoBackButton:true, - backgroundColor:'#D74B28', - titleColor:'#CCCCCC' - }, - backButtonAutoControl:'close', - scalable:false - }).show('pop-in'); -}; -/** - * 鍏煎鎻愮ず - */ -w.compatibleConfirm=function(){ - plus.nativeUI.confirm('鏈琌S鍘熺敓灞傞潰涓嶆彁渚涜鎺т欢锛岄渶浣跨敤mui妗嗘灦瀹炵幇绫讳技鏁堟灉銆傝鐐瑰嚮鈥滅‘瀹氣�濅笅杞紿ello mui绀轰緥',function(e){ - if(0==e.index){ - plus.runtime.openURL("http://www.dcloud.io/hellomui/"); + // DOMContentLoaded浜嬩欢澶勭悊 + document.addEventListener('DOMContentLoaded', function() { + gInit(); + document.body.onselectstart = shield; + }, false); + // 杩斿洖 + w.back = function(hide) { + if (w.plus) { + ws || (ws = plus.webview.currentWebview()); + (hide || ws.preate) ? ws.hide('auto'): ws.close('auto'); + } else if (history.length > 1) { + history.back(); + } else { + w.close(); } - },"",["纭畾","鍙栨秷"]); -} -// 閫氱敤鍏冪礌瀵硅薄 -var _dout_=null; -w.gInit=function(){ - _dout_=document.getElementById("output"); -}; -// 娓呯┖杈撳嚭鍐呭 -w.outClean=function(){ - _dout_.innerText=""; - _dout_.scrollTop=0;//鍦╥OS8瀛樺湪涓嶆粴鍔ㄧ殑鐜拌薄 -}; -// 杈撳嚭鍐呭 -w.outSet=function(s){ - console.log(s); - _dout_.innerText=s+"\n"; - (0==_dout_.scrollTop)&&(_dout_.scrollTop=1);//鍦╥OS8瀛樺湪涓嶆粴鍔ㄧ殑鐜拌薄 -}; -// 杈撳嚭琛屽唴瀹� -w.outLine=function(s){ - console.log(s); - _dout_.innerText+=s+"\n"; - (0==_dout_.scrollTop)&&(_dout_.scrollTop=1);//鍦╥OS8瀛樺湪涓嶆粴鍔ㄧ殑鐜拌薄 -}; -// 鏍煎紡鍖栨椂闀垮瓧绗︿覆锛屾牸寮忎负"HH:MM:SS" -w.timeToStr=function(ts){ - if(isNaN(ts)){ - return "--:--:--"; + }; + // 澶勭悊鐐瑰嚮浜嬩欢 + var openw = null; + /** + * 鎵撳紑鏂扮獥鍙� + * @param {URIString} id : 瑕佹墦寮�椤甸潰url + * @param {String} t : 椤甸潰鏍囬鍚嶇О + * @param {JSON} ws : Webview绐楀彛灞炴�� + */ + w.clicked = function(id, t, ws) { + if (openw) { //閬垮厤澶氭鎵撳紑鍚屼竴涓〉闈� + return null; + } + if (w.plus) { + ws = ws || {}; + ws.scrollIndicator || (ws.scrollIndicator = 'none'); + ws.scalable || (ws.scalable = false); + ws.backButtonAutoControl || (ws.backButtonAutoControl = 'close'); + ws.titleNView = ws.titleNView || { + autoBackButton: true + }; + ws.titleNView.backgroundColor = '#D74B28'; + ws.titleNView.titleColor = '#CCCCCC'; + ws.doc && (ws.titleNView.buttons = ws.titleNView.buttons || [], ws.titleNView.buttons.push({ + fontSrc: '_www/helloh5.ttf', + text: '\ue301', + fontSize: '20px', + onclick: 'javascript:openDoc()' + })); + t && (ws.titleNView.titleText = t); + openw = plus.webview.create(id, id, ws); + openw.addEventListener('loaded', function() { + openw.show(as); + }, false); + openw.addEventListener('close', function() { + openw = null; + }, false); + return openw; + } else { + w.open(id); + } + return null; + }; + /** + * 鍒涘缓鏂扮獥鍙o紙鏃犲師濮嬫爣棰樻爮锛夛紝 + * @param {URIString} id : 瑕佹墦寮�椤甸潰url + * @param {JSON} ws : Webview绐楀彛灞炴�� + */ + w.createWithoutTitle = function(id, ws) { + if (openw) { //閬垮厤澶氭鎵撳紑鍚屼竴涓〉闈� + return null; + } + if (w.plus) { + ws = ws || {}; + ws.scrollIndicator || (ws.scrollIndicator = 'none'); + ws.scalable || (ws.scalable = false); + ws.backButtonAutoControl || (ws.backButtonAutoControl = 'close'); + openw = plus.webview.create(id, id, ws); + openw.addEventListener('close', function() { + openw = null; + }, false); + return openw; + } else { + w.open(id); + } + return null; + }; + /** + * 鎵撳紑鏂囨。椤甸潰 + * @param {URIString} c : 瑕佹墦寮�椤甸潰url + */ + w.openDoc = function(c) { + plus.webview.create(c, 'document', { + titleNView: { + autoBackButton: true, + backgroundColor: '#D74B28', + titleColor: '#CCCCCC' + }, + backButtonAutoControl: 'close', + scalable: false + }).show('pop-in'); + }; + /** + * 鍏煎鎻愮ず + */ + w.compatibleConfirm = function() { + plus.nativeUI.confirm('鏈琌S鍘熺敓灞傞潰涓嶆彁渚涜鎺т欢锛岄渶浣跨敤mui妗嗘灦瀹炵幇绫讳技鏁堟灉銆傝鐐瑰嚮鈥滅‘瀹氣�濅笅杞紿ello mui绀轰緥', function(e) { + if (0 == e.index) { + plus.runtime.openURL("http://www.dcloud.io/hellomui/"); + } + }, "", ["纭畾", "鍙栨秷"]); } - var h=parseInt(ts/3600); - var m=parseInt((ts%3600)/60); - var s=parseInt(ts%60); - return (ultZeroize(h)+":"+ultZeroize(m)+":"+ultZeroize(s)); -}; -// 鏍煎紡鍖栨棩鏈熸椂闂村瓧绗︿覆锛屾牸寮忎负"YYYY-MM-DD HH:MM:SS" -w.dateToStr=function(d){ - return (d.getFullYear()+"-"+ultZeroize(d.getMonth()+1)+"-"+ultZeroize(d.getDate())+" "+ultZeroize(d.getHours())+":"+ultZeroize(d.getMinutes())+":"+ultZeroize(d.getSeconds())); -}; -/** - * zeroize value with length(default is 2). - * @param {Object} v - * @param {Number} l - * @return {String} - */ -w.ultZeroize=function(v,l){ - var z=""; - l=l||2; - v=String(v); - for(var i=0;i<l-v.length;i++){ - z+="0"; - } - return z+v; -}; + // 閫氱敤鍏冪礌瀵硅薄 + var _dout_ = null; + w.gInit = function() { + _dout_ = document.getElementById("output"); + }; + // 娓呯┖杈撳嚭鍐呭 + w.outClean = function() { + _dout_.innerText = ""; + _dout_.scrollTop = 0; //鍦╥OS8瀛樺湪涓嶆粴鍔ㄧ殑鐜拌薄 + }; + // 杈撳嚭鍐呭 + w.outSet = function(s) { + console.log(s); + _dout_.innerText = s + "\n"; + (0 == _dout_.scrollTop) && (_dout_.scrollTop = 1); //鍦╥OS8瀛樺湪涓嶆粴鍔ㄧ殑鐜拌薄 + }; + // 杈撳嚭琛屽唴瀹� + w.outLine = function(s) { + console.log(s); + _dout_.innerText += s + "\n"; + (0 == _dout_.scrollTop) && (_dout_.scrollTop = 1); //鍦╥OS8瀛樺湪涓嶆粴鍔ㄧ殑鐜拌薄 + }; + // 鏍煎紡鍖栨椂闀垮瓧绗︿覆锛屾牸寮忎负"HH:MM:SS" + w.timeToStr = function(ts) { + if (isNaN(ts)) { + return "--:--:--"; + } + var h = parseInt(ts / 3600); + var m = parseInt((ts % 3600) / 60); + var s = parseInt(ts % 60); + return (ultZeroize(h) + ":" + ultZeroize(m) + ":" + ultZeroize(s)); + }; + // 鏍煎紡鍖栨棩鏈熸椂闂村瓧绗︿覆锛屾牸寮忎负"YYYY-MM-DD HH:MM:SS" + w.dateToStr = function(d) { + return (d.getFullYear() + "-" + ultZeroize(d.getMonth() + 1) + "-" + ultZeroize(d.getDate()) + " " + + ultZeroize(d.getHours()) + ":" + ultZeroize(d.getMinutes()) + ":" + ultZeroize(d.getSeconds())); + }; + /** + * zeroize value with length(default is 2). + * @param {Object} v + * @param {Number} l + * @return {String} + */ + w.ultZeroize = function(v, l) { + var z = ""; + l = l || 2; + v = String(v); + for (var i = 0; i < l - v.length; i++) { + z += "0"; + } + return z + v; + }; })(window); // fast click -;(function () { +; +(function() { 'use strict'; /** @@ -282,7 +293,9 @@ // Some old versions of Android don't have Function.prototype.bind function bind(method, context) { - return function() { return method.apply(context, arguments); }; + return function() { + return method.apply(context, arguments); + }; } @@ -348,10 +361,10 @@ } /** - * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. - * - * @type boolean - */ + * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. + * + * @type boolean + */ var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0; /** @@ -401,27 +414,27 @@ FastClick.prototype.needsClick = function(target) { switch (target.nodeName.toLowerCase()) { - // Don't send a synthetic click to disabled inputs (issue #62) - case 'button': - case 'select': - case 'textarea': - if (target.disabled) { + // Don't send a synthetic click to disabled inputs (issue #62) + case 'button': + case 'select': + case 'textarea': + if (target.disabled) { + return true; + } + + break; + case 'input': + + // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) + if ((deviceIsIOS && target.type === 'file') || target.disabled) { + return true; + } + + break; + case 'label': + case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames + case 'video': return true; - } - - break; - case 'input': - - // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) - if ((deviceIsIOS && target.type === 'file') || target.disabled) { - return true; - } - - break; - case 'label': - case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames - case 'video': - return true; } return (/\bneedsclick\b/).test(target.className); @@ -436,25 +449,25 @@ */ FastClick.prototype.needsFocus = function(target) { switch (target.nodeName.toLowerCase()) { - case 'textarea': - return true; - case 'select': - return !deviceIsAndroid; - case 'input': - switch (target.type) { - case 'button': - case 'checkbox': - case 'file': - case 'image': - case 'radio': - case 'submit': - return false; - } + case 'textarea': + return true; + case 'select': + return !deviceIsAndroid; + case 'input': + switch (target.type) { + case 'button': + case 'checkbox': + case 'file': + case 'image': + case 'radio': + case 'submit': + return false; + } - // No point in attempting to focus disabled inputs - return !target.disabled && !target.readOnly; - default: - return (/\bneedsfocus\b/).test(target.className); + // No point in attempting to focus disabled inputs + return !target.disabled && !target.readOnly; + default: + return (/\bneedsfocus\b/).test(target.className); } }; @@ -477,7 +490,8 @@ // Synthesise a click event, with an extra attribute so it can be tracked clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); + clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, + touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); clickEvent.forwardedTouchEvent = true; targetElement.dispatchEvent(clickEvent); }; @@ -500,7 +514,8 @@ var length; // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. - if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { + if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && + targetElement.type !== 'time' && targetElement.type !== 'month') { length = targetElement.value.length; targetElement.setSelectionRange(length, length); } else { @@ -631,9 +646,11 @@ * @returns {boolean} */ FastClick.prototype.touchHasMoved = function(event) { - var touch = event.changedTouches[0], boundary = this.touchBoundary; + var touch = event.changedTouches[0], + boundary = this.touchBoundary; - if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { + if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > + boundary) { return true; } @@ -653,7 +670,8 @@ } // If the touch has moved, cancel the click tracking - if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { + if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved( + event)) { this.trackingClick = false; this.targetElement = null; } @@ -682,7 +700,8 @@ // If no for attribute exists, attempt to retrieve the first labellable descendant element // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label - return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); + return labelElement.querySelector( + 'button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); }; @@ -693,7 +712,8 @@ * @returns {boolean} */ FastClick.prototype.onTouchEnd = function(event) { - var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; + var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this + .targetElement; if (!this.trackingClick) { return true; @@ -726,7 +746,8 @@ touch = event.changedTouches[0]; // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null - targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; + targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window + .pageYOffset) || targetElement; targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; } @@ -745,7 +766,8 @@ // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). - if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { + if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && + targetTagName === 'input')) { this.targetElement = null; return false; } @@ -917,7 +939,7 @@ } // Chrome version - zero for other browsers - chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; + chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [, 0])[1]; if (chromeVersion) { @@ -935,7 +957,7 @@ } } - // Chrome desktop doesn't need FastClick (issue #15) + // Chrome desktop doesn't need FastClick (issue #15) } else { return true; } @@ -968,13 +990,14 @@ } // Firefox version - zero for other browsers - firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; + firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [, 0])[1]; if (firefoxVersion >= 27) { // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896 metaViewport = document.querySelector('meta[name=viewport]'); - if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) { + if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document + .documentElement.scrollWidth <= window.outerWidth)) { return true; } } @@ -1013,8 +1036,8 @@ window.FastClick = FastClick; } -document.addEventListener('DOMContentLoaded', function() { - FastClick.attach(document.body); -}, false); + document.addEventListener('DOMContentLoaded', function() { + FastClick.attach(document.body); + }, false); }()); -- Gitblit v1.9.3