feat: 初始化项目并完成基础功能开发
- 完成项目初始化
- 实现用户注册、登录功能
- 完成用户管理与权限管理模块
- 开发后端 Tracker 服务器项目管理接口
- 实现日志管理接口
Change-Id: Ia4bde1c9ff600352a7ff0caca0cc50b02cad1af7
diff --git a/react-ui/src/utils/IconUtil.ts b/react-ui/src/utils/IconUtil.ts
new file mode 100644
index 0000000..31102ee
--- /dev/null
+++ b/react-ui/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/react-ui/src/utils/downloadfile.ts b/react-ui/src/utils/downloadfile.ts
new file mode 100644
index 0000000..5d56cda
--- /dev/null
+++ b/react-ui/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/react-ui/src/utils/options.ts b/react-ui/src/utils/options.ts
new file mode 100644
index 0000000..79ee803
--- /dev/null
+++ b/react-ui/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/react-ui/src/utils/permission.ts b/react-ui/src/utils/permission.ts
new file mode 100644
index 0000000..e7c8a28
--- /dev/null
+++ b/react-ui/src/utils/permission.ts
@@ -0,0 +1,64 @@
+// /**
+// * 字符权限校验
+// * @param {Array} value 校验值
+// * @returns {Boolean}
+// */
+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 {Array} value 校验值
+ * @returns {Boolean}
+ */
+export function checkRole(roles: API.System.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/react-ui/src/utils/tree.ts b/react-ui/src/utils/tree.ts
new file mode 100644
index 0000000..d75395e
--- /dev/null
+++ b/react-ui/src/utils/tree.ts
@@ -0,0 +1,93 @@
+import { DataNode } from 'antd/es/tree';
+import { parse } from 'querystring';
+
+/**
+ * 构造树型结构数据
+ * @param {*} data 数据源
+ * @param {*} id id字段 默认 'id'
+ * @param {*} parentId 父节点字段 默认 'parentId'
+ * @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;
+}