添加主机身份卡片视图.

This commit is contained in:
lijiahangmax
2023-10-08 01:05:52 +08:00
parent 1036713f74
commit c7defdb80d
20 changed files with 404 additions and 90 deletions

View File

@@ -0,0 +1,230 @@
<template>
<card-list v-model:searchValue="formModel.searchValue"
search-input-placeholder="输入id/名称/用户名"
create-card-position="head"
:card-height="184"
:loading="loading"
:fieldConfig="fieldConfig"
:list="list"
:pagination="pagination"
:card-layout-cols="cardColLayout"
:filter-count="filterCount"
:add-permission="['asset:host-identity:create']"
@add="emits('openAdd')"
@reset="reset"
@search="fetchCardData"
@page-change="fetchCardData">
<!-- 标题 -->
<template #title="{ record }">
{{ record.name }}
</template>
<!-- 用户名 -->
<template #username="{ record }">
<a-tooltip content="点击复制">
<span class="pointer span-blue" @click="copy(record.username)">
<icon-copy class="mr4" />{{ record.username }}
</span>
</a-tooltip>
</template>
<!-- 秘钥名称 -->
<template #keyId="{ record }">
<template v-if="record.keyId">
<!-- 可查看详情 -->
<a-tooltip v-if="hasAnyPermission(['asset:host-key:detail', 'asset:host-key:update'])"
content="点击查看详情">
<a-tag :checked="true"
checkable
@click="emits('openKeyView',{id: record.keyId})">
{{ record.keyName }}
</a-tag>
</a-tooltip>
<!-- 不可查看详情 -->
<a-tag v-else>
{{ record.keyName }}
</a-tag>
</template>
</template>
<!-- 拓展操作 -->
<template #extra="{ record }">
<a-space>
<!-- 更多操作 -->
<a-dropdown trigger="hover">
<icon-more class="card-extra-icon" />
<template #content>
<!-- 修改 -->
<a-doption v-permission="['asset:host-identity:update']"
@click="emits('openUpdate', record)">
<icon-edit />
修改
</a-doption>
<!-- 删除 -->
<a-doption v-permission="['asset:host-identity:delete']"
class="span-red"
@click="deleteRow(record.id)">
<icon-delete />
删除
</a-doption>
</template>
</a-dropdown>
</a-space>
</template>
<!-- 右键菜单 -->
<template #contextMenu="{ record }">
<!-- 修改 -->
<a-doption v-permission="['asset:host-identity:update']"
@click="emits('openUpdate', record)">
<icon-edit />
修改
</a-doption>
<!-- 删除 -->
<a-doption v-permission="['asset:host-identity:delete']"
class="span-red"
@click="deleteRow(record.id)">
<icon-delete />
删除
</a-doption>
</template>
<!-- 过滤条件 -->
<template #filterContent>
<a-form :model="formModel"
class="modal-form"
size="small"
ref="formRef"
label-align="right"
:style="{ width: '320px' }"
:label-col-props="{ span: 6 }"
:wrapper-col-props="{ span: 18 }">
<!-- id -->
<a-form-item field="id" label="id">
<a-input-number v-model="formModel.id"
placeholder="请输入id"
allow-clear
hide-button />
</a-form-item>
<!-- 名称 -->
<a-form-item field="name" label="名称">
<a-input v-model="formModel.name" placeholder="请输入名称" allow-clear />
</a-form-item>
<!-- 用户名 -->
<a-form-item field="username" label="用户名">
<a-input v-model="formModel.username" placeholder="请输入用户名" allow-clear />
</a-form-item>
<!-- 主机秘钥 -->
<a-form-item field="keyId" label="主机秘钥">
<host-key-selector v-model="formModel.keyId" allow-clear />
</a-form-item>
</a-form>
</template>
</card-list>
</template>
<script lang="ts">
export default {
name: 'asset-host-identity-card-list'
};
</script>
<script setup lang="ts">
import { usePagination, useColLayout } from '@/types/card';
import { computed, reactive, ref } from 'vue';
import useLoading from '@/hooks/loading';
import { objectTruthKeyCount, resetObject } from '@/utils';
import fieldConfig from '../types/card.fields';
import { deleteHostIdentity, getHostIdentityPage, HostIdentityQueryRequest, HostIdentityQueryResponse } from '@/api/asset/host-identity';
import { Message, Modal } from '@arco-design/web-vue';
import usePermission from '@/hooks/permission';
import useCopy from '@/hooks/copy';
import HostKeySelector from '@/components/asset/host-key/host-key-selector.vue';
const { copy } = useCopy();
const { hasAnyPermission } = usePermission();
const { loading, setLoading } = useLoading();
const cardColLayout = useColLayout();
const pagination = usePagination();
const list = ref<HostIdentityQueryResponse[]>([]);
const emits = defineEmits(['openAdd', 'openUpdate', 'openKeyView']);
const formRef = ref();
const formModel = reactive<HostIdentityQueryRequest>({
searchValue: undefined,
id: undefined,
name: undefined,
username: undefined,
keyId: undefined,
});
// 条件数量
const filterCount = computed(() => {
return objectTruthKeyCount(formModel, ['searchValue']);
});
// 删除当前行
const deleteRow = (id: number) => {
Modal.confirm({
title: '删除前确认!',
titleAlign: 'start',
content: '确定要删除这条记录吗?',
okText: '删除',
onOk: async () => {
try {
setLoading(true);
// 调用删除接口
await deleteHostIdentity(id);
Message.success('删除成功');
// 重新加载数据
await fetchCardData();
} catch (e) {
} finally {
setLoading(false);
}
}
});
};
// 添加后回调
const addedCallback = () => {
fetchCardData();
};
// 更新后回调
const updatedCallback = () => {
fetchCardData();
};
defineExpose({
addedCallback, updatedCallback
});
// 重置条件
const reset = () => {
resetObject(formModel);
fetchCardData();
};
// 加载数据
const doFetchCardData = async (request: HostIdentityQueryRequest) => {
try {
setLoading(true);
const { data } = await getHostIdentityPage(request);
list.value = data.rows;
pagination.total = data.total;
pagination.current = request.page;
pagination.pageSize = request.limit;
} catch (e) {
} finally {
setLoading(false);
}
};
// 切换页码
const fetchCardData = (page = 1, limit = pagination.pageSize, form = formModel) => {
doFetchCardData({ page, limit, ...form });
};
fetchCardData();
</script>
<style scoped lang="less">
</style>

