Skip to content

Commit 3ff989f

Browse files
committed
feat: upate index page button
1 parent 8c4e4be commit 3ff989f

File tree

4 files changed

+161
-17
lines changed

4 files changed

+161
-17
lines changed

docs/index.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ information: |
1212
1313
actions:
1414
-
15-
- text: 报名参赛
16-
type: primary
17-
size: large
18-
click: signup
15+
- usevue: true
16+
# - text: 报名参赛
17+
# type: primary
18+
# size: large
19+
# click: signup
1920

2021
-
2122
- text: 快速入门

docs/index.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,39 @@ export function signup() {
1313
let matchname = 'newstar';
1414
let origin = 'endbm.ichunqiu.com';
1515
let protocol = 'https:';
16-
window.open(`${protocol}//${origin}` + `/${year + matchname}`);
16+
let path = '/' + year + matchname;
17+
window.open(`${protocol}//${origin}` + path);
18+
}
19+
}
20+
21+
export function participate(channel: 'internal' | 'external') {
22+
let time = {
23+
'internal': [new Date('2024-09-23 09:00:00').getTime(), new Date('2024-10-27 21:00:00').getTime()],
24+
'external': [new Date('2024-09-30 09:00:00').getTime(), new Date('2024-11-03 21:00:00').getTime()],
25+
}
26+
let now = Date.now();
27+
let gap = time[channel];
28+
if (!gap) return
29+
if (now < gap[0]) {
30+
ElMessage({
31+
message: '比赛尚未开始!',
32+
type: 'warning',
33+
})
34+
} else if (now > gap[1]) {
35+
ElMessage({
36+
message: '比赛已结束!',
37+
type: 'warning',
38+
})
39+
} else {
40+
let year = new Date(gap[0]).getFullYear();
41+
let matchname = 'newstar';
42+
let origin = 'match.ichunqiu.com';
43+
let protocol = 'https:';
44+
let tail = {
45+
'internal': 'xn',
46+
'external': 'gk',
47+
}[channel];
48+
let path = '/' + year + matchname + tail;
49+
window.open(`${protocol}//${origin}` + path);
1750
}
1851
}

docs/index.vue

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<script lang="ts" setup>
2+
import { ElButton, ElButtonGroup } from "element-plus";
3+
import { ElPopover } from "element-plus";
4+
import IndexButton from "@/components/IndexButton.vue";
5+
import { signup, participate } from "./index";
6+
</script>
7+
8+
<template>
9+
<div>
10+
<ElPopover placement="bottom" :width="270" trigger="click">
11+
<template #reference>
12+
<IndexButton text="报名参赛" type="primary" size="large" />
13+
</template>
14+
<div style="text-align: center">
15+
<ElButtonGroup class="group">
16+
<ElButton style="width: 100%" @click="signup()">立即报名</ElButton>
17+
</ElButtonGroup>
18+
<ElButtonGroup class="group">
19+
<div class="group-label"><label>参赛</label></div>
20+
<ElButton @click="participate('external')">公开赛道</ElButton>
21+
<ElButton @click="participate('internal')">校内赛道</ElButton>
22+
</ElButtonGroup>
23+
</div>
24+
</ElPopover>
25+
</div>
26+
</template>
27+
28+
<style lang="scss" scoped>
29+
.top-radius {
30+
border-radius: var(--el-border-radius-base) var(--el-border-radius-base) 0 0 !important;
31+
}
32+
.bottom-radius {
33+
border-radius: 0 0 var(--el-border-radius-base) var(--el-border-radius-base) !important;
34+
}
35+
36+
.group {
37+
display: flex;
38+
width: 100%;
39+
& + .group > * {
40+
&:first-child {
41+
border-top-left-radius: 0;
42+
}
43+
&:last-child {
44+
border-top-right-radius: 0;
45+
}
46+
}
47+
&:not(:last-child) > * {
48+
&:first-child {
49+
border-bottom-left-radius: 0;
50+
}
51+
&:last-child {
52+
border-bottom-right-radius: 0;
53+
}
54+
}
55+
56+
& + .group {
57+
margin-top: -1px;
58+
}
59+
}
60+
61+
.group-label {
62+
--label-bg-color: var(--el-color-info-light-9);
63+
.dark & {
64+
--label-bg-color: var(--el-color-info-light-8);
65+
}
66+
width: 100%;
67+
padding: 8px 15px;
68+
background-color: var(--label-bg-color);
69+
color: var(--el-color-info);
70+
border: var(--el-border);
71+
border-color: var(--el-border-color);
72+
border-radius: 0 0 0 var(--el-border-radius-base);
73+
border-right: none;
74+
align-items: center;
75+
box-sizing: border-box;
76+
display: inline-flex;
77+
font-weight: var(--el-button-font-weight);
78+
height: 32px;
79+
justify-content: center;
80+
line-height: 1;
81+
outline: none;
82+
text-align: center;
83+
transition: 0.1s;
84+
-webkit-user-select: none;
85+
-moz-user-select: none;
86+
user-select: none;
87+
vertical-align: middle;
88+
white-space: nowrap;
89+
}
90+
91+
.no-top-border {
92+
border-top: none;
93+
}
94+
95+
.no-bottom-border {
96+
border-bottom: none;
97+
}
98+
</style>

