添加对ele的支持,目前vben支持还不是特别完善
This commit is contained in:
136
web/apps/web-ele/src/models/base.ts
Normal file
136
web/apps/web-ele/src/models/base.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export interface CoreModel {
|
||||
remark: string;
|
||||
creator: string;
|
||||
modifier: string;
|
||||
update_time: string;
|
||||
create_time: string;
|
||||
is_deleted: boolean;
|
||||
}
|
||||
|
||||
// 通用Model基类
|
||||
export class BaseModel<
|
||||
T,
|
||||
CreateData = Omit<T, any>,
|
||||
UpdateData = Partial<CreateData>,
|
||||
> {
|
||||
protected baseUrl: string;
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用操作方法
|
||||
* @param url 操作路径
|
||||
* @param data 请求数据
|
||||
* @param id 是否针对单条记录的操作
|
||||
* @param method 请求方法
|
||||
*/
|
||||
async action(
|
||||
url: string,
|
||||
data: any = {},
|
||||
id: null | number = null,
|
||||
method = 'post',
|
||||
) {
|
||||
const baseUrl = id
|
||||
? `${this.baseUrl}${id}/${url}/`
|
||||
: `${this.baseUrl}${url}/`;
|
||||
|
||||
const config =
|
||||
method === 'get'
|
||||
? {
|
||||
url: baseUrl,
|
||||
method: 'get',
|
||||
params: data,
|
||||
}
|
||||
: {
|
||||
url: baseUrl,
|
||||
method,
|
||||
data,
|
||||
};
|
||||
|
||||
return requestClient.request(url, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建记录
|
||||
*/
|
||||
async create(data: CreateData) {
|
||||
return requestClient.post(this.baseUrl, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
*/
|
||||
async delete(id: number) {
|
||||
return requestClient.delete(`${this.baseUrl}${id}/`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
async export(params: Recordable<T> = {}) {
|
||||
return requestClient.get(`${this.baseUrl}export/`, {
|
||||
params,
|
||||
responseType: 'blob', // 二进制流
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表数据
|
||||
*/
|
||||
async list(params: Recordable<T> = {}) {
|
||||
return requestClient.get<Array<T>>(this.baseUrl, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* 部分更新记录
|
||||
*/
|
||||
async patch(id: number, data: Partial<UpdateData>) {
|
||||
return requestClient.patch(`${this.baseUrl}${id}/`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
*/
|
||||
async retrieve(id: number) {
|
||||
return requestClient.get<T>(`${this.baseUrl}${id}/`);
|
||||
}
|
||||
/**
|
||||
* 全量更新记录
|
||||
*/
|
||||
async update(id: number, data: UpdateData) {
|
||||
return requestClient.put(`${this.baseUrl}${id}/`, data);
|
||||
}
|
||||
}
|
||||
//
|
||||
// // 字典类型专用Model
|
||||
// export class SystemDictTypeModel extends BaseModel<SystemDictTypeApi.SystemDictType> {
|
||||
// constructor() {
|
||||
// super('/system/dict_type/');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // AmazonListingModel示例
|
||||
// export class AmazonListingModel extends BaseModel<AmazonListing> {
|
||||
// constructor() {
|
||||
// super('amazon/amazon_listing/');
|
||||
// }
|
||||
// }
|
||||
// const dictTypeModel = new SystemDictTypeModel();
|
||||
//
|
||||
// // 获取列表
|
||||
// dictTypeModel.list().then(({ data }) => console.log(data));
|
||||
//
|
||||
// // 创建记录
|
||||
// dictTypeModel.create({ name: '新字典', type: 'new_type' });
|
||||
//
|
||||
// // 更新记录
|
||||
// dictTypeModel.patch('123', { name: '更新后的字典' });
|
||||
1
web/apps/web-ele/src/models/index.ts
Normal file
1
web/apps/web-ele/src/models/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './base';
|
||||
23
web/apps/web-ele/src/models/system/login_log.ts
Normal file
23
web/apps/web-ele/src/models/system/login_log.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { BaseModel } from '#/models/base';
|
||||
|
||||
export namespace SystemLoginLogApi {
|
||||
export interface SystemLoginLog {
|
||||
id: number;
|
||||
remark: string;
|
||||
creator: string;
|
||||
modifier: string;
|
||||
update_time: string;
|
||||
create_time: string;
|
||||
is_deleted: boolean;
|
||||
username: string;
|
||||
result: number;
|
||||
user_ip: string;
|
||||
user_agent: string;
|
||||
}
|
||||
}
|
||||
|
||||
export class SystemLoginLogModel extends BaseModel<SystemLoginLogApi.SystemLoginLog> {
|
||||
constructor() {
|
||||
super('/system/login_log/');
|
||||
}
|
||||
}
|
||||
23
web/apps/web-ele/src/models/system/post.ts
Normal file
23
web/apps/web-ele/src/models/system/post.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { BaseModel } from '#/models/base';
|
||||
|
||||
export namespace SystemPostApi {
|
||||
export interface SystemPost {
|
||||
id: number;
|
||||
remark: string;
|
||||
creator: string;
|
||||
modifier: string;
|
||||
update_time: string;
|
||||
create_time: string;
|
||||
is_deleted: boolean;
|
||||
code: string;
|
||||
name: string;
|
||||
sort: number;
|
||||
status: number;
|
||||
}
|
||||
}
|
||||
|
||||
export class SystemPostModel extends BaseModel<SystemPostApi.SystemPost> {
|
||||
constructor() {
|
||||
super('/system/post/');
|
||||
}
|
||||
}
|
||||
40
web/apps/web-ele/src/models/system/user.ts
Normal file
40
web/apps/web-ele/src/models/system/user.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { BaseModel } from '#/models/base';
|
||||
|
||||
export namespace SystemUserApi {
|
||||
export interface SystemUser {
|
||||
id: number;
|
||||
password: string;
|
||||
last_login: string;
|
||||
is_superuser: boolean;
|
||||
username: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
is_staff: boolean;
|
||||
is_active: boolean;
|
||||
date_joined: string;
|
||||
remark: string;
|
||||
creator: string;
|
||||
modifier: string;
|
||||
update_time: string;
|
||||
create_time: string;
|
||||
is_deleted: boolean;
|
||||
mobile: string;
|
||||
nickname: string;
|
||||
gender: number;
|
||||
language: string;
|
||||
city: string;
|
||||
province: string;
|
||||
country: string;
|
||||
avatar_url: string;
|
||||
status: number;
|
||||
login_date: string;
|
||||
login_ip: any;
|
||||
}
|
||||
}
|
||||
|
||||
export class SystemUserModel extends BaseModel<SystemUserApi.SystemUser> {
|
||||
constructor() {
|
||||
super('/system/user/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user