From 3367f13d80d331c7ca8aecfff64ce80bae2db722 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:38:52 +0800 Subject: [PATCH] fix: incorrect update index in list when filter on --- backend/services/browser_service.go | 6 ++++-- backend/types/js_resp.go | 2 +- backend/types/redis_wrapper.go | 3 ++- backend/utils/map/map_util.go | 21 ------------------- .../content_value/ContentValueList.vue | 16 +++++++------- frontend/src/stores/tab.js | 21 +++++++++++++++++-- 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/backend/services/browser_service.go b/backend/services/browser_service.go index 4c48abc..50508c6 100644 --- a/backend/services/browser_service.go +++ b/backend/services/browser_service.go @@ -876,6 +876,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS continue } items = append(items, types.ListEntryItem{ + Index: len(items), Value: val, }) if doConvert { @@ -1614,10 +1615,11 @@ func (b *browserService) SetListItem(param types.SetListParam) (resp types.JSRes client, ctx := item.client, item.ctx key := strutil.DecodeRedisKey(param.Key) str := strutil.DecodeRedisKey(param.Value) + index := int64(param.Index) var replaced, removed []types.ListReplaceItem if len(str) <= 0 { // remove from list - err = client.LSet(ctx, key, param.Index, "---VALUE_REMOVED_BY_TINY_RDM---").Err() + err = client.LSet(ctx, key, index, "---VALUE_REMOVED_BY_TINY_RDM---").Err() if err != nil { resp.Msg = err.Error() return @@ -1639,7 +1641,7 @@ func (b *browserService) SetListItem(param types.SetListParam) (resp types.JSRes resp.Msg = fmt.Sprintf(`save to type "%s" fail: %s`, param.Format, err.Error()) return } - err = client.LSet(ctx, key, param.Index, saveStr).Err() + err = client.LSet(ctx, key, index, saveStr).Err() if err != nil { resp.Msg = err.Error() return diff --git a/backend/types/js_resp.go b/backend/types/js_resp.go index 04e1f96..43e9555 100644 --- a/backend/types/js_resp.go +++ b/backend/types/js_resp.go @@ -56,7 +56,7 @@ type SetListParam struct { Server string `json:"server"` DB int `json:"db"` Key any `json:"key"` - Index int64 `json:"index"` + Index int `json:"index"` Value any `json:"value"` Format string `json:"format,omitempty"` Decode string `json:"decode,omitempty"` diff --git a/backend/types/redis_wrapper.go b/backend/types/redis_wrapper.go index 803ec7c..102fd81 100644 --- a/backend/types/redis_wrapper.go +++ b/backend/types/redis_wrapper.go @@ -1,12 +1,13 @@ package types type ListEntryItem struct { + Index int `json:"index"` Value any `json:"v"` DisplayValue string `json:"dv,omitempty"` } type ListReplaceItem struct { - Index int64 `json:"index"` + Index int `json:"index"` Value any `json:"v,omitempty"` DisplayValue string `json:"dv,omitempty"` } diff --git a/backend/utils/map/map_util.go b/backend/utils/map/map_util.go index 7ca710f..eb816c4 100644 --- a/backend/utils/map/map_util.go +++ b/backend/utils/map/map_util.go @@ -107,27 +107,6 @@ func Merge[M ~map[K]V, K Hashable, V any](mapArr ...M) M { return result } -// DeepMerge 深度递归覆盖src值到dst中 -// 将返回新的值 -func DeepMerge[M ~map[K]any, K Hashable](src1, src2 M) M { - out := make(map[K]any, len(src1)) - for k, v := range src1 { - out[k] = v - } - for k, v := range src2 { - if v1, ok := v.(map[K]any); ok { - if bv, ok := out[k]; ok { - if bv1, ok := bv.(map[K]any); ok { - out[k] = DeepMerge(bv1, v1) - continue - } - } - } - out[k] = v - } - return out -} - // Omit 根据条件省略指定元素 func Omit[M ~map[K]V, K Hashable, V any](m M, omitFunc func(k K, v V) bool) (M, []K) { result := M{} diff --git a/frontend/src/components/content_value/ContentValueList.vue b/frontend/src/components/content_value/ContentValueList.vue index 859205e..c4a96c1 100644 --- a/frontend/src/components/content_value/ContentValueList.vue +++ b/frontend/src/components/content_value/ContentValueList.vue @@ -150,7 +150,7 @@ const saveEdit = async (pos, value, decode, format) => { server: props.name, db: props.db, key: keyName.value, - index, + index: row.index, value, decode, format, @@ -180,16 +180,16 @@ const actionColumn = { align: 'center', titleAlign: 'center', fixed: 'right', - render: (row, index) => { + render: ({ index, v }, _) => { return h(EditableTableColumn, { editing: false, bindKey: `#${index + 1}`, onCopy: async () => { - copy(row.v) + copy(v) $message.success(i18n.t('interface.copy_succ')) }, onEdit: () => { - startEdit(index + 1, row.v) + startEdit(index + 1, v) }, onDelete: async () => { try { @@ -221,7 +221,7 @@ const columns = computed(() => { width: 80, align: 'center', titleAlign: 'center', - render: (row, index) => { + render: ({ index }, _) => { return index + 1 }, }, @@ -236,7 +236,7 @@ const columns = computed(() => { width: 80, align: 'center', titleAlign: 'center', - render: (row, index) => { + render: ({ index }, _) => { if (index + 1 === currentEditRow.no) { // editing row, show edit state return h(NIcon, { size: 16, color: 'red' }, () => h(Edit, { strokeWidth: 5 })) @@ -250,12 +250,12 @@ const columns = computed(() => { } }) -const rowProps = (row, index) => { +const rowProps = ({ index, v }, _) => { return { onClick: () => { // in edit mode, switch edit row by click if (inEdit.value) { - startEdit(index + 1, row.v) + startEdit(index + 1, v) } }, } diff --git a/frontend/src/stores/tab.js b/frontend/src/stores/tab.js index 875ab08..1ab2dda 100644 --- a/frontend/src/stores/tab.js +++ b/frontend/src/stores/tab.js @@ -291,9 +291,25 @@ const useTabStore = defineStore('tab', { case 'list': // {v:string, dv:[string]}[] tab.value = tab.value || [] if (prepend === true) { - tab.value = [...entries, ...tab.value] + const originList = tab.value + const list = [] + let starIndex = 0 + for (const entry of entries) { + entry.index = starIndex++ + list.push(entry) + } + for (const entry of originList) { + entry.index = starIndex++ + list.push(entry) + } + tab.value = list } else { - tab.value.push(...entries) + const list = tab.value + let starIndex = list.length + for (const entry of entries) { + entry.index = starIndex++ + list.push(entry) + } } tab.length += size(entries) break @@ -392,6 +408,7 @@ const useTabStore = defineStore('tab', { for (const entry of entries) { if (size(tab.value) > entry.index) { tab.value[entry.index] = { + index: entry.index, v: entry.v, dv: entry.dv, }