feat:接口调整
This commit is contained in:
@@ -53,10 +53,10 @@
|
||||
<view v-if="createdTicket" class="queue-ticket-created">
|
||||
<text class="queue-ticket-created__eyebrow">取号成功</text>
|
||||
<text class="queue-ticket-created__label">您的排队号码</text>
|
||||
<text class="queue-ticket-created__number">{{ createdTicket.ticket.ticket_number }}</text>
|
||||
<text class="queue-ticket-created__number">{{ createdTicket.ticket.ticketNumber }}</text>
|
||||
<text class="queue-ticket-created__meta">
|
||||
{{ createdTicketProjectName }} · {{ createdTicket.ticket.party_size }} 人 · 手机号尾号
|
||||
{{ createdTicket.ticket.phone_last4 || "未返回" }}
|
||||
{{ createdTicketProjectName }} · {{ createdTicket.ticket.partySize }} 人 · 手机号尾号
|
||||
{{ createdTicket.ticket.phoneLast4 || "未返回" }}
|
||||
</text>
|
||||
<button
|
||||
v-if="createdTicketTarget"
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
import { normalizePublicStatus } from "../../utils/queueUtils.mjs";
|
||||
|
||||
// Weixin production builds must add this host to the mini program request domain allowlist.
|
||||
const QUEUE_API_BASE = "https://queue.nianxx.cn";
|
||||
|
||||
export class QueueApiError extends Error {
|
||||
constructor(message, status = 0, details = null, code = "") {
|
||||
super(message);
|
||||
this.name = "QueueApiError";
|
||||
this.status = status;
|
||||
this.details = details;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
const getQueueApiBase = () => {
|
||||
return QUEUE_API_BASE;
|
||||
}
|
||||
|
||||
const normalizePath = (path) => {
|
||||
if (/^https?:\/\//.test(path)) return path;
|
||||
return `${getQueueApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
||||
}
|
||||
|
||||
const getErrorPayload = (body) => {
|
||||
if (!body || typeof body !== "object") return {};
|
||||
const nested = body.error && typeof body.error === "object" ? body.error : {};
|
||||
return {
|
||||
message: body.message || nested.message || body.error || body.detail,
|
||||
code: nested.code || body.code,
|
||||
details: nested.details || body.details || body,
|
||||
};
|
||||
}
|
||||
|
||||
const queueRequest = (path, { method = "GET", data, header = {} } = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: normalizePath(path),
|
||||
method,
|
||||
data,
|
||||
header: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
...header,
|
||||
},
|
||||
success: (res) => {
|
||||
const statusCode = res.statusCode || 0;
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
resolve(res.data || {});
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = getErrorPayload(res.data);
|
||||
reject(new QueueApiError(
|
||||
typeof payload.message === "string" ? payload.message : `请求未成功(${statusCode})`,
|
||||
statusCode,
|
||||
payload.details,
|
||||
typeof payload.code === "string" ? payload.code : "",
|
||||
));
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(new QueueApiError("无法连接服务,请检查网络后重试。", 0, err));
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const newQueueIdempotencyKey = () => {
|
||||
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
return `mini-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||
}
|
||||
|
||||
export const getPublicProjects = () => {
|
||||
return queueRequest("/api/public/projects").then((response) => ({
|
||||
projects: Array.isArray(response.projects) ? response.projects : [],
|
||||
}));
|
||||
}
|
||||
|
||||
export const createPublicTicket = (projectId, payload, idempotencyKey = newQueueIdempotencyKey()) => {
|
||||
return queueRequest(`/api/public/projects/${encodeURIComponent(projectId)}/tickets`, {
|
||||
method: "POST",
|
||||
data: payload,
|
||||
header: {
|
||||
"Idempotency-Key": idempotencyKey,
|
||||
},
|
||||
}).then((response) => ({
|
||||
...response,
|
||||
ticket: normalizePublicStatus(response.ticket),
|
||||
}));
|
||||
}
|
||||
|
||||
export const getPublicStatus = (token) => {
|
||||
return queueRequest(`/api/public/status/${encodeURIComponent(token)}`)
|
||||
.then((response) => normalizePublicStatus(response));
|
||||
}
|
||||
|
||||
export const searchPublicStatusByPhone = (phone) => {
|
||||
return queueRequest("/api/public/status/search", {
|
||||
method: "POST",
|
||||
data: { phone },
|
||||
}).then((response) => ({
|
||||
tickets: Array.isArray(response.tickets) ? response.tickets.map(normalizePublicStatus) : [],
|
||||
}));
|
||||
}
|
||||
@@ -72,11 +72,8 @@ export const getPublicProjects = () => {
|
||||
export const createPublicTicket = (projectId, payload, idempotencyKey = newQueueIdempotencyKey()) => {
|
||||
return normalizeQueueRequest(request.post("/hotelBiz/visitorQueue/tickets", {
|
||||
project_id: projectId,
|
||||
idempotency_key: idempotencyKey,
|
||||
...payload,
|
||||
}, {
|
||||
header: {
|
||||
"Idempotency-Key": idempotencyKey,
|
||||
},
|
||||
})).then((response) => ({
|
||||
...response,
|
||||
ticket: normalizePublicStatus(response.ticket),
|
||||
|
||||
@@ -62,9 +62,9 @@
|
||||
hover-class="none"
|
||||
@click="selectedTicketKey = buildTicketKey(ticket)"
|
||||
>
|
||||
<text>{{ ticket.project_name }}</text>
|
||||
<text class="queue-result-option__number">{{ ticket.ticket_number }}</text>
|
||||
<text class="queue-result-option__meta">{{ ticket.party_size }} 人 · {{ visitorStatusMeta(ticket.status, ticket.people_ahead).label }}</text>
|
||||
<text>{{ ticket.projectName }}</text>
|
||||
<text class="queue-result-option__number">{{ ticket.ticketNumber }}</text>
|
||||
<text class="queue-result-option__meta">{{ ticket.partySize }} 人 · {{ visitorStatusMeta(ticket.status, ticket.peopleAhead).label }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user