From cad0535f3fb14ff09db99ec43169da3aa33b83f2 Mon Sep 17 00:00:00 2001
From: chenyibo <p-honggang.li@pcitc.com>
Date: 星期二, 30 三月 2021 16:06:08 +0800
Subject: [PATCH] 1.新增登录界面

---
 src/utils/tools.js | 1068 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1,068 insertions(+), 0 deletions(-)

diff --git a/src/utils/tools.js b/src/utils/tools.js
new file mode 100644
index 0000000..f47703e
--- /dev/null
+++ b/src/utils/tools.js
@@ -0,0 +1,1068 @@
+
+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) {
+  if (!_.isArray(collection)) return []
+  const arr = []
+  // 鏁版嵁浣�
+  _.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)
+      })
+    }
+    arr.push(tempObj)
+  })
+  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) {
+  let body = {}
+  let data = null
+  let pages = null
+  const collection = obj.collection
+  if (_.isObject(collection)) {
+    // 閿欒鐨勫満鏅�
+    if (Object.prototype.hasOwnProperty.call(collection, 'items')) {
+      return {
+        code: 300,
+        body: null,
+        msg: collection.error
+      }
+    }
+    // 鏁版嵁浣�
+    if (Object.prototype.hasOwnProperty.call(collection, 'items') && _.isArray(collection.items)) {
+      data = collectionToJson(collection.items)
+    }
+    // 鍒嗛〉淇℃伅
+    if (Object.prototype.hasOwnProperty.call(collection, 'page') && _.isArray(collection.data)) {
+      pages = collectionToJson([collection.page])
+    }
+    // 缁勮body鏁版嵁
+    body = {
+      data: data
+    }
+
+    if (pages) {
+      _.extend(body, {
+        total: pages[0].totalElements,
+        pageIndex: 0,
+        pageSize: pages[0].size,
+        pages: pages[0].totalPages
+      })
+    }
+
+    return {
+      code: 200,
+      body: body,
+      msg: '鎿嶄綔鎴愬姛'
+    }
+  }
+}
+
+/**
+ * POST PUT绛夎姹傚弬鏁拌浆鎹㈡垚闆嗗悎
+ * @param json object
+ * @returns collection
+ * @author TJ 2019/03/11
+ * @example 鐣�
+ */
+export function transformParams (obj) {
+  const collection = {
+    version: '1.0',
+    href: '',
+    items: [],
+    templates: []
+  }
+  if (_.isObject(obj)) {
+    const arr = []
+    _.each(obj, function (val, key) {
+      let newVal = val
+      if (_.isArray(val)) {
+        newVal = val.join(',')
+      }
+      arr.push({
+        name: key,
+        value: newVal
+      })
+    })
+
+    const o = {
+      data: arr
+    }
+    collection.templates.push(o)
+  }
+  return {
+    collection: collection
+  }
+}
+
+/**
+ * 灏嗗唴瀹瑰瓨鍌ㄥ埌sessionStorage
+ * @param key {string} key
+ * @param content {Object} 瀛樺偍json瀵硅薄
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function setSessionStorage (key, content) {
+  if (!key) return false
+  const jsonContent = JSON.stringify(content)
+  jsonContent ? sessionStorage.setItem(key, jsonContent) : sessionStorage.setItem(key, content)
+}
+
+/**
+ * 鑾峰彇瀛樺偍鍒皊essionStorage鐨勫唴瀹�
+ * @param key {string} key
+ * @return {object} 杩斿洖json瀵硅薄
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function getSessionStorage (key) {
+  const item = sessionStorage.getItem(key)
+  if (!item) return false
+  const result = JSON.parse(sessionStorage.getItem(key))
+  return result || item
+}
+
+/**
+ * 鍒犻櫎瀛樺偍鍒皊essionStorage鐨勫唴瀹�
+ * @param key {string} key
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function removeSessionStorage (key) {
+  sessionStorage.removeItem(key)
+}
+
+/**
+ * 灏嗗唴瀹瑰瓨鍌ㄥ埌localStorage
+ * @param key {string} key
+ * @param content {Object} 瀛樺偍json瀵硅薄
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function setLocalStorage (key, content) {
+  if (!key) return false
+  const jsonContent = JSON.stringify(content)
+  jsonContent ? localStorage.setItem(key, jsonContent) : localStorage.setItem(key, content)
+}
+
+/**
+ * 鑾峰彇瀛樺偍鍒發ocalStorage鐨勫唴瀹�
+ * @param key {string} key
+ * @return {object} 杩斿洖json瀵硅薄
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function getLocalStorage (key) {
+  const item = localStorage.getItem(key)
+  if (!item) return false
+  const result = JSON.parse(localStorage.getItem(key))
+  return result || item
+}
+
+/**
+ * localStorage
+ * @param key {string} key
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function removeLocalStorage (key) {
+  localStorage.removeItem(key)
+}
+
+/**
+ * 鍒ゆ柇json瀵硅薄鏄惁涓虹┖瀵硅薄
+ * @param obj {object} json瀵硅薄
+ * @return {boolean} 绌哄璞¤繑鍥� true 鍚﹀垯杩斿洖 false
+ * @author TJ 2018/05/28
+ * @example 鐣�
+ */
+export function isEmptyObject (obj) {
+  if (obj === null) return true
+  return Object.keys(obj).length === 0
+}
+
+/**
+ * 杩囨护鍙傛暟
+ * @param params {object} 闇�瑕佹牸寮忓寲鐨勬椂闂�
+ * @return {object} 鏍煎紡鍖栧悗鐨勬椂闂�
+ * @author TJ 2017/05/28
+ * @example 鐣�
+ */
+export function filterParams (params) {
+  if (!_.isObject(params)) {
+    return params
+  }
+  const newParams = {}
+  _.each(params, function (v, k) {
+    // 杩囨护鎺夋潯浠舵槸绌虹殑椤�
+    if (typeof v === 'string' && (v.length === 0 || v === '*鍏�*閮�*')) {
+
+    } else {
+      newParams[k] = v
+    }
+  })
+  return newParams
+}
+
+/**
+ * 灏唍ull杞崲涓虹┖瀵硅薄
+ * @param params {obj}
+ * @author TJ 2018/05/31
+ */
+export function emptyObjectWrapper (obj) {
+  return obj === null ? {} : obj
+}
+
+/**
+ * 鏍煎紡鍖栨椂闂�
+ * @param time {string} 闇�瑕佹牸寮忓寲鐨勬椂闂�
+ * @param cFormat {string} 鏃堕棿鏍煎紡
+ * @return {string} 鏍煎紡鍖栧悗鐨勬椂闂�
+ * @author TJ 2017/07/21
+ * @example 鐣�
+ */
+export function parseTime (time, cFormat) {
+  if (!time) return false
+  if (arguments.length === 0) {
+    return false
+  }
+  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
+  let date
+  if (typeof time === 'object') {
+    date = time
+  } else {
+    if (('' + time).length === 10) time = parseInt(time) * 1000
+    if (('' + time).length === 8 && ('' + time).indexOf('-') === -1 && ('' + time).indexOf('/') === -1) {
+      time = time.substring(0, 4) + '-' + time.substring(4, 6) + '-' + time.substring(6, 8)
+    }
+
+    date = new Date(time)
+  }
+  const formatObj = {
+    y: date.getFullYear(),
+    m: date.getMonth() + 1,
+    d: date.getDate(),
+    h: date.getHours(),
+    i: date.getMinutes(),
+    s: date.getSeconds(),
+    a: date.getDay()
+  }
+  const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
+    let value = formatObj[key]
+    if (key === 'a') return ['涓�', '浜�', '涓�', '鍥�', '浜�', '鍏�', '鏃�'][value - 1]
+    if (result.length > 0 && value < 10) {
+      value = '0' + value
+    }
+    return value || 0
+  })
+  return timeStr
+}
+
+/**
+ * 灏嗘椂闂存暟缁勫垎鍓叉垚寮�濮嬫椂闂村拰缁撴潫鏃堕棿
+ * @param time {array}
+ * @return {object}
+ * @author TJ 2017/08/01
+ * @example 鐣�
+ */
+export function formatTime (time) {
+  if (Array.isArray(time)) {
+    if (!time[0] || !time[1]) return false
+    var start = parseTime(time[0], '{y}-{m}-{d}')
+    var end = parseTime(time[1], '{y}-{m}-{d}')
+    return {
+      start: start,
+      end: end
+    }
+  }
+
+  return false
+}
+
+/**
+ * 鏉冮檺API鎷兼帴鐢ㄦ埛鍚�
+ * @param api {String}
+ * @return {boolean}
+ * @author TJ 2017/08/01
+ * @example 鐣�
+ */
+export function getJoinOauthApi (url) {
+  const name = window._loginName ? window._loginName : ''
+  if (url.includes('?')) {
+    url += '&createId=' + name
+  } else {
+    url += 'createId=' + name
+  }
+  return url
+}
+
+/**
+ * 鎷兼帴鏌ヨURL
+ * @param url {String}
+ * @param obj {obj}
+ * @return {String}
+ * @author TJ 2017/08/01
+ * @example 鐣�
+ */
+export function joinQueryUrl (url, obj) {
+  let str = ''
+  let fullUrl = ''
+  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
+  } else {
+    fullUrl = url + '?' + str
+  }
+  return fullUrl
+}
+
+/**
+ * 鍒ゆ柇鍙傛暟鏄惁宓屽叆鍦╱rl涓�
+ * @param url {String}
+ * @return {Boolean}
+ * @author TJ 2018/08/27
+ */
+export function isInlineParams (url) {
+  const splitChar = '{$'
+  if (url && url.indexOf(splitChar) > -1) {
+    return true
+  } else {
+    return false
+  }
+}
+
+/**
+ * 鏇挎崲url閲岀殑鍙傛暟
+ * @param url {String}
+ * @param params {obj}
+ * @author TJ 2018/05/31
+ */
+export function replaceUrlParams (url, params) {
+  if (url) {
+    if (!isInlineParams(url)) {
+      return url
+    }
+    // 姝e垯鍖归厤{}锛岀敓鎴愭暟缁�
+    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
+}
+
+/**
+ * 閰嶇疆Echart涓婚棰滆壊
+ * @param {obj} echart 瀹炰緥
+ * @author TJ 2017/10/17
+ * @return 鏃犺繑鍥炵粨鏋�
+ */
+export function resgisterTheme (echart) {
+  /* eslint-disable */
+  let theme = {
+    'color': [
+      '#29d0b0',
+      '#2d99ed',
+      '#fd8667',
+      '#72ccff',
+      '#f7c5a0',
+      '#d4a4eb',
+      '#fdc547',
+      '#76f2f2',
+      '#da4d00',
+      '#b0419e'
+    ],
+    'backgroundColor': 'transparents',
+    'textStyle': {
+      'itemStyle': {
+        'normal': {
+          'color': '#fff'
+        }
+      }
+    },
+    'title': {
+      'textStyle': {
+        'color': '#ffffff'
+      },
+      'subtextStyle': {
+        'color': '#dddddd'
+      }
+    },
+    'line': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': '1'
+        }
+      },
+      'lineStyle': {
+        'normal': {
+          'width': '1'
+        }
+      },
+      'symbolSize': '4',
+      'symbol': 'circle',
+      'smooth': false
+    },
+    'radar': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': '4'
+        }
+      },
+      'lineStyle': {
+        'normal': {
+          'width': '3'
+        }
+      },
+      'symbolSize': '1',
+      'symbol': 'circle',
+      'smooth': true
+    },
+    'bar': {
+      'itemStyle': {
+        'normal': {
+          'barBorderWidth': 0,
+          'barBorderColor': '#ccc'
+        },
+        'emphasis': {
+          'barBorderWidth': 0,
+          'barBorderColor': '#ccc'
+        }
+      }
+    },
+    'pie': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        },
+        'emphasis': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      }
+    },
+    'scatter': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        },
+        'emphasis': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      }
+    },
+    'boxplot': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        },
+        'emphasis': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      }
+    },
+    'parallel': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        },
+        'emphasis': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      }
+    },
+    'sankey': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        },
+        'emphasis': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      }
+    },
+    'funnel': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        },
+        'emphasis': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      }
+    },
+    'gauge': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 1,
+          'borderColor': '#fff'
+        },
+        'emphasis': {
+          'borderWidth': 1,
+          'borderColor': '#fff'
+        }
+      }
+    },
+    'candlestick': {
+      'itemStyle': {
+        'normal': {
+          'color': '#fc97af',
+          'color0': 'transparent',
+          'borderColor': '#fc97af',
+          'borderColor0': '#87f7cf',
+          'borderWidth': '2'
+        }
+      }
+    },
+    'graph': {
+      'itemStyle': {
+        'normal': {
+          'borderWidth': 0,
+          'borderColor': '#ccc'
+        }
+      },
+      'lineStyle': {
+        'normal': {
+          'width': '1',
+          'color': '#ffffff'
+        }
+      },
+      'symbolSize': '5',
+      'symbol': 'circle',
+      'smooth': true,
+      'color': [
+        '#29d0b0',
+        '#2d99ed',
+        '#fd8667',
+        '#72ccff',
+        '#f7c5a0',
+        '#d4a4eb',
+        '#fdc547',
+        '#76f2f2',
+        '#da4d00',
+        '#b0419e'
+      ],
+      'label': {
+        'normal': {
+          'textStyle': {
+            'color': '#293441'
+          }
+        }
+      }
+    },
+    'map': {
+      'itemStyle': {
+        'normal': {
+          'areaColor': '#f3f3f3',
+          'borderColor': '#999999',
+          'borderWidth': 0.5
+        },
+        'emphasis': {
+          'areaColor': 'rgba(255,178,72,1)',
+          'borderColor': '#eb8146',
+          'borderWidth': 1
+        }
+      },
+      'label': {
+        'normal': {
+          'textStyle': {
+            'color': '#893448'
+          }
+        },
+        'emphasis': {
+          'textStyle': {
+            'color': 'rgb(137,52,72)'
+          }
+        }
+      }
+    },
+    'geo': {
+      'itemStyle': {
+        'normal': {
+          'areaColor': '#f3f3f3',
+          'borderColor': '#999999',
+          'borderWidth': 0.5
+        },
+        'emphasis': {
+          'areaColor': 'rgba(255,178,72,1)',
+          'borderColor': '#eb8146',
+          'borderWidth': 1
+        }
+      },
+      'label': {
+        'normal': {
+          'textStyle': {
+            'color': '#893448'
+          }
+        },
+        'emphasis': {
+          'textStyle': {
+            'color': 'rgb(137,52,72)'
+          }
+        }
+      }
+    },
+    'categoryAxis': {
+      'axisLine': {
+        'show': true,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisTick': {
+        'show': false,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisLabel': {
+        'show': true,
+        'textStyle': {
+          'color': '#fff'
+        }
+      },
+      'splitLine': {
+        'show': false,
+        'lineStyle': {
+          'color': [
+            '#e6e6e6'
+          ]
+        }
+      },
+      'splitArea': {
+        'show': false,
+        'areaStyle': {
+          'color': [
+            'rgba(250,250,250,0.05)',
+            'rgba(200,200,200,0.02)'
+          ]
+        }
+      }
+    },
+    'valueAxis': {
+      'axisLine': {
+        'show': true,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisTick': {
+        'show': false,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisLabel': {
+        'show': true,
+        'textStyle': {
+          'color': '#fff'
+        }
+      },
+      'splitLine': {
+        'show': false,
+        'lineStyle': {
+          'color': [
+            '#e6e6e6'
+          ]
+        }
+      },
+      'splitArea': {
+        'show': false,
+        'areaStyle': {
+          'color': [
+            'rgba(250,250,250,0.05)',
+            'rgba(200,200,200,0.02)'
+          ]
+        }
+      }
+    },
+    'logAxis': {
+      'axisLine': {
+        'show': true,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisTick': {
+        'show': false,
+        'lineStyle': {
+          'color': '#333'
+        }
+      },
+      'axisLabel': {
+        'show': true,
+        'textStyle': {
+          'color': '#fff'
+        }
+      },
+      'splitLine': {
+        'show': false,
+        'lineStyle': {
+          'color': [
+            '#e6e6e6'
+          ]
+        }
+      },
+      'splitArea': {
+        'show': false,
+        'areaStyle': {
+          'color': [
+            'rgba(250,250,250,0.05)',
+            'rgba(200,200,200,0.02)'
+          ]
+        }
+      }
+    },
+    'timeAxis': {
+      'axisLine': {
+        'show': true,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisTick': {
+        'show': false,
+        'lineStyle': {
+          'color': '#fff'
+        }
+      },
+      'axisLabel': {
+        'show': true,
+        'textStyle': {
+          'color': '#fff'
+        }
+      },
+      'splitLine': {
+        'show': false,
+        'lineStyle': {
+          'color': [
+            '#fff'
+          ]
+        }
+      },
+      'splitArea': {
+        'show': false,
+        'areaStyle': {
+          'color': [
+            'rgba(250,250,250,0.05)',
+            'rgba(200,200,200,0.02)'
+          ]
+        }
+      }
+    },
+    'toolbox': {
+      'iconStyle': {
+        'normal': {
+          'borderColor': '#999999'
+        },
+        'emphasis': {
+          'borderColor': '#666666'
+        }
+      }
+    },
+    'legend': {
+      'textStyle': {
+        'color': '#e0e0e0'
+      }
+    },
+    'tooltip': {
+      'axisPointer': {
+        'lineStyle': {
+          'color': '#cccccc',
+          'width': 1
+        },
+        'crossStyle': {
+          'color': '#cccccc',
+          'width': 1
+        }
+      }
+    },
+    'timeline': {
+      'lineStyle': {
+        'color': '#87f7cf',
+        'width': 1
+      },
+      'itemStyle': {
+        'normal': {
+          'color': '#87f7cf',
+          'borderWidth': 1
+        },
+        'emphasis': {
+          'color': '#f7f494'
+        }
+      },
+      'controlStyle': {
+        'normal': {
+          'color': '#87f7cf',
+          'borderColor': '#87f7cf',
+          'borderWidth': 0.5
+        },
+        'emphasis': {
+          'color': '#87f7cf',
+          'borderColor': '#87f7cf',
+          'borderWidth': 0.5
+        }
+      },
+      'checkpointStyle': {
+        'color': '#fc97af',
+        'borderColor': 'rgba(252,151,175,0.3)'
+      },
+      'label': {
+        'normal': {
+          'textStyle': {
+            'color': '#87f7cf'
+          }
+        },
+        'emphasis': {
+          'textStyle': {
+            'color': '#87f7cf'
+          }
+        }
+      }
+    },
+    'visualMap': {
+      'color': [
+        '#fc97af',
+        '#87f7cf'
+      ]
+    },
+    'dataZoom': {
+      'backgroundColor': 'rgba(255,255,255,0)',
+      'dataBackgroundColor': 'rgba(114,204,255,1)',
+      'fillerColor': 'rgba(114,204,255,0.2)',
+      'handleColor': '#72ccff',
+      'handleSize': '100%',
+      'textStyle': {
+        'color': '#fff'
+      }
+    },
+    'markPoint': {
+      'label': {
+        'normal': {
+          'textStyle': {
+            'color': '#293441'
+          }
+        },
+        'emphasis': {
+          'textStyle': {
+            'color': '#293441'
+          }
+        }
+      }
+    }
+  }
+  echart.registerTheme('dark', theme)
+  /* eslint-enable */
+}
+
+/**
+ * 鏍规嵁璺敱鍒囨崲鐨偆鏍囪瘑锛岄粯璁ょ毊鑲ゆ湭钃濊壊
+ * @author TJ 2019/05/29
+ */
+export function changeThemeClass (toRouterName) {
+  const darkSkinRouterName = []
+
+  if (darkSkinRouterName.includes(toRouterName)) {
+    document.body.className = 'dark'
+  } else {
+    document.body.className = 'blue'
+  }
+}
+
+/**
+ * 鍒ゆ柇瑕佹煡璇㈢殑鏁扮粍鏄惁鑷冲皯鏈変竴涓厓绱犲寘鍚湪鐩爣鏁扮粍涓�
+ * @param {Array} target 鐩爣鏁扮粍
+ * @param {Array} arr 闇�瑕佹煡璇㈢殑鏁扮粍
+ */
+export const hasOneOf = (targetarr, arr) => {
+  return targetarr.some(_ => arr.indexOf(_) > -1)
+}
+
+/**
+ * 鍒ゆ柇涓や釜瀵硅薄鏄惁鐩哥瓑锛岃繖涓や釜瀵硅薄鐨勫�煎彧鑳芥槸鏁板瓧鎴栧瓧绗︿覆
+ * @param {Object} obj1 瀵硅薄
+ * @param {Object} obj2 瀵硅薄
+ */
+export const objEqual = (obj1, obj2) => {
+  const keysArr1 = Object.keys(obj1)
+  const keysArr2 = Object.keys(obj2)
+  if (keysArr1.length !== keysArr2.length) return false
+  else if (keysArr1.length === 0 && keysArr2.length === 0) return true
+  /* eslint-disable-next-line */
+  else return !keysArr1.some(key => obj1[key] != obj2[key])
+}
+
+/**
+ * 鍒ゆ柇鍊兼槸鍚︿负鐪�,涓嶅寘鎷0鐨勫垽鏂�
+ * @param {String} val 瀛楃
+ */
+export function isTrue (val) {
+  return !_.isNull(val) && !_.isUndefined(val) && val !== ''
+}
+
+/**
+ * 瑙f瀽URL鍙傛暟
+ *
+ * @param {String} url
+ * @return {object}
+ */
+export function getQueryObject (url = window.location.href) {
+  if (!url) return
+  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
+    // return rs
+  })
+  return obj
+}
+
+/**
+ * 閫掑綊鏌ヨ鏍戣妭鐐�
+ *
+ * @param {object} treeData 鏍戠粨鏋勬暟鎹泦鍚�
+ * @param {string} prop 灞炴�у瓧娈�
+ * @param {string} propValue 灞炴�у搴旂殑鍊�
+ * @return {object} 鑺傜偣瀵硅薄
+ */
+export function recursion (tree, prop, propValue) {
+  if (!tree || !Array.isArray(tree)) return false
+  let result = {}
+
+  function handelTree (tree) {
+    for (const o of tree) {
+      if (o.children && Array.isArray(o.children) && o.children.length) {
+        if (o[prop] !== propValue) {
+          // 閫掑綊
+          handelTree(o.children)
+        } else {
+          result = o
+          break
+        }
+      } else {
+        if (o[prop] === propValue) {
+          result = o
+        }
+      }
+    }
+    return result
+  }
+
+  return handelTree(tree)
+}
+
+export function success (msg = $CONST.MSG_SYS_SUCCESS) {
+  Message({
+    message: msg,
+    type: 'success'
+  })
+}
+
+export function fail (msg = $CONST.MSG_SYS_FAIL) {
+  Message({
+    message: msg,
+    type: 'error'
+  })
+}
+
+export function error (msg = $CONST.MSG_SYS_ERR) {
+  Message({
+    message: msg,
+    type: 'error'
+  })
+}
+
+export function warning (msg = $CONST.MSG_SYS_WARNING) {
+  Message({
+    message: msg,
+    type: 'warning'
+  })
+}
+
+export function info (msg = $CONST.MSG_SYS_CANCELED) {
+  Message({
+    message: msg,
+    type: 'info'
+  })
+}
+
+/**
+ * 寮傛鍔犺浇缁勪欢
+ * @author TJ 2019/05/30
+ */
+
+/* eslint-disable */
+export function lazyLoadView(AsyncView) {
+  const AsyncComponent = () => ({
+    // 闇�瑕佸姞杞界殑缁勪欢 (搴旇鏄竴涓� `Promise` 瀵硅薄)
+    component: AsyncView,
+    // 寮傛缁勪欢鍔犺浇鏃朵娇鐢ㄧ殑缁勪欢
+    loading: '',
+    // 鍔犺浇澶辫触鏃朵娇鐢ㄧ殑缁勪欢
+    error: '',
+    // 灞曠ず鍔犺浇鏃剁粍浠剁殑寤舵椂鏃堕棿銆傞粯璁ゅ�兼槸 200 (姣)
+    delay: 200,
+    // 濡傛灉鎻愪緵浜嗚秴鏃舵椂闂翠笖缁勪欢鍔犺浇涔熻秴鏃朵簡锛�
+    // 鍒欎娇鐢ㄥ姞杞藉け璐ユ椂浣跨敤鐨勭粍浠躲�傞粯璁ゅ�兼槸锛歚Infinity`
+    timeout: 3000
+  })
+
+  return Promise.resolve({
+    functional: true,
+    render(h, { data, children }) {
+      // Transparently pass any props or children
+      // to the view component.
+      return h(AsyncComponent, data, children)
+    }
+  })
+}

--
Gitblit v1.8.0