first commit
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
|
||||
const claimsConfig = {
|
||||
role: 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role',
|
||||
name: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name',
|
||||
nameidentifier: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'
|
||||
};
|
||||
|
||||
export class TokenStorage {
|
||||
dbName: string;
|
||||
storeName: string;
|
||||
db: IDBDatabase | null;
|
||||
|
||||
constructor(dbName = 'laitool', storeName = 'tokens') {
|
||||
this.dbName = dbName;
|
||||
this.storeName = storeName;
|
||||
this.db = null;
|
||||
|
||||
const request = indexedDB.open(this.dbName, 1);
|
||||
|
||||
request.onupgradeneeded = (event) => {
|
||||
const db = (event.target as IDBOpenDBRequest).result;
|
||||
db.createObjectStore(this.storeName, { keyPath: 'id' });
|
||||
};
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
this.db = (event.target as IDBOpenDBRequest).result;
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
console.error('Database error:', (event.target as IDBRequest).error);
|
||||
};
|
||||
}
|
||||
|
||||
private async initDB(): Promise<IDBDatabase> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.db) {
|
||||
return resolve(this.db);
|
||||
}
|
||||
|
||||
const request = indexedDB.open(this.dbName, 1);
|
||||
|
||||
request.onupgradeneeded = (event) => {
|
||||
const db = (event.target as IDBOpenDBRequest).result;
|
||||
db.createObjectStore(this.storeName, { keyPath: 'id' });
|
||||
};
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
this.db = (event.target as IDBOpenDBRequest).result;
|
||||
resolve(this.db);
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
console.error('Database error:', (event.target as IDBRequest).error);
|
||||
reject((event.target as IDBRequest).error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async saveToken(token: string): Promise<void> {
|
||||
const db = await this.initDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([this.storeName], 'readwrite');
|
||||
const objectStore = transaction.objectStore(this.storeName);
|
||||
const request = objectStore.put({ id: 'token', value: token });
|
||||
|
||||
transaction.oncomplete = () => {
|
||||
console.log('Token saved');
|
||||
resolve();
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
console.error('Save token error:', (event.target as IDBRequest).error);
|
||||
reject((event.target as IDBRequest).error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async getTokenAndDecode(): Promise<any | null> { // Replace 'any' with appropriate type
|
||||
const db = await this.initDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([this.storeName], 'readonly');
|
||||
const objectStore = transaction.objectStore(this.storeName);
|
||||
const request = objectStore.get('token');
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
const result = (event.target as IDBRequest).result;
|
||||
if (result) {
|
||||
console.log('Token:', result.value);
|
||||
let claims: any = null;
|
||||
if (result.value) {
|
||||
const decodedToken = jwtDecode(result.value);
|
||||
// 提取声明并创建新对象
|
||||
claims = {
|
||||
exp: decodedToken.exp,
|
||||
role: decodedToken[claimsConfig.role as keyof typeof decodedToken] as string,
|
||||
name: decodedToken[claimsConfig.name as keyof typeof decodedToken] as string,
|
||||
nameidentifier: decodedToken[claimsConfig.nameidentifier as keyof typeof decodedToken] as string,
|
||||
};
|
||||
}
|
||||
resolve(claims);
|
||||
} else {
|
||||
console.log('Token not found');
|
||||
resolve(null);
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
console.error('Get token error:', (event.target as IDBRequest).error);
|
||||
reject((event.target as IDBRequest).error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async getToken(): Promise<string> {
|
||||
const db = await this.initDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([this.storeName], 'readonly');
|
||||
const objectStore = transaction.objectStore(this.storeName);
|
||||
const request = objectStore.get('token');
|
||||
|
||||
request.onsuccess = (event) => {
|
||||
const result = (event.target as IDBRequest).result;
|
||||
if (result) {
|
||||
console.log('Token:', result.value);
|
||||
resolve(result.value);
|
||||
} else {
|
||||
console.log('Token not found');
|
||||
reject(new Error("Token not found"));
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
console.error('Get token error:', (event.target as IDBRequest).error);
|
||||
reject((event.target as IDBRequest).error);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async deleteToken(): Promise<void> {
|
||||
const db = await this.initDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction([this.storeName], 'readwrite');
|
||||
const objectStore = transaction.objectStore(this.storeName);
|
||||
const request = objectStore.delete('token');
|
||||
|
||||
transaction.oncomplete = () => {
|
||||
console.log('Token deleted');
|
||||
resolve();
|
||||
};
|
||||
|
||||
request.onerror = (event) => {
|
||||
console.error('Delete token error:', (event.target as IDBRequest).error);
|
||||
reject((event.target as IDBRequest).error);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
declare namespace Token {
|
||||
type TokenDecode = {
|
||||
exp: string;
|
||||
role: string;
|
||||
name: string;
|
||||
nameidentifier: string;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
import asiox from 'axios';
|
||||
// asiox.defaults.baseURL = 'http://localhost:1578';
|
||||
asiox.defaults.baseURL = 'https://localhost:44362';
|
||||
|
||||
|
||||
/** 退出登录接口 POST /api/login/outLogin */
|
||||
export async function outLogin(options?: { [key: string]: any }) {
|
||||
return asiox('/api/login/outLogin', {
|
||||
method: 'POST',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 将对象转换为查询字符串。
|
||||
*
|
||||
* @param params - 一个对象,其中键是查询参数名称,值是查询参数值。
|
||||
* @returns 表示查询参数的字符串。
|
||||
*/
|
||||
function objectToQueryString(params: Record<string, any>): string {
|
||||
const queryParams = new URLSearchParams();
|
||||
|
||||
for (const key in params) {
|
||||
if (params.hasOwnProperty(key) && params[key] != null) {
|
||||
if (Array.isArray(params[key])) {
|
||||
// 如果属性值是数组,将数组的每个元素分别添加到查询字符串中
|
||||
params[key].forEach((value: any) => {
|
||||
queryParams.append(key, value);
|
||||
});
|
||||
} else {
|
||||
queryParams.append(key, params[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queryParams.toString();
|
||||
}
|
||||
|
||||
export {
|
||||
objectToQueryString
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
// API 更新时间:
|
||||
// API 唯一标识:
|
||||
import * as api from './api';
|
||||
import * as login from './login';
|
||||
import * as role from './role';
|
||||
import * as user from './user';
|
||||
|
||||
export default {
|
||||
api,
|
||||
login,
|
||||
role,
|
||||
user
|
||||
};
|
||||
@@ -0,0 +1,146 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
import { request, useModel } from '@umijs/max';
|
||||
import CryptoJS from 'crypto-js';
|
||||
import { TokenStorage } from '../define/tokenStorage';
|
||||
import { errorMessage, successMessage } from './response';
|
||||
import { getCurrentUser } from './user';
|
||||
import forge from 'node-forge';
|
||||
|
||||
const tokenStorage = new TokenStorage();
|
||||
|
||||
/** 发送验证码 POST /api/login/captcha */
|
||||
export async function getFakeCaptcha(
|
||||
params: {
|
||||
// query
|
||||
/** 手机号 */
|
||||
phone?: string;
|
||||
},
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
return request<API.FakeCaptcha>('/api/login/captcha', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务i其的随机公钥给前端加密
|
||||
* @returns
|
||||
*/
|
||||
export async function getPublicKey(): Promise<UserModel.UserPublicKeyResPonse> {
|
||||
try {
|
||||
// 获取加密的公钥
|
||||
let publicKey = await request<ApiResponse.SuccessItem<UserModel.UserPublicKeyResPonse>>("/lms/User/GetPublicKey", {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
if (publicKey.code != 1) {
|
||||
throw new Error(publicKey.message);
|
||||
}
|
||||
return publicKey.data;
|
||||
} catch (error: any) {
|
||||
throw new Error(error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加密 password
|
||||
* @param publicKeyPem
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
export function encryptPassword(publicKeyPem: string, data: string) {
|
||||
// 解析 PEM 格式的公钥
|
||||
const publicKey = forge.pki.publicKeyFromPem(publicKeyPem);
|
||||
|
||||
// 将字符串转换为字节
|
||||
const bytes = forge.util.encodeUtf8(data);
|
||||
|
||||
// 使用 OAEP 和 SHA-256 进行加密
|
||||
const encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', {
|
||||
md: forge.md.sha256.create(),
|
||||
mgf1: {
|
||||
md: forge.md.sha256.create()
|
||||
}
|
||||
});
|
||||
|
||||
// 将加密后的数据转换为 Base64
|
||||
return forge.util.encode64(encrypted);
|
||||
}
|
||||
|
||||
export async function login(body: API.LoginParams, options?: { [key: string]: any }): Promise<UserModel.UserInfo> {
|
||||
try {
|
||||
let publicKey = await getPublicKey();
|
||||
|
||||
// 加密密码
|
||||
body.password = encryptPassword(publicKey.publicKey, body.password);
|
||||
let bodyData = {
|
||||
...body,
|
||||
rememberMe: true,
|
||||
deviceInfo: '2',
|
||||
loginType: 1,
|
||||
tokenId: publicKey.token
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserLoginResponse>>('/lms/User/Login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: bodyData,
|
||||
...(options || {}),
|
||||
});
|
||||
// 判断是不是登录成功,成功的话,保存token
|
||||
if (res.code == 1 && res.data) {
|
||||
|
||||
localStorage.setItem('token', res.data.token)
|
||||
localStorage.setItem('refreshToken', res.data.refreshToken)
|
||||
let userId = res.data.id;
|
||||
let userInfo = await getCurrentUser(userId);
|
||||
if (userInfo.code == 1) {
|
||||
localStorage.setItem('userInfo', JSON.stringify(userInfo.data));
|
||||
} else {
|
||||
throw new Error(userInfo.message);
|
||||
}
|
||||
return userInfo.data
|
||||
} else {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
} catch (error: any) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
* @param params
|
||||
*/
|
||||
export async function UserRegistr(params: UserModel.UserRegisterParams): Promise<void> {
|
||||
let publicKey = await getPublicKey();
|
||||
// 加密密码
|
||||
debugger;
|
||||
let secPassword = encryptPassword(publicKey.publicKey, params.password);
|
||||
let bodyData = {
|
||||
userName: params.userName,
|
||||
email: params.email ?? '',
|
||||
password: secPassword,
|
||||
tokenId: publicKey.token,
|
||||
affiliateCode : params.affiliateCode
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<string>>('/lms/User/Register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: bodyData
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { request } from "@umijs/max";
|
||||
import { objectToQueryString } from "./common"
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param tableParams
|
||||
* @param userParams
|
||||
* @returns
|
||||
*/
|
||||
async function QueryMachineList(tableParams: TableModel.TableParams, userParams: MachineModel.QueryUMachineParams) {
|
||||
let data = {
|
||||
...userParams,
|
||||
page: tableParams.pagination?.current,
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await request<ApiResponse.SuccessItem<MachineModel.QueryMachineData>>(`/lms/Machine/QueryMachineCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
console.log(QueryMachineList, res)
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将机器码升级为永久
|
||||
* @param id
|
||||
*/
|
||||
async function MachinePermanent(id: String): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/UpgradeMachine/${id}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用机器码
|
||||
* @param id
|
||||
*/
|
||||
async function DeactivationMachine(id: string): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/DeactivateMachine/${id}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机器码信息
|
||||
* @param id 机器码对应的ID
|
||||
* @returns
|
||||
*/
|
||||
async function GetMachineInfo(id: string): Promise<MachineModel.MachineInfo> {
|
||||
let res = await request<ApiResponse.SuccessItem<MachineModel.MachineInfo>>(`/lms/Machine/GetMachineDetail/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
console.log("GetMachineInfo", res)
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改机器码信息
|
||||
* @param id
|
||||
* @param params
|
||||
*/
|
||||
async function ModifyMachineData(id: string, params: MachineModel.ModifyMachineParams): Promise<void> {
|
||||
let deactivationTimeString = params.deactivationTime ? params.deactivationTime.toISOString() : undefined;
|
||||
let data = {
|
||||
...params,
|
||||
deactivationTime: deactivationTimeString
|
||||
}
|
||||
console.log("ModifyMachineData", params)
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/ModifyMachine/${id}`, {
|
||||
method: 'POST',
|
||||
data: data
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加机器码
|
||||
* @param params
|
||||
*/
|
||||
async function AddMachineData(params: MachineModel.AddMachineParams) {
|
||||
let deactivationTimeString = params.deactivationTime ? params.deactivationTime.toISOString() : undefined;
|
||||
let data = {
|
||||
...params,
|
||||
deactivationTime: deactivationTimeString
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/AddMachine`, {
|
||||
method: 'POST',
|
||||
data: data
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
QueryMachineList,
|
||||
MachinePermanent,
|
||||
DeactivationMachine,
|
||||
GetMachineInfo,
|
||||
ModifyMachineData,
|
||||
AddMachineData
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import { request } from '@umijs/max';
|
||||
import { errorMessage } from './response';
|
||||
|
||||
//#region 提示词数据相关
|
||||
/**
|
||||
* 获取提示词数据
|
||||
* @param typeId 提示类型的Id,要是获取全部,就是all
|
||||
* @param pageSize 每页的大小
|
||||
* @param current 当前也
|
||||
* @param options 其余请求操作项
|
||||
* @returns
|
||||
*/
|
||||
export async function getPromptSample(typeId: string, pageSize: number | undefined, current: number | undefined, options?: { [key: string]: any }): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
debugger
|
||||
return await request(`/api/Prompt/GetPromptString/${typeId}/${pageSize}/${current}`, {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
} catch (error: any) {
|
||||
return errorMessage(error.toString())
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPromptDetail(id: string): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
debugger
|
||||
return await request(`/api/Prompt/GetPromptDetailById/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
} catch (error: any) {
|
||||
return errorMessage(error.toString())
|
||||
}
|
||||
}
|
||||
|
||||
export async function addPrompt(data: Prompt.AddPrompt): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
return await request('/api/Prompt/AddPromptString', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: data.name,
|
||||
promptTypeId: data.promptTypeId,
|
||||
promptTypeCode: data.promptTypeCode,
|
||||
promptString: data.promptString,
|
||||
description: data.description,
|
||||
remark: data.remark,
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
return errorMessage(error.toString())
|
||||
}
|
||||
}
|
||||
|
||||
export async function modifyPrompt(data: Prompt.AddPrompt): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
return await request('/api/Prompt/ModifyPromptString', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
promptTypeId: data.promptTypeId,
|
||||
promptTypeCode: data.promptTypeCode,
|
||||
promptString: data.promptString,
|
||||
description: data.description,
|
||||
remark: data.remark,
|
||||
status: data.status,
|
||||
version: data.version,
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
return errorMessage(error.toString())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 提示词类型相关
|
||||
|
||||
/**
|
||||
* 获取提示词类型
|
||||
* @param pageSize 当每页的大小
|
||||
* @param current 页码
|
||||
* @returns
|
||||
*/
|
||||
export async function getPrompyType(pageSize: number | undefined, current: number | undefined): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
return await request(`/api/Prompt/GetPromptType/${pageSize}/${current}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
} catch (error: any) {
|
||||
return errorMessage(error.toString())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加提示词类型
|
||||
* @param data 添加的类型
|
||||
*/
|
||||
export async function addPromptType(data: Prompt.AddPromptType): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
let res = await request('/api/Prompt/AddPromptType', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: data.name,
|
||||
code: data.code,
|
||||
remark: data.remark,
|
||||
}
|
||||
})
|
||||
return res
|
||||
|
||||
} catch (error: any) {
|
||||
return errorMessage(error.toString())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改提示词类型
|
||||
* @param data 修改的数据
|
||||
*/
|
||||
export async function editPromptType(data: Prompt.AddPromptType): Promise<API.SuccessItem | API.ErrorItem> {
|
||||
try {
|
||||
debugger
|
||||
let res = await request('/api/Prompt/ModifyPromptType', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
code: data.code,
|
||||
remark: data.remark,
|
||||
status: data.status,
|
||||
}
|
||||
})
|
||||
return res;
|
||||
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
return errorMessage("修改提示词数据失败")
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 返回成功的消息,包含code,data,message
|
||||
* @param {*} data 返回的数据
|
||||
* @param {*} message 成功消息
|
||||
* @returns
|
||||
*/
|
||||
export function successMessage(data: any, message: string): API.SuccessItem {
|
||||
return {
|
||||
code: 1,
|
||||
data: data,
|
||||
message: message
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败的消息,
|
||||
* @param {*} message 错误信息
|
||||
* @returns
|
||||
*/
|
||||
export function errorMessage(message: string): API.ErrorItem {
|
||||
return {
|
||||
code: 0,
|
||||
message: message
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { request } from "@umijs/max";
|
||||
import { isEmpty } from "lodash";
|
||||
|
||||
/**
|
||||
* 查询角色列表
|
||||
* @param tableParams
|
||||
* @param roleParams
|
||||
* @returns
|
||||
*/
|
||||
export async function QueryRoleList(tableParams: TableModel.TableParams, roleParams: RoleModel.QueryRoleParams): Promise<RoleModel.QueryRoleData> {
|
||||
let data = {
|
||||
...tableParams.pagination,
|
||||
...roleParams,
|
||||
page: tableParams.pagination?.current,
|
||||
roleName: roleParams.roleName ?? null,
|
||||
roleId: roleParams.roleId ?? null,
|
||||
}
|
||||
delete data.current;
|
||||
delete data.total;
|
||||
let query = new URLSearchParams(data).toString();
|
||||
let res = await request<ApiResponse.SuccessItem<RoleModel.QueryRoleData>>(`/lms/Role/QueryRoleCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
console.log("QueryRoleList", res);
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的角色名称
|
||||
*/
|
||||
export async function QueryRoleOption() {
|
||||
let res = await request<ApiResponse.SuccessItem<string[]>>(`/lms/Role/QueryRoleOption`, {
|
||||
method: 'GET',
|
||||
});
|
||||
console.log("QueryRoleOption", res);
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询角色数据,通过指定ID
|
||||
* @param roleId
|
||||
* @returns
|
||||
*/
|
||||
export async function GetRoleById(roleId: number): Promise<RoleModel.Collection> {
|
||||
console.log("GetRoleById", roleId);
|
||||
let res = await request<ApiResponse.SuccessItem<RoleModel.Collection>>(`/lms/Role/QueryRoleById/${roleId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
console.log("GetRoleByIdRes", res);
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定的角色数据
|
||||
* @param roleId 角色的ID
|
||||
* @param roleName 角色的名称
|
||||
* @param roleRemark 角色的备注
|
||||
*/
|
||||
export async function UpdeteRole(roleId: number, roleName: string, roleRemark: string): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<void>>(`/lms/Role/UpdateRole/${roleId}`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: roleName,
|
||||
remark: roleRemark
|
||||
}
|
||||
});
|
||||
console.log("UpdeteRole", res);
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除角色信息
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
export async function DeleteRoleById(roleId: number): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<void>>(`/lms/Role/DeleteRole/${roleId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
console.log("DeleteRole", res);
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* x新增角色
|
||||
* @param roleNmae 角色名称
|
||||
* @param roleRemark 角色备注
|
||||
*/
|
||||
export async function AddRole(roleNmae: string, roleRemark: string): Promise<void> {
|
||||
if (isEmpty(roleNmae)) {
|
||||
throw new Error("角色名称不能为空");
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<void>>(`/lms/Role/AddRole`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: roleNmae,
|
||||
remark: roleRemark
|
||||
}
|
||||
});
|
||||
console.log("AddRole", res);
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
Vendored
+103
@@ -0,0 +1,103 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
|
||||
declare namespace API {
|
||||
type CurrentUser = {
|
||||
createTime?: Date,
|
||||
createUserId: string,
|
||||
email?: string,
|
||||
id: string,
|
||||
nickname: string,
|
||||
username: string,
|
||||
roleNames?: string,
|
||||
};
|
||||
|
||||
type LAIReponse = {
|
||||
code: number;
|
||||
data?: string | null;
|
||||
message: string;
|
||||
}
|
||||
|
||||
type SubUserResponse = {
|
||||
id: string;
|
||||
nickname: string;
|
||||
}
|
||||
|
||||
type LoginResult = {
|
||||
status?: string;
|
||||
type?: string;
|
||||
currentAuthority?: string;
|
||||
};
|
||||
|
||||
type PageParams = {
|
||||
current?: number;
|
||||
pageSize?: number;
|
||||
};
|
||||
|
||||
type RuleListItem = {
|
||||
key?: number;
|
||||
disabled?: boolean;
|
||||
href?: string;
|
||||
avatar?: string;
|
||||
name?: string;
|
||||
owner?: string;
|
||||
desc?: string;
|
||||
callNo?: number;
|
||||
status?: number;
|
||||
updatedAt?: string;
|
||||
createdAt?: string;
|
||||
progress?: number;
|
||||
};
|
||||
|
||||
type RuleList = {
|
||||
data?: RuleListItem[];
|
||||
/** 列表的内容总数 */
|
||||
total?: number;
|
||||
success?: boolean;
|
||||
};
|
||||
|
||||
type FakeCaptcha = {
|
||||
code?: number;
|
||||
status?: string;
|
||||
};
|
||||
|
||||
type LoginParams = {
|
||||
username?: string;
|
||||
password: string;
|
||||
email?: string;
|
||||
};
|
||||
|
||||
type SuccessItem = {
|
||||
code: number;
|
||||
data?: any;
|
||||
message: string;
|
||||
}
|
||||
|
||||
type ErrorItem = {
|
||||
code: number;
|
||||
data?: any;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
type NoticeIconList = {
|
||||
data?: NoticeIconItem[];
|
||||
/** 列表的内容总数 */
|
||||
total?: number;
|
||||
success?: boolean;
|
||||
};
|
||||
|
||||
type NoticeIconItemType = 'notification' | 'message' | 'event';
|
||||
|
||||
type NoticeIconItem = {
|
||||
id?: string;
|
||||
extra?: string;
|
||||
key?: string;
|
||||
read?: boolean;
|
||||
avatar?: string;
|
||||
title?: string;
|
||||
status?: string;
|
||||
datetime?: string;
|
||||
description?: string;
|
||||
type?: NoticeIconItemType;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import { request } from '@umijs/max';
|
||||
import { objectToQueryString } from './common';
|
||||
|
||||
/** 获取当前的用户 GET /api/currentUser */
|
||||
export async function getCurrentUser(id: number, options?: { [key: string]: any }) {
|
||||
return request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/GetUserInfo/${id}`, {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的信息
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
async function GetUserInfo(id: number): Promise<UserModel.UserInfo> {
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/GetUserInfo/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户的信息
|
||||
* @param userData
|
||||
* @returns
|
||||
*/
|
||||
async function UpdatedUserInfo(userData: UserModel.UserInfo) {
|
||||
if (userData.id == null) {
|
||||
throw new Error("用户ID不能为空");
|
||||
}
|
||||
let data = {
|
||||
...userData,
|
||||
createdDate: null,
|
||||
} as any;
|
||||
|
||||
delete data.id;
|
||||
delete data.createdDate;
|
||||
for (const element in data) {
|
||||
if (element === null || element === undefined) {
|
||||
delete data[element];
|
||||
}
|
||||
}
|
||||
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/UpdatedUser/${userData.id}`, {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param tableParams 表的参数
|
||||
* @param userParams 查询用户的参数
|
||||
* @returns
|
||||
*/
|
||||
async function QueryUserList(tableParams: TableModel.TableParams, userParams: UserModel.QueryUserParams) {
|
||||
let data = {
|
||||
...userParams,
|
||||
page: tableParams.pagination?.current,
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.QueryUserData>>(`/lms/User/QueryUserCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
console.log("QueryUserList", res);
|
||||
return res.data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将用户升级为代理
|
||||
* @param id
|
||||
*/
|
||||
async function EnableAgent() {
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/EnableAgent`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function GetUserAgentInfo(): Promise<UserModel.UserAgentInfo> {
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserAgentInfo>>(`/lms/User/GetUserAgentInfo`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
export {
|
||||
QueryUserList,
|
||||
GetUserInfo,
|
||||
UpdatedUserInfo,
|
||||
EnableAgent,
|
||||
GetUserAgentInfo,
|
||||
}
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
declare namespace AccessType {
|
||||
interface AccessType {
|
||||
canPrompt: boolean;
|
||||
canRoleManagement: boolean;
|
||||
|
||||
//#region 用户权限
|
||||
/** 是不是显示用户管理的菜单 */
|
||||
canUserManagement: boolean;
|
||||
/**是否显示编辑用户 */
|
||||
canEditUser: boolean;
|
||||
/**是否显示删除用户 */
|
||||
canDeleteUser: boolean;
|
||||
/**是不是管理员 */
|
||||
isAdmin: boolean;
|
||||
/**是不是超级管理员 */
|
||||
isSuperAdmin: boolean;
|
||||
/**是不是管理员或者超级管理员 */
|
||||
isAdminOrSuperAdmin: boolean;
|
||||
//#endregion
|
||||
|
||||
//#region 机器权限
|
||||
/** 是不是显示机器码管理的菜单 */
|
||||
canMachineManagement: boolean
|
||||
/** 是不是有添加机器码的权限 */
|
||||
canAddMachine: boolean;
|
||||
/** 是不是有修改机器码的权限 */
|
||||
canEditMachine: boolean;
|
||||
/** 是不是有删除机器码的权限 */
|
||||
canDeleteMachine: boolean;
|
||||
/** 是不是又升级机器码的权限 */
|
||||
canUpgradeMachine: boolean;
|
||||
/** 是不是有停用机器码的权限 */
|
||||
canDisableMachine: boolean;
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
declare namespace ApiResponse {
|
||||
type SuccessItem<T> = {
|
||||
code: number
|
||||
message?: string
|
||||
data: T
|
||||
}
|
||||
|
||||
type ErrorItem<T> = {
|
||||
code: number
|
||||
message: string
|
||||
data?: T
|
||||
}
|
||||
}
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
declare namespace MachineModel {
|
||||
|
||||
|
||||
type ModifyMachineParams = {
|
||||
machineId: string,
|
||||
deactivationTime?: Date,
|
||||
useStatus: number,
|
||||
status: number,
|
||||
remark?: string
|
||||
}
|
||||
|
||||
type AddMachineParams = {
|
||||
machineId: string,
|
||||
deactivationTime?: Date,
|
||||
useStatus: number,
|
||||
status: number,
|
||||
remark?: string,
|
||||
userId: number
|
||||
}
|
||||
|
||||
//#region 查询
|
||||
type QueryUMachineParams = {
|
||||
machineId?: string;
|
||||
createdUserName?: string;
|
||||
status?: number;
|
||||
useStatus?: number;
|
||||
remark?: string;
|
||||
ownUserName?: string
|
||||
}
|
||||
|
||||
type QueryMachineData = {
|
||||
collection: MachineCollection[];
|
||||
current: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
interface MachineCollection {
|
||||
id: string,
|
||||
machineId: string,
|
||||
createTime: Date,
|
||||
updateTime: Date,
|
||||
deactivationTime: Date,
|
||||
status: 0 | 1,
|
||||
createId: number,
|
||||
updateId: number,
|
||||
useStatus: 0 | 1,
|
||||
remark: string,
|
||||
userID: number,
|
||||
}
|
||||
|
||||
interface MachineInfo extends MachineCollection {
|
||||
createdUser: UserModel.UserInfo;
|
||||
updatedUser: UserModel.UserInfo;
|
||||
ownUser: UserModel.UserInfo;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
|
||||
declare namespace Prompt {
|
||||
|
||||
type PromptListItem = {
|
||||
key: string;
|
||||
id: string;
|
||||
name: string;
|
||||
promptTypeId: string;
|
||||
promptTypeCode: string;
|
||||
promptString: string;
|
||||
description?: string;
|
||||
remark?: string;
|
||||
createUser: API.SubUserResponse;
|
||||
createTime: Date;
|
||||
updateUser: API.SubUserResponse;
|
||||
updateTime: Date;
|
||||
status: string;
|
||||
version: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
|
||||
type AddPrompt = {
|
||||
id?: string;
|
||||
name: string;
|
||||
promptTypeId: string;
|
||||
promptTypeCode: string;
|
||||
promptString: string;
|
||||
description?: string;
|
||||
remark?: string;
|
||||
createUser: API.SubUserResponse;
|
||||
createTime: Date;
|
||||
updateUser: API.SubUserResponse;
|
||||
updateTime: Date;
|
||||
status: string;
|
||||
version: number;
|
||||
}
|
||||
|
||||
|
||||
type PromptTypeListItem = {
|
||||
key: string;
|
||||
id: string;
|
||||
name: string;
|
||||
code: string;
|
||||
remark?: string;
|
||||
status: string;
|
||||
createUser: API.SubUserResponse;
|
||||
createTime: Date;
|
||||
updateUser: API.SubUserResponse;
|
||||
updateTime: Date;
|
||||
coubt: number;
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
|
||||
type AddPromptType = {
|
||||
id?: string;
|
||||
name: string;
|
||||
code: string;
|
||||
remark?: string;
|
||||
status: string;
|
||||
createUser: API.SubUserResponse;
|
||||
updateUser: API.SubUserResponse;
|
||||
updateTime: Date;
|
||||
}
|
||||
}
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
declare namespace RoleModel {
|
||||
|
||||
//#region 查询角色列表
|
||||
/**
|
||||
* 查询角色列表参数
|
||||
*/
|
||||
type QueryRoleParams = {
|
||||
roleName: string | null
|
||||
roleId: numberq
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据的返回信息,包括分页信息
|
||||
*/
|
||||
type QueryRoleData = {
|
||||
collection: Collection[];
|
||||
current: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色列表返回的数据,只有角色数据
|
||||
*/
|
||||
type Collection = {
|
||||
createdTime: Date;
|
||||
createdUser: UserModel.UserInfo;
|
||||
id: number;
|
||||
name: string;
|
||||
remark: null | string;
|
||||
updatedTime: Date;
|
||||
updeatedUser: UserModel.UserInfo;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// import { TablePaginationConfig } from "antd";
|
||||
|
||||
declare namespace TableModel {
|
||||
|
||||
interface TableParams {
|
||||
pagination?: TablePaginationConfig;
|
||||
sortField?: SorterResult<any>['field'];
|
||||
sortOrder?: SorterResult<any>['order'];
|
||||
filters?: Parameters<GetProp<TableProps, 'onChange'>>[1];
|
||||
}
|
||||
}
|
||||
Vendored
+131
@@ -0,0 +1,131 @@
|
||||
declare namespace UserModel {
|
||||
type UserNameLogin = {
|
||||
userName: string
|
||||
password: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册参数
|
||||
*/
|
||||
type UserRegisterParams = {
|
||||
userName: string
|
||||
password: string
|
||||
email?: string
|
||||
confirm?: string
|
||||
affiliateCode: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户代理信息
|
||||
*/
|
||||
interface UserAgentInfo {
|
||||
userId: number,
|
||||
userName: string,
|
||||
nickName: string,
|
||||
affiliateCode: string,
|
||||
agentPercent: number,
|
||||
affiliateNumber: number,
|
||||
affiliateVIPNumber: number,
|
||||
affiliateMoney: number,
|
||||
}
|
||||
|
||||
//#region 用户基本的数据信息
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
nickName: string;
|
||||
userName: string;
|
||||
avatar?: string;
|
||||
email: string;
|
||||
phoneNumber?: string;
|
||||
roleNames: string[];
|
||||
allDeviceCount: number;
|
||||
agentPercent: number;
|
||||
freeCount: number;
|
||||
affiliateCode: string;
|
||||
createdDate: Date;
|
||||
options: userOptions
|
||||
}
|
||||
|
||||
type userOptions = {
|
||||
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 添加编辑用户相关
|
||||
|
||||
interface ModifyUserProps extends UserInfo {
|
||||
createdData: Date;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 查询用户列表相关
|
||||
|
||||
type QueryUserData = {
|
||||
collection: UserCollection[];
|
||||
current: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
type QueryUserParams = {
|
||||
userName?: string;
|
||||
userId?: number;
|
||||
nickName?: string;
|
||||
phoneNumber?: string;
|
||||
email?: string;
|
||||
roleNames?: string[];
|
||||
parentId?: number;
|
||||
}
|
||||
|
||||
type UserCollection = {
|
||||
id: number;
|
||||
nickName: string;
|
||||
userName: string;
|
||||
email: string;
|
||||
phoneNumber?: string;
|
||||
roleNames: string[];
|
||||
createdDate: Date;
|
||||
lastLoginDate: Date;
|
||||
lastLoginIp: string;
|
||||
lastLoginDevice: string;
|
||||
parentId: number;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 用户登录相关
|
||||
|
||||
/**
|
||||
* 用户登录的参数
|
||||
*/
|
||||
type UserLogin = {
|
||||
userName: string,
|
||||
email: string?,
|
||||
loginType: number = 1,
|
||||
password: string,
|
||||
rememberMe: boolean = true,
|
||||
deviceInfo: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录成功的返回
|
||||
*/
|
||||
type UserLoginResponse = {
|
||||
token: string,
|
||||
userName: string,
|
||||
id: number,
|
||||
nickName: string,
|
||||
refreshToken: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户请求公钥的返回
|
||||
*/
|
||||
type UserPublicKeyResPonse = {
|
||||
token: string,
|
||||
publicKey: string
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user