修改更新主机身份逻辑.

This commit is contained in:
lijiahang
2023-09-21 16:06:09 +08:00
parent b13cbd8cca
commit d236e57f85
10 changed files with 85 additions and 37 deletions

View File

@@ -7,7 +7,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
@@ -35,12 +34,10 @@ public class HostIdentityCreateRequest implements Serializable {
@Schema(description = "用户名")
private String username;
@NotBlank
@Size(max = 512)
@Schema(description = "用户密码")
private String password;
@NotNull
@Schema(description = "秘钥id")
private Long keyId;

View File

@@ -39,12 +39,10 @@ public class HostIdentityUpdateRequest implements UpdatePasswordAction {
@Schema(description = "用户名")
private String username;
@NotBlank
@Size(max = 512)
@Schema(description = "用户密码")
private String password;
@NotNull
@Schema(description = "秘钥id")
private Long keyId;

View File

@@ -2,6 +2,8 @@ package com.orion.ops.module.asset.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorMessage;
@@ -82,7 +84,10 @@ public class HostIdentityServiceImpl implements HostIdentityService {
String newPassword = PasswordModifier.getEncryptNewPassword(request);
updateRecord.setPassword(newPassword);
// 更新
int effect = hostIdentityDAO.updateById(updateRecord);
LambdaUpdateWrapper<HostIdentityDO> wrapper = Wrappers.<HostIdentityDO>lambdaUpdate()
.set(HostIdentityDO::getKeyId, request.getKeyId())
.eq(HostIdentityDO::getId, id);
int effect = hostIdentityDAO.update(updateRecord, wrapper);
// 设置缓存
if (!record.getName().equals(updateRecord.getName())) {
RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));

View File

@@ -33,10 +33,11 @@
label="用户密码"
style="justify-content: space-between;">
<a-input-password v-model="formModel.password"
:disabled="!formModel.useNewPassword"
class="password-input"
:disabled="!isAddHandle && !formModel.useNewPassword"
:class="[isAddHandle ? 'password-input-full' : 'password-input']"
placeholder="请输入用户密码" />
<a-switch v-model="formModel.useNewPassword"
v-if="!isAddHandle"
class="password-switch"
type="round"
size="large"
@@ -124,6 +125,10 @@
return false;
}
if (isAddHandle.value) {
if (!formModel.password && !formModel.keyId) {
Message.error('创建时密码和秘钥不能同时为空');
return false;
}
// 新增
await createHostIdentity(formModel as any);
Message.success('创建成功');
@@ -161,6 +166,10 @@
width: 240px;
}
.password-input-full {
width: 100%;
}
.password-switch {
margin-left: 16px;
}

View File

@@ -57,9 +57,31 @@
@page-change="(page) => fetchTableData(page, pagination.pageSize)"
@page-size-change="(size) => fetchTableData(pagination.current, size)"
:bordered="false">
<!-- 操作 -->
<!-- 用户名 -->
<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 }">
{{ record.keyName }}
<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 #handle="{ record }">
@@ -105,10 +127,15 @@
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';
const { copy } = useCopy();
const { hasAnyPermission } = usePermission();
const tableRenderData = ref<HostIdentityQueryResponse[]>();
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate']);
const emits = defineEmits(['openAdd', 'openUpdate', 'openViewKey']);
const cacheStore = useCacheStore();
const pagination = reactive(defaultPagination());

View File

