appstore/dist/components/app-menu.js

138 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2023-12-21 13:59:15 +08:00
import { html, css, Component } from 'wkit'
import { watch } from 'wkitd'
class Aside extends Component {
static styles = [
css`
.searchbar {
padding: 0 16px;
input {
width: 100%;
height: 30px;
padding: 0 16px;
line-height: 1;
border: 1px solid var(--color-grey-1);
border-radius: 16px;
background: rgba(255, 255, 255, 0.5);
font-size: 12px;
color: inherit;
outline: none;
transition: background 0.2s ease-in-out, border-color 0.2s ease-in-out;
&:focus {
background: rgba(255, 255, 255, 1);
border-color: transparent;
}
&::placeholder {
color: var(--color-grey-2);
}
}
}
.category {
display: flex;
flex-direction: column;
gap: 6px;
margin-top: 16px;
padding-left: 16px;
list-style: none;
--wc-icon-size: 16px;
.item {
position: relative;
display: flex;
align-items: center;
height: 36px;
padding: 0 16px;
gap: 4px;
2023-12-27 18:55:01 +08:00
line-height: 1;
2023-12-21 13:59:15 +08:00
border-radius: 8px 0 0 8px;
list-style: none;
2023-12-27 18:55:01 +08:00
transition: color 0.2s ease-in-out, background 0.2s ease-in-out;
2023-12-21 13:59:15 +08:00
&:hover {
2023-12-27 18:55:01 +08:00
background: #fff;
2023-12-21 13:59:15 +08:00
}
&.active {
2023-12-27 18:55:01 +08:00
background: #fff;
color: var(--color-blue-1);
2023-12-21 13:59:15 +08:00
&::before,
&::after {
position: absolute;
right: 0;
top: -12px;
width: 12px;
height: 12px;
background: url(/assets/img/round.webp);
content: '';
}
&::after {
top: unset;
bottom: -12px;
transform: rotate(-90deg);
}
}
}
2023-12-27 18:55:01 +08:00
router-link {
flex: 1;
height: 100%;
}
2023-12-21 13:59:15 +08:00
}
`
]
2023-12-27 18:55:01 +08:00
#path = '/'
mounted() {
watch('$router.path', r => {
this.#path = r.path
this.$requestUpdate()
})
}
2023-12-21 13:59:15 +08:00
render() {
2023-12-27 18:55:01 +08:00
let path = this.#path
2023-12-28 15:48:00 +08:00
let list = this.$store.categories
let paths = list.slice(4).map(it => it.path)
2023-12-27 18:55:01 +08:00
2023-12-21 13:59:15 +08:00
return html`
<aside class="container">
<search class="searchbar">
<input placeholder="搜索应用" />
</search>
<menu class="category">
2023-12-27 18:55:01 +08:00
<li class="item ${path === '/' ? 'active' : ''}">
<wc-icon name="home"></wc-icon>
<router-link>装机必备</router-link>
</li>
2023-12-28 15:48:00 +08:00
${list.slice(1, 4).map(
2023-12-27 18:55:01 +08:00
it => html`
<li class="item ${path === it.path ? 'active' : ''}">
<wc-icon name=${it.icon}></wc-icon>
<router-link :to=${{ path: it.path }}>${it.name}</router-link>
</li>
`
)}
2023-12-28 15:48:00 +08:00
<li
class="item ${path === list[0].path || paths.includes(path)
? 'active'
: ''}"
>
2023-12-27 18:55:01 +08:00
<wc-icon name="menu"></wc-icon>
2023-12-28 15:48:00 +08:00
<router-link :to=${{ path: list[0].path }}
>${list[0].name}</router-link
>
2023-12-27 18:55:01 +08:00
</li>
2023-12-21 13:59:15 +08:00
</menu>
</aside>
`
}
}
Aside.reg('aside')