From 4df0471b7dff0494625ff09969b1a13b5359a26e Mon Sep 17 00:00:00 2001 From: XingChuan <m17600301067@163.com> Date: 星期一, 31 五月 2021 22:41:47 +0800 Subject: [PATCH] 统计表弹框UI优化;增加点击企业名称缩放至企业;二级表展示功能优化。 --- src/utils/tools.js | 248 ++++++++++++++++--------------------------------- 1 files changed, 81 insertions(+), 167 deletions(-) diff --git a/src/utils/tools.js b/src/utils/tools.js index 45ce110..f47703e 100644 --- a/src/utils/tools.js +++ b/src/utils/tools.js @@ -1,24 +1,23 @@ -/* eslint-disable no-prototype-builtins */ -import { OAUTH_API_GROUP } from '@/utils/authorityAPI' + import * as $CONST from './constant' import { Message } from 'element-ui' +// import { notify } from '@nutui/nutui' export const _ = require('lodash') - /** * 闆嗗悎杞崲涓篔SON * @param obj collection鏁版嵁 * @author TJ 2019/03/11 * @example 鐣� */ -export function collectionToJson(collection) { +export function collectionToJson (collection) { if (!_.isArray(collection)) return [] - let arr = [] + const arr = [] // 鏁版嵁浣� - _.forEach(collection, function(item) { - let tempObj = {} - if (item.hasOwnProperty('data') && _.isArray(item.data)) { - _.forEach(item.data, function(obj) { + _.forEach(collection, function (item) { + const tempObj = {} + if (Object.prototype.hasOwnProperty.call(item, 'data') && _.isArray(item.data)) { + _.forEach(item.data, function (obj) { tempObj[_.trim(obj.name)] = _.trim(obj.value) }) } @@ -26,21 +25,30 @@ }) return arr } - +/** + * 鏍规嵁涓嶅悓鐨勫崗璁紝鏇挎崲env閰嶇疆鏂囦欢涓殑URL鍗忚 + * + * @return {String} + */ +export function getSchemeHost () { + const protocol = window.location.protocol + const host = process.env.VUE_APP_API_HOST + return host.replace(/scheme/g, protocol) +} /** * collection鏁版嵁杞崲涓烘爣鍑咼SON * @param obj collection鏁版嵁 * @author TJ 2019/03/11 * @example 鐣� */ -export function transformStandardJson(obj) { +export function transformStandardJson (obj) { let body = {} let data = null let pages = null - let collection = obj.collection + const collection = obj.collection if (_.isObject(collection)) { // 閿欒鐨勫満鏅� - if (collection.hasOwnProperty('error')) { + if (Object.prototype.hasOwnProperty.call(collection, 'items')) { return { code: 300, body: null, @@ -48,11 +56,11 @@ } } // 鏁版嵁浣� - if (collection.hasOwnProperty('items') && _.isArray(collection.items)) { + if (Object.prototype.hasOwnProperty.call(collection, 'items') && _.isArray(collection.items)) { data = collectionToJson(collection.items) } // 鍒嗛〉淇℃伅 - if (collection.hasOwnProperty('page') && _.isArray(collection.data)) { + if (Object.prototype.hasOwnProperty.call(collection, 'page') && _.isArray(collection.data)) { pages = collectionToJson([collection.page]) } // 缁勮body鏁版嵁 @@ -84,16 +92,16 @@ * @author TJ 2019/03/11 * @example 鐣� */ -export function transformParams(obj) { - let collection = { +export function transformParams (obj) { + const collection = { version: '1.0', href: '', items: [], templates: [] } if (_.isObject(obj)) { - let arr = [] - _.each(obj, function(val, key) { + const arr = [] + _.each(obj, function (val, key) { let newVal = val if (_.isArray(val)) { newVal = val.join(',') @@ -104,7 +112,7 @@ }) }) - let o = { + const o = { data: arr } collection.templates.push(o) @@ -121,9 +129,9 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function setSessionStorage(key, content) { +export function setSessionStorage (key, content) { if (!key) return false - let jsonContent = JSON.stringify(content) + const jsonContent = JSON.stringify(content) jsonContent ? sessionStorage.setItem(key, jsonContent) : sessionStorage.setItem(key, content) } @@ -134,11 +142,11 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function getSessionStorage(key) { - let item = sessionStorage.getItem(key) +export function getSessionStorage (key) { + const item = sessionStorage.getItem(key) if (!item) return false - let result = JSON.parse(sessionStorage.getItem(key)) - return result ? result : item + const result = JSON.parse(sessionStorage.getItem(key)) + return result || item } /** @@ -147,7 +155,7 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function removeSessionStorage(key) { +export function removeSessionStorage (key) { sessionStorage.removeItem(key) } @@ -158,9 +166,9 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function setLocalStorage(key, content) { +export function setLocalStorage (key, content) { if (!key) return false - let jsonContent = JSON.stringify(content) + const jsonContent = JSON.stringify(content) jsonContent ? localStorage.setItem(key, jsonContent) : localStorage.setItem(key, content) } @@ -171,11 +179,11 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function getLocalStorage(key) { - let item = localStorage.getItem(key) +export function getLocalStorage (key) { + const item = localStorage.getItem(key) if (!item) return false - let result = JSON.parse(localStorage.getItem(key)) - return result ? result : item + const result = JSON.parse(localStorage.getItem(key)) + return result || item } /** @@ -184,7 +192,7 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function removeLocalStorage(key) { +export function removeLocalStorage (key) { localStorage.removeItem(key) } @@ -195,7 +203,7 @@ * @author TJ 2018/05/28 * @example 鐣� */ -export function isEmptyObject(obj) { +export function isEmptyObject (obj) { if (obj === null) return true return Object.keys(obj).length === 0 } @@ -207,15 +215,15 @@ * @author TJ 2017/05/28 * @example 鐣� */ -export function filterParams(params) { +export function filterParams (params) { if (!_.isObject(params)) { return params } - let newParams = {} - _.each(params, function(v, k) { + const newParams = {} + _.each(params, function (v, k) { // 杩囨护鎺夋潯浠舵槸绌虹殑椤� if (typeof v === 'string' && (v.length === 0 || v === '*鍏�*閮�*')) { - console.log() + } else { newParams[k] = v } @@ -228,7 +236,7 @@ * @param params {obj} * @author TJ 2018/05/31 */ -export function emptyObjectWrapper(obj) { +export function emptyObjectWrapper (obj) { return obj === null ? {} : obj } @@ -240,7 +248,7 @@ * @author TJ 2017/07/21 * @example 鐣� */ -export function parseTime(time, cFormat) { +export function parseTime (time, cFormat) { if (!time) return false if (arguments.length === 0) { return false @@ -284,7 +292,7 @@ * @author TJ 2017/08/01 * @example 鐣� */ -export function formatTime(time) { +export function formatTime (time) { if (Array.isArray(time)) { if (!time[0] || !time[1]) return false var start = parseTime(time[0], '{y}-{m}-{d}') @@ -299,32 +307,14 @@ } /** - * 鍒ゆ柇璇锋眰鐨刟pi鏄惁鏄杩藉姞鏉冮檺鐨� - * @param api {String} - * @return {boolean} - * @author TJ 2017/08/01 - * @example 鐣� - */ -export function isExistOauthApi(api) { - let isExist = false - for (let item of OAUTH_API_GROUP) { - if (api && api.includes(item)) { - isExist = true - break - } - } - return isExist -} - -/** * 鏉冮檺API鎷兼帴鐢ㄦ埛鍚� * @param api {String} * @return {boolean} * @author TJ 2017/08/01 * @example 鐣� */ -export function getJoinOauthApi(url) { - let name = window._loginName ? window._loginName : '' +export function getJoinOauthApi (url) { + const name = window._loginName ? window._loginName : '' if (url.includes('?')) { url += '&createId=' + name } else { @@ -341,17 +331,15 @@ * @author TJ 2017/08/01 * @example 鐣� */ -export function joinQueryUrl(url, obj) { +export function joinQueryUrl (url, obj) { let str = '' let fullUrl = '' - for (let key in obj) { - if (key) { - if (!obj.hasOwnProperty(key)) return - if (str) { - str += '&' - } - str += key + '=' + obj[key] + for (const key in obj) { + if (!Object.prototype.hasOwnProperty.call(obj, key)) return + if (str) { + str += '&' } + str += key + '=' + obj[key] } if (url.includes('?')) { fullUrl = url + '&' + str @@ -367,7 +355,7 @@ * @return {Boolean} * @author TJ 2018/08/27 */ -export function isInlineParams(url) { +export function isInlineParams (url) { const splitChar = '{$' if (url && url.indexOf(splitChar) > -1) { return true @@ -382,70 +370,20 @@ * @param params {obj} * @author TJ 2018/05/31 */ -export function replaceUrlParams(url, params) { +export function replaceUrlParams (url, params) { if (url) { if (!isInlineParams(url)) { return url } // 姝e垯鍖归厤{}锛岀敓鎴愭暟缁� - let patt = /\{.*?\}/g - let arr = url.match(patt) ? url.match(patt) : [] - arr.forEach(function(item) { - let key = item.replace('{', '').replace('}', '').replace('$', '') + const patt = /\{.*?\}/g + const arr = url.match(patt) ? url.match(patt) : [] + arr.forEach(function (item) { + const key = item.replace('{', '').replace('}', '').replace('$', '') url = url.replace(item, params[key]) }) } return url -} - -/** - * 鑾峰彇浼犲叆灏忔椂涔嬪墠鐨勬棩鏈� - * @param pastHour {Number} - * @param format {String} - * @author ZC 2020/11/03 - */ -export function zcGetDate(pastHour, format) { - if (!format) { - format = 'yyyy-MM-dd' - } - // eslint-disable-next-line no-extend-native - Date.prototype.Format = function(fmt) { - let o = { - 'M+': this.getMonth() + 1, // 鏈堜唤 - 'd+': this.getDate(), // 鏃� - 'h+': this.getHours(), // 灏忔椂 - 'm+': this.getMinutes(), // 鍒� - 's+': this.getSeconds(), // 绉� - 'q+': Math.floor((this.getMonth() + 3) / 3), // 瀛e害 - 'S': this.getMilliseconds() // 姣 - } - if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)) - for (let k in o) { - // eslint-disable-next-line eqeqeq - if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) - } - return fmt - } - if (pastHour) { - // 鑾峰彇涔嬪墠鐨勬椂闂� - return new Date(new Date().getTime() - pastHour * 60 * 60 * 1000).Format(format) - } else { - return new Date(new Date().getTime()).Format(format) - } -} - -/** - * 鑾峰彇浼犲叆灏忔椂涔嬪墠鐨勬棩鏈� - * @param url {String} - * @author ZC 2020/12/09 - */ -export function zcDownload(url) { - let downloadElement = document.createElement('a') - downloadElement.href = url // 鍒涘缓 - downloadElement.download = '瀵煎嚭.zip' // 涓嬭浇鍚庢枃浠跺悕 - document.body.appendChild(downloadElement) - downloadElement.click() // 鐐瑰嚮涓嬭浇 - document.body.removeChild(downloadElement) // 涓嬭浇瀹屾垚绉婚櫎鍏冪礌 } /** @@ -454,7 +392,7 @@ * @author TJ 2017/10/17 * @return 鏃犺繑鍥炵粨鏋� */ -export function resgisterTheme(echart) { +export function resgisterTheme (echart) { /* eslint-disable */ let theme = { 'color': [ @@ -967,7 +905,7 @@ * 鏍规嵁璺敱鍒囨崲鐨偆鏍囪瘑锛岄粯璁ょ毊鑲ゆ湭钃濊壊 * @author TJ 2019/05/29 */ -export function changeThemeClass(toRouterName) { +export function changeThemeClass (toRouterName) { const darkSkinRouterName = [] if (darkSkinRouterName.includes(toRouterName)) { @@ -1004,7 +942,7 @@ * 鍒ゆ柇鍊兼槸鍚︿负鐪�,涓嶅寘鎷0鐨勫垽鏂� * @param {String} val 瀛楃 */ -export function isTrue(val) { +export function isTrue (val) { return !_.isNull(val) && !_.isUndefined(val) && val !== '' } @@ -1014,13 +952,13 @@ * @param {String} url * @return {object} */ -export function getQueryObject(url = window.location.href) { +export function getQueryObject (url = window.location.href) { if (!url) return - let search = url.substring(url.lastIndexOf('?') + 1) - let obj = {} - let reg = /([^?&=]+)=([^?&=]*)/g - search.replace(reg, function(rs, $1, $2) { - let name = decodeURIComponent($1) + const search = url.substring(url.lastIndexOf('?') + 1) + const obj = {} + const reg = /([^?&=]+)=([^?&=]*)/g + search.replace(reg, function (rs, $1, $2) { + const name = decodeURIComponent($1) let val = decodeURIComponent($2) val = String(val) obj[name] = val @@ -1037,12 +975,12 @@ * @param {string} propValue 灞炴�у搴旂殑鍊� * @return {object} 鑺傜偣瀵硅薄 */ -export function recursion(tree, prop, propValue) { +export function recursion (tree, prop, propValue) { if (!tree || !Array.isArray(tree)) return false let result = {} - function handelTree(tree) { - for (let o of tree) { + function handelTree (tree) { + for (const o of tree) { if (o.children && Array.isArray(o.children) && o.children.length) { if (o[prop] !== propValue) { // 閫掑綊 @@ -1063,63 +1001,39 @@ return handelTree(tree) } -export function success(msg = $CONST.MSG_SYS_SUCCESS) { +export function success (msg = $CONST.MSG_SYS_SUCCESS) { Message({ message: msg, type: 'success' }) } -export function fail(msg = $CONST.MSG_SYS_FAIL) { +export function fail (msg = $CONST.MSG_SYS_FAIL) { Message({ message: msg, type: 'error' }) } -export function error(msg = $CONST.MSG_SYS_ERR) { +export function error (msg = $CONST.MSG_SYS_ERR) { Message({ message: msg, type: 'error' }) } -export function warning(msg = $CONST.MSG_SYS_WARNING) { +export function warning (msg = $CONST.MSG_SYS_WARNING) { Message({ message: msg, type: 'warning' }) } -export function info(msg = $CONST.MSG_SYS_CANCELED) { +export function info (msg = $CONST.MSG_SYS_CANCELED) { Message({ message: msg, type: 'info' }) -} - -export function alertError(msg = $CONST.MSG_SYS_ERR, options) { - options = Object.assign({ - dangerouslyUseHTMLString: true, - title: '鎻愮ず', - type: 'error', - 'show-icon': true - }, options) - window.vm.$alert(msg, options) -} - -export function alertWarning(msg = $CONST.MSG_SYS_WARNING, options) { - options = Object.assign({ - dangerouslyUseHTMLString: true, - title: '鎻愮ず', - type: 'warning', - 'show-icon': true - }, options) - window.vm.$alert(msg, options) -} - -export function todo() { - warning('寮�鍙戜腑銆傘�傘��') } /** -- Gitblit v1.8.0