2022-08-05 21:41:21 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<el-dialog :title="title" v-model="dialogVisible" :before-close="cancel" width="800px" :destroy-on-close="true">
|
|
|
|
|
|
<el-form label-width="85px">
|
|
|
|
|
|
<el-form-item prop="key" label="key:">
|
|
|
|
|
|
<el-input :disabled="operationType == 2" v-model="key.key"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="timed" label="过期时间:">
|
|
|
|
|
|
<el-input v-model.number="key.timed" type="number"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="dataType" label="数据类型:">
|
|
|
|
|
|
<el-input v-model="key.type" disabled></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
<div id="string-value-text" style="width: 100%">
|
2022-11-25 18:59:23 +08:00
|
|
|
|
<format-input :title="`type:【${key.type}】key:【${key.key}】`" v-model="string.value" :autosize="{ minRows: 10, maxRows: 20 }"></format-input>
|
|
|
|
|
|
<!-- <el-select class="text-type-select" @change="onChangeTextType" v-model="string.type">
|
2022-08-05 21:41:21 +08:00
|
|
|
|
<el-option key="text" label="text" value="text"> </el-option>
|
|
|
|
|
|
<el-option key="json" label="json" value="json"> </el-option>
|
2022-11-25 18:59:23 +08:00
|
|
|
|
</el-select> -->
|
2022-08-05 21:41:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div class="dialog-footer">
|
|
|
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
|
|
|
|
|
<el-button @click="saveValue" type="primary" v-auth="'redis:data:save'">确 定</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|
2022-10-29 20:08:15 +08:00
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
|
import { reactive, watch, toRefs } from 'vue';
|
2022-08-05 21:41:21 +08:00
|
|
|
|
import { redisApi } from './api';
|
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
|
import { notEmpty } from '@/common/assert';
|
2022-11-25 18:59:23 +08:00
|
|
|
|
import FormatInput from './FormatInput.vue';
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
visible: {
|
|
|
|
|
|
type: Boolean,
|
2022-08-05 21:41:21 +08:00
|
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
|
title: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
},
|
|
|
|
|
|
redisId: {
|
|
|
|
|
|
type: [Number],
|
|
|
|
|
|
require: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
db: {
|
|
|
|
|
|
type: [String],
|
|
|
|
|
|
require: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
keyInfo: {
|
|
|
|
|
|
type: [Object],
|
|
|
|
|
|
},
|
|
|
|
|
|
// 操作类型,1:新增,2:修改
|
|
|
|
|
|
operationType: {
|
|
|
|
|
|
type: [Number],
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const emit = defineEmits(['update:visible', 'cancel', 'valChange'])
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const state = reactive({
|
|
|
|
|
|
dialogVisible: false,
|
|
|
|
|
|
operationType: 1,
|
|
|
|
|
|
redisId: '',
|
|
|
|
|
|
db: '0',
|
|
|
|
|
|
key: {
|
|
|
|
|
|
key: '',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
timed: -1,
|
|
|
|
|
|
},
|
|
|
|
|
|
string: {
|
|
|
|
|
|
type: 'text',
|
|
|
|
|
|
value: '',
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2022-09-29 13:14:50 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const {
|
|
|
|
|
|
dialogVisible,
|
|
|
|
|
|
operationType,
|
|
|
|
|
|
key,
|
|
|
|
|
|
string,
|
|
|
|
|
|
} = toRefs(state)
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
const cancel = () => {
|
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
|
emit('cancel');
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
state.key = {
|
|
|
|
|
|
key: '',
|
|
|
|
|
|
type: 'string',
|
|
|
|
|
|
timed: -1,
|
2022-08-05 21:41:21 +08:00
|
|
|
|
};
|
2022-10-29 20:08:15 +08:00
|
|
|
|
state.string.value = '';
|
|
|
|
|
|
state.string.type = 'text';
|
|
|
|
|
|
}, 500);
|
|
|
|
|
|
};
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.visible,
|
|
|
|
|
|
(val) => {
|
|
|
|
|
|
state.dialogVisible = val;
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.redisId,
|
|
|
|
|
|
(val) => {
|
|
|
|
|
|
state.redisId = val as any;
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.db,
|
|
|
|
|
|
(val) => {
|
|
|
|
|
|
state.db = val as any;
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2022-08-05 21:41:21 +08:00
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
|
watch(props, async (newValue: any) => {
|
|
|
|
|
|
state.dialogVisible = newValue.visible;
|
|
|
|
|
|
state.redisId = newValue.redisId;
|
|
|
|
|
|
state.db = newValue.db;
|
|
|
|
|
|
state.key = newValue.keyInfo;
|
|
|
|
|
|
state.operationType = newValue.operationType;
|
|
|
|
|
|
// 如果是查看编辑操作,则获取值
|
|
|
|
|
|
if (state.dialogVisible && state.operationType == 2) {
|
|
|
|
|
|
getStringValue();
|
|
|
|
|
|
}
|
2022-08-05 21:41:21 +08:00
|
|
|
|
});
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
const getStringValue = async () => {
|
|
|
|
|
|
state.string.value = await redisApi.getStringValue.request({
|
|
|
|
|
|
id: state.redisId,
|
|
|
|
|
|
db: state.db,
|
|
|
|
|
|
key: state.key.key,
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const saveValue = async () => {
|
|
|
|
|
|
notEmpty(state.key.key, 'key不能为空');
|
|
|
|
|
|
|
|
|
|
|
|
notEmpty(state.string.value, 'value不能为空');
|
2022-11-25 18:59:23 +08:00
|
|
|
|
const sv = { value: state.string.value, id: state.redisId, db: state.db };
|
2022-10-29 20:08:15 +08:00
|
|
|
|
Object.assign(sv, state.key);
|
|
|
|
|
|
await redisApi.saveStringValue.request(sv);
|
|
|
|
|
|
ElMessage.success('数据保存成功');
|
|
|
|
|
|
cancel();
|
|
|
|
|
|
emit('valChange');
|
|
|
|
|
|
};
|
2022-08-05 21:41:21 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
#string-value-text {
|
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
|
|
.text-type-select {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
z-index: 2;
|
|
|
|
|
|
right: 10px;
|
|
|
|
|
|
top: 10px;
|
|
|
|
|
|
max-width: 70px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-18 17:21:42 +08:00
|
|
|
|
</style>
|