feat: 默认手机号的填写
This commit is contained in:
@@ -104,7 +104,7 @@
|
||||
<label class="queue-field">
|
||||
<text>手机号</text>
|
||||
<input
|
||||
type="number"
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
maxlength="15"
|
||||
placeholder="请输入手机号"
|
||||
@@ -173,7 +173,7 @@
|
||||
<label class="queue-field">
|
||||
<text>手机号</text>
|
||||
<input
|
||||
type="number"
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
maxlength="15"
|
||||
placeholder="请输入手机号"
|
||||
@@ -255,6 +255,7 @@ import {
|
||||
isTimestampStale,
|
||||
resolveStatusTarget,
|
||||
} from "./utils/queueUtils.mjs";
|
||||
import { getLoginUserPhone } from "@/request/api/LoginApi";
|
||||
|
||||
const VIEW_HOME = "home";
|
||||
const VIEW_TOKEN = "token";
|
||||
@@ -271,6 +272,7 @@ const honorificOptions = [
|
||||
const viewMode = ref(VIEW_HOME);
|
||||
const activeTab = ref(TAB_TAKE);
|
||||
const currentToken = ref("");
|
||||
const loginUserPhone = ref("");
|
||||
const lookupPhone = ref("");
|
||||
const lookupError = ref("");
|
||||
const selectedProjectId = ref("");
|
||||
@@ -312,6 +314,8 @@ const tokenResource = reactive(createStatusResource());
|
||||
let statusTimer = null;
|
||||
let projectsRequestId = 0;
|
||||
let statusRequestId = 0;
|
||||
let loginUserPhoneRequested = false;
|
||||
let loginUserPhoneLoading = false;
|
||||
const statusRequestGate = createSingleFlight();
|
||||
|
||||
const selectedProject = computed(() => projectsResource.projects.find((project) => project.id === selectedProjectId.value) || null);
|
||||
@@ -373,6 +377,7 @@ onLoad((options = {}) => {
|
||||
|
||||
onShow(() => {
|
||||
if (viewMode.value === VIEW_HOME) {
|
||||
ensureLoginUserPhoneFilled();
|
||||
ensureProjectsLoaded();
|
||||
return;
|
||||
}
|
||||
@@ -419,8 +424,45 @@ const getErrorMessage = (error) => {
|
||||
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) => {
|
||||
activeTab.value = tab;
|
||||
ensureLoginUserPhoneFilled();
|
||||
if (tab === TAB_TAKE) {
|
||||
ensureProjectsLoaded();
|
||||
}
|
||||
@@ -598,7 +640,7 @@ const submitTicket = async () => {
|
||||
}
|
||||
|
||||
const resetTicketForm = () => {
|
||||
ticketForm.phone = "";
|
||||
ticketForm.phone = loginUserPhone.value || "";
|
||||
ticketForm.lastName = "";
|
||||
ticketForm.honorific = "";
|
||||
ticketForm.partySize = minPartySize.value;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const IMMINENT_PEOPLE_THRESHOLD = 50;
|
||||
|
||||
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) => {
|
||||
|
||||
Reference in New Issue
Block a user