Commit f62c5d85 by Tang

feat:头部菜单列最大数修改

parent 0cb6dc32
<script> <script>
const ROW_NUM = 4 const ROW_NUM = 24;
export default { export default {
name: "HeaderDropdown", name: "HeaderDropdown",
props: { props: {
nav: Object nav: Object,
}, },
data() { data() {
return {} return {};
}, },
computed: { computed: {
rowNum() { rowNum() {
return ROW_NUM - 1 return ROW_NUM - 1;
} },
}, },
methods: { methods: {
// 目前只支持两级子代 主要是设计图布局不递归 // 目前只支持两级子代 主要是设计图布局不递归
renderDropdown() { renderDropdown() {
const children = [] const children = [];
let itemBox = [] let itemBox = [];
if (this.nav.children && this.nav.children.length > 0) { if (this.nav.children && this.nav.children.length > 0) {
this.nav.children.forEach(item => { this.nav.children.forEach((item) => {
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
if (itemBox.length !== 0) { if (itemBox.length !== 0) {
// 循环到大版块,且之前有遗留非大版块导航选项 需要先处理下非大版块导航选项列 // 循环到大版块,且之前有遗留非大版块导航选项 需要先处理下非大版块导航选项列
children.push(this.renderItemBox([...itemBox])) children.push(this.renderItemBox([...itemBox]));
itemBox = [] itemBox = [];
} }
children.push(this.renderDropdownRect(item)) children.push(this.renderDropdownRect(item));
} else { } else {
// 处理非大版块导航选项 // 处理非大版块导航选项
if (itemBox.length === this.rowNum) { if (itemBox.length === this.rowNum) {
children.push(this.renderItemBox([...itemBox, item])) children.push(this.renderItemBox([...itemBox, item]));
itemBox = [] itemBox = [];
} else { } else {
itemBox.push(item) itemBox.push(item);
} }
} }
}) });
if (itemBox.length !== 0) { if (itemBox.length !== 0) {
// 循环完之后,有遗留非大版块导航选项 也需要处理 // 循环完之后,有遗留非大版块导航选项 也需要处理
children.push(this.renderItemBox([...itemBox])) children.push(this.renderItemBox([...itemBox]));
} }
} }
return (<div class="navbar-dropdown-menu-inner"> return <div class="navbar-dropdown-menu-inner">{children}</div>;
{children}
</div>)
}, },
// 渲染一个下拉导航里的一个大板块(#1) (带children) // 渲染一个下拉导航里的一个大板块(#1) (带children)
renderDropdownRect(nav) { renderDropdownRect(nav) {
const children = [] const children = [];
let itemBox = [] let itemBox = [];
nav.children.forEach(item => { nav.children.forEach((item) => {
if (itemBox.length === this.rowNum) { if (itemBox.length === this.rowNum) {
children.push(this.renderItemBox([...itemBox, item], true)) children.push(this.renderItemBox([...itemBox, item], true));
itemBox = [] itemBox = [];
} else { } else {
itemBox.push(item) itemBox.push(item);
} }
}) });
if (itemBox.length > 0) { if (itemBox.length > 0) {
children.push(this.renderItemBox([...itemBox], true)) children.push(this.renderItemBox([...itemBox], true));
} }
return (<div class="gs-dropdown-rect"> return (
<div class="rect-title" <div class="gs-dropdown-rect">
vOn:click={() => { <div
this.$emit('itemClick', {...nav, root: {...this.nav}}) class="rect-title"
}} vOn:click={() => {
> this.$emit("itemClick", { ...nav, root: { ...this.nav } });
<span class="pointer">{nav.nameInHeaderNav ? nav.nameInHeaderNav : nav.name}</span> }}
</div> >
<div class="rect-body"> <span class="pointer">
{children} {nav.nameInHeaderNav ? nav.nameInHeaderNav : nav.name}
</span>
</div>
<div class="rect-body">{children}</div>
</div> </div>
</div>) );
}, },
// 渲染一个下拉导航里的一列 这个分为在大版块(#1)里的列 和 只是单纯的一列 // 渲染一个下拉导航里的一列 这个分为在大版块(#1)里的列 和 只是单纯的一列
renderItemBox(items, isChild = false) { renderItemBox(items, isChild = false) {
const classNames = ['gs-dropdown-col', isChild ? 'no-padding-top' : ''] const classNames = ["gs-dropdown-col", isChild ? "no-padding-top" : ""];
return (<div class={classNames.join(' ').trim()}> return (
{items.map(item => { <div class={classNames.join(" ").trim()}>
return (<div class="gs-dropdown-item"> {items.map((item) => {
<span vOn:click={() => { return (
this.$emit('itemClick', {...item, root: {...this.nav}}) <div class="gs-dropdown-item">
}} <span
vOn:click={() => {
this.$emit("itemClick", { ...item, root: { ...this.nav } });
}}
class="pointer link-item gs-hover" class="pointer link-item gs-hover"
>{item.name} >
</span> {item.name}
</div>) </span>
})} </div>
</div>) );
})}
</div>
);
}, },
}, },
render() { render() {
return ( return (
<div class="dropdown-menu w-100 gs-nav-dropdown" <div
aria-labelledby={`gs-nav-item-${this.nav.id}`}> class="dropdown-menu w-100 gs-nav-dropdown"
<div class="row title"> aria-labelledby={`gs-nav-item-${this.nav.id}`}
{this.nav.name} >
</div> <div class="row title">{this.nav.name}</div>
<div class="row"> <div class="row">{this.renderDropdown()}</div>
{this.renderDropdown()} </div>
</div> );
</div> },
) };
}
}
</script> </script>
<style lang="scss"> <style lang="scss">
...@@ -139,6 +144,7 @@ export default { ...@@ -139,6 +144,7 @@ export default {
.gs-dropdown-rect { .gs-dropdown-rect {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding-right: 14px;
margin-bottom: 20px; margin-bottom: 20px;
.rect-title { .rect-title {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment