first commit

This commit is contained in:
jerryjzhang
2023-06-12 18:44:01 +08:00
commit dc4fc69b57
879 changed files with 573090 additions and 0 deletions

View File

@@ -0,0 +1,224 @@
import type { SqlParamsItem } from '@/pages/data-explore/data';
declare namespace API {
// export type CurrentUser = {
// avatar?: string;
// name?: string;
// title?: string;
// group?: string;
// signature?: string;
// tags?: {
// key: string;
// label: string;
// }[];
// userid?: string;
// access?: 'user' | 'guest' | 'admin';
// unreadCount?: number;
// };
export type CurrentUser = {
staffid: string;
staffName: string;
orgName: string;
access?: 'user' | 'guest' | 'admin';
};
export type LoginStateType = {
status?: 'ok' | 'error';
type?: string;
};
export type NoticeIconData = {
id: string;
key: string;
avatar: string;
title: string;
datetime: string;
type: string;
read?: boolean;
description: string;
clickClose?: boolean;
extra: any;
status: string;
};
export type FieldItem = {
fieldname: string; // 字段名
fieldtype: string; // 字段类型
fieldcomment: string; // 释义
dimensionorindex: '0' | '1'; // 维度-0 指标-1
rname: string; // 绑定现有维度/指标 -- name
rguid: string; // 绑定现有维度/指标 -- guid
};
export type QueryChangeLogParams = Pagination & {
typeId: string;
};
export type ChangeLogItem = {
typeId: string;
typeName: string;
changeTime: string; // 变更时间
owner: string; // 操作人
comment: string; // 变更说明
changeDetail: string; // 操作详情
};
export type ChangeLogRes = PaginationResponse<ChangeLogItem>;
export type SearchParams = {
name?: string; // 数据集名称
description?: string; // 数据集描述
bizcodes?: string[]; // 所属项目
dsowner?: string; // 负责人
startEndtime?: sting[]; // 开始-结束时间
assetStatus?: number[]; // 数据集状态
sensitivities?: number[]; // 敏感度
};
export type DataSetListParams = Pagination & SearchParams;
export type DataSetItem = {
guid: string;
longid: number;
name: string; // 数据集名称
description: string; // 数据集描述
datasouce: string; // 数据源名称
datasouceId: number; // 数据源id
tables: string; // 表名
projectId: string; // 业务名称
projectIdStr: string;
owner: string; // 负责人
updateperiod: string; // 更新周期
updateperiodStr: string; // 更新周期
opsource: number; // 来源
createTimeStr: string;
updateTimeStr: string;
assetStatusStr: string; // 上线/下线
isAsset: number; // 是否资产
sensitivity: number;
sensitivityStr: string; // 敏感度
sql: string; // 技术口径
sensitivity: number; // 数据敏感度1-底 2-中 3-高
variables: SqlParamsItem[]; // 数据集归属脚本参数
};
export type DataSetListRes = PaginationResponse<DataSetItem>;
export type DataSetBasicInfo = DataSetItem;
export type DimensionListSearchParams = {
name: string; // 中文名
dimensionSource: string[]; // 来源
projectIds: string[]; // 所属项目
dimensionbizName: string; // 英文名
description: string; // 描述
};
export type QueryFieldListParams = Pagination & {
guid: string;
name?: string;
};
export type DataSetFieldItem = {
columnXh: number; // 顺序标记从0开始
name: string; // 字段名
fieldtype: string; // 字段类型
description: string; // 释义
dimensionorindex: '0' | '1'; // 维度-0 指标-1
assetStatusStr: string; // 状态
rname: string; // 绑定现有维度/指标 -- name
rguid: string; // 绑定现有维度/指标 -- guid
};
export type DataSetFieldListRes = PaginationResponse<DataSetFieldItem>;
// 搜索条件
export type DataTableSearchParams = {
name: string; // 表名
description: string; // 描述详情
extDatasouceenums: string[]; // 数据库类型
extDwlayerenums: string[]; // 数仓分层
extBizenums: string[]; // 所属项目
queryRanges: string[]; // 查看范围
storagesize: string; // 存储大小
owner: string; // 所有者
createtime: string; // 创建时间
};
export type DataTableListParams = Pagination & DataTableSearchParams;
// 数据表列表
export type DataTableListItem = {
guid: string;
name: string; // 表名
description: string; // 描述
projectFullName: string; // 所属项目
isSpeedStr: string; // 是否加速
dbName: string; // 库名
dwLayer: string; // 数据分层
assetSensitivityStr: string; // 数据敏感度
storageSize: string; // 储存大小
owner: string; // 所有者
createTime: string; // 创建时间
dbTableName: string; // 库名::表名
};
// 数据表列表
export type DataTableListRes = PaginationResponse<DataTableListItem>;
// 业务项目对象
export type ProjectItem = AuthSdkType.AuthCodesItem & {
projectId: string; // 项目ID
projectIncreId: number; // 项目自增ID
projectName: string; // 项目名
projectParentId: string; // 父项目ID
projectFullName: string; // 父项目-子项目
projectLevel: number; // 项目层级
comment: string; // 项目描述
creator: string; // 项目创建人
projectType: number; // 项目类别 0-为私有项目 1-为公共项目
childProjectList?: ProjectList;
children?: ProjectList;
value: string;
};
export type ProjectList = ProjectItem[];
// 数据实例详情
export type DataInstanceDetail = {
type: string; // 类型 mysql、tdw
id: string; // id
name: string; // 名称
description: string; // 描述
ip?: string; // ip
port?: string; // 端口
bootstrap?: string; // 连接地址
};
export type AuthCodeItem = {
code: string; // 权限码
approverLevel: number;
ext: string;
isMenu: number;
isVisible: number;
no: number;
pcode: string;
url: string;
};
// 数据库查询参数
export type DatabaseParams = {
bindSourceId: number;
};
// 数据库列表子项
export type DatabaseItem = {
dbName: string; // 数据库名
cnt: number; // 库中有权限表数量
};
// 数据类型
export type DataInstanceItem = {
sourceInstanceId: number; // 数据实例id
sourceInstanceName: string; // 数据实例名
defaultSourceId: number; // 查询表需要的默认datasource id
bindSourceId: number;
};
}