@@ -3,11 +3,14 @@
<!-- 表格 -->
<host-identity-table ref="table"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)" />
@openUpdate="(e) => modal.openUpdate(e)"
@openKeyView="(e) => keyDrawer.openView(e) " />
<!-- 添加修改模态框 -->
<host-identity-form-modal ref="modal"
@added="() => table.addedCallback()"
@updated="() => table.updatedCallback()" />
<!-- 添加修改模态框 -->
<host-key-form-drawer ref="keyDrawer" />
</div>
</template>
@@ -20,12 +23,14 @@
<script lang="ts" setup>
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 { onUnmounted, ref } from 'vue';
import { useCacheStore } from '@/store';
const table = ref();
const modal = ref();
const keyDrawer = ref();
// 卸载时清除 tags cache
onUnmounted(() => {

View File

@@ -64,20 +64,17 @@
label="密码"
style="justify-content: space-between;">
<a-input-password v-model="formModel.password"
:disabled="!formModel.useNewPassword"
:disabled="!isAddHandle && !formModel.useNewPassword"
:class="[isAddHandle ? 'password-input-full' : 'password-input']"
class="password-input"
placeholder="请输入私钥密码" />
<a-switch v-model="formModel.useNewPassword"
v-if="!isAddHandle"
class="password-switch"
type="round"
size="large">
<template #checked>
使用密码
</template>
<template #unchecked>
使用原密码
</template>
</a-switch>
size="large"
checked-text="使用新密码"
unchecked-text="使用密码" />
</a-form-item>
</a-form>
</a-spin>
@@ -241,6 +238,10 @@
width: 240px;
}
.password-input-full {
width: 100%;
}
.password-switch {
margin-left: 16px;
}

View File

@@ -78,19 +78,17 @@
@page-change="(page) => fetchTableData(page, pagination.pageSize)"
@page-size-change="(size) => fetchTableData(pagination.current, size)"
:bordered="false">
<!-- 名称 -->
<template #name="{ record }">
<span class="span-blue">{{ record.name }}</span>
</template>
<!-- 编码 -->
<template #code="{ record }">
<a-tag>{{ record.code }}</a-tag>
</template>
<!-- 地址 -->
<template #address="{ record }">
<span class="host-address" title="点击复制" @click="copy(record.address)">
{{ record.address }}
</span>
<a-tooltip content="点击复制">
<span class="host-address" @click="copy(record.address)">
<icon-copy class="mr4" />{{ record.address }}
</span>
</a-tooltip>
</template>
<!-- 标签 -->
<template #tag="{ record }">

View File

@@ -84,18 +84,26 @@
field="type"
label="是否可见"
tooltip="选择隐藏后不会在菜单以及 tab 中显示 但是可以访问">
<a-radio-group type="button"
v-model="formModel.visible"
:options="toOptions(MenuVisibleEnum)" />
<a-switch type="round"
size="large"
v-model="formModel.visible"
:checked-text="MenuVisibleEnum.SHOW.label"
:checked-value="MenuVisibleEnum.SHOW.value"
:unchecked-text="MenuVisibleEnum.HIDE.label"
:unchecked-value="MenuVisibleEnum.HIDE.value" />
</a-form-item>
<!-- 是否缓存 -->
<a-form-item v-if="formModel.type !== MenuTypeEnum.FUNCTION.value"
field="type"
label="是否缓存"
tooltip="选择缓存后则会使用 keep-alive 缓存组件">
<a-radio-group type="button"
v-model="formModel.cache"
:options="toOptions(MenuCacheEnum)" />
<a-switch type="round"
size="large"
v-model="formModel.cache"
:checked-text="MenuCacheEnum.ENABLED.label"
:checked-value="MenuCacheEnum.ENABLED.value"
:unchecked-text="MenuCacheEnum.DISABLED.label"
:unchecked-value="MenuCacheEnum.DISABLED.value" />
</a-form-item>
</a-form>
</a-spin>
@@ -136,7 +144,7 @@
permission: undefined,
sort: undefined,
visible: MenuVisibleEnum.SHOW.value,
cache: MenuCacheEnum.SHOW.value,
cache: MenuCacheEnum.ENABLED.value,
icon: undefined,
path: undefined,
component: undefined,

View File

@@ -52,11 +52,11 @@ export const MenuVisibleEnum = {
* 菜单缓存状态
*/
export const MenuCacheEnum = {
HIDE: {
DISABLED: {
value: 0,
label: '不缓存',
},
SHOW: {
ENABLED: {
value: 1,
label: '缓存',
}