From 2a95c67ccca24be413c6cdc6edf6f19a746069c5 Mon Sep 17 00:00:00 2001
From: mullins <476823686@qq.com>
Date: Wed, 24 Jun 2020 12:19:26 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=AD=9B=E9=80=89=E4=BB=A5?=
=?UTF-8?q?=E5=8F=8A=E5=88=86=E4=BA=AB=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.vue | 155 +++++++++++----------
.../HMFilterDropdown/HMFilterDropdown.vue | 106 ++++++++------
src/pages/index/index.vue | 2 +
3 files changed, 145 insertions(+), 118 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 62b0b6f..380f54f 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,82 +1,91 @@
diff --git a/src/components/HMFilterDropdown/HMFilterDropdown.vue b/src/components/HMFilterDropdown/HMFilterDropdown.vue
index 69d04ac..5d3b601 100644
--- a/src/components/HMFilterDropdown/HMFilterDropdown.vue
+++ b/src/components/HMFilterDropdown/HMFilterDropdown.vue
@@ -210,33 +210,33 @@ export default {
componentTop: 0, // 组件top
isReadNewSelect: false,
on: [1, 0, 0, 0, 0],
- selectedData: {}
+ selectedData: {},
}
},
props: {
filterData: {
value: Array,
- default: []
+ default: [],
},
defaultSelected: {
value: Array,
- default: []
+ default: [],
},
updateMenuName: {
value: Boolean,
- default: true
+ default: true,
},
dataFormat: {
value: String,
- default: 'Array'
- }
+ default: 'Array',
+ },
},
watch: {
filterData: {
handler () {
this.initMenu() // filterData重新赋值初始化菜单
},
- immediate: true
+ immediate: true,
},
defaultSelected (newVal) {
if (newVal.length === 0) {
@@ -245,7 +245,7 @@ export default {
this.defaultActive = JSON.parse(JSON.stringify(newVal))
this.activeMenuArr = JSON.parse(JSON.stringify(newVal))
this.shadowActiveMenuArr = JSON.parse(JSON.stringify(newVal))
- }
+ },
},
methods: {
initMenu () {
@@ -257,7 +257,7 @@ export default {
// 如果没有设置name,则取第一个菜单作为menu.name,filter类型则将"筛选"作为menu.name
name: tmpitem.name || (tmpitem.type === 'filter' ? '筛选' : tmpitem.submenu[0].name),
type: tmpitem.type,
- isNoPull: tmpitem.isNoPull
+ isNoPull: tmpitem.isNoPull,
})
// 初始化选中项数组-ui状态
tmpMenuActiveArr.push(this.processActive(tmpitem))
@@ -290,41 +290,41 @@ export default {
this.$forceUpdate()
},
// 选中
- selectHierarchyMenu (page_index, level1_index, level2_index, level3_index) {
+ selectHierarchyMenu (pageIndex, level1Index, level2Index, level3Index) {
// 读取记录
- if (level1_index != null && level2_index == null && level3_index == null && this.shadowActiveMenuArr[page_index][0] === level1_index) {
- this.activeMenuArr.splice(page_index, 1, JSON.parse(JSON.stringify(this.shadowActiveMenuArr[page_index])))
+ if (level1Index != null && level2Index == null && level3Index == null && this.shadowActiveMenuArr[pageIndex][0] === level1Index) {
+ this.activeMenuArr.splice(pageIndex, 1, JSON.parse(JSON.stringify(this.shadowActiveMenuArr[pageIndex])))
} else {
- this.activeMenuArr[page_index].splice(0, 1, level1_index);
- (level2_index != null || this.activeMenuArr[page_index].length >= 2) && this.activeMenuArr[page_index].splice(1, 1, level2_index) || this.activeMenuArr[page_index].splice(1, 1);
- (level3_index != null || this.activeMenuArr[page_index].length >= 3) && this.activeMenuArr[page_index].splice(2, 1, level3_index) || this.activeMenuArr[page_index].splice(2, 1)
+ this.activeMenuArr[pageIndex].splice(0, 1, level1Index);
+ (level2Index != null || this.activeMenuArr[pageIndex].length >= 2) && (this.activeMenuArr[pageIndex].splice(1, 1, level2Index) || this.activeMenuArr[pageIndex].splice(1, 1));
+ (level3Index != null || this.activeMenuArr[pageIndex].length >= 3) && (this.activeMenuArr[pageIndex].splice(2, 1, level3Index) || this.activeMenuArr[pageIndex].splice(2, 1))
}
// 写入结果
- if (level3_index != null || level2_index != null || (level1_index != null && this.subData[page_index].submenu[level1_index].submenu.length == 0)
+ if (level3Index != null || level2Index != null || (level1Index != null && this.subData[pageIndex].submenu[level1Index].submenu.length === 0)
) {
- const sub = this.subData[page_index].submenu[level1_index].submenu[level2_index]
- this.shadowActiveMenuArr[page_index] = JSON.parse(JSON.stringify(this.activeMenuArr[page_index]))
+ // const sub = this.subData[pageIndex].submenu[level1Index].submenu[level2Index]
+ this.shadowActiveMenuArr[pageIndex] = JSON.parse(JSON.stringify(this.activeMenuArr[pageIndex]))
this.togglePage(this.showPage)
}
},
// 写入结果,筛选
- setFilterData (page_index) {
- this.shadowActiveMenuArr[page_index] = JSON.parse(JSON.stringify(this.activeMenuArr[page_index]))
+ setFilterData (pageIndex) {
+ this.shadowActiveMenuArr[pageIndex] = JSON.parse(JSON.stringify(this.activeMenuArr[pageIndex]))
this.togglePage(this.showPage)
},
// 重置结果和ui,筛选
- resetFilterData (page_index) {
+ resetFilterData (pageIndex) {
const tmpArr = []
- let level = this.shadowActiveMenuArr[page_index].length
+ let level = this.shadowActiveMenuArr[pageIndex].length
while (level > 0) {
tmpArr.push([])
- const box = this.subData[page_index].submenu[level - 1].submenu
+ const box = this.subData[pageIndex].submenu[level - 1].submenu
for (let i = 0; i < box.length; i++) {
- this.subData[page_index].submenu[level - 1].submenu[i].selected = false
+ this.subData[pageIndex].submenu[level - 1].submenu[i].selected = false
}
level--
}
- this.activeMenuArr[page_index] = JSON.parse(JSON.stringify(tmpArr))
+ this.activeMenuArr[pageIndex] = JSON.parse(JSON.stringify(tmpArr))
this.$forceUpdate()
},
// 选中筛选类label-UI状态
@@ -372,7 +372,10 @@ export default {
this.$forceUpdate()
},
// 菜单开关
- togglePage (index, isRequest = true) {
+ togglePage (index, isRequest = true) {
+ if (!isRequest && this.maskVisibility) {
+ return
+ }
if (index === this.showPage) {
this.hidePageLayer(true, isRequest)
this.hideMask()
@@ -391,12 +394,14 @@ export default {
},
showAll () {
this.on = [1, 0, 0, 0, 0]
+ this.showPage = -1
+ console.log('showPage-', this.showPage)
// 输出
this.$emit('search', {
index: {},
value: {},
on: this.on,
- selectedData: this.selectedData
+ selectedData: this.selectedData,
})
},
// hide遮罩层
@@ -416,17 +421,17 @@ export default {
})
},
// hide菜单页
- hidePageLayer (isAnimation,isRequset = true) {
+ hidePageLayer (isAnimation, isRequset = true) {
this.triangleDeg[this.showPage] = 0
const tmpIndex = this.showPage
if (isAnimation) {
setTimeout(() => {
this.pageState.splice(tmpIndex, 1, false)
- }, 200)
- // debugger
- if(isRequset){
- this.confirm()
- }
+ }, 200)
+ // debugger
+ if (isRequset) {
+ this.confirm()
+ }
} else {
this.pageState.splice(tmpIndex, 1, false)
}
@@ -478,13 +483,24 @@ export default {
}
index[i] = item
})
- // 输出
- this.$emit('search', {
- index: index,
- value: value,
- on: this.on,
- selectedData: this.selectedData
- })
+ const params = this.selectedData
+ console.log('params--1', params)
+ for (const key in params) {
+ if (params[key].length === 0) {
+ delete params[key]
+ }
+ }
+ // 若筛选未选择
+ if (Object.getOwnPropertyNames(params).length === 1) {
+ this.showAll()
+ } else {
+ this.$emit('search', {
+ index: index,
+ value: value,
+ on: this.on,
+ selectedData: params,
+ })
+ }
},
// show菜单页
showPageLayer (index) {
@@ -587,7 +603,7 @@ export default {
},
// 计算菜单层级
getMaxFloor (treeData) {
- const floor = 0
+ // const floor = 0
let max = 0
function each (data, floor) {
data.forEach(e => {
@@ -603,8 +619,8 @@ export default {
},
discard () {
- }
- }
+ },
+ },
}