From ffd0af47ee31a9592cfab56a907e9841a9113c52 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期四, 20 七月 2023 10:37:17 +0800 Subject: [PATCH] 代码提交,前端代码打包 --- Source/UBCS-WEB/dist/src/util/util.js | 391 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 391 insertions(+), 0 deletions(-) diff --git a/Source/UBCS-WEB/dist/src/util/util.js b/Source/UBCS-WEB/dist/src/util/util.js new file mode 100644 index 0000000..9df90d0 --- /dev/null +++ b/Source/UBCS-WEB/dist/src/util/util.js @@ -0,0 +1,391 @@ +import {validatenull} from './validate' +//琛ㄥ崟搴忓垪鍖� +export const serialize = data => { + let list = []; + Object.keys(data).forEach(ele => { + list.push(`${ele}=${data[ele]}`) + }) + return list.join('&'); +}; +export const getObjType = obj => { + var toString = Object.prototype.toString; + var map = { + '[object Boolean]': 'boolean', + '[object Number]': 'number', + '[object String]': 'string', + '[object Function]': 'function', + '[object Array]': 'array', + '[object Date]': 'date', + '[object RegExp]': 'regExp', + '[object Undefined]': 'undefined', + '[object Null]': 'null', + '[object Object]': 'object' + }; + if (obj instanceof Element) { + return 'element'; + } + return map[toString.call(obj)]; +}; +export const getViewDom = () => { + return window.document.getElementById('avue-view').getElementsByClassName('el-scrollbar__wrap')[0] +} +/** + * 瀵硅薄娣辨嫹璐� + */ +export const deepClone = data => { + var type = getObjType(data); + var obj; + if (type === 'array') { + obj = []; + } else if (type === 'object') { + obj = {}; + } else { + //涓嶅啀鍏锋湁涓嬩竴灞傛 + return data; + } + if (type === 'array') { + for (var i = 0, len = data.length; i < len; i++) { + obj.push(deepClone(data[i])); + } + } else if (type === 'object') { + for (var key in data) { + obj[key] = deepClone(data[key]); + } + } + return obj; +}; +/** + * 璁剧疆鐏板害妯″紡 + */ +export const toggleGrayMode = (status) => { + if (status) { + document.body.className = document.body.className + ' grayMode'; + } else { + document.body.className = document.body.className.replace(' grayMode', ''); + } +}; +/** + * 璁剧疆涓婚 + */ +export const setTheme = (name) => { + document.body.className = name; +} + +/** + * 鍔犲瘑澶勭悊 + */ +export const encryption = (params) => { + let { + data, + type, + param, + key + } = params; + let result = JSON.parse(JSON.stringify(data)); + if (type == 'Base64') { + param.forEach(ele => { + result[ele] = btoa(result[ele]); + }) + } else if (type == 'Aes') { + param.forEach(ele => { + result[ele] = window.CryptoJS.AES.encrypt(result[ele], key).toString(); + }) + + } + return result; +}; + + +/** + * 娴忚鍣ㄥ垽鏂槸鍚﹀叏灞� + */ +export const fullscreenToggel = () => { + if (fullscreenEnable()) { + exitFullScreen(); + } else { + reqFullScreen(); + } +}; +/** + * esc鐩戝惉鍏ㄥ睆 + */ +export const listenfullscreen = (callback) => { + function listen() { + callback() + } + + document.addEventListener("fullscreenchange", function () { + listen(); + }); + document.addEventListener("mozfullscreenchange", function () { + listen(); + }); + document.addEventListener("webkitfullscreenchange", function () { + listen(); + }); + document.addEventListener("msfullscreenchange", function () { + listen(); + }); +}; +/** + * 娴忚鍣ㄥ垽鏂槸鍚﹀叏灞� + */ +export const fullscreenEnable = () => { + var isFullscreen = document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen + return isFullscreen; +} + +/** + * 娴忚鍣ㄥ叏灞� + */ +export const reqFullScreen = () => { + if (document.documentElement.requestFullScreen) { + document.documentElement.requestFullScreen(); + } else if (document.documentElement.webkitRequestFullScreen) { + document.documentElement.webkitRequestFullScreen(); + } else if (document.documentElement.mozRequestFullScreen) { + document.documentElement.mozRequestFullScreen(); + } +}; +/** + * 娴忚鍣ㄩ��鍑哄叏灞� + */ +export const exitFullScreen = () => { + if (document.documentElement.requestFullScreen) { + document.exitFullScreen(); + } else if (document.documentElement.webkitRequestFullScreen) { + document.webkitCancelFullScreen(); + } else if (document.documentElement.mozRequestFullScreen) { + document.mozCancelFullScreen(); + } +}; +/** + * 閫掑綊瀵绘壘瀛愮被鐨勭埗绫� + */ + +export const findParent = (menu, id) => { + for (let i = 0; i < menu.length; i++) { + if (menu[i].children.length != 0) { + for (let j = 0; j < menu[i].children.length; j++) { + if (menu[i].children[j].id == id) { + return menu[i]; + } else { + if (menu[i].children[j].children.length != 0) { + return findParent(menu[i].children[j].children, id); + } + } + } + } + } +}; +/** + * 鍒ゆ柇2涓璞″睘鎬у拰鍊兼槸鍚︾浉绛� + */ + +/** + * 鍔ㄦ�佹彃鍏ss + */ + +export const loadStyle = url => { + const link = document.createElement('link'); + link.type = 'text/css'; + link.rel = 'stylesheet'; + link.href = url; + const head = document.getElementsByTagName('head')[0]; + head.appendChild(link); +}; +/** + * 鍒ゆ柇璺敱鏄惁鐩哥瓑 + */ +export const diff = (obj1, obj2) => { + delete obj1.close; + var o1 = obj1 instanceof Object; + var o2 = obj2 instanceof Object; + if (!o1 || !o2) { /* 鍒ゆ柇涓嶆槸瀵硅薄 */ + return obj1 === obj2; + } + + if (Object.keys(obj1).length !== Object.keys(obj2).length) { + return false; + //Object.keys() 杩斿洖涓�涓敱瀵硅薄鐨勮嚜韬彲鏋氫妇灞炴��(key鍊�)缁勬垚鐨勬暟缁�,渚嬪锛氭暟缁勮繑鍥炰笅琛細let arr = ["a", "b", "c"];console.log(Object.keys(arr))->0,1,2; + } + + for (var attr in obj1) { + var t1 = obj1[attr] instanceof Object; + var t2 = obj2[attr] instanceof Object; + if (t1 && t2) { + return diff(obj1[attr], obj2[attr]); + } else if (obj1[attr] !== obj2[attr]) { + return false; + } + } + return true; +} +/** + * 鏍规嵁瀛楀吀鐨剉alue鏄剧ずlabel + */ +export const findByvalue = (dic, value) => { + let result = ''; + if (validatenull(dic)) return value; + if (typeof (value) == 'string' || typeof (value) == 'number' || typeof (value) == 'boolean') { + let index = 0; + index = findArray(dic, value); + if (index != -1) { + result = dic[index].label; + } else { + result = value; + } + } else if (value instanceof Array) { + result = []; + let index = 0; + value.forEach(ele => { + index = findArray(dic, ele); + if (index != -1) { + result.push(dic[index].label); + } else { + result.push(value); + } + }); + result = result.toString(); + } + return result; +}; +/** + * 鏍规嵁瀛楀吀鐨剉alue鏌ユ壘瀵瑰簲鐨刬ndex + */ +export const findArray = (dic, value) => { + for (let i = 0; i < dic.length; i++) { + if (dic[i].value == value) { + return i; + } + } + return -1; +}; +/** + * 鐢熸垚闅忔満len浣嶆暟瀛� + */ +export const randomLenNum = (len, date) => { + let random = ''; + random = Math.ceil(Math.random() * 100000000000000).toString().substr(0, len ? len : 4); + if (date) random = random + Date.now(); + return random; +}; +/** + * 鎵撳紑灏忕獥鍙� + */ +export const openWindow = (url, title, w, h) => { + // Fixes dual-screen position Most browsers Firefox + const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left + const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top + + const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width + const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height + + const left = ((width / 2) - (w / 2)) + dualScreenLeft + const top = ((height / 2) - (h / 2)) + dualScreenTop + const newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left) + + // Puts focus on the newWindow + if (window.focus) { + newWindow.focus() + } +} + +/** + * 鑾峰彇椤堕儴鍦板潃鏍忓湴鍧� + */ +export const getTopUrl = () => { + return window.location.href.split("/#/")[0]; +} + +/** + * 鑾峰彇url鍙傛暟 + * @param name 鍙傛暟鍚� + */ +export const getQueryString = (name) => { + let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); + let r = window.location.search.substr(1).match(reg); + if (r != null) return unescape(decodeURI(r[2])); + return null; +} + +/** + * 涓嬭浇鏂囦欢 + * @param {String} path - 鏂囦欢鍦板潃 + * @param {String} name - 鏂囦欢鍚�,eg: test.png + */ +export const downloadFileBlob = (path, name) => { + const xhr = new XMLHttpRequest(); + xhr.open('get', path); + xhr.responseType = 'blob'; + xhr.send(); + xhr.onload = function () { + if (this.status === 200 || this.status === 304) { + // 濡傛灉鏄疘E10鍙婁互涓婏紝涓嶆敮鎸乨ownload灞炴�э紝閲囩敤msSaveOrOpenBlob鏂规硶锛屼絾鏄疘E10浠ヤ笅涔熶笉鏀寔msSaveOrOpenBlob + if ('msSaveOrOpenBlob' in navigator) { + navigator.msSaveOrOpenBlob(this.response, name); + return; + } + const url = URL.createObjectURL(this.response); + const a = document.createElement('a'); + a.style.display = 'none'; + a.href = url; + a.download = name; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } + }; +} + +/** + * 涓嬭浇鏂囦欢 + * @param {String} path - 鏂囦欢鍦板潃 + * @param {String} name - 鏂囦欢鍚�,eg: test.png + */ +export const downloadFileBase64 = (path, name) => { + const xhr = new XMLHttpRequest(); + xhr.open('get', path); + xhr.responseType = 'blob'; + xhr.send(); + xhr.onload = function () { + if (this.status === 200 || this.status === 304) { + const fileReader = new FileReader(); + fileReader.readAsDataURL(this.response); + fileReader.onload = function () { + const a = document.createElement('a'); + a.style.display = 'none'; + a.href = this.result; + a.download = name; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + }; + } + }; +} + +/** + * 涓嬭浇excel + * @param {blob} fileArrayBuffer 鏂囦欢娴� + * @param {String} filename 鏂囦欢鍚嶇О + */ +export const downloadXls = (fileArrayBuffer, filename) => { + let data = new Blob([fileArrayBuffer], {type: 'application/vnd.ms-excel,charset=utf-8'}); + if (typeof window.chrome !== 'undefined') { + // Chrome + var link = document.createElement('a'); + link.href = window.URL.createObjectURL(data); + link.download = filename; + link.click(); + } else if (typeof window.navigator.msSaveBlob !== 'undefined') { + // IE + var blob = new Blob([data], {type: 'application/force-download'}); + window.navigator.msSaveBlob(blob, filename); + } else { + // Firefox + var file = new File([data], filename, {type: 'application/force-download'}); + window.open(URL.createObjectURL(file)); + } +} -- Gitblit v1.9.3