feat: 账号列表-查看账号支持类型为password的账号修改密码

This commit is contained in:
“huailei000” 2023-04-26 15:24:12 +08:00 committed by Jiangjie.Bai
parent d14cbce2d6
commit e365eaef8a
5 changed files with 97 additions and 30 deletions

View File

@ -29,7 +29,9 @@
:cell-value="secretInfo.secret" :cell-value="secretInfo.secret"
:col="{ formatterArgs: { :col="{ formatterArgs: {
name: account['name'], name: account['name'],
secretType: secretType || ''
}}" }}"
@input="onShowKeyCopyFormatterChange"
/> />
</el-form-item> </el-form-item>
<el-form-item v-if="secretType === 'ssh_key'" :label="$tc('assets.sshKeyFingerprint')"> <el-form-item v-if="secretType === 'ssh_key'" :label="$tc('assets.sshKeyFingerprint')">
@ -102,6 +104,7 @@ export default {
}, },
data() { data() {
return { return {
modifiedSecret: '',
secretInfo: {}, secretInfo: {},
versions: '-', versions: '-',
showSecret: false, showSecret: false,
@ -129,9 +132,19 @@ export default {
}, },
methods: { methods: {
accountConfirmHandle() { accountConfirmHandle() {
this.modifiedSecret && this.onChangeSecretSubmit()
this.showSecret = false this.showSecret = false
this.mfaDialogVisible = false this.mfaDialogVisible = false
}, },
onChangeSecretSubmit() {
const params = {
name: this.secretInfo.name,
secret: this.secretInfo.secret
}
this.$axios.patch(`/api/v1/accounts/accounts/${this.account.id}/`, params).then(() => {
this.$message.success(this.$tc('common.updateSuccessMsg'))
})
},
getAuthInfo() { getAuthInfo() {
this.$axios.get(this.url, { disableFlashErrorMsg: true }).then(resp => { this.$axios.get(this.url, { disableFlashErrorMsg: true }).then(resp => {
this.secretInfo = resp this.secretInfo = resp
@ -144,6 +157,10 @@ export default {
}, },
showHistoryDialog() { showHistoryDialog() {
this.showPasswordHistoryDialog = true this.showPasswordHistoryDialog = true
},
onShowKeyCopyFormatterChange(value) {
if (value === this.secretInfo.secret) return
this.modifiedSecret = value
} }
} }
} }

View File

@ -1,31 +1,26 @@
<template> <template>
<div class="content"> <div class="content">
<pre class="text">{{ currentValue }}</pre> <pre v-if="!isEdit" class="text">{{ currentValue }}</pre>
<span v-if="cellValue" class="action"> <el-input
<el-tooltip v-else
v-if="hasShow" ref="editInput"
effect="dark" v-model="realValue"
placement="top" size="small"
:content="$tc('common.View')" class="text edit-input"
> @blur="onEditBlur"
<i class="fa" :class="isShow ? 'fa-eye-slash' : 'fa-eye'" @click="onShow()" /> />
</el-tooltip> <span v-if="realValue" class="action">
<el-tooltip <template v-for="(item, index) in iActions">
v-if="hasDownload" <el-tooltip
effect="dark" v-if="item.has"
placement="top" :key="index"
:content="$tc('common.Download')" effect="dark"
> placement="top"
<i class="fa fa-download" @click="onDownload()" /> :content="item.tooltip"
</el-tooltip> >
<el-tooltip <i class="fa" :class="[item.class, item.icon]" @click="item.action()" />
v-if="hasCopy" </el-tooltip>
effect="dark" </template>
placement="top"
:content="$tc('common.Copy')"
>
<i class="fa fa-clone" @click="onCopy()" />
</el-tooltip>
</span> </span>
</div> </div>
</template> </template>
@ -47,6 +42,7 @@ export default {
hasShow: true, hasShow: true,
hasDownload: true, hasDownload: true,
hasCopy: true, hasCopy: true,
hasEdit: true,
defaultShow: false defaultShow: false
} }
} }
@ -54,6 +50,8 @@ export default {
}, },
data() { data() {
return { return {
isEdit: false,
realValue: this.cellValue,
formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs || {}), formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs || {}),
isShow: false isShow: false
} }
@ -68,14 +66,46 @@ export default {
hasCopy: function() { hasCopy: function() {
return this.formatterArgs.hasCopy return this.formatterArgs.hasCopy
}, },
hasEdit: function() {
return this.formatterArgs.hasEdit
},
name: function() { name: function() {
return this.formatterArgs.name return this.formatterArgs.name
}, },
iActions() {
const actions = [
{
has: this.hasEdit && this.formatterArgs?.secretType === 'password',
class: this.isEdit ? 'fa-check' : 'fa-pencil',
action: this.onEdit,
tooltip: this.$t('common.Edit')
},
{
has: this.hasShow,
class: this.isShow ? 'fa-eye-slash' : 'fa-eye',
action: this.onShow,
tooltip: this.$t('common.View')
},
{
has: this.hasDownload,
icon: 'fa-download',
action: this.onDownload,
tooltip: this.$t('common.Download')
},
{
has: this.hasCopy,
icon: 'fa-clone',
action: this.onCopy,
tooltip: this.$t('common.Copy')
}
]
return actions
},
currentValue() { currentValue() {
if (this.isShow) { if (this.isShow) {
return this.cellValue || '-' return this.realValue || '-'
} else { } else {
return this.cellValue ? '******' : '-' return this.realValue ? '******' : '-'
} }
} }
}, },
@ -87,10 +117,21 @@ export default {
this.isShow = !this.isShow this.isShow = !this.isShow
}, },
onCopy() { onCopy() {
copy(this.cellValue) copy(this.realValue)
}, },
onDownload() { onDownload() {
downloadText(this.cellValue, this.name + '.txt') downloadText(this.realValue, this.name + '.txt')
},
onEdit() {
this.isEdit = !this.isEdit
if (this.isEdit) {
this.$nextTick(() => {
this.$refs.editInput.focus()
})
}
},
onEditBlur() {
this.$emit('input', this.realValue)
} }
} }
} }
@ -128,4 +169,10 @@ export default {
} }
} }
} }
.edit-input >>> input {
border-left: none;
border-right: none;
border-top: none;
height: 30px;
}
</style> </style>

View File

@ -622,6 +622,7 @@
"Username": "Username", "Username": "Username",
"Validity": "Validity", "Validity": "Validity",
"Invalidity": "Invalidity", "Invalidity": "Invalidity",
"Edit": "Edit",
"View": "View", "View": "View",
"Yes": "Yes", "Yes": "Yes",
"action": "Action", "action": "Action",

View File

@ -620,6 +620,7 @@
"Username": "ユーザー名", "Username": "ユーザー名",
"Validity": "有効", "Validity": "有効",
"Invalidity": "無効", "Invalidity": "無効",
"Edit": "編集",
"View": "表示", "View": "表示",
"Yes": "はい", "Yes": "はい",
"action": "アクション", "action": "アクション",

View File

@ -643,6 +643,7 @@
"Username": "用户名", "Username": "用户名",
"Validity": "有效", "Validity": "有效",
"Invalidity": "无效", "Invalidity": "无效",
"Edit": "编辑",
"View": "查看", "View": "查看",
"Yes": "是", "Yes": "是",
"action": "动作", "action": "动作",