hookehuyr

refactor: 优化页面组件和路由配置

重构了用户个人资料页、活动详情页、签到页和消息页的代码,移除了未使用的导入和调试日志。调整了路由配置,简化了消息页的UI,并优化了签到逻辑。这些改动旨在提高代码的可维护性和用户体验。
1 <!-- 1 <!--
2 * @Date: 2025-04-17 13:16:20 2 * @Date: 2025-04-17 13:16:20
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-04-21 14:56:50 4 + * @LastEditTime: 2025-04-21 15:29:42
5 * @FilePath: /mlaj-reading-club/src/components/shared/ActivityCard.vue 5 * @FilePath: /mlaj-reading-club/src/components/shared/ActivityCard.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -61,17 +61,29 @@ ...@@ -61,17 +61,29 @@
61 </div> 61 </div>
62 </div> 62 </div>
63 63
64 - <router-link :to="`/activity/${activity.id}`" 64 + <router-link v-if="!isRegistrationOpen" :to="`/activity/${activity.id}`"
65 class="mt-4 inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600"> 65 class="mt-4 inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600">
66 - {{ isPast ? '查看详情' : isRegistrationOpen ? '立即报名' : '了解更多' }} 66 + {{ isPast ? '查看详情' : '了解更多' }}
67 </router-link> 67 </router-link>
68 + <div v-else @click="handleRegistration"
69 + class="mt-4 inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600">
70 + 立即报名
71 + </div>
68 </div> 72 </div>
69 </div> 73 </div>
70 </div> 74 </div>
75 +
76 + <!-- Register Modal -->
77 + <Modal :isOpen="showRegisterModal" title="活动报名" @close="showRegisterModal = false">
78 + <form @submit.prevent="submitRegistration">
79 + <!-- Registration form fields -->
80 + </form>
81 + </Modal>
71 </template> 82 </template>
72 83
73 <script setup> 84 <script setup>
74 import { ref, computed, defineProps } from 'vue' 85 import { ref, computed, defineProps } from 'vue'
86 +import Modal from './Modal.vue'
75 87
76 const props = defineProps({ 88 const props = defineProps({
77 activity: { 89 activity: {
...@@ -136,4 +148,15 @@ const statusText = computed(() => { ...@@ -136,4 +148,15 @@ const statusText = computed(() => {
136 } 148 }
137 return ''; 149 return '';
138 }); 150 });
151 +
152 +const showRegisterModal = ref(false)
153 +
154 +const handleRegistration = () => {
155 + showRegisterModal.value = true
156 +}
157 +
158 +const submitRegistration = async () => {
159 + // TODO: Implement registration submission
160 + showRegisterModal.value = false
161 +}
139 </script> 162 </script>
......
1 /* 1 /*
2 * @Date: 2025-04-17 14:26:17 2 * @Date: 2025-04-17 14:26:17
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-04-21 13:26:32 4 + * @LastEditTime: 2025-04-21 15:07:36
5 * @FilePath: /mlaj-reading-club/src/main.js 5 * @FilePath: /mlaj-reading-club/src/main.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -27,8 +27,8 @@ const router = createRouter({ ...@@ -27,8 +27,8 @@ const router = createRouter({
27 { path: '/create-activity', component: () => import('./pages/CreateActivity.vue') }, 27 { path: '/create-activity', component: () => import('./pages/CreateActivity.vue') },
28 { path: '/profile', component: () => import('./pages/UserProfile.vue') }, 28 { path: '/profile', component: () => import('./pages/UserProfile.vue') },
29 { path: '/registration/:activityId', component: () => import('./pages/Registration.vue') }, 29 { path: '/registration/:activityId', component: () => import('./pages/Registration.vue') },
30 - { path: '/check-in/:activityId', component: () => import('./pages/CheckIn.vue') }, 30 + { path: '/check-in/:id', component: () => import('./pages/CheckIn.vue') },
31 - { path: '/messages/:activityId', component: () => import('./pages/Messages.vue') }, 31 + { path: '/messages', component: () => import('./pages/Messages.vue') },
32 { path: '/:pathMatch(.*)*', redirect: '/' } 32 { path: '/:pathMatch(.*)*', redirect: '/' }
33 ] 33 ]
34 }) 34 })
......
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
231 </div> 231 </div>
232 <div class="mt-2 flex items-center"> 232 <div class="mt-2 flex items-center">
233 <span class="text-sm text-green-700 mr-2">报名状态:</span> 233 <span class="text-sm text-green-700 mr-2">报名状态:</span>
234 - <span :class="registrationStatusBadge.class">{{ registrationStatusBadge.text 234 + <span :class="registrationStatusBadge?.class">{{ registrationStatusBadge?.text
235 }}</span> 235 }}</span>
236 </div> 236 </div>
237 </div> 237 </div>
...@@ -271,13 +271,10 @@ ...@@ -271,13 +271,10 @@
271 </template> 271 </template>
272 272
273 <!-- Register Modal --> 273 <!-- Register Modal -->
274 - <Modal v-if="showRegisterModal" @close="showRegisterModal = false"> 274 + <Modal :isOpen="showRegisterModal" title="活动报名" @close="showRegisterModal = false">
275 - <template #title>活动报名</template>
276 - <template #content>
277 <form @submit.prevent="submitRegistration"> 275 <form @submit.prevent="submitRegistration">
278 <!-- Registration form fields --> 276 <!-- Registration form fields -->
279 </form> 277 </form>
280 - </template>
281 </Modal> 278 </Modal>
282 </div> 279 </div>
283 </template> 280 </template>
......
...@@ -261,6 +261,7 @@ import { useRoute, useRouter } from 'vue-router' ...@@ -261,6 +261,7 @@ import { useRoute, useRouter } from 'vue-router'
261 import activitiesData from '../data/activities.json' 261 import activitiesData from '../data/activities.json'
262 import registrationsData from '../data/registrations.json' 262 import registrationsData from '../data/registrations.json'
263 import usersData from '../data/users.json' 263 import usersData from '../data/users.json'
264 +import checkinsData from '../data/checkins.json'
264 import Button from '../components/shared/Button.vue' 265 import Button from '../components/shared/Button.vue'
265 266
266 const route = useRoute() 267 const route = useRoute()
...@@ -268,8 +269,9 @@ const router = useRouter() ...@@ -268,8 +269,9 @@ const router = useRouter()
268 const activities = ref(activitiesData.activities) 269 const activities = ref(activitiesData.activities)
269 const registrations = ref(registrationsData.registrations) 270 const registrations = ref(registrationsData.registrations)
270 const currentUser = ref(usersData.users[0]) 271 const currentUser = ref(usersData.users[0])
272 +const checkIns = ref(checkinsData)
271 273
272 -const activityId = route.params.activityId 274 +const activityId = route.params.id
273 const activity = ref(null) 275 const activity = ref(null)
274 const loading = ref(true) 276 const loading = ref(true)
275 const error = ref(null) 277 const error = ref(null)
...@@ -303,8 +305,8 @@ const fetchData = async () => { ...@@ -303,8 +305,8 @@ const fetchData = async () => {
303 userRegistration.value = registration 305 userRegistration.value = registration
304 306
305 // Check if user already checked in 307 // Check if user already checked in
306 - const checkIn = appStore.checkIns.find( 308 + const checkIn = checkIns.value.find(
307 - check => check.activity_id === activityId && check.user_id === appStore.currentUser.id 309 + check => check.activity_id === activityId && check.user_id === currentUser.id
308 ) 310 )
309 311
310 if (checkIn) { 312 if (checkIn) {
...@@ -341,8 +343,8 @@ const handleSubmitCode = async () => { ...@@ -341,8 +343,8 @@ const handleSubmitCode = async () => {
341 try { 343 try {
342 if (inputCode.value === checkInCode.value) { 344 if (inputCode.value === checkInCode.value) {
343 const now = new Date().toISOString().replace('T', ' ').substring(0, 19) 345 const now = new Date().toISOString().replace('T', ' ').substring(0, 19)
344 - const checkInResult = await appStore.addCheckIn({ 346 + const checkInResult = await addCheckIn({
345 - user_id: appStore.currentUser.id, 347 + user_id: currentUser.id,
346 activity_id: activityId, 348 activity_id: activityId,
347 check_in_time: now, 349 check_in_time: now,
348 status: 'checked_in' 350 status: 'checked_in'
...@@ -350,7 +352,7 @@ const handleSubmitCode = async () => { ...@@ -350,7 +352,7 @@ const handleSubmitCode = async () => {
350 352
351 if (checkInResult.success) { 353 if (checkInResult.success) {
352 userCheckIn.value = { 354 userCheckIn.value = {
353 - user_id: appStore.currentUser.id, 355 + user_id: currentUser.id,
354 activity_id: activityId, 356 activity_id: activityId,
355 check_in_time: now, 357 check_in_time: now,
356 status: 'checked_in' 358 status: 'checked_in'
...@@ -418,4 +420,33 @@ watch(countdown, (newValue) => { ...@@ -418,4 +420,33 @@ watch(countdown, (newValue) => {
418 420
419 // Initial data fetch 421 // Initial data fetch
420 onMounted(fetchData) 422 onMounted(fetchData)
423 +
424 +
425 +// 添加签到记录
426 +const addCheckIn = async (checkInData) => {
427 + try {
428 + // 模拟API调用延迟
429 + await new Promise(resolve => setTimeout(resolve, 1000))
430 +
431 + // 创建新的签到记录
432 + const newCheckIn = {
433 + id: `C${Math.floor(Math.random() * 10000).toString().padStart(4, '0')}`,
434 + activity_id: checkInData.activity_id,
435 + user_id: checkInData.user_id,
436 + checkin_time: checkInData.check_in_time,
437 + checkin_type: 'code',
438 + status: 'successful',
439 + notes: '',
440 + is_late: false
441 + }
442 +
443 + // 添加到签到记录中
444 + checkIns.value.push(newCheckIn)
445 +
446 + return { success: true }
447 + } catch (err) {
448 + console.error('Failed to add check-in:', err)
449 + return { success: false }
450 + }
451 +}
421 </script> 452 </script>
......
This diff is collapsed. Click to expand it.
...@@ -262,7 +262,6 @@ ...@@ -262,7 +262,6 @@
262 262
263 <script setup> 263 <script setup>
264 import { ref, computed, onMounted } from 'vue' 264 import { ref, computed, onMounted } from 'vue'
265 -import { useAppStore } from '../stores/app'
266 import Button from '../components/shared/Button.vue' 265 import Button from '../components/shared/Button.vue'
267 import Input from '../components/shared/Input.vue' 266 import Input from '../components/shared/Input.vue'
268 import ActivityCard from '../components/shared/ActivityCard.vue' 267 import ActivityCard from '../components/shared/ActivityCard.vue'
...@@ -351,8 +350,6 @@ onMounted(() => { ...@@ -351,8 +350,6 @@ onMounted(() => {
351 } 350 }
352 } 351 }
353 352
354 - console.warn(registrations.value);
355 - console.warn(activities.value);
356 if (currentUser.value && registrations.value && activities.value) { 353 if (currentUser.value && registrations.value && activities.value) {
357 // Filter user registrations 354 // Filter user registrations
358 const userRegs = registrations.value.filter(reg => reg.user_id === currentUser.value.id) 355 const userRegs = registrations.value.filter(reg => reg.user_id === currentUser.value.id)
......