From f8b694c16ad55da7b801b0e03da8361304d3b7a3 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 14 Sep 2023 16:18:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E8=97=8F=E4=B8=BB=E6=9C=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orion-ops-ui/src/api/asset/host.ts | 69 ++++++--- orion-ops-ui/src/api/meta/favorite.ts | 25 ++++ orion-ops-ui/src/api/meta/tag.ts | 33 +++++ orion-ops-ui/src/assets/style/layout.less | 4 + .../src/components/tag/tag-multi-selector.vue | 113 +++++++++++++++ orion-ops-ui/src/hooks/favorite.ts | 29 ++++ orion-ops-ui/src/utils/index.ts | 11 ++ .../asset/host/components/host-form-modal.vue | 13 +- .../asset/host/components/host-table.vue | 131 ++++++++++++------ orion-ops-ui/src/views/asset/host/index.vue | 17 ++- .../src/views/asset/host/types/const.ts | 4 + .../src/views/asset/host/types/form.rules.ts | 6 + .../views/asset/host/types/table.columns.ts | 5 + 13 files changed, 386 insertions(+), 74 deletions(-) create mode 100644 orion-ops-ui/src/api/meta/favorite.ts create mode 100644 orion-ops-ui/src/api/meta/tag.ts create mode 100644 orion-ops-ui/src/components/tag/tag-multi-selector.vue create mode 100644 orion-ops-ui/src/hooks/favorite.ts create mode 100644 orion-ops-ui/src/views/asset/host/types/const.ts diff --git a/orion-ops-ui/src/api/asset/host.ts b/orion-ops-ui/src/api/asset/host.ts index 3568da21..b18590ff 100644 --- a/orion-ops-ui/src/api/asset/host.ts +++ b/orion-ops-ui/src/api/asset/host.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import qs from 'query-string'; import { DataGrid, Pagination } from '@/types/global'; /** @@ -9,6 +8,7 @@ export interface HostCreateRequest { name?: string; code?: string; address?: string; + tags?: Array; } /** @@ -26,6 +26,10 @@ export interface HostQueryRequest extends Pagination { name?: string; code?: string; address?: string; + favorite?: boolean; + tags?: Array; + extra?: boolean; + config?: boolean; } /** @@ -40,6 +44,28 @@ export interface HostQueryResponse { updateTime: number; creator: string; updater: string; + favorite: boolean; + tags: Record; + configs: Record; +} + +/** + * 主机配置请求 + */ +export interface HostConfigRequest { + hostId?: number; + type?: string; + version?: number; + config?: string; +} + +/** + * 主机配置查询响应 + */ +export interface HostConfigQueryResponse { + id: number; + version: number; + config: Record; } /** @@ -59,20 +85,8 @@ export function updateHost(request: HostUpdateRequest) { /** * 通过 id 查询主机 */ -export function getHost(id: number) { - return axios.get('/asset/host/get', { params: { id } }); -} - -/** - * 通过 id 批量查询主机 - */ -export function getHostList(idList: Array) { - return axios.get('/asset/host/list', { - params: { idList }, - paramsSerializer: params => { - return qs.stringify(params, { arrayFormat: 'comma' }); - } - }); +export function getHost(params: HostQueryRequest) { + return axios.get('/asset/host/get', { params }); } /** @@ -97,13 +111,22 @@ export function deleteHost(id: number) { } /** - * 通过 id 批量删除主机 + * 查询主机配置 */ -export function batchDeleteHost(idList: Array) { - return axios.delete('/asset/host/delete-batch', { - params: { idList }, - paramsSerializer: params => { - return qs.stringify(params, { arrayFormat: 'comma' }); - } - }); +export function getHostConfig(params: HostConfigRequest) { + return axios.get('/asset/host/get-config', { params }); +} + +/** + * 查询主机配置 - 全部 + */ +export function getHostConfigAll(params: HostConfigRequest) { + return axios.get>('/asset/host/get-config-all', { params }); +} + +/** + * 更新主机配置 + */ +export function updateHostConfig(request: HostConfigRequest) { + return axios.put('/asset/host/update-config', request); } diff --git a/orion-ops-ui/src/api/meta/favorite.ts b/orion-ops-ui/src/api/meta/favorite.ts new file mode 100644 index 00000000..f22aa77e --- /dev/null +++ b/orion-ops-ui/src/api/meta/favorite.ts @@ -0,0 +1,25 @@ +import axios from 'axios'; + +export type FavoriteType = 'HOST' + +/** + * 收藏操作对象 + */ +export interface FavoriteOperatorRequest { + relId: number; + type: FavoriteType; +} + +/** + * 添加收藏 + */ +export function addFavorite(request: FavoriteOperatorRequest) { + return axios.put('/infra/favorite/add', request); +} + +/** + * 取消收藏 + */ +export function cancelFavorite(request: FavoriteOperatorRequest) { + return axios.put('/infra/favorite/cancel', request); +} diff --git a/orion-ops-ui/src/api/meta/tag.ts b/orion-ops-ui/src/api/meta/tag.ts new file mode 100644 index 00000000..b0c80d39 --- /dev/null +++ b/orion-ops-ui/src/api/meta/tag.ts @@ -0,0 +1,33 @@ +import axios from 'axios'; + +export type TagType = 'HOST' + +/** + * tag 创建对象 + */ +export interface TagCreateRequest { + name: number; + type: TagType; +} + +/** + * tag 响应对象 + */ +export interface TagResponse { + id: number; + name: string; +} + +/** + * 创建标签 + */ +export function createTag(request: TagCreateRequest) { + return axios.post('/infra/tag/create', request); +} + +/** + * 查询标签 + */ +export function getTagList(type: TagType) { + return axios.get('/infra/tag/list', { params: { type } }); +} diff --git a/orion-ops-ui/src/assets/style/layout.less b/orion-ops-ui/src/assets/style/layout.less index 50525289..2f213ab2 100644 --- a/orion-ops-ui/src/assets/style/layout.less +++ b/orion-ops-ui/src/assets/style/layout.less @@ -66,6 +66,10 @@ } } +.usn { + user-select: none; +} + .hide { display: none; } diff --git a/orion-ops-ui/src/components/tag/tag-multi-selector.vue b/orion-ops-ui/src/components/tag/tag-multi-selector.vue new file mode 100644 index 00000000..7e4fda89 --- /dev/null +++ b/orion-ops-ui/src/components/tag/tag-multi-selector.vue @@ -0,0 +1,113 @@ + + + + + + + diff --git a/orion-ops-ui/src/hooks/favorite.ts b/orion-ops-ui/src/hooks/favorite.ts new file mode 100644 index 00000000..ff6af06c --- /dev/null +++ b/orion-ops-ui/src/hooks/favorite.ts @@ -0,0 +1,29 @@ +import { Message } from '@arco-design/web-vue'; +import { FavoriteType, addFavorite, cancelFavorite } from '@/api/meta/favorite'; + +export default function useFavorite(type: FavoriteType) { + const toggle = async (record: any, id: number, cancelField = 'favorite') => { + const request = { relId: id, type } as any; + const loading = Message.loading(record[cancelField] ? '取消中' : '收藏中'); + try { + if (record[cancelField]) { + // 取消收藏 + await cancelFavorite(request); + record[cancelField] = false; + Message.success('已取消'); + } else { + // 添加收藏 + await addFavorite(request); + record[cancelField] = true; + Message.success('已收藏'); + } + } finally { + loading.close(); + } + }; + return { + toggle + }; +} + + diff --git a/orion-ops-ui/src/utils/index.ts b/orion-ops-ui/src/utils/index.ts index 2ca87960..75a8a787 100644 --- a/orion-ops-ui/src/utils/index.ts +++ b/orion-ops-ui/src/utils/index.ts @@ -50,6 +50,17 @@ export function md5(plain: string): string { return Md5.hashStr(plain); } +/** + * 获取数据颜色 + */ +export function dataColor(str: string, colors: string[]): string { + let total = 0; + for (let i = 0; i < str.length; i++) { + total += str.charCodeAt(i); + } + return colors[total % colors.length]; +} + /** * 判断值是否非空 */ diff --git a/orion-ops-ui/src/views/asset/host/components/host-form-modal.vue b/orion-ops-ui/src/views/asset/host/components/host-form-modal.vue index 040bf4e2..98a505ff 100644 --- a/orion-ops-ui/src/views/asset/host/components/host-form-modal.vue +++ b/orion-ops-ui/src/views/asset/host/components/host-form-modal.vue @@ -32,6 +32,14 @@ + + + + @@ -50,8 +58,7 @@ import formRules from '../types/form.rules'; import { createHost, updateHost } from '@/api/asset/host'; import { Message } from '@arco-design/web-vue'; - import {} from '../types/enum.types'; - import { toOptions } from '@/utils/enum'; + import TagMultiSelector from '@/components/tag/tag-multi-selector.vue'; const { visible, setVisible } = useVisible(); const { loading, setLoading } = useLoading(); @@ -65,7 +72,7 @@ name: undefined, code: undefined, address: undefined, - favorite: undefined, + tags: undefined, }; }; diff --git a/orion-ops-ui/src/views/asset/host/components/host-table.vue b/orion-ops-ui/src/views/asset/host/components/host-table.vue index 634d4e8d..a6532374 100644 --- a/orion-ops-ui/src/views/asset/host/components/host-table.vue +++ b/orion-ops-ui/src/views/asset/host/components/host-table.vue @@ -21,6 +21,15 @@ + + + + @@ -33,6 +42,18 @@
+ + + + - - - - 删除 - - -
@@ -67,8 +73,6 @@ label-align="left" :loading="loading" :columns="columns" - v-model:selectedKeys="selectedKeys" - :row-selection="rowSelection" :data="tableRenderData" :pagination="pagination" @page-change="(page) => fetchTableData(page, pagination.pageSize)" @@ -80,6 +84,16 @@ {{ record.address }} + + @@ -121,46 +143,38 @@ diff --git a/orion-ops-ui/src/views/asset/host/index.vue b/orion-ops-ui/src/views/asset/host/index.vue index 1a1e173f..b5c7b1c5 100644 --- a/orion-ops-ui/src/views/asset/host/index.vue +++ b/orion-ops-ui/src/views/asset/host/index.vue @@ -2,12 +2,12 @@
+ @openAdd="() => modal.openAdd()" + @openUpdate="(e) => modal.openUpdate(e)" /> + @added="() => table.addedCallback()" + @updated="() => table.updatedCallback()" />
@@ -20,11 +20,18 @@