|
@@ -2,11 +2,6 @@ import { defineStore } from 'pinia'
|
|
|
import { ref } from 'vue'
|
|
import { ref } from 'vue'
|
|
|
import * as api from '@/api/screen'
|
|
import * as api from '@/api/screen'
|
|
|
|
|
|
|
|
-// ===== 开发调试开关 =====
|
|
|
|
|
-// 正式联调前请关闭此开关
|
|
|
|
|
-const ENABLE_APPOINTMENT_CONFIRM_MOCK = import.meta.env.DEV
|
|
|
|
|
-// =========================
|
|
|
|
|
-
|
|
|
|
|
export const useVisitorStore = defineStore('visitor', () => {
|
|
export const useVisitorStore = defineStore('visitor', () => {
|
|
|
// 当前访客信息
|
|
// 当前访客信息
|
|
|
const currentVisitor = ref({
|
|
const currentVisitor = ref({
|
|
@@ -27,12 +22,13 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
visitorName: '',
|
|
visitorName: '',
|
|
|
mobile: '',
|
|
mobile: '',
|
|
|
idCardNo: '',
|
|
idCardNo: '',
|
|
|
- visitType: 'walk_in',
|
|
|
|
|
- registerType: 'manual',
|
|
|
|
|
|
|
+ visitType: 'WALK_IN',
|
|
|
|
|
+ registerType: 'SCREEN',
|
|
|
visitorSource: '',
|
|
visitorSource: '',
|
|
|
visitReason: '',
|
|
visitReason: '',
|
|
|
visitedPerson: '',
|
|
visitedPerson: '',
|
|
|
- appointmentNo: ''
|
|
|
|
|
|
|
+ appointmentNo: '',
|
|
|
|
|
+ visitorPhoto: ''
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// 登记表单验证状态
|
|
// 登记表单验证状态
|
|
@@ -54,7 +50,7 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
currentVisitor.value = {
|
|
currentVisitor.value = {
|
|
|
...currentVisitor.value,
|
|
...currentVisitor.value,
|
|
|
name: info.name || '',
|
|
name: info.name || '',
|
|
|
- idCardNo: info.idCardNo || '',
|
|
|
|
|
|
|
+ idCardNo: info.idCardNo || info.idNum || '',
|
|
|
gender: info.gender || '',
|
|
gender: info.gender || '',
|
|
|
nation: info.nation || '',
|
|
nation: info.nation || '',
|
|
|
address: info.address || '',
|
|
address: info.address || '',
|
|
@@ -62,7 +58,8 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
}
|
|
}
|
|
|
// 自动填充登记信息
|
|
// 自动填充登记信息
|
|
|
registrationInfo.value.visitorName = info.name || ''
|
|
registrationInfo.value.visitorName = info.name || ''
|
|
|
- registrationInfo.value.idCardNo = info.idCardNo || ''
|
|
|
|
|
|
|
+ registrationInfo.value.idCardNo = info.idCardNo || info.idNum || ''
|
|
|
|
|
+ registrationInfo.value.visitorPhoto = info.photoUrl || ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function setMobile(mobile) {
|
|
function setMobile(mobile) {
|
|
@@ -91,60 +88,50 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
return Object.keys(errors).length === 0
|
|
return Object.keys(errors).length === 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async function queryAppointment(mobile) {
|
|
|
|
|
|
|
+ async function queryAppointment(params) {
|
|
|
|
|
+ // #region debug log
|
|
|
|
|
+ fetch('http://127.0.0.1:7870/ingest/a84a825e-d3f2-4bc0-99e9-e2345f77eced',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'ce506e'},body:JSON.stringify({sessionId:'ce506e',location:'visitor.js:queryAppointment',message:'store queryAppointment 被调用',data:{params},timestamp:Date.now()})}).catch(()=>{});
|
|
|
|
|
+ // #endregion
|
|
|
try {
|
|
try {
|
|
|
- const res = await api.queryAppointment({ mobile })
|
|
|
|
|
- appointmentInfo.value = res
|
|
|
|
|
- return res
|
|
|
|
|
|
|
+ const res = await api.queryAppointment(params)
|
|
|
|
|
+ // #region debug log
|
|
|
|
|
+ fetch('http://127.0.0.1:7870/ingest/a84a825e-d3f2-4bc0-99e9-e2345f77eced',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'ce506e'},body:JSON.stringify({sessionId:'ce506e',location:'visitor.js:queryAppointment',message:'api.queryAppointment 返回',data:{res},timestamp:Date.now()})}).catch(()=>{});
|
|
|
|
|
+ // #endregion
|
|
|
|
|
+ // 后端返回格式: { code, msg, data }
|
|
|
|
|
+ appointmentInfo.value = res.data || res
|
|
|
|
|
+ // #region debug log
|
|
|
|
|
+ fetch('http://127.0.0.1:7870/ingest/a84a825e-d3f2-4bc0-99e9-e2345f77eced',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'ce506e'},body:JSON.stringify({sessionId:'ce506e',location:'visitor.js:queryAppointment',message:'设置 appointmentInfo',data:{appointmentInfo:appointmentInfo.value},timestamp:Date.now()})}).catch(()=>{});
|
|
|
|
|
+ // #endregion
|
|
|
|
|
+ return appointmentInfo.value
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
|
|
+ // #region debug log
|
|
|
|
|
+ fetch('http://127.0.0.1:7870/ingest/a84a825e-d3f2-4bc0-99e9-e2345f77eced',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'ce506e'},body:JSON.stringify({sessionId:'ce506e',location:'visitor.js:queryAppointment',message:'api.queryAppointment 异常',data:{error:e?.message||e},timestamp:Date.now()})}).catch(()=>{});
|
|
|
|
|
+ // #endregion
|
|
|
appointmentInfo.value = null
|
|
appointmentInfo.value = null
|
|
|
throw e
|
|
throw e
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Mock 预约数据,用于开发调试
|
|
|
|
|
- * 正式联调前请关闭 ENABLE_APPOINTMENT_CONFIRM_MOCK
|
|
|
|
|
- */
|
|
|
|
|
- function setMockAppointment(mobile = '13800000000') {
|
|
|
|
|
- const now = new Date()
|
|
|
|
|
- const dateStr = now.toISOString().slice(0, 10)
|
|
|
|
|
- const timeStr = `${dateStr} 14:30`
|
|
|
|
|
- const mockData = {
|
|
|
|
|
- appointmentNo: `APT${dateStr.replace(/-/g, '')}0001`,
|
|
|
|
|
- visitorName: '张三',
|
|
|
|
|
- mobile: mobile,
|
|
|
|
|
- idCardNo: '320***********1234',
|
|
|
|
|
- visitedPerson: '李经理',
|
|
|
|
|
- visitedDepartment: '综合管理部',
|
|
|
|
|
- appointmentTime: timeStr,
|
|
|
|
|
- visitPurpose: '业务拜访',
|
|
|
|
|
- companyName: '测试单位',
|
|
|
|
|
- remark: '前端调试预约数据',
|
|
|
|
|
- _isMock: true
|
|
|
|
|
- }
|
|
|
|
|
- appointmentInfo.value = mockData
|
|
|
|
|
- return mockData
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
async function submitRegistration() {
|
|
async function submitRegistration() {
|
|
|
if (!validateForm()) {
|
|
if (!validateForm()) {
|
|
|
throw new Error('表单验证失败')
|
|
throw new Error('表单验证失败')
|
|
|
}
|
|
}
|
|
|
- // 开发环境:Mock 提交成功
|
|
|
|
|
- if (import.meta.env.DEV) {
|
|
|
|
|
- const now = new Date()
|
|
|
|
|
- const pad = (n) => String(n).padStart(2, '0')
|
|
|
|
|
- const dateTime = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
|
|
|
|
|
- registrationInfo.value = {
|
|
|
|
|
- ...registrationInfo.value,
|
|
|
|
|
- registerTime: dateTime
|
|
|
|
|
- }
|
|
|
|
|
- return registrationInfo.value
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 开发环境:Mock 提交成功(临时禁用以测试后端接口)
|
|
|
|
|
+ // TODO: 正式部署时删除此 Mock 逻辑
|
|
|
|
|
+ // if (import.meta.env.DEV) {
|
|
|
|
|
+ // const now = new Date()
|
|
|
|
|
+ // const pad = (n) => String(n).padStart(2, '0')
|
|
|
|
|
+ // const dateTime = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
|
|
|
|
|
+ // registrationInfo.value = {
|
|
|
|
|
+ // ...registrationInfo.value,
|
|
|
|
|
+ // registerTime: dateTime
|
|
|
|
|
+ // }
|
|
|
|
|
+ // return registrationInfo.value
|
|
|
|
|
+ // }
|
|
|
try {
|
|
try {
|
|
|
const res = await api.submitVisitorRegistration(registrationInfo.value)
|
|
const res = await api.submitVisitorRegistration(registrationInfo.value)
|
|
|
- return res
|
|
|
|
|
|
|
+ // 后端返回格式: { code, msg, data }
|
|
|
|
|
+ return res.data || res
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
throw e
|
|
throw e
|
|
|
}
|
|
}
|
|
@@ -153,8 +140,16 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
async function readIdCard() {
|
|
async function readIdCard() {
|
|
|
try {
|
|
try {
|
|
|
const res = await api.readIdCard()
|
|
const res = await api.readIdCard()
|
|
|
- setIdCardInfo(res)
|
|
|
|
|
- return res
|
|
|
|
|
|
|
+ // 后端返回格式: { code, msg, data }
|
|
|
|
|
+ const info = res.data || res
|
|
|
|
|
+
|
|
|
|
|
+ // 验证身份证数据是否有效
|
|
|
|
|
+ if (!info.name || !info.idCardNo) {
|
|
|
|
|
+ throw new Error('未检测到身份证,请确认身份证已放置正确')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setIdCardInfo(info)
|
|
|
|
|
+ return info
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
throw e
|
|
throw e
|
|
|
}
|
|
}
|
|
@@ -175,12 +170,13 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
visitorName: '',
|
|
visitorName: '',
|
|
|
mobile: '',
|
|
mobile: '',
|
|
|
idCardNo: '',
|
|
idCardNo: '',
|
|
|
- visitType: 'walk_in',
|
|
|
|
|
- registerType: 'manual',
|
|
|
|
|
|
|
+ visitType: 'WALK_IN',
|
|
|
|
|
+ registerType: 'SCREEN',
|
|
|
visitorSource: '',
|
|
visitorSource: '',
|
|
|
visitReason: '',
|
|
visitReason: '',
|
|
|
visitedPerson: '',
|
|
visitedPerson: '',
|
|
|
- appointmentNo: ''
|
|
|
|
|
|
|
+ appointmentNo: '',
|
|
|
|
|
+ visitorPhoto: ''
|
|
|
}
|
|
}
|
|
|
formErrors.value = {}
|
|
formErrors.value = {}
|
|
|
}
|
|
}
|
|
@@ -198,9 +194,6 @@ export const useVisitorStore = defineStore('visitor', () => {
|
|
|
queryAppointment,
|
|
queryAppointment,
|
|
|
submitRegistration,
|
|
submitRegistration,
|
|
|
readIdCard,
|
|
readIdCard,
|
|
|
- clearVisitorData,
|
|
|
|
|
- // 开发调试用
|
|
|
|
|
- setMockAppointment,
|
|
|
|
|
- ENABLE_APPOINTMENT_CONFIRM_MOCK
|
|
|
|
|
|
|
+ clearVisitorData
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|