12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { isDate } from 'date-fns';
- import { AES, mode, pad, enc } from "crypto-js";
- export const isTimestamp = (value) => {
-
- if (typeof value !== 'number') return false;
-
- if (value <= 0) return false;
-
- if (value !== Math.floor(value)) return false;
-
- return isDate(new Date(value));
- }
- export const generateNumberArray = (start, end) => {
- return Array.from(new Array(end + 1).keys()).slice(start);
- }
- export const encryptByEnAESLogin = (str) => {
- str = enc.Utf8.parse(str);
- let Key = enc.Utf8.parse('Aes2Util666AQWER');
- let tmpAES = AES.encrypt(str, Key, {
- mode: mode.ECB,
- padding: pad.Pkcs7,
- });
- return tmpAES.toString();
- }
- export const transform = (nodes, id, parentid) => {
- let parents = [];
- const idMapping = nodes.reduce((acc, el, i) => {
- acc[el[id]] = i;
- return acc;
- }, {});
- nodes.forEach((el) => {
- if (el[parentid] === null || el[parentid] === undefined) {
- parents.push(el);
- } else {
- const parentEl = nodes[idMapping[el[parentid]]];
- parentEl.children = [...(parentEl.children || []), el];
- }
- });
- return parents;
- }
|