fix: incorrect update index in list when filter on

This commit is contained in:
Lykin 2024-11-06 16:38:52 +08:00
parent b601ba255b
commit 3367f13d80
6 changed files with 34 additions and 35 deletions

View File

@ -876,6 +876,7 @@ func (b *browserService) GetKeyDetail(param types.KeyDetailParam) (resp types.JS
continue continue
} }
items = append(items, types.ListEntryItem{ items = append(items, types.ListEntryItem{
Index: len(items),
Value: val, Value: val,
}) })
if doConvert { if doConvert {
@ -1614,10 +1615,11 @@ func (b *browserService) SetListItem(param types.SetListParam) (resp types.JSRes
client, ctx := item.client, item.ctx client, ctx := item.client, item.ctx
key := strutil.DecodeRedisKey(param.Key) key := strutil.DecodeRedisKey(param.Key)
str := strutil.DecodeRedisKey(param.Value) str := strutil.DecodeRedisKey(param.Value)
index := int64(param.Index)
var replaced, removed []types.ListReplaceItem var replaced, removed []types.ListReplaceItem
if len(str) <= 0 { if len(str) <= 0 {
// remove from list // 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 { if err != nil {
resp.Msg = err.Error() resp.Msg = err.Error()
return 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()) resp.Msg = fmt.Sprintf(`save to type "%s" fail: %s`, param.Format, err.Error())
return return
} }
err = client.LSet(ctx, key, param.Index, saveStr).Err() err = client.LSet(ctx, key, index, saveStr).Err()
if err != nil { if err != nil {
resp.Msg = err.Error() resp.Msg = err.Error()
return return

View File

@ -56,7 +56,7 @@ type SetListParam struct {
Server string `json:"server"` Server string `json:"server"`
DB int `json:"db"` DB int `json:"db"`
Key any `json:"key"` Key any `json:"key"`
Index int64 `json:"index"` Index int `json:"index"`
Value any `json:"value"` Value any `json:"value"`
Format string `json:"format,omitempty"` Format string `json:"format,omitempty"`
Decode string `json:"decode,omitempty"` Decode string `json:"decode,omitempty"`

View File

@ -1,12 +1,13 @@
package types package types
type ListEntryItem struct { type ListEntryItem struct {
Index int `json:"index"`
Value any `json:"v"` Value any `json:"v"`
DisplayValue string `json:"dv,omitempty"` DisplayValue string `json:"dv,omitempty"`
} }
type ListReplaceItem struct { type ListReplaceItem struct {
Index int64 `json:"index"` Index int `json:"index"`
Value any `json:"v,omitempty"` Value any `json:"v,omitempty"`
DisplayValue string `json:"dv,omitempty"` DisplayValue string `json:"dv,omitempty"`
} }

View File

@ -107,27 +107,6 @@ func Merge[M ~map[K]V, K Hashable, V any](mapArr ...M) M {
return result 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 根据条件省略指定元素 // Omit 根据条件省略指定元素
func Omit[M ~map[K]V, K Hashable, V any](m M, omitFunc func(k K, v V) bool) (M, []K) { func Omit[M ~map[K]V, K Hashable, V any](m M, omitFunc func(k K, v V) bool) (M, []K) {
result := M{} result := M{}

View File

@ -150,7 +150,7 @@ const saveEdit = async (pos, value, decode, format) => {
server: props.name, server: props.name,
db: props.db, db: props.db,
key: keyName.value, key: keyName.value,
index, index: row.index,
value, value,
decode, decode,
format, format,
@ -180,16 +180,16 @@ const actionColumn = {
align: 'center', align: 'center',
titleAlign: 'center', titleAlign: 'center',
fixed: 'right', fixed: 'right',
render: (row, index) => { render: ({ index, v }, _) => {
return h(EditableTableColumn, { return h(EditableTableColumn, {
editing: false, editing: false,
bindKey: `#${index + 1}`, bindKey: `#${index + 1}`,
onCopy: async () => { onCopy: async () => {
copy(row.v) copy(v)
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}, },
onEdit: () => { onEdit: () => {
startEdit(index + 1, row.v) startEdit(index + 1, v)
}, },
onDelete: async () => { onDelete: async () => {
try { try {
@ -221,7 +221,7 @@ const columns = computed(() => {
width: 80, width: 80,
align: 'center', align: 'center',
titleAlign: 'center', titleAlign: 'center',
render: (row, index) => { render: ({ index }, _) => {
return index + 1 return index + 1
}, },
}, },
@ -236,7 +236,7 @@ const columns = computed(() => {
width: 80, width: 80,
align: 'center', align: 'center',
titleAlign: 'center', titleAlign: 'center',
render: (row, index) => { render: ({ index }, _) => {
if (index + 1 === currentEditRow.no) { if (index + 1 === currentEditRow.no) {
// editing row, show edit state // editing row, show edit state
return h(NIcon, { size: 16, color: 'red' }, () => h(Edit, { strokeWidth: 5 })) 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 { return {
onClick: () => { onClick: () => {
// in edit mode, switch edit row by click // in edit mode, switch edit row by click
if (inEdit.value) { if (inEdit.value) {
startEdit(index + 1, row.v) startEdit(index + 1, v)
} }
}, },
} }

View File

@ -291,9 +291,25 @@ const useTabStore = defineStore('tab', {
case 'list': // {v:string, dv:[string]}[] case 'list': // {v:string, dv:[string]}[]
tab.value = tab.value || [] tab.value = tab.value || []
if (prepend === true) { 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 { } 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) tab.length += size(entries)
break break
@ -392,6 +408,7 @@ const useTabStore = defineStore('tab', {
for (const entry of entries) { for (const entry of entries) {
if (size(tab.value) > entry.index) { if (size(tab.value) > entry.index) {
tab.value[entry.index] = { tab.value[entry.index] = {
index: entry.index,
v: entry.v, v: entry.v,
dv: entry.dv, dv: entry.dv,
} }