feat(checkin): 支持活动打卡接口动态切换
根据 URL 参数 activityId 动态选择打卡接口: - 有 activityId 参数时使用新接口(需要 activity_id) - 无 activityId 参数时使用老接口(保持向后兼容) - 影响接口:isCheckedActivityAPI 和 checkinActivityAPI Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Showing
2 changed files
with
53 additions
and
6 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-09-04 16:44:18 | 2 | * @Date: 2025-09-04 16:44:18 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2026-02-09 16:33:11 | 4 | + * @LastEditTime: 2026-02-10 10:38:23 |
| 5 | * @FilePath: /map-demo/src/api/checkin.js | 5 | * @FilePath: /map-demo/src/api/checkin.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| 8 | import { fn, fetch } from '@/api/fn'; | 8 | import { fn, fetch } from '@/api/fn'; |
| 9 | 9 | ||
| 10 | const Api = { | 10 | const Api = { |
| 11 | - IS_CHECKED: '/srv/?f=walk&a=map_activity&t=is_checked', | 11 | + IS_CHECKED: '/srv/?f=walk&a=map&t=is_checked', |
| 12 | - CHECKIN: '/srv/?f=walk&a=map_activity&t=checkin', | 12 | + CHECKIN: '/srv/?f=walk&a=map&t=checkin', |
| 13 | + IS_CHECKED_ACTIVITY: '/srv/?f=walk&a=map_activity&t=is_checked', | ||
| 14 | + CHECKIN_ACTIVITY: '/srv/?f=walk&a=map_activity&t=checkin', | ||
| 13 | }; | 15 | }; |
| 14 | 16 | ||
| 15 | /** | 17 | /** |
| ... | @@ -34,3 +36,28 @@ export const isCheckedAPI = (params) => fn(fetch.get(Api.IS_CHECKED, params)); | ... | @@ -34,3 +36,28 @@ export const isCheckedAPI = (params) => fn(fetch.get(Api.IS_CHECKED, params)); |
| 34 | * @returns {Object} response.data - 响应数据 | 36 | * @returns {Object} response.data - 响应数据 |
| 35 | */ | 37 | */ |
| 36 | export const checkinAPI = (params) => fn(fetch.post(Api.CHECKIN, params)); | 38 | export const checkinAPI = (params) => fn(fetch.post(Api.CHECKIN, params)); |
| 39 | + | ||
| 40 | +/** | ||
| 41 | + * @description: 检查是否签到 | ||
| 42 | + * @param {*} params | ||
| 43 | + * @param {String} params.activity_id - 活动ID | ||
| 44 | + * @param {String} params.detail_id - 打卡点ID | ||
| 45 | + * @param {String} params.openid - openid | ||
| 46 | + * @returns {string} response.code - 响应状态码 | ||
| 47 | + * @returns {string} response.msg - 响应消息 | ||
| 48 | + * @returns {Object} response.data - 响应数据 | ||
| 49 | + * @returns {number} response.data.is_checked - 是否签到 | ||
| 50 | + */ | ||
| 51 | +export const isCheckedActivityAPI = (params) => fn(fetch.get(Api.IS_CHECKED_ACTIVITY, params)); | ||
| 52 | + | ||
| 53 | +/** | ||
| 54 | + * @description: 签到 | ||
| 55 | + * @param {*} params | ||
| 56 | + * @param {String} params.activity_id - 活动ID | ||
| 57 | + * @param {String} params.detail_id - 打卡点ID | ||
| 58 | + * @param {String} params.openid - openid | ||
| 59 | + * @returns {string} response.code - 响应状态码 | ||
| 60 | + * @returns {string} response.msg - 响应消息 | ||
| 61 | + * @returns {Object} response.data - 响应数据 | ||
| 62 | + */ | ||
| 63 | +export const checkinActivityAPI = (params) => fn(fetch.post(Api.CHECKIN_ACTIVITY, params)); | ... | ... |
| ... | @@ -95,7 +95,7 @@ import $ from 'jquery'; | ... | @@ -95,7 +95,7 @@ import $ from 'jquery'; |
| 95 | import AMapLoader from '@amap/amap-jsapi-loader' | 95 | import AMapLoader from '@amap/amap-jsapi-loader' |
| 96 | 96 | ||
| 97 | import { mapAPI, mapAudioAPI } from '@/api/map.js' | 97 | import { mapAPI, mapAudioAPI } from '@/api/map.js' |
| 98 | -import { isCheckedAPI, checkinAPI } from '@/api/checkin.js' | 98 | +import { isCheckedAPI, checkinAPI, isCheckedActivityAPI, checkinActivityAPI } from '@/api/checkin.js' |
| 99 | import { getAdaptiveFontSize, getAdaptivePadding, getDeviceInfo } from '@/utils/tools.js' | 99 | import { getAdaptiveFontSize, getAdaptivePadding, getDeviceInfo } from '@/utils/tools.js' |
| 100 | // 导入标签页配置和工具函数 | 100 | // 导入标签页配置和工具函数 |
| 101 | import { TAB_CONFIGS, setTabTitles, updateTabConfigsFromAPI, updateDefaultTitleFromURL } from './tab-config.js' | 101 | import { TAB_CONFIGS, setTabTitles, updateTabConfigsFromAPI, updateDefaultTitleFromURL } from './tab-config.js' |
| ... | @@ -488,9 +488,19 @@ const checkInitialCheckinStatus = async () => { | ... | @@ -488,9 +488,19 @@ const checkInitialCheckinStatus = async () => { |
| 488 | try { | 488 | try { |
| 489 | const detail_id = page_details.value.id; | 489 | const detail_id = page_details.value.id; |
| 490 | const openid = page_details.value.openid; | 490 | const openid = page_details.value.openid; |
| 491 | + const activityId = $route.query.activityId; // 从 URL 获取 activityId | ||
| 491 | 492 | ||
| 492 | if (detail_id && openid) { | 493 | if (detail_id && openid) { |
| 493 | - const res = await isCheckedAPI({ detail_id, openid }); | 494 | + let res; |
| 495 | + // 根据 URL 是否有 activityId 参数决定调用哪个接口 | ||
| 496 | + if (activityId) { | ||
| 497 | + // 有 activityId,调用新接口 | ||
| 498 | + res = await isCheckedActivityAPI({ activity_id: activityId, detail_id, openid }); | ||
| 499 | + } else { | ||
| 500 | + // 没有 activityId,调用老接口 | ||
| 501 | + res = await isCheckedAPI({ detail_id, openid }); | ||
| 502 | + } | ||
| 503 | + | ||
| 494 | if (res.code) { | 504 | if (res.code) { |
| 495 | check_in_status.value = res.data.is_checked; | 505 | check_in_status.value = res.data.is_checked; |
| 496 | } | 506 | } |
| ... | @@ -608,6 +618,7 @@ const checkIn = async () => { // 打卡 | ... | @@ -608,6 +618,7 @@ const checkIn = async () => { // 打卡 |
| 608 | 618 | ||
| 609 | const detail_id = page_details.value.id; | 619 | const detail_id = page_details.value.id; |
| 610 | const openid = page_details.value.openid; | 620 | const openid = page_details.value.openid; |
| 621 | + const activityId = $route.query.activityId; // 从 URL 获取 activityId | ||
| 611 | 622 | ||
| 612 | // 判断用户时候在范围内 | 623 | // 判断用户时候在范围内 |
| 613 | if (!checkInRange(page_details.value.current_lng, page_details.value.current_lat, page_details.value?.position)) { | 624 | if (!checkInRange(page_details.value.current_lng, page_details.value.current_lat, page_details.value?.position)) { |
| ... | @@ -619,7 +630,16 @@ const checkIn = async () => { // 打卡 | ... | @@ -619,7 +630,16 @@ const checkIn = async () => { // 打卡 |
| 619 | if (page_details.value?.position.length) { | 630 | if (page_details.value?.position.length) { |
| 620 | // emit("checkIn", {name: '打卡', point: [+page_details.value?.position[0], +page_details.value?.position[1]]}); | 631 | // emit("checkIn", {name: '打卡', point: [+page_details.value?.position[0], +page_details.value?.position[1]]}); |
| 621 | // 执行打卡操作 | 632 | // 执行打卡操作 |
| 622 | - let res = await checkinAPI({ detail_id, openid }); | 633 | + let res; |
| 634 | + // 根据 URL 是否有 activityId 参数决定调用哪个接口 | ||
| 635 | + if (activityId) { | ||
| 636 | + // 有 activityId,调用新接口 | ||
| 637 | + res = await checkinActivityAPI({ activity_id: activityId, detail_id, openid }); | ||
| 638 | + } else { | ||
| 639 | + // 没有 activityId,调用老接口 | ||
| 640 | + res = await checkinAPI({ detail_id, openid }); | ||
| 641 | + } | ||
| 642 | + | ||
| 623 | if (res.code) { | 643 | if (res.code) { |
| 624 | // 提示打卡成功 | 644 | // 提示打卡成功 |
| 625 | showDialog({ | 645 | showDialog({ | ... | ... |
-
Please register or login to post a comment