View File

@@ -0,0 +1,15 @@
import { request } from 'umi';
export type LoginParamsType = {
username: string;
password: string;
mobile: string;
captcha: string;
type: string;
};
export async function queryToken(code: string) {
return request(`${process.env.API_BASE_URL}user/ioaLoginCallback`, {
params: { code },
});
}

View File

@@ -0,0 +1,120 @@
import { FROM_URL_KEY } from '@/common/constants';
import type {
RequestOptionsInit,
RequestOptionsWithoutResponse,
RequestMethod,
RequestOptionsWithResponse,
RequestResponse,
CancelTokenStatic,
CancelStatic,
} from 'umi-request';
import { extend } from 'umi-request';
import { history } from 'umi';
import { AUTH_TOKEN_KEY } from '@/common/constants';
export const TOKEN_KEY = AUTH_TOKEN_KEY;
const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
const headers: any = {};
const { query } = history.location as any;
const token = query[TOKEN_KEY] || localStorage.getItem(TOKEN_KEY);
if (token) {
headers.auth = `Bearer ${token}`;
localStorage.setItem(TOKEN_KEY, token);
}
return {
url,
options: { ...options, headers },
};
};
const responseInterceptor = async (response: Response) => {
const data: Result<any> = await response?.clone()?.json?.();
if (Number(data.code) === 403) {
history.push('/login');
return response;
}
const redirect = response.headers.get('redirect'); // 若HEADER中含有REDIRECT说明后端想重定向
if (redirect === 'REDIRECT') {
localStorage.removeItem(TOKEN_KEY);
let win: any = window;
while (win !== win.top) {
win = win.top;
}
if (!/fromExternal=true/.test(win.location.search)) {
localStorage.setItem(FROM_URL_KEY, win.location.href);
}
// 将后端重定向的地址取出来,使用win.location.href去实现重定向的要求
const contextpath = response.headers.get('contextpath');
win.location.href = contextpath;
}
return response;
};
let requestMethodInstance: RequestMethod;
const getRequestMethod = () => {
if (requestMethodInstance) {
return requestMethodInstance;
}
requestMethodInstance = extend({});
const requestInterceptors = [authHeaderInterceptor];
const responseInterceptors = [responseInterceptor];
requestMethodInstance.use(async (ctx, next) => {
await next();
});
requestInterceptors.map((ri) => requestMethodInstance.interceptors.request.use(ri));
responseInterceptors.map((ri) => requestMethodInstance.interceptors.response.use(ri));
return requestMethodInstance;
};
const requestMethod = getRequestMethod();
interface RequestMethodInUmi<R = false> {
<T = any>(url: string, options: RequestOptionsWithResponse): Promise<RequestResponse<T>>;
<T = any>(url: string, options: RequestOptionsWithoutResponse): Promise<T>;
<T = any>(url: string, options?: RequestOptionsInit): R extends true
? Promise<RequestResponse<T>>
: Promise<T>;
get: RequestMethodInUmi<R>;
post: RequestMethodInUmi<R>;
delete: RequestMethodInUmi<R>;
put: RequestMethodInUmi<R>;
patch: RequestMethodInUmi<R>;
head: RequestMethodInUmi<R>;
options: RequestMethodInUmi<R>;
rpc: RequestMethodInUmi<R>;
Cancel: CancelStatic;
CancelToken: CancelTokenStatic;
isCancel: (value: any) => boolean;
}
// @ts-ignore
const tRequest: RequestMethodInUmi = (url: any, options: any) => {
return requestMethod(url, options);
};
const METHODS = ['get', 'post', 'delete', 'put', 'patch', 'head', 'options', 'rpc'];
METHODS.forEach((method) => {
tRequest[method] = (url: any, options: any) => {
return requestMethod(url, {
...options,
method,
});
};
});
tRequest.Cancel = requestMethod.Cancel;
tRequest.CancelToken = requestMethod.CancelToken;
tRequest.isCancel = requestMethod.isCancel;
export default tRequest;
export const request = {
requestInterceptors: [authHeaderInterceptor],
responseInterceptors: [responseInterceptor],
};

View File

@@ -0,0 +1,9 @@
import { request } from 'umi';
export async function query() {
return request<API.CurrentUser[]>(`${process.env.API_BASE_URL}users`);
}
export async function queryCurrentUser() {
return request<Result<API.CurrentUser>>(`${process.env.AUTH_API_BASE_URL}user/getCurrentUser`);
}