qii404 9ecb4ad757
Custom shell formater support (#645)
* add custom formatter support (#638)
2021-08-16 18:50:26 +08:00

103 lines
2.3 KiB
JavaScript

<template>
<el-form class='key-content-string'>
<!-- key content textarea -->
<el-form-item>
<FormatViewer
ref='formatViewer'
:content.sync='content'
:binary='binary'
:redisKey='redisKey'
float=''
:textrows=12>
</FormatViewer>
</el-form-item>
<!-- save btn -->
<el-form-item>
<el-button ref='saveBtn' type="primary" @click="execSave" title='Ctrl+s'>{{ $t('message.save') }}</el-button>
</el-form-item>
<ScrollToTop parentNum='4'></ScrollToTop>
</el-form>
</template>
<script>
import FormatViewer from '@/components/FormatViewer';
import ScrollToTop from '@/components/ScrollToTop';
export default {
data() {
return {
content: Buffer.from(''),
binary: false,
};
},
props: ['client', 'redisKey', 'hotKeyScope'],
components: { FormatViewer, ScrollToTop },
methods: {
initShow() {
this.client.getBuffer(this.redisKey).then((reply) => {
this.content = reply;
// this.$refs.formatViewer.autoFormat();
});
},
execSave() {
const key = this.redisKey;
this.client.set(
key,
this.content
).then((reply) => {
if (reply === 'OK') {
this.initShow()
this.$message.success({
message: this.$t('message.modify_success'),
duration: 1000,
});
}
else {
this.$message.error({
message: this.$t('message.modify_failed'),
duration: 1000,
});
}
}).catch(e => {
this.$message.error(e.message);
});
},
initShortcut() {
this.$shortcut.bind('ctrl+s, ⌘+s', this.hotKeyScope, () => {
// make input blur to fill the new value
this.$refs.saveBtn.$el.focus();
this.execSave();
return false;
});
},
},
mounted() {
this.initShow();
this.initShortcut();
},
};
</script>
<style type="text/css">
.key-content-string .format-viewer-container {
min-height: calc(100vh - 253px);
}
/*text viewer box*/
.key-content-string .el-textarea textarea {
font-size: 14px;
height: calc(100vh - 286px);
}
/*not text viewer box, such as json*/
.key-content-string .text-formated-container {
box-sizing: border-box;
min-height: calc(100vh - 286px);
}
</style>