Files
xiaozhi-esp32-server/main/manager-web/src/components/DictDataDialog.vue
T

116 lines
3.3 KiB
Vue
Raw Normal View History

2025-05-01 16:57:58 +08:00
<template>
2025-05-08 17:57:11 +08:00
<el-dialog :title="title" :visible.sync="dialogVisible" width="30%" @close="handleClose">
<el-form :model="form" :rules="rules" ref="form" label-width="auto">
<el-form-item :label="$t('dictDataDialog.dictLabel')" prop="dictLabel">
<el-input v-model="form.dictLabel" :placeholder="$t('dictDataDialog.dictLabelPlaceholder')"></el-input>
2025-05-01 16:57:58 +08:00
</el-form-item>
<el-form-item :label="$t('dictDataDialog.dictValue')" prop="dictValue">
<el-input v-model="form.dictValue" :placeholder="$t('dictDataDialog.dictValuePlaceholder')"></el-input>
2025-05-01 16:57:58 +08:00
</el-form-item>
<el-form-item :label="$t('dictDataDialog.sort')" prop="sort">
2025-05-01 16:57:58 +08:00
<el-input-number v-model="form.sort" :min="0" :max="999" style="width: 100%;"></el-input-number>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">{{ $t('button.cancel') }}</el-button>
<el-button type="primary" @click="handleSave">{{ $t('button.save') }}</el-button>
2025-05-01 16:57:58 +08:00
</div>
</el-dialog>
</template>
<script>
export default {
name: 'DictDataDialog',
props: {
visible: {
type: Boolean,
default: false
},
title: {
type: String,
default: () => this.$t('dictDataDialog.addDictData')
2025-05-01 16:57:58 +08:00
},
dictData: {
type: Object,
default: () => ({})
},
dictTypeId: {
type: [Number, String],
default: null
}
},
data() {
return {
2025-05-08 17:57:11 +08:00
dialogVisible: this.visible,
2025-05-01 16:57:58 +08:00
form: {
id: null,
dictTypeId: null,
dictLabel: '',
dictValue: '',
sort: 0
},
rules: {
dictLabel: [{ required: true, message: this.$t('dictDataDialog.requiredDictLabel'), trigger: 'blur' }],
dictValue: [{ required: true, message: this.$t('dictDataDialog.requiredDictValue'), trigger: 'blur' }]
2025-05-01 16:57:58 +08:00
}
}
},
watch: {
dictData: {
handler(val) {
if (val) {
this.form = { ...val }
}
},
immediate: true
},
dictTypeId: {
handler(val) {
if (val) {
this.form.dictTypeId = val
}
},
immediate: true
2025-05-08 17:57:11 +08:00
},
visible(val) {
this.dialogVisible = val;
},
dialogVisible(val) {
this.$emit('update:visible', val);
2025-05-01 16:57:58 +08:00
}
},
methods: {
handleClose() {
2025-05-08 17:57:11 +08:00
this.dialogVisible = false;
this.resetForm();
2025-05-01 16:57:58 +08:00
},
resetForm() {
this.form = {
id: null,
dictTypeId: this.dictTypeId,
dictLabel: '',
dictValue: '',
sort: 0
}
this.$refs.form?.resetFields()
},
handleSave() {
this.$refs.form.validate(valid => {
if (valid) {
this.$emit('save', this.form)
}
})
}
}
}
</script>
<style scoped>
.dialog-footer {
text-align: right;
}
2025-05-08 17:57:11 +08:00
:deep(.el-dialog) {
border-radius: 15px;
}
2025-05-01 16:57:58 +08:00
</style>