固定资产项目前端文件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
6.3 KiB

2 years ago
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { JwResponse, NullableProps } from 'app/types'
import { Utils } from 'app/utils'
import { NzTreeNodeOptions } from 'ng-zorro-antd/tree'
import { BehaviorSubject, map, of, tap } from 'rxjs'
import {
AuthDTO,
AuthorityDTO,
AuthorizeItemDTO,
ConsoleClientTopDTO,
ConsoleCountDTO,
ConsoleExpireDTO,
EntityDTO,
EntityDetailDTO,
PermissionDTO,
ProductDTO,
RoleFormDTO,
RoleListDTO,
UserDTO,
} from './api.dto'
import { PermissionService } from 'app/shared/permission/permission.service'
export interface UserGroupTreeItem {
name: string
id: string
parentId: string
children: UserGroupTreeItem[]
}
@Injectable({
providedIn: 'root',
})
export class ApiService {
constructor(
private http: HttpClient,
private permission: PermissionService,
) {}
authInfo: AuthDTO = {
createTime: '',
enable: false,
groupId: '',
id: '',
name: '',
remark: '',
roleId: '',
roleName: '',
updateTime: '',
username: '',
authorities: [],
}
getAuthInfo(force?: boolean) {
if (this.authInfo && !force) {
return of(this.authInfo)
}
localStorage.setItem('da', 'af')
return of(this.authInfo)
// return this.http.get<JwResponse<AuthDTO>>('/api/auth/info').pipe(
// map((res) => res.data),
// tap((res) => {
// this.authInfo = res
// this.permission.loadPermission(res.authorities.map((f) => f.authority))
// }),
// )
}
login(data: {}) {
return this.http.post<JwResponse>('/api/oauth/login', data)
}
private _parseUserGroupTree(group: UserGroupTreeItem[]): NzTreeNodeOptions[] {
if (group?.length === 0) {
return []
}
return group.map((i) => {
return {
...i,
key: i.id,
title: i.name,
children: this._parseUserGroupTree(i.children ?? []),
isLeaf: i.children?.length === 0 || !i.children,
}
})
}
changeUserPassword(id: string, password: string) {
return this.http.put('/api/user/reset/password', {
id,
password,
})
}
getDashboardCounter() {
return this.http.get<JwResponse<ConsoleCountDTO>>(`/api/console/count`)
}
getDashboardExpire() {
return this.http.get<JwResponse<ConsoleExpireDTO[]>>(`/api/console/expire`)
}
getDashboardClientTop() {
return this.http.get<JwResponse<ConsoleClientTopDTO[]>>(`/api/console/client/top`)
}
getUserInfo(id: string) {
return this.http.get<JwResponse<UserDTO>>(`/api/user/${id}`).pipe()
}
changePassword(data: {}) {
return this.http.put<JwResponse>('/api/user/password', data)
}
getUserPage(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/user/pages?${params}`)
}
saveUser(user: any) {
if (user.id) {
return this.http.put<JwResponse>('/api/user', user)
} else {
return this.http.post<JwResponse>('/api/user', user)
}
}
deleteUser(id: string) {
return this.http.delete<JwResponse>(`/api/user/${id}`)
}
getUserGroupTree() {
return this.http.get<JwResponse<any[]>>('/api/user/group/tree').pipe(
map((res) => {
return this._parseUserGroupTree(res.data)
}),
)
}
saveUserGroup(group: Partial<UserGroupTreeItem>) {
if (group.id) {
return this.http.put<JwResponse>('/api/user/group', group)
} else {
return this.http.post<JwResponse>('/api/user/group', group)
}
}
updateUserStatus(id: string) {
return this.http.put<JwResponse>(`/api/user/enable/${id}`, null)
}
deleteUserGroup(id: string) {
return this.http.delete<JwResponse>(`/api/user/group/${id}`)
}
getAllRole() {
return this.http.get<JwResponse<RoleListDTO[]>>(`/api/sysRole/list`)
}
getRolePage(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/sysRole/pages?${params}`)
}
getAllPermission() {
return this.http.get<JwResponse<PermissionDTO[]>>('/api/authority/tree')
}
getRoleById(id: string) {
return this.http.get<JwResponse<RoleFormDTO>>(`/api/sysRole/${id}`)
}
deleteRole(id: string) {
return this.http.delete<JwResponse>(`/api/sysRole/${id}`)
}
saveRole(role: NullableProps<RoleFormDTO>) {
if (role.id) {
return this.http.put<JwResponse>('/api/sysRole', role)
} else {
return this.http.post<JwResponse>('/api/sysRole', role)
}
}
authorize(v: {}) {
return this.http.post<JwResponse>('/api/client/license', v)
}
getSysLog(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/sysLog/pages?${params}`)
}
getEntityPage(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/client/pages?${params}`)
}
getEntityAuthorizeList(clientId: string) {
return this.http.get<JwResponse<AuthorizeItemDTO[]>>(`/api/licenseLog/${clientId}/list`)
}
getEntityDetail(id: string) {
return this.http.get<JwResponse<EntityDetailDTO>>(`/api/client/${id}`)
}
saveEntity(entity: Partial<NullableProps<EntityDTO>>) {
if (entity.id) {
return this.http.put<JwResponse>('/api/client', entity)
} else {
return this.http.post<JwResponse>('/api/client', entity)
}
}
deleteEntity(id: string) {
return this.http.delete<JwResponse>(`/api/client/${id}`)
}
getProductPage(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/product/pages?${params}`)
}
getAllProduct() {
return this.http.get<JwResponse<{ id: string; name: string }[]>>(`/api/product/list`)
}
saveProduct(entity: Partial<NullableProps<ProductDTO>>) {
if (entity.id) {
return this.http.put<JwResponse>('/api/product', entity)
} else {
return this.http.post<JwResponse>('/api/product', entity)
}
}
deleteProduct(id: string) {
return this.http.delete<JwResponse>(`/api/product/${id}`)
}
getProductVersionPage(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/product/pages?${params}`)
}
saveVersion(entity: Partial<NullableProps<ProductDTO>>) {
if (entity.id) {
return this.http.put<JwResponse>('/api/product', entity)
} else {
return this.http.post<JwResponse>('/api/product', entity)
}
}
deleteVersion(id: string, pid: string) {
return this.http.delete<JwResponse>(`/api/product/${id}`)
}
getProductDetail(pid: string) {
return this.http.get<JwResponse>(`/api/product/${pid}`)
}
}