对接访客邀请接口

This commit is contained in:
zhouyanli
2026-05-06 17:48:39 +08:00
parent e030bb7cb9
commit 231de9cde8
13 changed files with 1028 additions and 1037 deletions

View File

@@ -1,113 +0,0 @@
<template>
<canvas v-if="value" :type="type" :style="{width: size + 'px', height: size + 'px'}" :canvas-id="canvasId"
ref="qrcodeCanvas"></canvas>
</template>
<script setup>
import {
ref,
onMounted,
watch
} from 'vue';
import {
uqrcode
} from 'uqrcodejs'
const props = defineProps({
// 二维码内容(必填,如链接/文本)
value: {
type: String,
default: ''
},
// 尺寸默认300px
size: {
type: [Number, String],
default: 300
},
// 二维码颜色
color: {
type: String,
default: '#000000'
},
// 背景色
backgroundColor: {
type: String,
default: '#ffffff'
},
// logo图片地址
logo: {
type: String,
default: ''
},
// logo大小占二维码比例
logoSize: {
type: Number,
default: 0.2
},
// canvas 类型(小程序需指定)
type: {
type: String,
default: '2d'
},
// canvas ID避免重复
canvasId: {
type: String,
default: 'uqrcode'
}
});
const emit = defineEmits(['success', 'fail']);
const qrcodeCanvas = ref(null);
// 生成二维码核心方法
const createQRCode = async () => {
if (!props.value) return;
try {
// 引入uQRCode核心库
const uQRCode = require('uqrcodejs');
// 获取canvas上下文
const query = uni.createSelectorQuery().in(getCurrentInstance());
const res = await query.select(`#${props.canvasId}`).fields({
node: true,
size: true
}).exec();
const canvas = res[0].node;
const ctx = canvas.getContext('2d');
// 设置canvas尺寸
const dpr = uni.getSystemInfoSync().pixelRatio;
canvas.width = props.size * dpr;
canvas.height = props.size * dpr;
ctx.scale(dpr, dpr);
// 生成二维码
await uQRCode.default.draw({
canvas: canvas,
componentInstance: getCurrentInstance(),
text: props.value,
width: props.size,
color: props.color,
background: props.backgroundColor,
logo: props.logo,
logoSize: props.logoSize
});
// 生成临时图片(可选,用于分享/保存)
uni.canvasToTempFilePath({
canvasId: props.canvasId,
success: (res) => emit('success', res.tempFilePath),
fail: (err) => emit('fail', err)
}, getCurrentInstance());
} catch (err) {
emit('fail', err);
}
};
// 监听value变化重新生成
watch(() => props.value, () => createQRCode(), {
immediate: true
});
onMounted(() => createQRCode());
</script>

View File

