import { request } from './api'; /* 扫码接单(任务中心):大屏任务卡二维码 → 扫码 → 按 task_code 领取。 接单走 OPC/创业者身份:由后端按本账号 find-or-create 平台 OPC 身份后领单。 属小程序「我的」页增量,web C 端暂不做(见 小程序同步约束.md 第5节)。 */ /** 扫码领单:task_code → claimed */ export async function claimByCode(code) { return request('POST', '/api/tasks/claim-by-code', { task_code: code }, true); } /** 我的接单(已领取任务) */ export async function getMyTasks() { return request('GET', '/api/tasks/my', {}, true); } /** 任务广场(公开):已发布 + C端可见任务,登录后附带 can_accept/accept_reasons */ export async function listSquare(withAuth = false) { return request('GET', '/opc/tasks', {}, withAuth); } /** 任务详情(公开) */ export async function getTask(id, withAuth = false) { return request('GET', `/opc/tasks/${encodeURIComponent(id)}`, {}, withAuth); } /** 抢单/报名(需登录) */ export async function grabById(id) { return request('POST', `/opc/tasks/${encodeURIComponent(id)}/grab`, {}, true); } /** 解析扫码文本 → task_code:支持纯短码 / URL(?c=、?task_code=、末段) */ export function parseTaskCode(raw) { const s = (raw || '').trim(); if (!s) return ''; if (s.includes('://') || s.includes('/') || s.includes('?')) { const m = s.match(/[?&](?:c|task_code|taskCode)=([^&]+)/); if (m) return decodeURIComponent(m[1]); const seg = s.split('?')[0].split('#')[0].split('/').filter(Boolean).pop(); return (seg && /^TK-/i.test(seg)) ? seg : ''; } return s; }