Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
center-resource
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
center-resource
Commits
b9ae504c
提交
b9ae504c
authored
6月 13, 2022
作者:
matian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore:类别列表搜索修改
上级
67ac6b1a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
16 行删除
+67
-16
AppList.vue
src/components/base/AppList.vue
+1
-1
List.vue
src/modules/admin/category/views/List.vue
+66
-15
没有找到文件。
src/components/base/AppList.vue
浏览文件 @
b9ae504c
...
...
@@ -73,7 +73,7 @@ const fetchList = (isReset = false) => {
return
(
httpRequest
(
requestParams
)
.
then
((
res
:
any
)
=>
{
const
{
list
=
[],
total
=
0
}
=
callback
?
callback
(
res
.
data
)
:
res
.
data
||
{}
const
{
list
=
[],
total
=
0
}
=
callback
?
callback
(
res
.
data
,
requestParams
)
:
res
.
data
||
{}
page
.
total
=
total
dataList
.
value
=
list
})
...
...
src/modules/admin/category/views/List.vue
浏览文件 @
b9ae504c
...
...
@@ -2,7 +2,6 @@
import
Sortable
from
'sortablejs'
import
type
{
MoveEvent
,
SortableEvent
}
from
'sortablejs'
import
AddDialog
from
'../component/AddDialog.vue'
import
{
Operation
}
from
'@element-plus/icons-vue'
import
{
getCategoryList
,
delCategory
,
moveCategory
}
from
'../api'
import
{
ElMessage
,
ElMessageBox
}
from
'element-plus'
import
AppList
from
'@/components/base/AppList.vue'
...
...
@@ -98,16 +97,16 @@ const listOptions = computed(() => {
remote
:
{
httpRequest
:
getCategoryList
,
params
:
{
type
:
'tree'
,
category_name
:
''
},
callback
(
data
:
ICategory
[])
{
tableData
=
data
tableDataList
=
flatten
(
data
)
return
{
list
:
data
}
callback
(
data
:
ICategory
[],
params
:
any
)
{
const
list
=
rebuildData
(
params
.
category_name
,
data
)
tableData
=
list
tableDataList
=
flatten
(
list
)
return
{
list
}
}
},
filters
:
[{
type
:
'input'
,
prop
:
'name'
,
label
:
'类别名称:'
}],
filters
:
[{
type
:
'input'
,
prop
:
'
category_
name'
,
label
:
'类别名称:'
}],
columns
:
[
{
align
:
'center'
,
slots
:
'table-drag'
},
{
label
:
'类别名称'
,
prop
:
'category_name'
,
align
:
'center'
},
{
label
:
'类别名称'
,
prop
:
'category_name'
,
align
:
'left'
},
{
label
:
'层级'
,
prop
:
'depth'
,
align
:
'center'
},
{
label
:
'状态'
,
prop
:
'status_name'
,
align
:
'center'
},
{
label
:
'操作'
,
slots
:
'table-operate'
,
width
:
230
,
align
:
'center'
}
...
...
@@ -148,7 +147,11 @@ function useSortable() {
if
(
oldIndex
===
undefined
||
newIndex
===
undefined
||
oldIndex
===
newIndex
)
return
const
draggedRow
=
tableDataList
[
oldIndex
]
const
relatedRow
=
tableDataList
[
newIndex
]
moveCategory
({
id
:
draggedRow
.
id
,
brother_id
:
relatedRow
.
id
,
type
:
newIndex
>
oldIndex
?
'after'
:
'before'
}).
then
(()
=>
{
moveCategory
({
id
:
draggedRow
.
id
,
brother_id
:
relatedRow
.
id
,
type
:
newIndex
>
oldIndex
?
'after'
:
'before'
}).
then
(()
=>
{
// 修复拖拽后数据顺序不对的问题
if
(
oldIndex
<
newIndex
)
{
tableData
=
[]
...
...
@@ -169,17 +172,57 @@ function onExpandChange(row: ICategory, expanded: boolean) {
}
}
// 重点代码 根据name字段模糊匹配树状结构数据,最后将处理好的数据返回出来
const
rebuildData
=
(
value
:
any
,
arr
:
any
)
=>
{
if
(
!
arr
)
{
return
[]
}
let
newArr
:
any
=
[]
arr
.
forEach
((
element
:
any
)
=>
{
console
.
log
(
element
,
'element'
)
// indexOf用来判读当前节点name字段是否包含所搜索的字符串value
// 返回值:包含则返回索引值,反之返回-1
if
(
element
.
category_name
.
indexOf
(
value
)
>
-
1
)
{
const
ab
=
rebuildData
(
value
,
element
.
children
)
const
obj
=
{
...
element
,
children
:
ab
}
newArr
.
push
(
obj
)
}
else
{
// 判断当前节点知否有子节点,并且子节点中有数据,有数据继续递归查找
if
(
element
.
children
&&
element
.
children
.
length
>
0
)
{
const
ab
=
rebuildData
(
value
,
element
.
children
)
const
obj
=
{
...
element
,
children
:
ab
}
if
(
ab
&&
ab
.
length
>
0
)
{
newArr
.
push
(
obj
)
}
}
}
})
return
newArr
}
onMounted
(()
=>
{
useSortable
()
})
</
script
>
<
template
>
<AppCard
title=
"类别管理"
>
<AppList
v-bind=
"listOptions"
:has-pagination=
"false"
row-key=
"id"
ref=
"appList"
:expand-row-keys=
"expandRowKeys"
@
expand-change=
"onExpandChange"
>
<el-button
type=
"primary"
@
click=
"handleAddCategory"
>
新增类别
</el-button>
<template
#
table-drag
>
<el-icon><Operation
/></el-icon>
</
template
>
<AppList
v-bind=
"listOptions"
:has-pagination=
"false"
row-key=
"id"
ref=
"appList"
:expand-row-keys=
"expandRowKeys"
@
expand-change=
"onExpandChange"
border
stripe
>
<el-button
type=
"primary"
@
click=
"handleAddCategory"
style=
"margin-bottom: 20px"
>
新增类别
</el-button>
<template
#
table-operate=
"
{ row }">
<el-link
type=
"primary"
style=
"margin-right: 5px"
@
click=
"handleEdit(row)"
>
编辑
</el-link>
<el-link
type=
"primary"
style=
"margin-right: 5px"
@
click=
"handleAddRow(row)"
>
新增
</el-link>
...
...
@@ -187,5 +230,13 @@ onMounted(() => {
</
template
>
</AppList>
</AppCard>
<AddDialog
v-model:dialogVisible=
"dialogVisible"
@
updatePage=
"handleUpdate"
:editData=
"editData"
:isEdit=
"isEdit"
:title=
"title"
:prevCategoryName=
"prevCategoryName"
v-if=
"dialogVisible"
/>
<AddDialog
v-model:dialogVisible=
"dialogVisible"
@
updatePage=
"handleUpdate"
:editData=
"editData"
:isEdit=
"isEdit"
:title=
"title"
:prevCategoryName=
"prevCategoryName"
v-if=
"dialogVisible"
/>
</template>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论