officialAccount/pages/addjigou/name.vue

573 lines
14 KiB
Vue
Raw Normal View History

2025-06-09 17:33:50 +08:00
<template>
<div class="container">
<u-modal v-model="show" :content="content"></u-modal>
<view class="title-back">
<view class="left-father" @click="goBack">
<image class="back-img" src="@/static/index/left.png" />
<view style="font-size: 30rpx;">返回</view>
</view>
2025-06-11 17:33:34 +08:00
<!-- <view :class="!statesTarget? `rightStautes`:statesTarget==1? `rightStautesred`:`rightStautesblue`" @click="shenhe">
2025-06-09 17:33:50 +08:00
{{ states[statesTarget] }}
2025-06-11 17:33:34 +08:00
</view> -->
2025-06-09 17:33:50 +08:00
</view>
<view class="white-content">
<view class="content-title">
<view class="content-weight">身份证上传</view>
<image class="content-img" src="@/static/index/bian.png" />
</view>
<view class="white-photo" @click="getMessage">
<view class="photo-left">
<view class="photo-weight">人像面</view>
<view class="photo-font">请上传身份证人像面</view>
</view>
<view style="position: relative;">
<image class="photo" :src="headImge ? headImge : `/static/index/IDcard.png`" />
<image v-show="!headImge"
style="position: absolute;top: 50%;left: 50%;width: 70rpx;height: 60rpx;transform: translate(-50%,-50%);"
src="@/static/index/takephoto.png" />
</view>
</view>
<view class="white-photo" style="margin-top: 30rpx;" @click="getMessage">
<view class="photo-left">
<view class="photo-weight">国徽面</view>
<view class="photo-font">请上传身份证国徽面</view>
</view>
<view style="position: relative;">
2025-06-11 17:33:34 +08:00
<image class="photo" :src="backImge ? backImge : `/static/index/backIDcard.png`" />
<image v-show="!backImge"
style="position: absolute;top: 50%;left: 50%;width: 70rpx;height: 60rpx;transform: translate(-50%,-50%);"
src="@/static/index/takephoto.png" />
2025-06-09 17:33:50 +08:00
</view>
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
</view>
<view class="white-message">
<view class="message-title">
<view class="shu"></view>
<view class="message-weight">
确认身份证信息
</view>
</view>
<view style="margin-bottom: 20rpx;">
<view v-for="(item,index) in nameArray" :key="index" class="one"
@click="openLook(textArray[index])">
<view class="one-left">{{item}}</view>
<!-- <view class="one-right">{{textArray[index] ? textArray[index] : "自动获取" }}</view> -->
<view class="one-right">{{textArray[index] ? textArray[index] : "自动获取" }}</view>
</view>
</view>
</view>
</view>
<view class="gray-font">
<view class="">注意事项:</view>
<view style="margin-top: 30rpx;">
同一个身份证号只能认证一个账号国徽而与正面信息应为同一身份证的信息目在有效期内,所有上传照片需清晰且未遮挡请勿进行美化和修改,所有上传信息均会被妥善保管,不会用于其他商业用途或传输给第三方</view>
</view>
<view style="display: flex;width: 100%;">
<!-- <view class="finish-button" @click="goBack">
上一步
</view> -->
<view class="finish-button" @click="next">
下一步
</view>
</view>
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
</div>
</template>
<script setup>
import {
ref,
reactive
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app';
2025-06-11 17:33:34 +08:00
import {
base_url
} from '@/request/index.js';
import {
changemessage
} from './api/addjigou.js'
2025-06-09 17:33:50 +08:00
const show = ref(false);
const content = ref("");
const nameArray = ["姓名", "性别", "身份证号码", "民族", "出生日期", "住址", "签发机关", "有效期限"];
const textArray = reactive(["", "", "", "", "", "", "", ""]);
2025-06-11 17:33:34 +08:00
const states = ["审核中", "审核未通过", "审核通过"];
const fontphoto = ref("");
const endphoto = ref("");
2025-06-09 17:33:50 +08:00
const statesTarget = ref(0);
const shenhe = () => {
2025-06-11 17:33:34 +08:00
if (statesTarget.value == 2) {
statesTarget.value = 0
} else {
2025-06-09 17:33:50 +08:00
statesTarget.value++
}
}
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
// 本地保存的临时文件路径
const tempImagePath = ref('')
// 拍照并上传
function getMessage() {
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
// wx.ready(() => {
// wx.chooseAddress({
// success(res) {
// console.log('address', res)
// },
// fail(err) {
// console.error('fail', err)
// }
// })
// })
// 使用 UniApp 的 API 调用摄像头
uni.chooseImage({
count: 1,
sourceType: ['camera'],
success: chooseRes => {
tempImagePath.value = chooseRes.tempFilePaths[0]
// 拍照成功后,调用上传函数
uploadImage(tempImagePath.value)
},
fail: err => {
console.error('拍照失败:', err)
}
})
}
const headImge = ref("");
const backImge = ref("");
2025-06-11 17:33:34 +08:00
// 日期转换
function formatChineseDate(chineseDate) {
return chineseDate.replace(/(\d+)年(\d+)月(\d+)日/, (_, y, m, d) => {
return `${y}.${m}.${d}`;
});
}
2025-06-09 17:33:50 +08:00
2025-06-11 17:33:34 +08:00
function toIsoDate(dateStr) {
return dateStr.replace(
/(\d{2,4})\.(\d{1,2})\.(\d{1,2})/,
(_, y, m, d) => {
// 月日补齐两位
const mm = m.padStart(2, '0');
const dd = d.padStart(2, '0');
return `${y}-${mm}-${dd}`;
}
);
}
2025-06-09 17:33:50 +08:00
// 上传图片到服务器
function uploadImage(filePath) {
uni.showLoading()
uni.uploadFile({
url: `${base_url}/api/ocr/idCard`, // 替换为你的POST接口地址
filePath,
name: 'file', // 后端接收时的字段名
header: {
'X-Access-Token': uni.getStorageSync('token') || '',
},
formData: {},
success: uploadRes => {
2025-06-11 17:33:34 +08:00
console.log("token", uni.getStorageSync('token'))
2025-06-09 17:33:50 +08:00
if (!JSON.parse(uploadRes.data).success) {
uni.showToast({
title: '识别失败',
icon: 'error'
})
uni.hideLoading()
return
}
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.face) {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.face.data;
textArray[0] = father.name;
textArray[1] = father.sex;
textArray[2] = father.idNumber;
textArray[3] = father.ethnicity;
textArray[4] = father.birthDate;
textArray[5] = father.address;
uni.showToast({
title: '识别成功',
})
headImge.value = filePath;
2025-06-11 17:33:34 +08:00
savephoto(filePath, 0);
2025-06-09 17:33:50 +08:00
uni.hideLoading()
} else {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.back.data;
textArray[6] = father.issueAuthority;
textArray[7] = father.validPeriod;
uni.showToast({
title: '识别成功',
})
backImge.value = filePath;
2025-06-11 17:33:34 +08:00
savephoto(filePath, 1);
2025-06-09 17:33:50 +08:00
uni.hideLoading()
}
},
fail: err => {
uni.showToast({
title: '上传出错',
icon: 'error'
})
uni.hideLoading()
}
})
}
2025-06-11 17:33:34 +08:00
const savephoto = (filePath, type) => {
2025-06-09 17:33:50 +08:00
uni.uploadFile({
url: `${base_url}/sys/common/upload`, // 替换为你的POST接口地址
filePath,
name: 'file', // 后端接收时的字段名
header: {
'X-Access-Token': uni.getStorageSync('token') || '',
},
formData: {
biz: `temp`
},
success: uploadRes => {
2025-06-11 17:33:34 +08:00
if (!type) {
fontphoto.value = JSON.parse(uploadRes.data).message
} else {
endphoto.value = JSON.parse(uploadRes.data).message
}
2025-06-09 17:33:50 +08:00
},
fail: err => {
uni.showToast({
title: '上传出错',
icon: 'error'
})
uni.hideLoading()
}
})
}
const openLook = (res) => {
if (res) {
content.value = res;
show.value = true
}
}
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
const next = () => {
2025-06-11 17:33:34 +08:00
const allNonEmpty = textArray.every(item => {
// 如果想忽略前后空格,可用 item.trim() !== ''
return item !== '';
2025-06-09 17:33:50 +08:00
});
2025-06-11 17:33:34 +08:00
if (allNonEmpty) {
const range = textArray[7];
const [start, end] = range.split('-');
let pushMessage = {
id: uni.getStorageSync('specicalid') || "",
tel: uni.getStorageSync('tel'),
name: textArray[0],
sex: textArray[1],
idCard: textArray[2],
national: textArray[3],
birthDate: textArray[4],
idCardAddress: textArray[5],
issuingAuthority: textArray[6],
startTime: start,
endTime: end,
cardZmPath:fontphoto.value,
cardFmPath:endphoto.value
}
// console.log("????",pushMessage)
changemessage(pushMessage).then(res => {
if(res.success){
if(res.message==`保存成功!`){
uni.navigateTo({
url: "/pages/addjigou/card"
});
}else{
uni.setStorageSync('specicalid', res.result.id);
uni.navigateTo({
url: "/pages/addjigou/card"
});
}
}else{
uni.showToast({
title: res.message,
icon: 'error'
})
}
})
} else {
uni.showToast({
title: '请完善信息',
icon: 'error'
})
}
2025-06-09 17:33:50 +08:00
}
// 1. 动态加载微信 JSSDK 脚本
// async function loadWxJSSDK() {
// // if (window.wx) return
// await new Promise(resolve => {
// const script = document.createElement('script')
// script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'
// script.onload = resolve
// document.head.appendChild(script)
// getapi()
// })
// }
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
// const getapi = () => {
// const post = `${uni.getStorageSync('serverUrl')}/weiXinPay/getJsApiInfo`;
// const pay = {
// url: location.href.split('#')[0],
// };
// console.log("????",pay)
// fetch(post, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(pay)
// })
// .then(res => res.json())
// .then(data => {
// // secondArray.value = [...data.result];
// // console.log("???调取微信", data)
// wx.config({
// debug: false, // 开启调试会 alert 所有调用结果
// appId: `wx8fc3e4305d2fbf0b`, // 必填,公众号的唯一标识
// timestamp: data.timestamp, // 必填,生成签名的时间戳
// nonceStr: data.nonceStr, // 必填,生成签名的随机串
// signature: data.signature, // 必填,签名
// jsApiList: [ // 必填,需要使用的 JS 接口列表
// 'chooseAddress',
// 'getLocation',
// 'openLocation',
// /* …根据实际业务增删 */
// ]
// })
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
// })
// .catch(err => {
// console.error('请求失败:', err);
// });
// }
const goBack = () => {
uni.navigateBack()
}
onLoad(() => {
// loadWxJSSDK()
// 后端接口要接受当前页面 URL不能带 # 后面),用于计算 signature
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
})
</script>
<style lang="scss" scoped>
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: rgb(239, 241, 252);
position: relative;
box-shadow: 2rpx 2rpx 4rpx rgba(0, 0, 0, 0.1);
.white-content {
width: 90%;
margin-left: 5%;
// margin-top: 30rpx;
// height: 1200rpx;
border-radius: 35rpx;
background-color: rgb(245, 251, 254);
.content-title {
display: flex;
// align-items: center;
height: 100rpx;
position: relative;
.content-weight {
// font-size: 35rpx;
font-weight: 600;
margin-left: 70rpx;
margin-top: 20rpx;
}
.content-img {
position: absolute;
right: 0;
top: 0;
width: 400rpx;
height: 100%;
}
}
}
.white-photo {
width: 90%;
margin-left: 5%;
// margin-top: 30rpx;
height: 300rpx;
border-radius: 35rpx;
background-color: #fff;
box-shadow: 4rpx 4rpx 8rpx rgba(0, 0, 0, 0.1);
justify-content: space-around;
align-items: center;
display: flex;
.photo {
width: 300rpx;
height: 200rpx;
}
}
.white-message {
width: 90%;
margin-left: 5%;
margin-top: 30rpx;
margin-bottom: 30rpx;
// height: 800rpx;
border-radius: 35rpx;
background-color: #fff;
box-shadow: 4rpx 4rpx 8rpx rgba(0, 0, 0, 0.1);
justify-content: space-around;
// align-items: center;
display: flex;
flex-direction: column;
.message-title {
width: 100%;
height: 100rpx;
align-items: center;
display: flex;
.shu {
width: 10rpx;
height: 30rpx;
background-color: #0097FF;
border-radius: 10rpx;
margin: 0 20rpx 0 30rpx;
}
.message-weight {
font-size: 30rpx;
// font-weight: 600;
}
}
.one {
width: 90%;
margin-left: 5%;
border-bottom: 1rpx solid #d7d7d7;
height: 90rpx;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10rpx;
.one-left {
margin-left: 10rpx;
}
.one-right {
margin-right: 10rpx;
color: #999999;
overflow: hidden;
/* 隐藏超出内容 */
white-space: nowrap;
/* 不换行 */
text-overflow: ellipsis;
max-width: 300rpx;
}
}
}
}
.photo-left {
.photo-weight {
font-size: 26rpx;
font-weight: 600;
}
.photo-font {
font-size: 23rpx;
margin-top: 10rpx;
}
}
.gray-font {
padding: 30rpx 60rpx;
color: #999999;
}
.finish-button {
display: flex;
justify-content: center;
align-items: center;
width: 45%;
height: 100rpx;
margin: 0rpx auto;
margin-bottom: 80rpx;
color: #fff;
background: linear-gradient(to right, #00C9FF, #0076FF);
border-radius: 50rpx;
font-size: 35rpx;
}
2025-06-11 17:33:34 +08:00
.title-back {
2025-06-09 17:33:50 +08:00
width: 100%;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
2025-06-11 17:33:34 +08:00
.left-father {
2025-06-09 17:33:50 +08:00
display: flex;
align-items: center;
2025-06-11 17:33:34 +08:00
.back-img {
2025-06-09 17:33:50 +08:00
width: 50rpx;
height: 50rpx;
margin-left: 40rpx;
margin-right: 5rpx;
}
}
2025-06-11 17:33:34 +08:00
.rightStautes {
2025-06-09 17:33:50 +08:00
width: 170rpx;
height: 62rpx;
border-radius: 60rpx;
background-color: #FF913A;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
margin-right: 30rpx;
}
2025-06-11 17:33:34 +08:00
.rightStautesred {
2025-06-09 17:33:50 +08:00
width: 170rpx;
height: 62rpx;
border-radius: 60rpx;
2025-06-11 17:33:34 +08:00
background: linear-gradient(to right, #FF4A76, #FF553A);
2025-06-09 17:33:50 +08:00
display: flex;
justify-content: center;
align-items: center;
color: #fff;
margin-right: 30rpx;
}
2025-06-11 17:33:34 +08:00
.rightStautesblue {
2025-06-09 17:33:50 +08:00
width: 170rpx;
height: 62rpx;
border-radius: 60rpx;
2025-06-11 17:33:34 +08:00
background: linear-gradient(to right, #00C9FF, #0076FF);
2025-06-09 17:33:50 +08:00
display: flex;
justify-content: center;
align-items: center;
color: #fff;
margin-right: 30rpx;
}
</style>