View File

@@ -127,8 +127,6 @@
import useLoading from '@/hooks/loading';
import columns from '../types/table.columns';
import { usePagination } from '@/types/table';
import { getHostKeyList } from '@/api/asset/host-key';
import { useCacheStore } from '@/store';
import HostKeySelector from '@/components/asset/host-key/host-key-selector.vue';
import useCopy from '@/hooks/copy';
import usePermission from '@/hooks/permission';
@@ -140,7 +138,6 @@
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate', 'openKeyView']);
const cacheStore = useCacheStore();
const pagination = usePagination();
const formModel = reactive<HostIdentityQueryRequest>({
@@ -202,16 +199,6 @@
};
fetchTableData();
// 获取主机秘钥列表
const fetchHostKeyList = async () => {
try {
const { data } = await getHostKeyList();
cacheStore.set('hostKeys', data);
} catch (e) {
}
};
fetchHostKeyList();
</script>
<style lang="less" scoped>

View File

@@ -1,14 +1,21 @@
<template>
<div class="layout-container">
<!-- 表格 -->
<host-identity-table ref="table"
<!-- 列表-表格 -->
<host-identity-table v-if="renderTable"
ref="table"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)"
@openKeyView="(e) => keyDrawer.openView(e) " />
<!-- 列表-卡片 -->
<host-identity-card-list v-else
ref="card"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)"
@openKeyView="(e) => keyDrawer.openView(e) " />
<!-- 添加修改模态框 -->
<host-identity-form-modal ref="modal"
@added="() => table.addedCallback()"
@updated="() => table.updatedCallback()" />
@added="modalAddCallback"
@updated="modalAddCallback" />
<!-- 添加修改模态框 -->
<host-key-form-drawer ref="keyDrawer" />
</div>
@@ -21,16 +28,51 @@
</script>
<script lang="ts" setup>
import HostIdentityCardList from './components/host-identity-card-list.vue';
import HostIdentityTable from './components/host-identity-table.vue';
import HostIdentityFormModal from './components/host-identity-form-modal.vue';
import HostKeyFormDrawer from '../host-key/components/host-key-form-drawer.vue';
import { getHostKeyList } from '@/api/asset/host-key';
import { onUnmounted, ref } from 'vue';
import { useCacheStore } from '@/store';
import { onUnmounted, ref, computed } from 'vue';
import { useAppStore, useCacheStore } from '@/store';
const table = ref();
const card = ref();
const modal = ref();
const keyDrawer = ref();
const appStore = useAppStore();
const cacheStore = useCacheStore();
const renderTable = computed(() => appStore.hostIdentityView === 'table');
// 添加回调
const modalAddCallback = () => {
if (renderTable.value) {
table.value.addedCallback();
} else {
card.value.addedCallback();
}
};
// 修改回调
const modalUpdateCallback = () => {
if (renderTable.value) {
table.value.updatedCallback();
} else {
card.value.updatedCallback();
}
};
// 获取主机秘钥列表
const fetchHostKeyList = async () => {
try {
const { data } = await getHostKeyList();
cacheStore.set('hostKeys', data);
} catch (e) {
}
};
fetchHostKeyList();
// 卸载时清除 tags cache
onUnmounted(() => {

View File

@@ -0,0 +1,33 @@
import { CardField, CardFieldConfig } from '@/types/card';
import { dateFormat } from '@/utils';
const fieldConfig = {
rowGap: '12px',
labelSpan: 8,
fields: [
{
label: 'id',
dataIndex: 'id',
slotName: 'id',
}, {
label: '用户名',
dataIndex: 'username',
slotName: 'username',
ellipsis: true,
}, {
label: '主机秘钥',
dataIndex: 'keyId',
slotName: 'keyId',
height: '24px',
}, {
label: '修改时间',
dataIndex: 'updateTime',
slotName: 'updateTime',
render: ({ record }) => {
return dateFormat(new Date(record.updateTime));
},
}
] as CardField[]
} as CardFieldConfig;
export default fieldConfig;

View File

@@ -1,6 +1,6 @@
<template>
<card-list v-model:searchValue="formModel.searchValue"
search-input-placeholder="输入名称/id"
search-input-placeholder="输入id/名称"
create-card-position="head"
:card-height="148"
:loading="loading"
@@ -101,7 +101,7 @@
// 删除当前行
const deleteRow = (id: number) => {
Modal.confirm({
title: '删除前确认?',
title: '删除前确认!',
titleAlign: 'start',
content: '确定要删除这条记录吗?',
okText: '删除',

View File

@@ -26,12 +26,13 @@
</script>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { useAppStore } from '@/store';
import HostKeyCardList from './components/host-key-card-list.vue';
import HostKeyTable from './components/host-key-table.vue';
import HostKeyFormDrawer from './components/host-key-form-drawer.vue';
import { computed, ref } from 'vue';
import { useAppStore } from '@/store';
const table = ref();
const card = ref();
const drawer = ref();

View File

@@ -2,7 +2,7 @@ import { CardField, CardFieldConfig } from '@/types/card';
import { dateFormat } from '@/utils';
const fieldConfig = {
rowGap: '10px',
rowGap: '12px',
labelSpan: 8,
fields: [
{

View File

@@ -1,8 +1,8 @@
<template>
<card-list v-model:searchValue="formModel.searchValue"
search-input-placeholder="输入名称/地址"
search-input-placeholder="输入id/名称/标签/地址"
create-card-position="head"
:card-height="174"
:card-height="214"
:loading="loading"
:fieldConfig="fieldConfig"
:list="list"
@@ -160,6 +160,7 @@
const list = ref<HostQueryResponse[]>([]);
const emits = defineEmits(['openAdd', 'openUpdate', 'openUpdateConfig']);
const formRef = ref();
const formModel = reactive<HostQueryRequest>({
searchValue: undefined,
id: undefined,
@@ -179,7 +180,7 @@
// 删除当前行
const deleteRow = (id: number) => {
Modal.confirm({
title: '删除前确认?',
title: '删除前确认!',
titleAlign: 'start',
content: '确定要删除这条记录吗?',
okText: '删除',

View File

@@ -28,8 +28,6 @@
</script>
<script lang="ts" setup>
import { computed, onUnmounted, ref } from 'vue';
import { useAppStore, useCacheStore } from '@/store';
import HostTable from './components/host-table.vue';
import HostCardList from '@/views/asset/host/components/host-card-list.vue';
import HostFormModal from './components/host-form-modal.vue';
@@ -37,6 +35,9 @@
import { getTagList } from '@/api/meta/tag';
import { Message } from '@arco-design/web-vue';
import { computed, onUnmounted, ref } from 'vue';
import { useAppStore, useCacheStore } from '@/store';
const table = ref();
const card = ref();
const modal = ref();

View File

@@ -1,10 +1,15 @@
import { CardField, CardFieldConfig } from '@/types/card';
const fieldConfig = {
rowGap: '10px',
rowGap: '12px',
labelSpan: 8,
minHeight: '24px',
fields: [
{
label: 'id',
dataIndex: 'id',
slotName: 'id',
}, {
label: '主机编码',
dataIndex: 'code',
slotName: 'code',
@@ -12,7 +17,6 @@ const fieldConfig = {
label: '主机地址',
dataIndex: 'address',
slotName: 'address',
height: '24px',
tooltip: true,
}, {
label: '主机标签',