hookehuyr

feat(router): 添加活动页和活动详情页路由

新增活动页和活动详情页的路由配置,以便用户可以访问活动相关页面
1 /* 1 /*
2 * @Date: 2025-03-20 20:36:36 2 * @Date: 2025-03-20 20:36:36
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-03-20 21:16:30 4 + * @LastEditTime: 2025-03-20 21:47:32
5 * @FilePath: /mlaj/src/router/index.js 5 * @FilePath: /mlaj/src/router/index.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -44,6 +44,19 @@ const routes = [ ...@@ -44,6 +44,19 @@ const routes = [
44 component: () => import('../views/auth/RegisterPage.vue'), 44 component: () => import('../views/auth/RegisterPage.vue'),
45 meta: { title: 'Register' } 45 meta: { title: 'Register' }
46 }, 46 },
47 + {
48 + path: '/activities',
49 + name: 'Activities',
50 + component: () => import('../views/activities/ActivitiesPage.vue'),
51 + meta: { title: 'Activities' }
52 + },
53 + {
54 + path: '/activities/:id',
55 + name: 'ActivityDetail',
56 + component: () => import('../views/activities/ActivityDetailPage.vue'),
57 + props: true,
58 + meta: { title: 'Home' }
59 + },
47 ] 60 ]
48 61
49 const router = createRouter({ 62 const router = createRouter({
......
1 +<template>
2 + <AppLayout title="最新活动" :showBackButton="true" :rightContent="RightContent">
3 + <div class="bg-gradient-to-b from-green-50/70 to-white/90 min-h-screen pb-20">
4 + <!-- Top filter section -->
5 + <div class="sticky top-0 z-10 bg-white/80 backdrop-blur-sm shadow-sm">
6 + <!-- Category filters -->
7 + <div class="px-4 pt-3 pb-2 overflow-x-auto">
8 + <div class="flex space-x-6 whitespace-nowrap">
9 + <button
10 + v-for="filter in filterCategories"
11 + :key="filter"
12 + :class="[
13 + 'pb-1',
14 + activeFilter === filter
15 + ? 'text-green-600 border-b-2 border-green-600 font-medium'
16 + : 'text-gray-500'
17 + ]"
18 + @click="activeFilter = filter"
19 + >
20 + {{ filter }}
21 + </button>
22 + </div>
23 + </div>
24 +
25 + <!-- Additional filters -->
26 + <div class="px-4 py-2 flex justify-between items-center border-b border-gray-100">
27 + <div class="flex space-x-2">
28 + <div
29 + class="flex items-center px-3 py-1 bg-white/70 backdrop-blur-sm rounded-full text-sm border border-gray-200 shadow-sm"
30 + @click="showFilters = !showFilters"
31 + >
32 + <span class="text-gray-700">{{ locationFilter || '活动地点' }}</span>
33 + <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 ml-1 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
34 + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
35 + </svg>
36 + </div>
37 +
38 + <div
39 + class="flex items-center px-3 py-1 bg-white/70 backdrop-blur-sm rounded-full text-sm border border-gray-200 shadow-sm"
40 + @click="showFilters = !showFilters"
41 + >
42 + <span class="text-gray-700">{{ statusFilter || '活动状态' }}</span>
43 + <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 ml-1 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
44 + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
45 + </svg>
46 + </div>
47 + </div>
48 +
49 + <button
50 + :class="[
51 + 'p-1 rounded-lg',
52 + showFilters ? 'bg-green-100 text-green-600' : 'bg-white/70 text-gray-500'
53 + ]"
54 + @click="toggleFilters"
55 + >
56 + <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
57 + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
58 + </svg>
59 + </button>
60 + </div>
61 + </div>
62 +
63 + <!-- Filter panel -->
64 + <div v-if="showFilters" class="bg-white/90 backdrop-blur-md p-4 shadow-md">
65 + <div class="mb-4">
66 + <h3 class="font-medium text-gray-700 mb-2">活动地点</h3>
67 + <div class="flex flex-wrap gap-2">
68 + <button
69 + v-for="location in locationOptions"
70 + :key="location"
71 + :class="[
72 + 'px-3 py-1 rounded-full text-sm',
73 + (location === '全部' && !locationFilter) || locationFilter === location
74 + ? 'bg-green-100 text-green-600 border border-green-200'
75 + : 'bg-gray-100 text-gray-600 border border-gray-200'
76 + ]"
77 + @click="applyLocationFilter(location)"
78 + >
79 + {{ location }}
80 + </button>
81 + </div>
82 + </div>
83 +
84 + <div class="mb-4">
85 + <h3 class="font-medium text-gray-700 mb-2">活动状态</h3>
86 + <div class="flex flex-wrap gap-2">
87 + <button
88 + v-for="status in statusOptions"
89 + :key="status"
90 + :class="[
91 + 'px-3 py-1 rounded-full text-sm',
92 + (status === '全部' && !statusFilter) || statusFilter === status
93 + ? 'bg-green-100 text-green-600 border border-green-200'
94 + : 'bg-gray-100 text-gray-600 border border-gray-200'
95 + ]"
96 + @click="applyStatusFilter(status)"
97 + >
98 + {{ status }}
99 + </button>
100 + </div>
101 + </div>
102 +
103 + <div class="flex justify-between">
104 + <button
105 + class="px-4 py-2 text-gray-600 bg-gray-100 rounded-lg"
106 + @click="resetFilters"
107 + >
108 + 重置
109 + </button>
110 + <button
111 + class="px-4 py-2 text-white bg-green-600 rounded-lg"
112 + @click="showFilters = false"
113 + >
114 + 确认
115 + </button>
116 + </div>
117 + </div>
118 +
119 + <!-- Activity count -->
120 + <div class="px-4 py-3 text-sm text-gray-500">
121 + 共 {{ filteredActivities.length }} 个活动
122 + </div>
123 +
124 + <!-- Activity list -->
125 + <div class="px-4 pb-4 space-y-4">
126 + <template v-if="filteredActivities.length > 0">
127 + <ActivityCard
128 + v-for="activity in filteredActivities"
129 + :key="activity.id"
130 + :activity="activity"
131 + />
132 + </template>
133 + <div v-else class="flex flex-col items-center justify-center py-10">
134 + <svg xmlns="http://www.w3.org/2000/svg" class="h-16 w-16 text-gray-300" fill="none" viewBox="0 0 24 24" stroke="currentColor">
135 + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
136 + </svg>
137 + <p class="mt-4 text-gray-500">没有找到符合条件的活动</p>
138 + <button
139 + class="mt-2 px-4 py-2 text-green-600 border border-green-600 rounded-full text-sm"
140 + @click="resetFilters"
141 + >
142 + 重置筛选条件
143 + </button>
144 + </div>
145 + </div>
146 + </div>
147 + </AppLayout>
148 +</template>
149 +
150 +<script setup>
151 +import { ref, computed, defineComponent, h } from 'vue'
152 +import AppLayout from '@/components/layout/AppLayout.vue'
153 +import ActivityCard from '@/components/ui/ActivityCard.vue'
154 +import { activities } from '@/utils/mockData'
155 +
156 +// 响应式状态
157 +const activeFilter = ref('全部')
158 +const locationFilter = ref('')
159 +const statusFilter = ref('')
160 +const showFilters = ref(false)
161 +
162 +// 过滤选项
163 +const filterCategories = ['全部', '游学', '共读', '营地', '线上讲座']
164 +const locationOptions = ['全部', '线上', '北京', '上海', '广州', '成都']
165 +const statusOptions = ['全部', '活动中', '即将开始', '已结束']
166 +
167 +// 右侧内容组件
168 +const RightContent = defineComponent({
169 + setup() {
170 + return () => h('button', { class: 'p-2' }, [
171 + h('svg', {
172 + xmlns: 'http://www.w3.org/2000/svg',
173 + class: 'h-6 w-6 text-gray-700',
174 + fill: 'none',
175 + viewBox: '0 0 24 24',
176 + stroke: 'currentColor'
177 + }, [
178 + h('path', {
179 + 'stroke-linecap': 'round',
180 + 'stroke-linejoin': 'round',
181 + 'stroke-width': '2',
182 + d: 'M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z'
183 + })
184 + ])
185 + ])
186 + }
187 +})
188 +
189 +// 切换筛选面板
190 +const toggleFilters = () => {
191 + showFilters.value = !showFilters.value
192 +}
193 +
194 +// 应用地点筛选
195 +const applyLocationFilter = (location) => {
196 + locationFilter.value = location === '全部' ? '' : location
197 +}
198 +
199 +// 应用状态筛选
200 +const applyStatusFilter = (status) => {
201 + statusFilter.value = status === '全部' ? '' : status
202 +}
203 +
204 +// 重置所有筛选
205 +const resetFilters = () => {
206 + locationFilter.value = ''
207 + statusFilter.value = ''
208 + activeFilter.value = '全部'
209 + showFilters.value = false
210 +}
211 +
212 +// 计算筛选后的活动列表
213 +const filteredActivities = computed(() => {
214 + return activities.filter(activity => {
215 + // 地点筛选
216 + if (locationFilter.value && activity.location !== locationFilter.value) {
217 + return false
218 + }
219 +
220 + // 状态筛选
221 + if (statusFilter.value && activity.status !== statusFilter.value) {
222 + return false
223 + }
224 +
225 + return true
226 + })
227 +})
228 +</script>
This diff is collapsed. Click to expand it.