Files
training/miniprogram/src/utils/booking.js
T
Pine 1f65a1a7a8 feat: 培训小程序(Taro+React,OPC AI 移动端)
- 页面:首页/活动/报名/测评/政策/流程/调研/我的
- 自定义 tabBar、骨架屏、后端驱动测评
2026-08-23 22:32:39 +08:00

73 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { request, cachedRequest } from './api';
/* 报名字段契约(与 web 端 data/booking.js 保持一致,见 小程序同步约束.md) */
export const BK_STATUS_OPTIONS = ['上班族', '自由职业 / 副业', '创业者 / 小老板', '大学生 / 应届', '其他'];
export const BK_WANT_OPTIONS = ['公益课', '沙龙', '都可以'];
export const BK_TOPIC_OPTIONS = [
'副业 / 技能变现',
'民宿 / 文旅创业',
'咖啡 / 鲜花 / 农特产',
'AI 工具 / 智能体实操',
'数字游民',
'政策补贴 / 园区入驻',
'财税 / 注册合规',
'还没方向,想先了解'
];
export const BK_SOURCE_OPTIONS = ['公众号', '小红书', '短视频', '朋友推荐', '园区活动', '其他'];
/** 报名 = 需登录(Bearer token)+ 账号已绑手机号;报名信息由前端带 token 提交 */
export async function submitBooking(data) {
const r = await request('POST', '/api/bookings', data, true);
return r; // { id, username, name, auditStatus }
}
/** 可报名场次(公益课/沙龙) */
export async function getBookableEvents() {
return cachedRequest('GET', '/api/events?bookable=1');
}
/** 活动详情 */
export async function getEventDetail(id) {
return cachedRequest('GET', `/api/events/${id}`);
}
/** 我的报名列表(需登录) */
export async function getMyBookings() {
return request('GET', '/api/bookings/mine', {}, true);
}
/** 活动签到(需登录,同一报名只能签一次) */
export async function checkIn(bookingId) {
return request('POST', '/api/checkins', { bookingId }, true);
}
/* 手动解析 ISO 时间(iOS/微信对 new Date(ISO带时区) 兼容差,避免 Invalid Date */
export function parseIso(iso) {
if (!iso) return null;
const m = String(iso).match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?(?:([+-])(\d{2}):(\d{2}))?/);
if (!m) {
const d = new Date(iso);
return isNaN(d.getTime()) ? null : d;
}
const [, Y, Mo, Da, H, Mi, S, sign, oh, om] = m;
const utc = Date.UTC(+Y, +Mo - 1, +Da, +H, +Mi, +(S || 0));
const offset = sign ? (sign === '+' ? 1 : -1) * (+(oh || 0) * 60 + +(om || 0)) * 60000 : 0;
return new Date(utc - offset);
}
export function fmtEvt(iso) {
const d = parseIso(iso);
if (!d) return '';
const p = (n) => String(n).padStart(2, '0');
const week = ['日', '一', '二', '三', '四', '五', '六'][d.getDay()];
return `${d.getMonth() + 1}${d.getDate()}日 周${week} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
/** 查当前登录用户是否已报名某活动及其审核状态(详情页判断用) */
export async function getMyBookingForEvent(eventId) {
return request('GET', `/api/bookings/by-event/${eventId}`, {}, true);
}