'init_again'

Change-Id: Ib7ecdb9f5baeab1e4681152a57b936edf7475b35
diff --git a/src/utils/IconUtil.ts b/src/utils/IconUtil.ts
new file mode 100644
index 0000000..31102ee
--- /dev/null
+++ b/src/utils/IconUtil.ts
@@ -0,0 +1,20 @@
+import * as AntdIcons from '@ant-design/icons';
+import React from 'react';
+
+const allIcons: Record<string, any> = AntdIcons;
+
+export function getIcon(name: string): React.ReactNode | string {
+  const icon = allIcons[name];
+  return icon || '';
+}
+
+export function createIcon(icon: string | any): React.ReactNode | string {
+  if (typeof icon === 'object') {
+    return icon;
+  }
+  const ele = allIcons[icon];
+  if (ele) {
+    return React.createElement(allIcons[icon]);
+  }
+  return '';
+}
diff --git a/src/utils/downloadfile.ts b/src/utils/downloadfile.ts
new file mode 100644
index 0000000..5d56cda
--- /dev/null
+++ b/src/utils/downloadfile.ts
@@ -0,0 +1,63 @@
+import { request } from '@umijs/max';
+
+const mimeMap = {
+  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+  zip: 'application/zip',
+};
+
+/**
+ * 解析blob响应内容并下载
+ * @param {*} res blob响应内容
+ * @param {String} mimeType MIME类型
+ */
+export function resolveBlob(res: any, mimeType: string) {
+  const aLink = document.createElement('a');
+  const blob = new Blob([res.data], { type: mimeType });
+  // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名;
+  const patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*');
+  // console.log(res);
+  const contentDisposition = decodeURI(res.headers['content-disposition']);
+  const result = patt.exec(contentDisposition);
+  let fileName = result ? result[1] : 'file';
+  fileName = fileName.replace(/"/g, '');
+  aLink.style.display = 'none';
+  aLink.href = URL.createObjectURL(blob);
+  aLink.setAttribute('download', fileName); // 设置下载文件名称
+  document.body.appendChild(aLink);
+  aLink.click();
+  URL.revokeObjectURL(aLink.href); // 清除引用
+  document.body.removeChild(aLink);
+}
+
+export function downLoadZip(url: string) {
+  request(url, {
+    method: 'GET',
+    responseType: 'blob',
+    getResponse: true,
+  }).then((res) => {
+    resolveBlob(res, mimeMap.zip);
+  });
+}
+
+export async function downLoadXlsx(url: string, params: any, fileName: string) {
+  return request(url, {
+    ...params,
+    method: 'POST',
+    responseType: 'blob',
+  }).then((data) => {
+    const aLink = document.createElement('a');
+    const blob = data as any; // new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
+    aLink.style.display = 'none';
+    aLink.href = URL.createObjectURL(blob);
+    aLink.setAttribute('download', fileName); // 设置下载文件名称
+    document.body.appendChild(aLink);
+    aLink.click();
+    URL.revokeObjectURL(aLink.href); // 清除引用
+    document.body.removeChild(aLink);
+  });
+}
+
+
+export function download(fileName: string) {
+  window.location.href = `/api/common/download?fileName=${encodeURI(fileName)}&delete=${true}`;
+}
diff --git a/src/utils/options.ts b/src/utils/options.ts
new file mode 100644
index 0000000..79ee803
--- /dev/null
+++ b/src/utils/options.ts
@@ -0,0 +1,12 @@
+import { DictValueEnumObj } from "@/components/DictTag";
+import { ProSchemaValueEnumObj, ProSchemaValueEnumType } from "@ant-design/pro-components";
+
+export function getValueEnumLabel(options: DictValueEnumObj | ProSchemaValueEnumObj, val: string | number | undefined, defaultValue?: string) {
+    if (val !== undefined) {
+       const data = options[val] as ProSchemaValueEnumType;
+       if(data) {
+        return data.text;
+       }
+    }
+    return defaultValue?defaultValue:val;
+}
diff --git a/src/utils/permission.ts b/src/utils/permission.ts
new file mode 100644
index 0000000..2b39e48
--- /dev/null
+++ b/src/utils/permission.ts
@@ -0,0 +1,67 @@
+// /**
+//  * 字符权限校验
+//  * @param {Array} value 校验值
+//  * @returns {Boolean}
+
+// import Role = API.System.Role;
+
+export function matchPerms(permissions: string[], value: string[]) {
+  if (value && value instanceof Array && value.length > 0) {
+    const permissionDatas = value;
+    const all_permission = '*:*:*';
+    const hasPermission = permissions.some((permission) => {
+      return all_permission === permission || permissionDatas.includes(permission);
+    });
+    if (!hasPermission) {
+      return false;
+    }
+    return true;
+  }
+  console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`);
+  return false;
+}
+
+export function matchPerm(permissions: string[], value: string) {
+  if (value && value.length > 0) {
+    const permissionDatas = value;
+    const all_permission = '*:*:*';
+    const hasPermission = permissions.some((permission) => {
+      return all_permission === permission || permissionDatas === permission;
+    });
+    if (!hasPermission) {
+      return false;
+    }
+    return true;
+  }
+  console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`);
+  return false;
+}
+
+export function matchPermission(permissions: string[] | undefined, value: any): boolean {
+  if (permissions === undefined) return false;
+  const type = typeof value;
+  if (type === 'string') {
+    return matchPerm(permissions, value);
+  }
+  return matchPerms(permissions, value);
+}
+
+/**
+ * 角色权限校验
+ * @param roles
+ * @param {Array} value 校验值
+ * @returns {Boolean}
+ */
+export function checkRole(roles: Role[] | undefined, value: string[]) {
+  if (roles && value && value.length > 0) {
+    for (let i = 0; i < roles?.length; i++) {
+      for (let j = 0; j < value?.length; j++) {
+        if (value[j] === roles[i].roleKey) {
+          return true;
+        }
+      }
+    }
+  }
+  console.error(`need roles! Like checkRole="['admin','editor']"`);
+  return false;
+}
diff --git a/src/utils/tree.ts b/src/utils/tree.ts
new file mode 100644
index 0000000..7f1a2e5
--- /dev/null
+++ b/src/utils/tree.ts
@@ -0,0 +1,95 @@
+import { DataNode } from 'antd/es/tree';
+import { parse } from 'querystring';
+
+/**
+ * 构造树型结构数据
+ * @param {*} data 数据源
+ * @param {*} id id字段 默认 'id'
+ * @param name
+ * @param {*} parentId 父节点字段 默认 'parentId'
+ * @param parentName
+ * @param {*} children 孩子节点字段 默认 'children'
+ */
+export function buildTreeData(
+  data: any[],
+  id: string,
+  name: string,
+  parentId: string,
+  parentName: string,
+  children: string,
+) {
+  const config = {
+    id: id || 'id',
+    name: name || 'name',
+    parentId: parentId || 'parentId',
+    parentName: parentName || 'parentName',
+    childrenList: children || 'children',
+  };
+
+  const childrenListMap: any[] = [];
+  const nodeIds: any[] = [];
+  const tree: any[] = [];
+  data.forEach((item) => {
+    const d = item;
+    const pId = d[config.parentId];
+    if (!childrenListMap[pId]) {
+      childrenListMap[pId] = [];
+    }
+    d.key = d[config.id];
+    d.title = d[config.name];
+    d.value = d[config.id];
+    d[config.childrenList] = null;
+    nodeIds[d[config.id]] = d;
+    childrenListMap[pId].push(d);
+  });
+
+  data.forEach((item: any) => {
+    const d = item;
+    const pId = d[config.parentId];
+    if (!nodeIds[pId]) {
+      d[config.parentName] = '';
+      tree.push(d);
+    }
+  });
+
+  function adaptToChildrenList(item: any) {
+    const o = item;
+    if (childrenListMap[o[config.id]]) {
+      if (!o[config.childrenList]) {
+        o[config.childrenList] = [];
+      }
+      o[config.childrenList] = childrenListMap[o[config.id]];
+    }
+    if (o[config.childrenList]) {
+      o[config.childrenList].forEach((child: any) => {
+        const c = child;
+        c[config.parentName] = o[config.name];
+        adaptToChildrenList(c);
+      });
+    }
+  }
+
+  tree.forEach((t: any) => {
+    adaptToChildrenList(t);
+  });
+
+  return tree;
+}
+
+export const getPageQuery = () => parse(window.location.href.split('?')[1]);
+
+export function formatTreeData(arrayList: any): DataNode[] {
+  const treeSelectData: DataNode[] = arrayList.map((item: any) => {
+    const node: DataNode = {
+      id: item.id,
+      title: item.label,
+      key: `${item.id}`,
+      value: item.id,
+    } as DataNode;
+    if (item.children) {
+      node.children = formatTreeData(item.children);
+    }
+    return node;
+  });
+  return treeSelectData;
+}