theme/layouts/LayoutIndex.vue

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { useSidebar } from "vitepress/theme";
1313
import { VPButton } from "vitepress/theme";
1414
import IndexButton from "@/components/IndexButton.vue";
1515
16+
import IndexAction from "@docs/index.vue";
17+
1618
// const { isOpen: isSidebarOpen, open: openSidebar, close: closeSidebar } = useSidebar();
1719
1820
// const route = useRoute();
@@ -28,10 +30,10 @@ const heroImageSlotExists = computed(() => !!slots["home-hero-image"]);
2830
provide("hero-image-slot-exists", heroImageSlotExists);
2931
3032
function fmtActionsArray(actions: any) {
31-
if(!actions) return [];
32-
if(!Array.isArray(actions)) actions = [actions];
33-
if(actions.length === 0) return [];
34-
if(!Array.isArray(actions[0])) actions = [actions];
33+
if (!actions) return [];
34+
if (!Array.isArray(actions)) actions = [actions];
35+
if (actions.length === 0) return [];
36+
if (!Array.isArray(actions[0])) actions = [actions];
3537
return actions;
3638
}
3739
</script>
@@ -50,12 +52,22 @@ function fmtActionsArray(actions: any) {
5052
<div class="layout-center">
5153
<div class="grid-box">
5254
<div class="content-logo"></div>
53-
<div class="content-description">
55+
<div class="content-information">
5456
<p v-for="line of frontmatter.information.split(/\r?\n/)" v-html="line"></p>
5557
</div>
5658
<div class="content-action">
5759
<span class="action-line" v-for="a of fmtActionsArray(frontmatter.actions)">
58-
<IndexButton v-for="b of a" :text="b.text" :link="b.link" :type="b.type" :size="b.size" :click="b.click" />
60+
<span v-for="b of a">
61+
<IndexAction v-if="b.usevue" />
62+
<IndexButton
63+
v-else
64+
:text="b.text"
65+
:link="b.link"
66+
:type="b.type"
67+
:size="b.size"
68+
:click="b.click"
69+
/>
70+
</span>
5971
</span>
6072
</div>
6173
<Content class="content-doc" />
@@ -91,11 +103,11 @@ function fmtActionsArray(actions: any) {
91103
background-position: center;
92104
}
93105
94-
.content-description {
106+
.content-information {
95107
font-size: 1.3rem;
96108
font-weight: 300;
97109
p {
98-
margin: .5rem 0;
110+
margin: 0.5rem 0;
99111
}
100112
}
101113
@@ -121,10 +133,10 @@ function fmtActionsArray(actions: any) {
121133
}
122134
123135
.layout-index-footer {
124-
// position: absolute;
125-
// bottom: 0;
126-
// left: 0;
127-
// width: 100%;
136+
// position: absolute;
137+
// bottom: 0;
138+
// left: 0;
139+
// width: 100%;
128140
border: none;
129141
}
130142
</style>

0 commit comments

Comments
 (0)