<!-- 新增密钥 -->
|
<template>
|
<div>
|
<el-drawer size="40%" :with-header="false" :visible.sync="visible" :before-close="handleAddClose">
|
<el-form ref="form" :model="form" label-width="100px" :rules="rules" style="width: 90%;margin: 50px auto;">
|
<el-form-item :label="$t('security.keyId')" v-if="type == 'detail'">
|
<el-input v-model="form.securityId" :placeholder="$t('common.placeholder')"></el-input>
|
</el-form-item>
|
<el-form-item :label="$t('security.keyType')">
|
<el-radio-group v-model="form.type">
|
<el-radio label="RSA">RSA</el-radio>
|
<el-radio label="AES">AES</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
<el-form-item :label="$t('security.keyEncoding')" prop="key">
|
<el-input v-model="form.key" :placeholder="$t('common.placeholder')"></el-input>
|
</el-form-item>
|
<el-form-item :label="$t('security.keyValue')" prop="value">
|
<el-input type="textarea" clearable :rows="5" v-model="form.value"
|
:placeholder="$t('common.placeholder')"></el-input>
|
</el-form-item>
|
<el-form-item :label="$t('security.validTime')">
|
<el-date-picker :clearable="false" v-model="dateTimes" value-format="timestamp"
|
:default-time="['00:00:00', '23:59:59']" type="datetimerange" :range-separator="$t('common.to')"
|
:start-placeholder="$t('common.startTime')" :end-placeholder="$t('common.endTime')">
|
</el-date-picker>
|
</el-form-item>
|
</el-form>
|
<div class="dialog-footer">
|
<el-button type="warning" @click="handleAddClose(false)">{{ $t('common.cancel') }}</el-button>
|
<el-button v-if="type == 'add'" type="primary" @click="updata()">{{ $t('common.confirm') }}</el-button>
|
</div>
|
</el-drawer>
|
</div>
|
</template>
|
|
<script>
|
import { generateRandomString, resetObjectValues } from '@/utils/index.js'
|
export default {
|
data () {
|
return {
|
form: {
|
securityId: "",
|
type: "",
|
key: "",
|
value: ""
|
},
|
rules: {
|
key: [{ required: true, message: this.$t('common.placeholder'), trigger: ["blur"] },],
|
value: [{ required: true, message: this.$t('common.placeholder'), trigger: ["blur"] },],
|
},
|
dateTimes: [],
|
visible: false,
|
type: 'info'
|
}
|
},
|
created () {
|
this.initialForm = JSON.parse(JSON.stringify(this.form));
|
},
|
mounted () {
|
|
},
|
methods: {
|
open (type, row) {
|
if (type == 'add') {
|
this.form.type = 'RSA'
|
console.log('add')
|
} else {
|
this.form.securityId = row.securityId
|
this.form.type = row.type
|
this.form.key = row.key
|
this.form.value = row.value
|
this.dateTimes = [row.startTime * 1000, row.endTime * 1000]
|
}
|
this.type = type
|
this.visible = true
|
},
|
|
handleAddClose (showConfirm = true) {
|
const closeAction = () => {
|
if (this.$refs.form) {
|
this.$refs.form.clearValidate();
|
}
|
this.visible = false;
|
this.form = { ...this.initialForm };
|
this.dateTimes = []
|
};
|
if (showConfirm) {
|
this.$confirm(this.$t('common.closeTips'))
|
.then(closeAction)
|
.catch(() => { });
|
} else {
|
closeAction();
|
}
|
},
|
|
updata () {
|
let that = this
|
this.$refs['form'].validate(async (valid) => {
|
if (valid) {
|
if (!that.dateTimes.length) {
|
that.$message.warning(this.$t('permission.choose_time_range'));
|
return false
|
}
|
let data = {
|
securityId: generateRandomString(),
|
type: that.form.type,
|
key: that.form.key,
|
value: that.form.value,
|
startTime: new Date(that.dateTimes[0]).getTime() / 1000,
|
endTime: new Date(that.dateTimes[1]).getTime() / 1000
|
}
|
const res = await this.$http.post(
|
"/insertSecurity",
|
{ data: [data] }
|
);
|
if (res.code == 200) {
|
this.$message.success(this.$t('common.addSuccess'))
|
this.visible = false
|
resetObjectValues(this.form)
|
this.$emit("operation-success")
|
} else {
|
if (res.data && res.data[0]) {
|
this.$message.error(res.data[0].errmsg)
|
}
|
}
|
}
|
})
|
}
|
}
|
}
|
</script>
|