@@ -122,6 +122,14 @@ export const getRepairDetail = (data) =>{
export const getVisitorList = (data) =>{
return get('/api/visitor/list',data)
}
// 获取详情信息
export const getVisitorDetail = (id) =>{
return get(`/api/visitor/${id}`)
}
// 新增访客
export const addVisitorData = (data) =>{
return post("/api/visitor", data)
}
// 通用文件上传
export const uploadImage = () => {

View File

@@ -2,7 +2,7 @@ let baseUrl = '';
if (process.env.NODE_ENV === 'development') {
// http://192.168.1.215
// http://192.168.0.224
baseUrl = 'http://192.168.1.215:8080'; // 开发环境
baseUrl = 'http://192.168.0.239:8080'; // 开发环境
} else {
baseUrl = 'http://192.168.0.224:8080'; // 生产环境
}

View File

@@ -13,28 +13,26 @@
<!-- 手机号输入框 -->
<view class="input-item">
<view class="input-icon">
<image src="http://47.104.199.163:9090/images/login/phone.png" mode="" style="height: 100%;width: 100%;"></image>
<image src="http://47.104.199.163:9090/images/login/phone.png" mode=""
style="height: 100%;width: 100%;"></image>
</view>
<uni-easyinput class="input-content" type="number" v-model="phoneNumber"
placeholder="请输入手机号" :inputBorder="false" maxlength="11" :placeholderStyle="placeholderStyle">
<uni-easyinput class="input-content" type="number" v-model="phoneNumber" placeholder="请输入手机号"
:inputBorder="false" maxlength="11" :placeholderStyle="placeholderStyle">
</uni-easyinput>
</view>
<!-- 验证码输入 + 获取验证码按钮 -->
<view class="input-item verify-item">
<view class="input-icon">
<image src="http://47.104.199.163:9090/images/login/code.png" mode="" style="height: 100%;width: 100%;"></image>
<image src="http://47.104.199.163:9090/images/login/code.png" mode="" style="height: 100%;width: 100%;">
</image>
<!-- <uni-icons type="locked" size="24" color="#999"></uni-icons> -->
</view>
<uni-easyinput class="input-content verify-input" type="number" v-model="verifyCode"
placeholder="请输入验证码" :inputBorder="false" maxlength="6" :placeholderStyle="placeholderStyle">
<uni-easyinput class="input-content verify-input" type="number" v-model="verifyCode" placeholder="请输入验证码"
:inputBorder="false" maxlength="6" :placeholderStyle="placeholderStyle">
</uni-easyinput>
<button
class="get-verify-btn"
:disabled="!canGetVerify || countDown > 0"
@click="getVerifyCode"
>
<button class="get-verify-btn" :disabled="!canGetVerify || countDown > 0" @click="getVerifyCode">
{{ countDown > 0 ? `${countDown}s后重新获取` : '获取验证码' }}
</button>
</view>
@@ -42,11 +40,12 @@
<!-- 账号输入框 -->
<view class="input-item">
<view class="input-icon">
<image src="http://47.104.199.163:9090/images/login/account.png" mode="" style="height: 100%;width: 100%;"></image>
<image src="http://47.104.199.163:9090/images/login/account.png" mode=""
style="height: 100%;width: 100%;"></image>
<!-- <uni-icons type="person" size="24" color="#999"></uni-icons> -->
</view>
<uni-easyinput class="input-content" type="text" v-model="account"
placeholder="请输入账号" :inputBorder="false" :placeholderStyle="placeholderStyle">
<uni-easyinput class="input-content" type="text" v-model="account" placeholder="请输入账号" :inputBorder="false"
:placeholderStyle="placeholderStyle">
</uni-easyinput>
</view>
@@ -54,40 +53,28 @@
<!-- 密码输入框 -->
<view class="input-item">
<view class="input-icon">
<image src="http://47.104.199.163:9090/images/login/password.png" mode="" style="height: 100%;width: 100%;"></image>
<image src="http://47.104.199.163:9090/images/login/password.png" mode=""
style="height: 100%;width: 100%;"></image>
<!-- <uni-icons type="locked" size="24" color="#999"></uni-icons> -->
</view>
<uni-easyinput class="input-content" type="password" v-model="password"
placeholder="请输入密码" :inputBorder="false" :placeholderStyle="placeholderStyle" >
<uni-easyinput class="input-content" type="password" v-model="password" placeholder="请输入密码"
:inputBorder="false" :placeholderStyle="placeholderStyle">
</uni-easyinput>
</view>
<!-- 协议勾选 -->
<view class="agreement-item">
<view @click="toggleAgreement">
<uni-icons
type="checkbox-filled"
size="24"
color="#007aff"
v-if="agreeAgreement"
></uni-icons>
<uni-icons
type="checkbox"
size="24"
color="#999"
v-else
></uni-icons>
<uni-icons type="checkbox-filled" size="24" color="#007aff" v-if="agreeAgreement"></uni-icons>
<uni-icons type="checkbox" size="24" color="#999" v-else></uni-icons>
</view>
<text class="agreement-text" @click.stop="goToPrivacy">我已阅读并同意<text class="agreePrivacy">用户隐私政策</text></text>
<text class="agreement-text" @click.stop="goToPrivacy">我已阅读并同意<text
class="agreePrivacy">用户隐私政策</text></text>
</view>
<!-- 立即注册按钮 -->
<button
class="register-btn"
:disabled="!canRegister"
@click="handleRegister"
>
<button class="register-btn" :disabled="!canRegister" @click="handleRegister">
立即注册
</button>
@@ -99,8 +86,15 @@
</template>
<script setup>
import { ref, computed, onUnmounted } from 'vue';
import {getRegisterUser,getSendCode} from '../api/api.js'
import {
ref,
computed,
onUnmounted
} from 'vue';
import {
getRegisterUser,
getSendCode
} from '../api/api.js'
// ========== 响应式数据 ==========
// 表单数据
@@ -129,11 +123,11 @@ const canRegister = computed(() => {
const accountReg = /^.{4,20}$/; // 账号4-20位
const pwdReg = /^.{6,16}$/; // 密码6-16位
return phoneReg.test(phoneNumber.value)
&& verifyReg.test(verifyCode.value)
&& accountReg.test(account.value)
&& pwdReg.test(password.value)
&& agreeAgreement.value;
return phoneReg.test(phoneNumber.value) &&
verifyReg.test(verifyCode.value) &&
accountReg.test(account.value) &&
pwdReg.test(password.value) &&
agreeAgreement.value;
});
// ========== 方法 ==========
@@ -198,7 +192,10 @@ const getVerifyCode = () => {
// 处理注册逻辑
const handleRegister = () => {
if (!canRegister.value) return;
uni.showLoading({ title: '注册中...', mask: true });
uni.showLoading({
title: '注册中...',
mask: true
});
let params = {
phone: phoneNumber.value,
smsCode: verifyCode.value,
@@ -213,7 +210,9 @@ const handleRegister = () => {
icon: 'success'
});
setTimeout(() => {
uni.redirectTo({ url: '/pageSubPack/loginSub/pwd-login' });
uni.redirectTo({
url: '/pageSubPack/loginSub/pwd-login'
});
}, 1500);
} else {
@@ -255,6 +254,7 @@ onUnmounted(() => {
min-height: 100vh;
background: repeating-linear-gradient(180deg, #E2F0FF, #F6FAFF);
}
.status_bar {
height: 46px;
width: 100%;
@@ -344,6 +344,7 @@ onUnmounted(() => {
background-color: #ccc;
color: #fff;
}
.get-verify-btn::after {
border-radius: 50px;
}
@@ -361,6 +362,7 @@ onUnmounted(() => {
color: #666;
margin-left: 10rpx;
}
.agreePrivacy {
color: #2F77FD;
}
@@ -376,9 +378,11 @@ onUnmounted(() => {
font-size: 28rpx;
margin-bottom: 40rpx;
}
button:after {
border-radius: 8px;
}
.register-btn:disabled {
background-color: #99c8ff;
color: #fff;

View File

@@ -128,7 +128,7 @@ const getCommunityList = async (pageNum = 1, keyword = '') => {
const res = await getVillageList(params)
if (res.code === 200) {
const listData = res.data?.rows || res.data?.list || res.data || []
const listData = res.data || []
const total = res.data?.total || listData.length
if (pageNum === 1) {

View File

@@ -155,7 +155,7 @@ const fetchRepairList = async () => {
const res = await getQueryRepair(params);
// console.log('接口返回:', res);
if (res.code === 200) {
const list = res.data || [];
const list = res.rows || [];
repairList.value = list.map(item => {
const statusInfo = getStatusInfo(item.problemStatus);
const images = item.problemImageUrl ? item.problemImageUrl.split(',').filter(Boolean) : [];

View File

@@ -349,7 +349,7 @@ const uploadImages = async () => {
return urls
}
// ========== 表单提交 ✅ 修复:所有错误都解决 ==========
// ========== 表单提交 ==========
const submitForm = async () => {
if (!houseName.value) return uni.showToast({ title: '请选择报修房屋', icon: 'none' })
if (!projectName.value) return uni.showToast({ title: '请选择维修项目', icon: 'none' })
@@ -406,7 +406,7 @@ const submitForm = async () => {
uni.showToast({ title: res.msg || '提交失败', icon: 'none' })
}
} catch (e) {
console.error('提交异常:', e) // 看控制台真实错误
// console.error('提交异常:', e)
uni.showToast({ title: '提交失败,请检查网络或重试', icon: 'none' })
} finally {
uni.hideLoading()

View File

@@ -108,11 +108,12 @@ const selectProject = (item) => {
padding: 10px;
height: 100vh;
box-sizing: border-box;
background-color: #f9f9f9;
}
.search-bar {
display: flex;
align-items: center;
padding: 8px 10px;
padding: 15px 10px;
background: #f5f5f5;
border-radius: 6px;
margin-bottom: 10px;
@@ -128,8 +129,10 @@ const selectProject = (item) => {
.category-left {
width: 120px;
height: 100%;
background: #f8f8f8;
background: #fff;
border-radius: 6px 0 0 6px;
margin-right: 20rpx;
color: #666;
}
.category-item {
padding: 15px 10px;
@@ -138,8 +141,8 @@ const selectProject = (item) => {
border-bottom: 1px solid #eee;
}
.category-item.active {
background: #fff;
color: #007aff;
background: #f9f9f9;
color: #222;
font-weight: bold;
}
.category-right {
@@ -148,6 +151,7 @@ const selectProject = (item) => {
background: #fff;
border-radius: 0 6px 6px 0;
padding: 10px;
text-align: center;
}
.project-item {
padding: 12px 10px;

View File

@@ -12,7 +12,7 @@
<image src="http://47.104.199.163:9090/images/repair/house.png" style="width: 48rpx;height: 48rpx;"></image>
<view class="house-name">
{{ item.villageName }}
<view class="house-detail">{{ item.houseType }}</view>
<view class="house-detail">{{item.unitNo}}-{{item.floorNo}}-{{item.houseNo}}</view>
</view>
<uni-icons type="checkbox-filled" size="20" color="#007aff" v-if="selectedHouse.id === item.id"></uni-icons>
@@ -93,7 +93,7 @@ const confirmSelect = () => {
// 把选中的房屋信息传给表单页通过uni.$emit
uni.$emit('selectHouse', {
id: selectedHouse.value.id,
name: `${selectedHouse.value.villageName} ${selectedHouse.value.houseType}`
name: `${selectedHouse.value.villageName} ${selectedHouse.value.unitNo}-${selectedHouse.value.floorNo}-${selectedHouse.value.houseNo}`
})
// 返回上一页

View File

@@ -1,72 +1,66 @@
<template>
<view class="qrcode-page">
<view class="qrcode-wrap">
<!-- 显示后台返回的二维码图片 -->
<view class="qrcode-box">
<!-- 调用uqrcode组件 -->
<uqrcode
:value="qrcodeValue"
:size="400"
:logo="'http://47.104.199.163:9090/images/logo.png'"
:logoSize="0.2"
canvasId="visitor-qrcode"
@success="onQrcodeSuccess"
></uqrcode>
<!-- 二维码边框装饰 -->
<image :src="qrcodeUrl" mode="widthFix" class="qrcode-img" />
<!-- 四角装饰边框保留 -->
<view class="qrcode-border border-top"></view>
<view class="qrcode-border border-right"></view>
<view class="qrcode-border border-bottom"></view>
<view class="qrcode-border border-left"></view>
</view>
<text class="qrcode-desc">桂花园别墅东门通行二维码</text>
<text class="qrcode-desc">{{houseName}}通行二维码</text>
<text class="qrcode-tips">分享此二维码给访客可扫码开门单次有效</text>
</view>
<view class="btn-wrap">
<button class="send-btn" @click="sendToFriend">发送给好友</button>
<button class="send-btn" open-type="share" :image-url="qrcodeUrl">发送给好友</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue';
// import { navigateBack, showToast, share } from '@dcloudio/uni-app';
// 引入本地uqrcode组件
import uqrcode from '@/components/uqrcode/uqrcode.vue';
import { onLoad } from '@dcloudio/uni-app';
// 二维码内容(替换为实际的通行链接)
const qrcodeValue = ref('https://your-domain.com/visitor/123456');
// 生成的二维码临时图片地址
// 直接接收图片URL
const qrcodeUrl = ref('');
const qrcodeImage = ref('');
const houseName = ref('')
// 二维码生成成功回调
const onQrcodeSuccess = (tempFilePath) => {
qrcodeImage.value = tempFilePath;
uni.showToast({ title: '二维码生成成功', icon: 'success' });
};
onLoad((option) => {
if (option.qrcodeUrl) {
// 接收后台返回的二维码图片链接
qrcodeUrl.value = decodeURIComponent(option.qrcodeUrl);
qrcodeImage.value = qrcodeUrl.value;
houseName.value = option.villageName
console.log('最终二维码图片:', qrcodeUrl.value);
}
});
// 分享给好友
const sendToFriend = () => {
if (!qrcodeImage.value) {
uni.showToast({ title: '二维码生成中...', icon: 'none' });
return;
}
// const sendToFriend = () => {
// if (!qrcodeImage.value) {
// uni.showToast({ title: '二维码生成中...', icon: 'none' });
// return;
// }
uni.share({
provider: 'weixin',
type: 0,
title: '访客通行二维码',
imageUrl: qrcodeImage.value,
success: () => uni.showToast({ title: '分享成功' }),
fail: () => uni.showToast({ title: '分享失败', icon: 'none' })
});
};
// uni.share({
// provider: 'weixin',
// type: 0,
// title: '访客通行二维码',
// imageUrl: qrcodeImage.value,
// success: () => uni.showToast({ title: '分享成功' }),
// fail: () => uni.showToast({ title: '分享失败', icon: 'none' })
// });
// };
</script>
<style scoped>
.qrcode-page {
/* background-color: #f8f8f8; */
min-height: 100vh;
}
.qrcode-wrap {
@@ -80,7 +74,12 @@ const sendToFriend = () => {
width: 400rpx;
height: 400rpx;
}
/* 二维码边框样式 */
/* 图片铺满 */
.qrcode-img {
width: 100%;
height: 100%;
}
/* 边框装饰 */
.qrcode-border {
position: absolute;
width: 40rpx;
@@ -91,7 +90,7 @@ const sendToFriend = () => {
.border-right { top: 0; right: 0; border-left: none; border-bottom: none; }
.border-bottom { bottom: 0; right: 0; border-left: none; border-top: none; }
.border-left { bottom: 0; left: 0; border-right: none; border-top: none; }
/* 文字样式 */
.qrcode-desc {
font-size: 32rpx;
font-weight: 600;
@@ -103,9 +102,8 @@ const sendToFriend = () => {
color: #999;
margin-top: 10rpx;
}
/* 按钮样式 */
.btn-wrap {
margin: 80rpx 20rpx 20rpx;
margin: 80rpx 40rpx 20rpx;
}
.send-btn {
background-color: #007aff;
@@ -114,6 +112,5 @@ const sendToFriend = () => {
height: 88rpx;
font-size: 28rpx;
line-height: 88rpx;
}
</style>

View File

@@ -2,18 +2,10 @@
<view class="visitor-invite">
<!-- 标签切换车辆来访/人员来访 -->
<view class="tab-wrap">
<view
class="tab-item"
:class="{ active: activeTab === 'car' }"
@click="switchTab('car')"
>
<view class="tab-item" :class="{ active: activeTab === 'car' }" @click="switchTab('car')">
车辆来访
</view>
<view
class="tab-item"
:class="{ active: activeTab === 'person' }"
@click="switchTab('person')"
>
<view class="tab-item" :class="{ active: activeTab === 'person' }" @click="switchTab('person')">
人员来访
</view>
</view>
@@ -40,11 +32,7 @@
<view class="form-item">
<view class="label">访客姓名</view>
<input
class="input"
placeholder="请输入访客姓名"
v-model="form.name"
/>
<input class="input" placeholder="请输入访客姓名" v-model="form.name" />
</view>
<view class="form-item">
<view class="label">
@@ -59,12 +47,7 @@
<view class="label">
<text class="required">*</text>访客联系方式
</view>
<input
class="input"
placeholder="请输入联系方式"
v-model="form.phone"
type="number"
/>
<input class="input" placeholder="请输入联系方式" v-model="form.phone" type="number" />
</view>
<!-- 车牌号仅车辆来访显示 -->
@@ -73,14 +56,9 @@
<text class="required">*</text>车牌号
</view>
<view class="car-number-wrap">
<input
class="car-input"
v-for="(item, index) in 8"
:key="index"
v-model="form.carNumber[index]"
maxlength="1"
type="text"
/>
<input class="car-input" v-for="(item, index) in 8" :key="index"
:value="form.carNumber[index]" @input="(e) => onCarInput(index, e)"
type="text" />
</view>
</view>
@@ -88,12 +66,7 @@
<view class="label">
<text class="required">*</text>随行人数
</view>
<input
class="input"
placeholder="请输入随行人数"
v-model="form.peopleNum"
type="number"
/>
<input class="input" placeholder="请输入随行人数" v-model="form.peopleNum" type="number" />
</view>
</view>
@@ -106,7 +79,8 @@
<text class="required">*</text>来访时间
</view>
<view class="value">
<uni-datetime-picker type="datetime" v-model="form.visitTime" @change="handleTimeChange" :border="false"/>
<uni-datetime-picker type="datetime" v-model="form.visitTime" @change="handleTimeChange"
:border="false" />
</view>
</view>
<view class="form-item">
@@ -114,7 +88,8 @@
<text class="required">*</text>离开时间
</view>
<view class="value">
<uni-datetime-picker type="datetime" v-model="form.leaveTime" @change="handleTimeChange" :border="false"/>
<uni-datetime-picker type="datetime" v-model="form.leaveTime" @change="handleTimeChange"
:border="false" />
</view>
</view>
<view class="tips">预计来访时间和预计离开时间间隔不能超过24小时</view>
@@ -124,10 +99,7 @@
<!-- 底部按钮 -->
<view class="btn-wrap">
<button
class="submit-btn"
@click="submitForm"
>
<button class="submit-btn" @click="submitForm">
{{ activeTab === 'car' ? '确认邀请' : '生成通行二维码' }}
</button>
</view>
@@ -137,22 +109,12 @@
<view class="modal-wrap">
<view class="modal-title">选择来访地址</view>
<view class="address-list">
<view
class="address-item"
:class="{ active: item === form.address }"
v-for="item in addressList"
:key="item"
@click="selectAddress(item)"
>
{{ item }}
<view class="address-item" :class="{ active: item.label === form.address }" v-for="item in addressList"
:key="item.id" @click="selectAddress(item)">
{{ item.label }}
</view>
</view>
<uni-icons
type="closeempty"
size="20"
class="modal-close"
@click="closeAddressModal"
></uni-icons>
<uni-icons type="closeempty" size="20" class="modal-close" @click="closeAddressModal"></uni-icons>
</view>
</uni-popup>
@@ -160,13 +122,8 @@
<uni-popup ref="genderModalRef" type="bottom" :mask-click="false">
<view class="modal-wrap">
<view class="gender-list">
<view
class="gender-item"
:class="{ active: item === form.gender }"
v-for="item in genderList"
:key="item"
@click="selectGender(item)"
>
<view class="gender-item" :class="{ active: item === form.gender }" v-for="item in genderList"
:key="item" @click="selectGender(item)">
{{ item }}
</view>
</view>
@@ -176,9 +133,15 @@
</template>
<script setup>
import { ref, reactive} from 'vue';
import{onLoad } from "@dcloudio/uni-app"
import {
ref,
reactive
} from 'vue';
import {
onLoad
} from "@dcloudio/uni-app"
import moment from 'moment';
import{getHouseList,addVisitorData} from '../api/api.js'
// 标签激活状态
const activeTab = ref('car');
@@ -186,20 +149,19 @@ const activeTab = ref('car');
// 表单数据
const form = reactive({
address: '',
villageId: '',
houseId: '',
name: '',
gender: '',
phone: '',
carNumber: ['', '', '', '', '', '', '', ''], // 修复8位车牌
carNumber:['', '', '', '', '', '', '', ''],
peopleNum: '',
visitTime: '',
leaveTime: ''
});
// 地址列表
const addressList = ref([
'桂花园别墅1号楼1层',
'桂花园别墅2号楼2层'
]);
const addressList = ref([]);
// 性别列表
const genderList = ref(['男', '女']);
@@ -208,8 +170,24 @@ const genderList = ref(['男', '女']);
const addressModalRef = ref(null);
const genderModalRef = ref(null);
onLoad(() => {
// =========方法===========
// 获取房屋列表
const fetchHouseList = async () => {
try {
const res = await getHouseList({ pageNum: 1, pageSize: 10 })
if (res.code === 200) {
addressList.value = (res.rows || []).map(item => ({
...item,
label: `${item.buildingName || ''}${item.unitNo}-${item.floorNo || ''}-${item.houseNo || ''}`.trim()
}))
}
} catch (e) {
console.error('获取房屋列表失败', e)
}
}
onLoad(() => {
fetchHouseList()
});
// 切换tab
@@ -230,7 +208,9 @@ const closeAddressModal = () => {
// 选择地址
const selectAddress = (item) => {
form.address = item;
form.address = item.label;
form.villageId = item.villageId || '';
form.houseId = item.id || '';
closeAddressModal();
};
@@ -245,6 +225,12 @@ const selectGender = (item) => {
genderModalRef.value.close();
};
// 车牌号单格输入
const onCarInput = (index, e) => {
const val = (e.detail && e.detail.value !== undefined) ? e.detail.value : (e.target ? e.target.value : '');
form.carNumber[index] = (val || '').toUpperCase().slice(0, 1);
};
// 时间校验
const handleTimeChange = () => {
if (!form.visitTime || !form.leaveTime) return true;
@@ -276,68 +262,118 @@ const handleTimeChange = () => {
};
// 提交表单
const submitForm = () => {
const submitForm = async () => {
// 1. 必填项校验
if (!form.address) {
uni.showToast({ title: '请选择来访地址', icon: 'none' });
uni.showToast({
title: '请选择来访地址',
icon: 'none'
});
return;
}
if (!form.name) {
uni.showToast({ title: '请输入访客姓名', icon: 'none' });
uni.showToast({
title: '请输入访客姓名',
icon: 'none'
});
return;
}
if (!form.gender) {
uni.showToast({ title: '请选择性别', icon: 'none' });
uni.showToast({
title: '请选择性别',
icon: 'none'
});
return;
}
if (!form.phone) {
uni.showToast({ title: '请输入访客联系方式', icon: 'none' });
uni.showToast({
title: '请输入访客联系方式',
icon: 'none'
});
return;
}
if (!/^1[3-9]\d{9}$/.test(form.phone)) {
uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
uni.showToast({
title: '请输入正确的手机号',
icon: 'none'
});
return;
}
if (activeTab === 'car' && form.carNumber.join('').length < 7) {
uni.showToast({ title: '请填写完整车牌号', icon: 'none' });
if (activeTab.value === 'car' && form.carNumber.filter(Boolean).join('').length < 7) {
uni.showToast({
title: '请填写完整车牌号',
icon: 'none'
});
return;
}
if (!form.peopleNum || form.peopleNum <= 0) {
uni.showToast({ title: '请输入正确的随行人数', icon: 'none' });
uni.showToast({
title: '请输入正确的随行人数',
icon: 'none'
});
return;
}
if (!form.visitTime) {
uni.showToast({ title: '请选择来访时间', icon: 'none' });
uni.showToast({
title: '请选择来访时间',
icon: 'none'
});
return;
}
if (!form.leaveTime) {
uni.showToast({ title: '请选择离开时间', icon: 'none' });
uni.showToast({
title: '请选择离开时间',
icon: 'none'
});
return;
}
// 2. 时间规则校验
if (!handleTimeChange()) return;
// 3. 提交成功
// 3. 构造参数并提交
const villageId = uni.getStorageSync('currentVillageId')
const carNumStr = form.carNumber.filter(Boolean).join('')
const params = {
villageId: villageId,
houseId: form.houseId,
visitorName: form.name,
visitorGender: form.gender === '男' ? '0' : (form.gender === '女' ? '1' : ''),
visitorPhone: form.phone,
carNum: activeTab.value === 'car' ? carNumStr : '',
visitorNum: String(form.peopleNum),
startTime: form.visitTime,
endTime: form.leaveTime,
type: activeTab.value === 'car' ? '0' : '1',
status: '0'
}
uni.showLoading({ title: '提交中...' });
setTimeout(() => {
try {
const res = await addVisitorData(params)
uni.hideLoading();
if (res.code === 200) {
uni.showToast({
title: activeTab === 'car' ? '邀请成功' : '二维码生成成功',
title: activeTab.value === 'car' ? '邀请成功' : '二维码生成成功',
icon: 'success'
});
}, 1000);
setTimeout(() => {
uni.navigateTo({
url:"/pageSubPack/visitor/qrcode-page"
})
},1500)
uni.navigateTo({ url: `/pageSubPack/visitor/qrcode-page?qrcodeUrl=${encodeURIComponent(res.data.url)}&villageName=${res.data.villageName}` })
}, 1500);
} else {
uni.showToast({ title: res.msg || '提交失败', icon: 'none' });
}
} catch (e) {
uni.hideLoading();
uni.showToast({ title: '网络异常,请重试', icon: 'none' });
}
};
// 重置表单
const resetForm = () => {
form.address = '';
form.villageId = '';
form.houseId = '';
form.name = '';
form.gender = '';
form.phone = '';
@@ -362,6 +398,7 @@ const resetForm = () => {
padding: 20rpx;
background-color: #fff;
}
.nav-title {
font-size: 36rpx;
font-weight: 500;
@@ -374,6 +411,7 @@ const resetForm = () => {
background-color: #fff;
border-bottom: 1rpx solid #eee;
}
.tab-item {
/* flex: 1; */
display: flex;
@@ -382,6 +420,7 @@ const resetForm = () => {
font-size: 32rpx;
color: #333;
}
.tab-item.active {
color: #007aff;
/* border-bottom: 4rpx solid #007aff; */
@@ -391,35 +430,42 @@ const resetForm = () => {
.form-wrap {
padding: 10rpx;
}
.form-section {
background-color: #fff;
margin-bottom: 10rpx;
padding: 20rpx 40rpx;
}
.section-title {
font-size: 28rpx;
font-weight: 500;
/* margin-bottom: 20rpx; */
margin: 30rpx 40rpx 10rpx;
}
.form-item {
display: flex;
align-items: center;
padding: 30rpx 0;
border-bottom: 1rpx solid #f0f0f0;
}
.form-item:last-child {
border-bottom: none;
}
.label {
width: 205rpx;
font-size: 32rpx;
color: #333;
}
.required {
color: red;
margin-right: 4rpx;
}
.value {
flex: 1;
font-size: 30rpx;
@@ -428,6 +474,7 @@ const resetForm = () => {
justify-content: flex-end;
align-items: center;
}
.input {
flex: 1;
font-size: 30rpx;
@@ -441,6 +488,7 @@ const resetForm = () => {
display: flex;
justify-content: space-between;
}
.car-input {
width: 52rpx;
height: 60rpx;
@@ -456,6 +504,7 @@ const resetForm = () => {
margin-top: 44rpx;
text-align: center;
}
.tips-2 {
font-size: 24rpx;
color: #999;
@@ -467,6 +516,7 @@ const resetForm = () => {
.btn-wrap {
padding: 20rpx 40rpx 50rpx;
}
.submit-btn {
background-color: #007aff;
color: #fff;
@@ -484,30 +534,38 @@ const resetForm = () => {
border-top-right-radius: 20rpx;
position: relative;
}
.modal-title {
font-size: 32rpx;
text-align: center;
margin-bottom: 30rpx;
}
.modal-close {
position: absolute;
top: 20rpx;
right: 20rpx;
color: #999;
}
.address-list, .gender-list {
.address-list,
.gender-list {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.address-item, .gender-item {
.address-item,
.gender-item {
padding: 20rpx;
background-color: #f5f5f5;
border-radius: 8rpx;
text-align: center;
font-size: 30rpx;
}
.address-item.active, .gender-item.active {
.address-item.active,
.gender-item.active {
background-color: #007aff;
color: #fff;
}

View File

@@ -20,8 +20,7 @@
<text class="label">联系方式</text>
<text class="value">{{ visitorInfo.phone }}</text>
</view>
<!-- 车牌号可选显示 -->
<view class="info-item" v-if="visitorInfo.carNumber">
<view class="info-item">
<text class="label">车牌号</text>
<text class="value">{{ visitorInfo.carNumber }}</text>
</view>
@@ -52,35 +51,68 @@
</view>
<!-- 分享二维码按钮仅等待来访状态显示 -->
<view class="btn-wrap" v-if="visitorInfo.status === 'waiting'">
<!-- <view class="btn-wrap" v-if="visitorInfo.status === 'waiting'">
<button class="share-btn" @click="goToQrcode">分享通行二维码</button>
</view>
</view> -->
</view>
</template>
<script setup>
import { ref } from 'vue';
import {onLoad} from '@dcloudio/uni-app'
import {getVisitorDetail} from '../api/api.js'
// 访客信息(实际项目中从接口获取)
// const visitorInfo = ref({})
const visitorInfo = ref({
name: '张三',
name: '',
status: 'waiting', // waiting:等待来访visited:已到访
address: '桂花园别墅2号楼2层',
phone: '13866666666',
carNumber: '京A88888', // 可传空隐藏
address: '',
phone: '',
carNumber: '',
escortNum: 0,
validTime: '2023.06.30 10:00至2023.06.30 23:00',
inviteTime: '2023年06月30日 09:35',
visitTime: '2023年06月30日 14:32' // 已到访时显示
});
validTime: '',
inviteTime: '',
visitTime: ''
})
// 把后端返回的字段映射成详情页
const mapDetail = (item) => {
const addressParts = [
item.villageName,
item.floorNo ? item.floorNo + '栋' : '',
item.unitNo ? item.unitNo + '单元' : '',
item.houseNo
].filter(Boolean)
const status = item.status === 1 || item.status === '1' ? 'visited' : 'waiting'
return {
name: item.visitorName || '',
status,
address: addressParts.join(''),
phone: item.visitorPhone || '',
carNumber: item.carNum || '',
escortNum: item.visitorNum || 0,
validTime: item.startTime && item.endTime ? `${item.startTime}${item.endTime}` : '',
inviteTime: item.createTime || '',
visitTime: item.visitTime || ''
}
}
// 获取访客详情
const fetchVisitorDetail = async (id) => {
try {
const res = await getVisitorDetail(id)
if (res && res.data) {
visitorInfo.value = mapDetail(res.data)
}
} catch (e) {
console.error('获取访客详情失败:', e)
}
}
onLoad((option) => {
const infoStr = decodeURIComponent(JSON.stringify(option))
// console.log('infoStr',infoStr)
visitorInfo.value = infoStr.item
if (option && option.id) {
fetchVisitorDetail(option.id)
}
})
// 跳转到二维码页面
const goToQrcode = () => {
@@ -92,7 +124,7 @@ const goToQrcode = () => {
<style scoped>
.visitor-detail-page {
background-color: #f8f8f8;
background-color: #fff;
min-height: 100vh;
}
@@ -111,8 +143,7 @@ const goToQrcode = () => {
}
.title {
font-size: 32rpx;
font-weight: 600;
font-size: 28rpx;
}
.status {
@@ -123,7 +154,6 @@ const goToQrcode = () => {
.waiting {
color: #007aff;
background: #e8f4ff;
}
.visited {
@@ -142,20 +172,22 @@ const goToQrcode = () => {
}
.label {
color: #666;
color: #222;
width: 160rpx;
}
.value {
color: #333;
color: #222;
flex: 1;
}
.tips-text {
margin: 0 20rpx;
font-size: 24rpx;
color: #999;
color: #666;
line-height: 1.6;
text-align: center;
margin-top: 98rpx;
}
.btn-wrap {

View File

@@ -55,14 +55,14 @@
</view>
<!-- 车牌号 -->
<view class="item-row" v-if="item.carNumber">
<view class="item-row">
<text class="label" :class="item.status">车牌号</text>
<text class="value" :class="item.status">{{ item.carNumber }}</text>
</view>
<!-- 时间+查看详情 -->
<view class="item-footer">
<text class="time-text">时间{{ item.createTime }}</text>
<text class="time-text" :class="item.status">时间{{ item.createTime }}</text>
<view class="detail-btn" @click="viewDetail(item)">
<text>查看详情</text>
<uni-icons type="arrowright" size="14"></uni-icons>
@@ -97,13 +97,14 @@ const activeTab = ref('waiting')
// 访客列表数据
const visitorList = ref([])
// 后端数据映射到前端结构(根据实际字段名调整)
// 后端数据映射到前端
const mapData = (list) => {
if (!Array.isArray(list)) return []
return list.map(item => {
const status = item.status === 1 || item.status === '1' ? 'visited' : 'waiting'
return {
name: item.visitorName,
...item,
visitorName: item.visitorName,
status,
statusText: status === 'visited' ? '已到访' : '等待来访',
startTime: item.startTime,
@@ -121,8 +122,8 @@ const fetchVisitorList = async () => {
let params = {userId:userId}
try {
const res = await getVisitorList(params)
// visitorList.value = mapData(res.data|| [])
visitorList.value = res.data || []
visitorList.value = mapData(res.data || [])
// console.log('222222',visitorList.value)
} catch (e) {
console.error('获取访客列表失败:', e)
@@ -154,10 +155,8 @@ const goBack = () => {
// 查看详情
const viewDetail = (item) => {
const itemStr = encodeURIComponent(JSON.stringify(item))
console.log('eeeee',itemStr)
uni.navigateTo({
url: `/pageSubPack/visitor/visitor-detail?item=${itemStr}` // 传到详情页
url: `/pageSubPack/visitor/visitor-detail?id=${item.id}` // 传 id 到详情页
})
}
@@ -249,7 +248,7 @@ const addInvitation = () => {
/* 列表容器 */
.list-container {
height: calc(100vh - 150px); /* 预留导航、标签、按钮高度 */
height: calc(100vh - 220px); /* 预留导航、标签、按钮高度 */
}
/* 访客列表项 */
@@ -308,7 +307,9 @@ const addInvitation = () => {
.value.visited{
color: #999;
}
.time-text.visited{
color: #999;
}
/* 列表项底部(时间+查看详情) */
.item-footer {
display: flex;
@@ -316,11 +317,11 @@ const addInvitation = () => {
align-items: center;
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid #f5f5f5;
/* border-top: 1px solid #f5f5f5; */
}
.time-text {
font-size: 12px;
color: #666;
font-size: 28rpx;
/* color: #666; */
}
.detail-btn {
display: flex;