From 983c78a2f2e62b9a8746abaf4626e58d64fed8c1 Mon Sep 17 00:00:00 2001 From: qishibo Date: Tue, 15 Sep 2020 11:01:27 +0800 Subject: [PATCH 1/2] add binary viewer --- src/components/FormatViewer.vue | 6 +++++- src/components/KeyContentString.vue | 3 +++ src/components/ViewerBinary.vue | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/components/ViewerBinary.vue diff --git a/src/components/FormatViewer.vue b/src/components/FormatViewer.vue index ae80ac692..c94dfecac 100644 --- a/src/components/FormatViewer.vue +++ b/src/components/FormatViewer.vue @@ -16,6 +16,7 @@ ref='viewer' :is='selectedView' :content='content' + :contentBuff='contentBuff' :textrows='textrows' @updateContent="$emit('update:content', $event)"> @@ -25,6 +26,7 @@ From 3b0772ed008001ea9d426398ff8ba7734887f625 Mon Sep 17 00:00:00 2001 From: qishibo Date: Sat, 3 Oct 2020 20:51:28 +0800 Subject: [PATCH 2/2] binary view support --- src/components/FormatViewer.vue | 17 ++++++----- src/components/InputBinary.vue | 42 ++++++++++++++++++++++++++++ src/components/KeyContentHash.vue | 31 ++++++++++---------- src/components/KeyContentList.vue | 17 ++++++----- src/components/KeyContentSet.vue | 29 +++++++++++-------- src/components/KeyContentString.vue | 13 +++------ src/components/KeyContentZset.vue | 33 ++++++++++++---------- src/components/KeyDetail.vue | 6 ---- src/components/ViewerBinary.vue | 20 ++++++++----- src/components/ViewerJson.vue | 2 +- src/components/ViewerText.vue | 15 ++++++++-- src/components/ViewerUnserialize.vue | 2 +- src/main.js | 4 +++ src/util.js | 21 ++++++++++++++ 14 files changed, 168 insertions(+), 84 deletions(-) create mode 100644 src/components/InputBinary.vue diff --git a/src/components/FormatViewer.vue b/src/components/FormatViewer.vue index c94dfecac..13994c8ff 100644 --- a/src/components/FormatViewer.vue +++ b/src/components/FormatViewer.vue @@ -9,14 +9,14 @@ :value="item.value"> - Hex + Hex
@@ -47,10 +47,13 @@ export default { components: {ViewerText, ViewerJson, ViewerBinary, ViewerUnserialize}, props: { float: {default: 'right'}, - content: {default: ''}, - contentBuff: {default: () => Buffer.from('')}, + content: {default: () => Buffer.from('')}, textrows: {default: 6}, - binary: {default: false}, + }, + computed: { + contentVisible() { + return this.$util.bufVisible(this.content); + }, }, methods: { autoFormat() { @@ -117,8 +120,8 @@ export default { float: right; padding: 9px 0; } - .formater-binary { - padding-left: 5px; + .formater-binary-tag { + /*padding-left: 5px;*/ color: #7ab3ef; font-size: 80%; } diff --git a/src/components/InputBinary.vue b/src/components/InputBinary.vue new file mode 100644 index 000000000..b897fe783 --- /dev/null +++ b/src/components/InputBinary.vue @@ -0,0 +1,42 @@ + + + + + diff --git a/src/components/KeyContentHash.vue b/src/components/KeyContentHash.vue index 4926b14ad..6de2ce2f0 100644 --- a/src/components/KeyContentHash.vue +++ b/src/components/KeyContentHash.vue @@ -12,12 +12,10 @@ - Hex - + - Hex @@ -43,7 +41,7 @@ width="150"> import PaginationTable from '@/components/PaginationTable'; import FormatViewer from '@/components/FormatViewer'; +import InputBinary from '@/components/InputBinary'; export default { data() { @@ -110,7 +109,7 @@ export default { loadMoreDisable: false, }; }, - components: {PaginationTable, FormatViewer}, + components: {PaginationTable, FormatViewer, InputBinary}, props: ['client', 'redisKey'], computed: { dialogTitle() { @@ -160,10 +159,10 @@ export default { for (let i = 0; i < reply.length; i += 2) { hashData.push({ - key: this.$util.bufToString(reply[i]), - value: this.$util.bufToString(reply[i + 1]), - binaryK: !this.$util.bufVisible(reply[i]), - binaryV: !this.$util.bufVisible(reply[i + 1]), + key: reply[i], + keyDisplay: this.$util.bufToString(reply[i]), + value: reply[i + 1], + valueDisplay: this.$util.bufToString(reply[i + 1]), }); } @@ -191,7 +190,7 @@ export default { }, showEditDialog(row) { this.editLineItem = row; - this.beforeEditItem = JSON.parse(JSON.stringify(row)); + this.beforeEditItem = this.$util.cloneObjWithBuff(row); this.editDialog = true; }, editLine() { @@ -208,14 +207,14 @@ export default { client.hset( key, - before.binaryK ? this.$util.xToBuffer(after.key) : after.key, - before.binaryV ? this.$util.xToBuffer(after.value) : after.value + after.key, + after.value ).then((reply) => { // edit key && key changed - if (before.key && before.key !== after.key) { + if (before.key && !before.key.equals(after.key)) { client.hdel( key, - before.binaryK ? this.$util.xToBuffer(before.key) : before.key + before.key ).then((reply) => { this.initShow(); }); @@ -239,7 +238,7 @@ export default { ).then(() => { this.client.hdel( this.redisKey, - row.binaryK ? this.$util.xToBuffer(row.key) : row.key + row.key ).then((reply) => { if (reply === 1) { this.$message.success({ diff --git a/src/components/KeyContentList.vue b/src/components/KeyContentList.vue index e2db8f85d..6cdac95e2 100644 --- a/src/components/KeyContentList.vue +++ b/src/components/KeyContentList.vue @@ -12,7 +12,6 @@ - Hex @@ -38,7 +37,7 @@ width="150"> { // reply return list length if success if (reply > 0) { @@ -168,7 +167,7 @@ export default { client.lrem( key, 1, - before.binary ? this.$util.xToBuffer(before.value) : before.value + before.value ).then((reply) => { this.initShow(); }); @@ -193,7 +192,7 @@ export default { this.client.lrem( this.redisKey, 1, - row.binary ? this.$util.xToBuffer(row.value) : row.value + row.value ).then((reply) => { if (reply === 1) { this.$message.success({ diff --git a/src/components/KeyContentSet.vue b/src/components/KeyContentSet.vue index 465765570..a4ff73028 100644 --- a/src/components/KeyContentSet.vue +++ b/src/components/KeyContentSet.vue @@ -9,11 +9,10 @@ - + - Hex - + @@ -38,7 +37,7 @@ width="150"> import PaginationTable from '@/components/PaginationTable'; +import FormatViewer from '@/components/FormatViewer'; export default { data() { @@ -96,7 +96,7 @@ export default { }; }, props: ['client', 'redisKey'], - components: {PaginationTable}, + components: {PaginationTable, FormatViewer}, computed: { dialogTitle() { return this.beforeEditItem.value ? this.$t('message.edit_line') : @@ -145,8 +145,8 @@ export default { for (const i of reply) { setData.push({ - value: this.$util.bufToString(i), - binary: !this.$util.bufVisible(i), + value: i, + valueDisplay: this.$util.bufToString(i), }); } @@ -167,9 +167,14 @@ export default { getScanMatch() { return this.filterValue ? `*${this.filterValue}*` : '*'; }, + openDialog() { + this.$nextTick(() => { + this.$refs.formatViewer.autoFormat(); + }); + }, showEditDialog(row) { this.editLineItem = row; - this.beforeEditItem = JSON.parse(JSON.stringify(row)); + this.beforeEditItem = this.$util.cloneObjWithBuff(row); this.editDialog = true; }, editLine() { @@ -180,13 +185,13 @@ export default { this.editDialog = false; - if (!after.value || before.value == after.value) { + if (!after.value || (before.value && before.value.equals(after.value))) { return; } client.sadd( key, - before.binary ? this.$util.xToBuffer(after.value) : after.value + after.value ).then((reply) => { // add success if (reply === 1) { @@ -194,7 +199,7 @@ export default { if (before.value) { client.srem( key, - before.binary ? this.$util.xToBuffer(before.value) : before.value + before.value ).then((reply) => { this.initShow(); }); @@ -226,7 +231,7 @@ export default { ).then(() => { this.client.srem( this.redisKey, - row.binary ? this.$util.xToBuffer(row.value) : row.value + row.value ).then((reply) => { if (reply === 1) { this.$message.success({ diff --git a/src/components/KeyContentString.vue b/src/components/KeyContentString.vue index 1bce27047..a6ce4caf5 100644 --- a/src/components/KeyContentString.vue +++ b/src/components/KeyContentString.vue @@ -5,9 +5,8 @@ @@ -25,8 +24,7 @@ import FormatViewer from '@/components/FormatViewer'; export default { data() { return { - content: '', - contentBuff: '', + content: Buffer.from(''), binary: false, }; }, @@ -35,10 +33,7 @@ export default { methods: { initShow() { this.client.getBuffer(this.redisKey).then((reply) => { - this.contentBuff = reply; - this.content = this.$util.bufToString(reply); - this.binary = !this.$util.bufVisible(reply); - + this.content = reply; this.$refs.formatViewer.autoFormat(); }); }, @@ -47,7 +42,7 @@ export default { this.client.set( key, - this.binary ? this.$util.xToBuffer(this.content) : this.content + this.content ).then((reply) => { if (reply === 'OK') { this.initShow() diff --git a/src/components/KeyContentZset.vue b/src/components/KeyContentZset.vue index 33b9ae1fc..b77deee19 100644 --- a/src/components/KeyContentZset.vue +++ b/src/components/KeyContentZset.vue @@ -9,15 +9,14 @@ - + - - Hex - - + + +