From 1820aef3fb5c926664de1d4d484f64a5c9ba7099 Mon Sep 17 00:00:00 2001
From: YANGDL <114714267@qq.com>
Date: 星期二, 05 一月 2021 17:06:08 +0800
Subject: [PATCH] 优化逻辑

---
 src/utils/tools.js |  237 +++++++++++++++++-----------------------------------------
 1 files changed, 71 insertions(+), 166 deletions(-)

diff --git a/src/utils/tools.js b/src/utils/tools.js
index 45ce110..0838a7f 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)
       })
     }
@@ -33,14 +32,14 @@
  * @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 +47,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 +83,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 +103,7 @@
       })
     })
 
-    let o = {
+    const o = {
       data: arr
     }
     collection.templates.push(o)
@@ -121,9 +120,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 +133,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 +146,7 @@
  * @author TJ 2018/05/28
  * @example 鐣�
  */
-export function removeSessionStorage(key) {
+export function removeSessionStorage (key) {
   sessionStorage.removeItem(key)
 }
 
@@ -158,9 +157,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 +170,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 +183,7 @@
  * @author TJ 2018/05/28
  * @example 鐣�
  */
-export function removeLocalStorage(key) {
+export function removeLocalStorage (key) {
   localStorage.removeItem(key)
 }
 
@@ -195,7 +194,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 +206,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 +227,7 @@
  * @param params {obj}
  * @author TJ 2018/05/31
  */
-export function emptyObjectWrapper(obj) {
+export function emptyObjectWrapper (obj) {
   return obj === null ? {} : obj
 }
 
@@ -240,7 +239,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 +283,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 +298,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 +322,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 +346,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 +361,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 +383,7 @@
  * @author TJ 2017/10/17
  * @return 鏃犺繑鍥炵粨鏋�
  */
-export function resgisterTheme(echart) {
+export function resgisterTheme (echart) {
   /* eslint-disable */
   let theme = {
     'color': [
@@ -967,7 +896,7 @@
  * 鏍规嵁璺敱鍒囨崲鐨偆鏍囪瘑锛岄粯璁ょ毊鑲ゆ湭钃濊壊
  * @author TJ 2019/05/29
  */
-export function changeThemeClass(toRouterName) {
+export function changeThemeClass (toRouterName) {
   const darkSkinRouterName = []
 
   if (darkSkinRouterName.includes(toRouterName)) {
@@ -1004,7 +933,7 @@
  * 鍒ゆ柇鍊兼槸鍚︿负鐪�,涓嶅寘鎷0鐨勫垽鏂�
  * @param {String} val 瀛楃
  */
-export function isTrue(val) {
+export function isTrue (val) {
   return !_.isNull(val) && !_.isUndefined(val) && val !== ''
 }
 
@@ -1014,13 +943,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 +966,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 +992,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