From 2f96ef3f59c0084d2943a7fdac9f47f51fe30da5 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期四, 18 十一月 2021 17:35:08 +0800
Subject: [PATCH] 完善权限管理.清理无用的代码

---
 src/utils/index.js |  261 +++++++++++++++++++--------------------------------
 1 files changed, 97 insertions(+), 164 deletions(-)

diff --git a/src/utils/index.js b/src/utils/index.js
index 80e89c1..2f6a0e1 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -1,26 +1,19 @@
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 鏍煎紡鍖栨椂闂�
- * @param time
- * @param cFormat
- * @returns {string|null}
- */
 export function parseTime(time, cFormat) {
   if (arguments.length === 0) {
-    return null
+    return null;
   }
-  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
-  let date
-  if (typeof time === 'object') {
-    date = time
+  const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
+  let date;
+  if (typeof time === "object") {
+    date = time;
   } else {
-    if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
-      time = parseInt(time)
+    if (typeof time === "string" && /^[0-9]+$/.test(time)) {
+      time = parseInt(time);
     }
-    if (typeof time === 'number' && time.toString().length === 10) {
-      time = time * 1000
+    if (typeof time === "number" && time.toString().length === 10) {
+      time = time * 1000;
     }
-    date = new Date(time)
+    date = new Date(time);
   }
   const formatObj = {
     y: date.getFullYear(),
@@ -30,75 +23,62 @@
     i: date.getMinutes(),
     s: date.getSeconds(),
     a: date.getDay(),
-  }
+  };
   const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
-    let value = formatObj[key]
-    if (key === 'a') {
-      return ['鏃�', '涓�', '浜�', '涓�', '鍥�', '浜�', '鍏�'][value]
+    let value = formatObj[key];
+    if (key === "a") {
+      return ["鏃�", "涓�", "浜�", "涓�", "鍥�", "浜�", "鍏�"][value];
     }
     if (result.length > 0 && value < 10) {
-      value = '0' + value
+      value = "0" + value;
     }
-    return value || 0
-  })
-  return time_str
+    return value || 0;
+  });
+  return time_str;
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 鏍煎紡鍖栨椂闂�
- * @param time
- * @param option
- * @returns {string}
- */
 export function formatTime(time, option) {
-  if (('' + time).length === 10) {
-    time = parseInt(time) * 1000
+  if (("" + time).length === 10) {
+    time = parseInt(time) * 1000;
   } else {
-    time = +time
+    time = +time;
   }
-  const d = new Date(time)
-  const now = Date.now()
+  const d = new Date(time);
+  const now = Date.now();
 
-  const diff = (now - d) / 1000
+  const diff = (now - d) / 1000;
 
   if (diff < 30) {
-    return '鍒氬垰'
+    return "鍒氬垰";
   } else if (diff < 3600) {
     // less 1 hour
-    return Math.ceil(diff / 60) + '鍒嗛挓鍓�'
+    return Math.ceil(diff / 60) + "鍒嗛挓鍓�";
   } else if (diff < 3600 * 24) {
-    return Math.ceil(diff / 3600) + '灏忔椂鍓�'
+    return Math.ceil(diff / 3600) + "灏忔椂鍓�";
   } else if (diff < 3600 * 24 * 2) {
-    return '1澶╁墠'
+    return "1澶╁墠";
   }
   if (option) {
-    return parseTime(time, option)
+    return parseTime(time, option);
   } else {
     return (
       d.getMonth() +
       1 +
-      '鏈�' +
+      "鏈�" +
       d.getDate() +
-      '鏃�' +
+      "鏃�" +
       d.getHours() +
-      '鏃�' +
+      "鏃�" +
       d.getMinutes() +
-      '鍒�'
-    )
+      "鍒�"
+    );
   }
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 灏唘rl璇锋眰鍙傛暟杞负json鏍煎紡
- * @param url
- * @returns {{}|any}
- */
 export function paramObj(url) {
-  const search = url.split('?')[1]
+  const search = url.split("?")[1];
   if (!search) {
-    return {}
+    return {};
   }
   return JSON.parse(
     '{"' +
@@ -106,161 +86,114 @@
         .replace(/"/g, '\\"')
         .replace(/&/g, '","')
         .replace(/=/g, '":"')
-        .replace(/\+/g, ' ') +
+        .replace(/\+/g, " ") +
       '"}'
-  )
+  );
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 鐖跺瓙鍏崇郴鐨勬暟缁勮浆鎹㈡垚鏍戝舰缁撴瀯鏁版嵁
- * @param data
- * @returns {*}
- */
 export function translateDataToTree(data) {
   const parent = data.filter(
-    (value) => value.parentId === 'undefined' || value.parentId == null
-  )
+    (value) => value.parentId === "undefined" || value.parentId == null
+  );
   const children = data.filter(
-    (value) => value.parentId !== 'undefined' && value.parentId != null
-  )
+    (value) => value.parentId !== "undefined" && value.parentId != null
+  );
   const translator = (parent, children) => {
     parent.forEach((parent) => {
       children.forEach((current, index) => {
         if (current.parentId === parent.id) {
-          const temp = JSON.parse(JSON.stringify(children))
-          temp.splice(index, 1)
-          translator([current], temp)
-          typeof parent.children !== 'undefined'
+          const temp = JSON.parse(JSON.stringify(children));
+          temp.splice(index, 1);
+          translator([current], temp);
+          typeof parent.children !== "undefined"
             ? parent.children.push(current)
-            : (parent.children = [current])
+            : (parent.children = [current]);
         }
-      })
-    })
-  }
-  translator(parent, children)
-  return parent
+      });
+    });
+  };
+  translator(parent, children);
+  return parent;
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 鏍戝舰缁撴瀯鏁版嵁杞崲鎴愮埗瀛愬叧绯荤殑鏁扮粍
- * @param data
- * @returns {[]}
- */
 export function translateTreeToData(data) {
-  const result = []
+  const result = [];
   data.forEach((item) => {
     const loop = (data) => {
       result.push({
         id: data.id,
         name: data.name,
         parentId: data.parentId,
-      })
-      const child = data.children
+      });
+      const child = data.children;
       if (child) {
         for (let i = 0; i < child.length; i++) {
-          loop(child[i])
+          loop(child[i]);
         }
       }
-    }
-    loop(item)
-  })
-  return result
+    };
+    loop(item);
+  });
+  return result;
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 10浣嶆椂闂存埑杞崲
- * @param time
- * @returns {string}
- */
 export function tenBitTimestamp(time) {
-  const date = new Date(time * 1000)
-  const y = date.getFullYear()
-  let m = date.getMonth() + 1
-  m = m < 10 ? '' + m : m
-  let d = date.getDate()
-  d = d < 10 ? '' + d : d
-  let h = date.getHours()
-  h = h < 10 ? '0' + h : h
-  let minute = date.getMinutes()
-  let second = date.getSeconds()
-  minute = minute < 10 ? '0' + minute : minute
-  second = second < 10 ? '0' + second : second
-  return y + '骞�' + m + '鏈�' + d + '鏃� ' + h + ':' + minute + ':' + second //缁勫悎
+  const date = new Date(time * 1000);
+  const y = date.getFullYear();
+  let m = date.getMonth() + 1;
+  m = m < 10 ? "" + m : m;
+  let d = date.getDate();
+  d = d < 10 ? "" + d : d;
+  let h = date.getHours();
+  h = h < 10 ? "0" + h : h;
+  let minute = date.getMinutes();
+  let second = date.getSeconds();
+  minute = minute < 10 ? "0" + minute : minute;
+  second = second < 10 ? "0" + second : second;
+  return y + "骞�" + m + "鏈�" + d + "鏃� " + h + ":" + minute + ":" + second; //缁勫悎
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 13浣嶆椂闂存埑杞崲
- * @param time
- * @returns {string}
- */
 export function thirteenBitTimestamp(time) {
-  const date = new Date(time / 1)
-  const y = date.getFullYear()
-  let m = date.getMonth() + 1
-  m = m < 10 ? '' + m : m
-  let d = date.getDate()
-  d = d < 10 ? '' + d : d
-  let h = date.getHours()
-  h = h < 10 ? '0' + h : h
-  let minute = date.getMinutes()
-  let second = date.getSeconds()
-  minute = minute < 10 ? '0' + minute : minute
-  second = second < 10 ? '0' + second : second
-  return y + '骞�' + m + '鏈�' + d + '鏃� ' + h + ':' + minute + ':' + second //缁勫悎
+  const date = new Date(time / 1);
+  const y = date.getFullYear();
+  let m = date.getMonth() + 1;
+  m = m < 10 ? "" + m : m;
+  let d = date.getDate();
+  d = d < 10 ? "" + d : d;
+  let h = date.getHours();
+  h = h < 10 ? "0" + h : h;
+  let minute = date.getMinutes();
+  let second = date.getSeconds();
+  minute = minute < 10 ? "0" + minute : minute;
+  second = second < 10 ? "0" + second : second;
+  return y + "骞�" + m + "鏈�" + d + "鏃� " + h + ":" + minute + ":" + second; //缁勫悎
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description 鑾峰彇闅忔満id
- * @param length
- * @returns {string}
- */
 export function uuid(length = 32) {
-  const num = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
-  let str = ''
+  const num = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+  let str = "";
   for (let i = 0; i < length; i++) {
-    str += num.charAt(Math.floor(Math.random() * num.length))
+    str += num.charAt(Math.floor(Math.random() * num.length));
   }
-  return str
+  return str;
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description m鍒皀鐨勯殢鏈烘暟
- * @param m
- * @param n
- * @returns {number}
- */
 export function random(m, n) {
-  return Math.floor(Math.random() * (m - n) + n)
+  return Math.floor(Math.random() * (m - n) + n);
 }
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description addEventListener
- * @type {function(...[*]=)}
- */
 export const on = (function () {
   return function (element, event, handler, useCapture = false) {
     if (element && event && handler) {
-      element.addEventListener(event, handler, useCapture)
+      element.addEventListener(event, handler, useCapture);
     }
-  }
-})()
+  };
+})();
 
-/**
- * @author chuzhixin 1204505056@qq.com 锛堜笉鎯充繚鐣檃uthor鍙垹闄わ級
- * @description removeEventListener
- * @type {function(...[*]=)}
- */
 export const off = (function () {
   return function (element, event, handler, useCapture = false) {
     if (element && event) {
-      element.removeEventListener(event, handler, useCapture)
+      element.removeEventListener(event, handler, useCapture);
     }
-  }
-})()
+  };
+})();

--
Gitblit v1.8.0