feat(project): base smatec's frontend
This commit is contained in:
24
src/services/master/AlarmController.ts
Normal file
24
src/services/master/AlarmController.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { API_ALARMS, API_ALARMS_CONFIRM } from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiGetAlarms(params?: MasterModel.SearchPaginationBody) {
|
||||
return request<MasterModel.AlarmsResponse>(API_ALARMS, {
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiConfirmAlarm(body: MasterModel.ConfirmAlarmRequest) {
|
||||
return request(API_ALARMS_CONFIRM, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiUnconfirmAlarm(body: MasterModel.ConfirmAlarmRequest) {
|
||||
return request(API_ALARMS_CONFIRM, {
|
||||
method: 'DELETE',
|
||||
data: body,
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
42
src/services/master/AuthController.ts
Normal file
42
src/services/master/AuthController.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
API_CHANGE_PASSWORD,
|
||||
API_PATH_GET_PROFILE,
|
||||
API_PATH_LOGIN,
|
||||
API_USERS,
|
||||
} from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiLogin(body: MasterModel.LoginRequestBody) {
|
||||
// console.log('Login request body:', body);
|
||||
|
||||
return request<MasterModel.LoginResponse>(API_PATH_LOGIN, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiQueryProfile() {
|
||||
return request<MasterModel.ProfileResponse>(API_PATH_GET_PROFILE);
|
||||
}
|
||||
|
||||
export async function apiUpdateProfile(
|
||||
body: Partial<MasterModel.ProfileMetadata>,
|
||||
) {
|
||||
return request<MasterModel.ProfileResponse>(API_USERS, {
|
||||
method: 'PUT',
|
||||
data: {
|
||||
metadata: body,
|
||||
},
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiChangePassword(
|
||||
body: MasterModel.ChangePasswordRequestBody,
|
||||
) {
|
||||
return request<void>(API_CHANGE_PASSWORD, {
|
||||
method: 'PATCH',
|
||||
data: body,
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
57
src/services/master/GroupController.ts
Normal file
57
src/services/master/GroupController.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { API_GROUP_MEMBERS, API_GROUPS } from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiQueryGroups(
|
||||
params: MasterModel.GroupQueryParams,
|
||||
): Promise<MasterModel.GroupResponse> {
|
||||
return request<MasterModel.GroupQueryParams>(API_GROUPS, {
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiQueryGroupsById(
|
||||
id: string,
|
||||
): Promise<MasterModel.GroupResponse> {
|
||||
return request(`${API_GROUPS}/${id}`);
|
||||
}
|
||||
|
||||
export async function apiQueryMembers(
|
||||
user_id: string,
|
||||
): Promise<MasterModel.GroupResponse> {
|
||||
return request(`${API_GROUP_MEMBERS}/${user_id}/groups`);
|
||||
}
|
||||
|
||||
export async function apiQueryChildren(
|
||||
group_id: string,
|
||||
params: MasterModel.GroupQueryParams,
|
||||
): Promise<MasterModel.GroupResponse> {
|
||||
return request(`${API_GROUPS}/${group_id}/children`, {
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiUpdateGroup(body: Partial<MasterModel.GroupNode>) {
|
||||
return request<MasterModel.GroupNode>(`${API_GROUPS}/${body.id}`, {
|
||||
method: 'PUT',
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
export async function apiCreateGroup(
|
||||
body: Partial<MasterModel.GroupBodyRequest>,
|
||||
) {
|
||||
return request<MasterModel.AddGroupBodyResponse>(`${API_GROUPS}`, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
contentType: 'application/json',
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiDeleteGroup(group_id: string) {
|
||||
return request<MasterModel.AddGroupBodyResponse>(
|
||||
`${API_GROUPS}/${group_id}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
getResponse: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
11
src/services/master/LogController.ts
Normal file
11
src/services/master/LogController.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { API_LOGS } from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiQueryLogs(
|
||||
params: MasterModel.SearchLogPaginationBody,
|
||||
type: MasterModel.LogTypeRequest,
|
||||
) {
|
||||
return request<MasterModel.LogResponse>(`${API_LOGS}/${type}/messages`, {
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
30
src/services/master/ThingController.ts
Normal file
30
src/services/master/ThingController.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { API_THINGS_SEARCH } from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiSearchThings(
|
||||
body: MasterModel.SearchPaginationBody,
|
||||
domain: string = process.env.DOMAIN_ENV || 'gms',
|
||||
) {
|
||||
switch (domain) {
|
||||
case 'sgw':
|
||||
return request<SgwModel.SgwThingsResponse>(API_THINGS_SEARCH, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
case 'gms':
|
||||
return request<GmsModel.GmsThingsResponse>(API_THINGS_SEARCH, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
case 'spole':
|
||||
return request<SpoleModel.SpoleThingsResponse>(API_THINGS_SEARCH, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
default:
|
||||
return request<GmsModel.GmsThingsResponse>(API_THINGS_SEARCH, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
}
|
||||
24
src/services/master/UserController.ts
Normal file
24
src/services/master/UserController.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { API_USERS, API_USERS_BY_GROUP } from '@/constants/api';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function apiQueryUsers(
|
||||
params: MasterModel.SearchUserPaginationBody,
|
||||
) {
|
||||
return request<MasterModel.UserResponse>(API_USERS, {
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiQueryUsersByGroup(
|
||||
group_id: string,
|
||||
): Promise<MasterModel.UserResponse> {
|
||||
return request<MasterModel.UserResponse>(`${API_USERS_BY_GROUP}/${group_id}`);
|
||||
}
|
||||
|
||||
export async function apiCreateUsers(body: MasterModel.CreateUserBodyRequest) {
|
||||
return request(API_USERS, {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
getResponse: true,
|
||||
});
|
||||
}
|
||||
3
src/services/master/index.ts
Normal file
3
src/services/master/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
/* eslint-disable */
|
||||
|
||||
export default {};
|
||||
225
src/services/master/typings.d.ts
vendored
Normal file
225
src/services/master/typings.d.ts
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
|
||||
declare namespace MasterModel {
|
||||
interface SearchPaginationBody {
|
||||
name?: string;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
dir?: 'asc' | 'desc';
|
||||
}
|
||||
interface SearchThingPaginationBody extends SearchPaginationBody {
|
||||
order?: string;
|
||||
metadata?: ThingMetadata;
|
||||
}
|
||||
interface ThingMetadata {
|
||||
group_id?: string;
|
||||
external_id?: string;
|
||||
}
|
||||
|
||||
interface SearchAlarmPaginationBody extends SearchPaginationBody {
|
||||
order?: 'name' | undefined;
|
||||
thing_name?: string;
|
||||
thing_id?: string;
|
||||
level?: number;
|
||||
}
|
||||
|
||||
interface SearchUserPaginationBody extends SearchPaginationBody {
|
||||
order?: 'email' | 'name' | undefined;
|
||||
email?: string;
|
||||
metadata?: Partial<ProfileMetadata>;
|
||||
}
|
||||
interface SearchLogPaginationBody extends SearchPaginationBody {
|
||||
from?: number;
|
||||
to?: number;
|
||||
publisher?: string;
|
||||
subtopic?: string;
|
||||
}
|
||||
|
||||
interface LoginRequestBody {
|
||||
guid: string;
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface LoginResponse {
|
||||
token?: string;
|
||||
}
|
||||
|
||||
interface ChangePasswordRequestBody {
|
||||
old_password: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface ProfileResponse {
|
||||
id?: string;
|
||||
email?: string;
|
||||
metadata?: ProfileMetadata;
|
||||
}
|
||||
|
||||
interface ProfileMetadata {
|
||||
frontend_thing_id?: string;
|
||||
frontend_thing_key?: string;
|
||||
full_name?: string;
|
||||
phone_number?: string;
|
||||
telegram?: string;
|
||||
user_type?: 'admin' | 'enduser' | 'sysadmin' | 'users';
|
||||
}
|
||||
|
||||
interface CreateUserMetadata extends ProfileMetadata {
|
||||
group_id?: string;
|
||||
}
|
||||
|
||||
interface CreateUserBodyRequest extends Partial<ProfileResponse> {
|
||||
password: string;
|
||||
full_name?: string;
|
||||
metadata?: CreateUserMetadata;
|
||||
}
|
||||
|
||||
interface UserResponse {
|
||||
total?: number;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
users: ProfileResponse[];
|
||||
}
|
||||
interface AlarmsResponse {
|
||||
total?: number;
|
||||
limit?: number;
|
||||
order?: string;
|
||||
dir?: string;
|
||||
alarms?: Alarm[];
|
||||
}
|
||||
|
||||
interface ConfirmAlarmRequest {
|
||||
id?: string;
|
||||
description?: string;
|
||||
thing_id?: string;
|
||||
time?: number;
|
||||
}
|
||||
|
||||
interface Alarm {
|
||||
name?: string;
|
||||
time?: number;
|
||||
level?: number;
|
||||
id?: string;
|
||||
confirmed?: boolean;
|
||||
confirmed_email?: string;
|
||||
confirmed_time?: number;
|
||||
confirmed_desc?: string;
|
||||
thing_id?: string;
|
||||
thing_name?: string;
|
||||
thing_type?: string;
|
||||
}
|
||||
interface ThingMetadata {
|
||||
address?: string;
|
||||
alarm_list?: string;
|
||||
cfg_channel_id?: string;
|
||||
connected?: boolean;
|
||||
ctrl_channel_id?: string;
|
||||
data_channel_id?: string;
|
||||
enduser?: string;
|
||||
external_id?: string;
|
||||
group_id?: string;
|
||||
req_channel_id?: string;
|
||||
state?: string;
|
||||
state_level?: number;
|
||||
state_updated_time?: number;
|
||||
type?: string;
|
||||
updated_time?: number;
|
||||
}
|
||||
|
||||
interface ThingsResponse<T extends ThingMetadata = ThingMetadata> {
|
||||
total?: number;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
order?: string;
|
||||
direction?: string;
|
||||
metadata?: ThingsResponseMetadata;
|
||||
things?: Thing<T>[];
|
||||
}
|
||||
|
||||
interface ThingsResponseMetadata {
|
||||
total_connected?: number;
|
||||
total_filter?: number;
|
||||
total_sos?: number;
|
||||
total_state_level_0?: number;
|
||||
total_state_level_1?: number;
|
||||
total_state_level_2?: number;
|
||||
total_thing?: number;
|
||||
}
|
||||
|
||||
interface Thing<T extends ThingMetadata = ThingMetadata> {
|
||||
id?: string;
|
||||
name?: string;
|
||||
key?: string;
|
||||
metadata?: T;
|
||||
}
|
||||
|
||||
interface GroupBodyRequest {
|
||||
id?: string;
|
||||
name: string;
|
||||
parent_id?: string;
|
||||
description?: string;
|
||||
metadata?: GroupMetadata;
|
||||
}
|
||||
interface AddGroupBodyResponse extends Partial<GroupBodyRequest> {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface GroupMetadata {
|
||||
code?: string;
|
||||
short_name?: string;
|
||||
has_thing?: boolean;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface GroupResponse {
|
||||
total?: number;
|
||||
level?: number;
|
||||
name?: string;
|
||||
groups?: GroupNode[];
|
||||
}
|
||||
interface GroupNode {
|
||||
id: string;
|
||||
name: string;
|
||||
owner_id: string;
|
||||
description: string;
|
||||
metadata: GroupMetadata;
|
||||
level: number;
|
||||
path: string;
|
||||
parent_id?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
children?: GroupNode[]; // Đệ quy: mỗi node có thể có children là mảng GroupNode
|
||||
[key: string]: any; // Nếu có thêm trường động
|
||||
}
|
||||
|
||||
interface GroupQueryParams {
|
||||
level?: number;
|
||||
tree?: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
type LogTypeRequest = 'user_logs' | undefined;
|
||||
|
||||
interface LogResponse {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
publisher?: string;
|
||||
from?: number;
|
||||
to?: number;
|
||||
format?: string;
|
||||
total?: number;
|
||||
messages?: Message[];
|
||||
}
|
||||
|
||||
interface Message {
|
||||
channel?: string;
|
||||
subtopic?: string;
|
||||
publisher?: string;
|
||||
protocol?: string;
|
||||
name?: string;
|
||||
time?: number;
|
||||
string_value?: string;
|
||||
}
|
||||
}
|
||||
9
src/services/slave/gms/gms.typings.d.ts
vendored
Normal file
9
src/services/slave/gms/gms.typings.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
|
||||
declare namespace GmsModel {
|
||||
interface ThingMedata extends MasterModel.ThingMetadata {}
|
||||
|
||||
type GmsThingsResponse = MasterModel.ThingsResponse<GmsModel.ThingMedata>;
|
||||
type GmsThing = MasterModel.Thing<GmsModel.ThingMedata>;
|
||||
}
|
||||
3
src/services/slave/gms/index.ts
Normal file
3
src/services/slave/gms/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
/* eslint-disable */
|
||||
|
||||
export default {};
|
||||
3
src/services/slave/sgw/index.ts
Normal file
3
src/services/slave/sgw/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
/* eslint-disable */
|
||||
|
||||
export default {};
|
||||
25
src/services/slave/sgw/sgw.typing.d.ts
vendored
Normal file
25
src/services/slave/sgw/sgw.typing.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
|
||||
declare namespace SgwModel {
|
||||
interface ThingMedata extends MasterModel.ThingMetadata {
|
||||
gps?: string;
|
||||
gps_time?: string;
|
||||
ship_group_id?: string;
|
||||
ship_id?: string;
|
||||
ship_length?: string;
|
||||
ship_name?: string;
|
||||
ship_power?: string;
|
||||
ship_reg_number?: string;
|
||||
ship_type?: string;
|
||||
sos?: string;
|
||||
sos_time?: string;
|
||||
uptime?: number;
|
||||
zone_approaching_alarm_list?: string;
|
||||
zone_entered_alarm_list?: string;
|
||||
zone_fishing_alarm_list?: string;
|
||||
}
|
||||
|
||||
type SgwThingsResponse = MasterModel.ThingsResponse<SgwModel.ThingMedata>;
|
||||
type SgwThing = MasterModel.Thing<SgwModel.ThingMedata>;
|
||||
}
|
||||
3
src/services/slave/spole/index.ts
Normal file
3
src/services/slave/spole/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
/* eslint-disable */
|
||||
|
||||
export default {};
|
||||
9
src/services/slave/spole/spole.typings.d.ts
vendored
Normal file
9
src/services/slave/spole/spole.typings.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
|
||||
declare namespace SpoleModel {
|
||||
interface ThingMedata extends MasterModel.ThingMetadata {}
|
||||
|
||||
type SpoleThingsResponse = MasterModel.ThingsResponse<SpoleModel.ThingMedata>;
|
||||
type SpoleThing = MasterModel.Thing<SpoleModel.ThingMedata>;
|
||||
}
|
||||
Reference in New Issue
Block a user