2021-07-28 18:03:19 +08:00
|
|
|
<template>
|
2021-08-18 17:57:33 +08:00
|
|
|
<el-dialog :title="keyValue.key" v-model="visible" :before-close="cancel" :show-close="false" width="800px">
|
2021-07-28 18:03:19 +08:00
|
|
|
<el-form>
|
|
|
|
|
<el-form-item>
|
2021-08-18 17:57:33 +08:00
|
|
|
<!-- <el-input v-model="keyValue.value" type="textarea" :autosize="{ minRows: 10, maxRows: 20 }" autocomplete="off"></el-input> -->
|
|
|
|
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
</el-form-item>
|
2021-08-18 17:57:33 +08:00
|
|
|
<vue3-json-editor v-model="keyValue.jsonValue" @json-change="valueChange" :show-btns="false" :expandedOnStart="true" />
|
2021-07-28 18:03:19 +08:00
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
|
|
|
|
<el-button @click="saveValue" type="primary" size="mini">确 定</el-button>
|
|
|
|
|
<el-button @click="cancel()" size="mini">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { defineComponent, reactive, watch, toRefs } from 'vue';
|
|
|
|
|
import { redisApi } from './api';
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
import { isTrue } from '@/common/assert';
|
2021-08-18 17:57:33 +08:00
|
|
|
import { Vue3JsonEditor } from 'vue3-json-editor';
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'ValueDialog',
|
2021-08-18 17:57:33 +08:00
|
|
|
components: {
|
|
|
|
|
Vue3JsonEditor,
|
|
|
|
|
},
|
2021-07-28 18:03:19 +08:00
|
|
|
props: {
|
|
|
|
|
visible: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
keyValue: {
|
|
|
|
|
type: [String, Object],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
setup(props: any, { emit }) {
|
|
|
|
|
const state = reactive({
|
|
|
|
|
visible: false,
|
|
|
|
|
keyValue: {} as any,
|
|
|
|
|
});
|
|
|
|
|
const cancel = () => {
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
emit('cancel');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.visible,
|
|
|
|
|
(val) => {
|
|
|
|
|
state.visible = val;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.keyValue,
|
|
|
|
|
(val) => {
|
|
|
|
|
state.keyValue = val;
|
2021-08-18 17:57:33 +08:00
|
|
|
if (typeof val.value == 'string') {
|
|
|
|
|
state.keyValue.jsonValue = JSON.parse(val.value)
|
|
|
|
|
} else {
|
|
|
|
|
state.keyValue.jsonValue = val.value;
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const saveValue = async () => {
|
2021-08-18 17:57:33 +08:00
|
|
|
isTrue(state.keyValue.type == 'string', '暂不支持除string外其他类型修改');
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
await redisApi.saveStringValue.request(state.keyValue);
|
|
|
|
|
ElMessage.success('保存成功');
|
|
|
|
|
cancel();
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-18 17:57:33 +08:00
|
|
|
const valueChange = (val: any) => {
|
|
|
|
|
state.keyValue.value = JSON.stringify(val);
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
return {
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
saveValue,
|
2021-08-18 17:57:33 +08:00
|
|
|
valueChange,
|
2021-07-28 18:03:19 +08:00
|
|
|
cancel,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|