feat: 默认手机号的填写

This commit is contained in:
2026-07-28 11:30:21 +08:00
parent 010f238b65
commit 51e7277ab1
2 changed files with 47 additions and 4 deletions

View File

@@ -104,7 +104,7 @@
<label class="queue-field"> <label class="queue-field">
<text>手机号</text> <text>手机号</text>
<input <input
type="number" type="text"
inputmode="numeric" inputmode="numeric"
maxlength="15" maxlength="15"
placeholder="请输入手机号" placeholder="请输入手机号"
@@ -173,7 +173,7 @@
<label class="queue-field"> <label class="queue-field">
<text>手机号</text> <text>手机号</text>
<input <input
type="number" type="text"
inputmode="numeric" inputmode="numeric"
maxlength="15" maxlength="15"
placeholder="请输入手机号" placeholder="请输入手机号"
@@ -255,6 +255,7 @@ import {
isTimestampStale, isTimestampStale,
resolveStatusTarget, resolveStatusTarget,
} from "./utils/queueUtils.mjs"; } from "./utils/queueUtils.mjs";
import { getLoginUserPhone } from "@/request/api/LoginApi";
const VIEW_HOME = "home"; const VIEW_HOME = "home";
const VIEW_TOKEN = "token"; const VIEW_TOKEN = "token";
@@ -271,6 +272,7 @@ const honorificOptions = [
const viewMode = ref(VIEW_HOME); const viewMode = ref(VIEW_HOME);
const activeTab = ref(TAB_TAKE); const activeTab = ref(TAB_TAKE);
const currentToken = ref(""); const currentToken = ref("");
const loginUserPhone = ref("");
const lookupPhone = ref(""); const lookupPhone = ref("");
const lookupError = ref(""); const lookupError = ref("");
const selectedProjectId = ref(""); const selectedProjectId = ref("");
@@ -312,6 +314,8 @@ const tokenResource = reactive(createStatusResource());
let statusTimer = null; let statusTimer = null;
let projectsRequestId = 0; let projectsRequestId = 0;
let statusRequestId = 0; let statusRequestId = 0;
let loginUserPhoneRequested = false;
let loginUserPhoneLoading = false;
const statusRequestGate = createSingleFlight(); const statusRequestGate = createSingleFlight();
const selectedProject = computed(() => projectsResource.projects.find((project) => project.id === selectedProjectId.value) || null); const selectedProject = computed(() => projectsResource.projects.find((project) => project.id === selectedProjectId.value) || null);
@@ -373,6 +377,7 @@ onLoad((options = {}) => {
onShow(() => { onShow(() => {
if (viewMode.value === VIEW_HOME) { if (viewMode.value === VIEW_HOME) {
ensureLoginUserPhoneFilled();
ensureProjectsLoaded(); ensureProjectsLoaded();
return; return;
} }
@@ -419,8 +424,45 @@ const getErrorMessage = (error) => {
return error.message || "暂时无法更新数据。"; return error.message || "暂时无法更新数据。";
} }
const ensureLoginUserPhoneFilled = async () => {
if (loginUserPhoneRequested || loginUserPhoneLoading) return;
loginUserPhoneLoading = true;
try {
const response = await getLoginUserPhone();
if (response?.code !== undefined && response.code !== 0) return;
const phone = formatLoginUserPhone(response?.data ?? response);
if (!phone) return;
loginUserPhone.value = phone;
applyDefaultLoginUserPhone(phone);
} catch {
} finally {
loginUserPhoneRequested = true;
loginUserPhoneLoading = false;
}
}
const applyDefaultLoginUserPhone = (phone) => {
if (!phone) return;
if (!ticketForm.phone) {
ticketForm.phone = phone;
phoneError.value = "";
clearCreateIntent();
}
if (!lookupPhone.value) {
lookupPhone.value = phone;
lookupError.value = "";
}
}
const formatLoginUserPhone = (value) => {
const text = String(value ?? "").trim();
if (text.includes("*")) return text;
return digitsOnly(text);
}
const setActiveTab = (tab) => { const setActiveTab = (tab) => {
activeTab.value = tab; activeTab.value = tab;
ensureLoginUserPhoneFilled();
if (tab === TAB_TAKE) { if (tab === TAB_TAKE) {
ensureProjectsLoaded(); ensureProjectsLoaded();
} }
@@ -598,7 +640,7 @@ const submitTicket = async () => {
} }
const resetTicketForm = () => { const resetTicketForm = () => {
ticketForm.phone = ""; ticketForm.phone = loginUserPhone.value || "";
ticketForm.lastName = ""; ticketForm.lastName = "";
ticketForm.honorific = ""; ticketForm.honorific = "";
ticketForm.partySize = minPartySize.value; ticketForm.partySize = minPartySize.value;

View File

@@ -1,7 +1,8 @@
const IMMINENT_PEOPLE_THRESHOLD = 50; const IMMINENT_PEOPLE_THRESHOLD = 50;
export const isPhoneInputValid = (value) => { export const isPhoneInputValid = (value) => {
return /^\d{7,15}$/.test(String(value ?? "").trim()); const text = String(value ?? "").trim();
return /^\d{7,15}$/.test(text) || /^\d{3}\*{4}\d{4}$/.test(text);
}; };
export const digitsOnly = (value) => { export const digitsOnly = (value) => {