Files
training/website/src/services/enterprise.js
T
Pine 9b5eb3fbbf feat(website): API基址统一+扫码登录倒计时/失效蒙版+绑定状态修复
- 新增 services/base.js 统一 API_BASE(VITE_API_BASE 可覆盖),9 个 service 去硬编码
- 登录页去账密(手机号/微信/小程序);二维码倒计时+失效模糊蒙版+手动刷新(绝不自动刷新、失效即停轮询)
- AuthGate/Login logo 换标准 /logo.png;Profile 挂载即刷新绑定状态;Header refreshMe 同步头像
2026-08-28 17:20:31 +08:00

50 lines
2.1 KiB
JavaScript

/** 企业端(甲方企业 / service 角色)任务 Portal:发标 / 提交发布 / 竞标评审 / 验收。走 /enterprise 端点。 */
import { getToken } from '@/services/auth';
import { API_BASE } from './base';
function auth() {
const t = getToken();
return { 'Content-Type': 'application/json', ...(t ? { Authorization: `Bearer ${t}` } : {}) };
}
export async function listTasks() {
const res = await fetch(`${API_BASE}/enterprise/tasks`, { headers: auth() });
const d = await res.json().catch(() => ({}));
return res.ok ? (Array.isArray(d.items) ? d.items : []) : []; // 企业端返回已发布列表
}
export async function createTask(body) {
const res = await fetch(`${API_BASE}/enterprise/tasks`, { method: 'POST', headers: auth(), body: JSON.stringify(body) });
const d = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(d.detail || '发布失败');
return d;
}
export async function submitTask(id) {
const res = await fetch(`${API_BASE}/enterprise/tasks/${encodeURIComponent(id)}/submit`, { method: 'POST', headers: auth() });
const d = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(d.detail || '提交失败');
return d;
}
export async function listBids(id) {
const res = await fetch(`${API_BASE}/enterprise/tasks/${encodeURIComponent(id)}/bids`, { headers: auth() });
const d = await res.json().catch(() => ({}));
return res.ok ? (Array.isArray(d.items) ? d.items : []) : [];
}
export async function winBid(taskId, bidId) {
const res = await fetch(`${API_BASE}/enterprise/tasks/${encodeURIComponent(taskId)}/bids/${encodeURIComponent(bidId)}/win`, { method: 'POST', headers: auth() });
const d = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(d.detail || '评标失败');
return d;
}
export async function reviewTask(id, action) {
const res = await fetch(`${API_BASE}/enterprise/tasks/${encodeURIComponent(id)}/review`, { method: 'POST', headers: auth(), body: JSON.stringify({ action }) });
const d = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(d.detail || '验收失败');
return d;
}