jscdn.ink/dist/components/header.vue

178 lines
3.4 KiB
Vue
Raw Normal View History

2022-12-29 19:05:15 +08:00
<template>
2023-02-10 18:26:10 +08:00
<div
class="common-header noselect"
:class="{ 'search-show': $store.searchShow }"
>
2022-12-29 19:05:15 +08:00
<header class="navibar">
<div class="wrapper">
2023-02-10 17:03:51 +08:00
<a class="logo"><img src="/assets/logo.svg" /></a>
2022-12-29 19:05:15 +08:00
<nav class="navi">
<router-link to="/"> </router-link>
<router-link to="/request"> </router-link>
<router-link to="/about"> </router-link>
</nav>
</div>
</header>
<cite class="banner">
<p>
我们的目标是提供这样一个仓库让它尽可能全面收录优秀的支持ESM访问的开源库并免费为之提供
CDN加速服务使之有更好的访问速度和稳定的环境
</p>
<p>同时我们也提供自主提交开源库的收录(前提是在npm上发布的)</p>
</cite>
2023-02-13 23:00:15 +08:00
<wc-input
class="search"
no-border
placeholder="请输入开源库的名字~~"
clearable
v-model="input"
@submit="search"
/>
2022-12-29 19:05:15 +08:00
</div>
</template>
<script>
2023-02-13 23:00:15 +08:00
import fetch from '@/lib/fetch'
2022-12-29 19:05:15 +08:00
export default {
2023-02-13 23:00:15 +08:00
data() {
return { input: '' }
},
2023-03-09 19:42:22 +08:00
watch: {
'$store.searchInput'(v) {
this.input = v
this.search()
}
},
2023-02-13 23:00:15 +08:00
methods: {
search() {
let id = this.input.trim()
if (id) {
fetch('/package/search/' + encodeURIComponent(id)).then(r => {
let dict = { versions: [], id }
let last = null
for (let it of r.data) {
let tmp = it.split('/')
2023-04-20 14:34:35 +08:00
let v = tmp.shift()
let n = tmp.join('/')
if (last === v) {
dict[last].push(n)
2023-02-13 23:00:15 +08:00
} else {
2023-04-20 14:34:35 +08:00
last = v
dict.versions.push(last)
dict[last] = [n]
2023-02-13 23:00:15 +08:00
}
}
this.$store.result = dict
})
} else {
this.$store.result = null
}
}
}
2022-12-29 19:05:15 +08:00
}
</script>
<style lang="scss">
.common-header {
flex-shrink: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
width: 100%;
height: 240px;
background: var(--color-red-1);
color: #fff;
.wrapper {
display: flex;
width: 1024px;
justify-content: space-between;
align-items: center;
}
.navibar {
height: 36px;
margin-top: 24px;
.logo {
font-weight: bold;
font-size: 26px;
2023-02-10 17:03:51 +08:00
img {
display: block;
height: 36px;
}
2022-12-29 19:05:15 +08:00
}
.navi {
display: flex;
align-items: center;
font-size: 16px;
a {
margin: 0 16px;
padding: 3px 6px;
border-radius: 4px;
transition: background 0.2s ease-in-out;
&:hover {
background: rgba(255, 255, 255, 0.3);
}
&.router-link-active {
text-decoration: underline;
}
}
}
}
.banner {
width: 640px;
text-align: center;
}
.search {
display: none;
width: 520px;
color: #fff;
--bg-color: rgba(0, 0, 0, 0.3);
}
&.search-show {
height: 320px;
.search {
display: inline-block;
}
}
&::after {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 48px;
font-size: 16px;
background: rgba(0, 0, 0, 0.1);
content: '免费、快速、开放的 CDN 服务';
}
}
2023-01-06 19:07:48 +08:00
@media screen and (max-width: 1024px) {
.common-header {
.navibar {
width: 100%;
padding: 0 32px;
}
.wrapper {
width: 100%;
}
}
}
2022-12-29 19:05:15 +08:00
</style>