Browse Source

在线办证/首页二维码

master
xuhuajiao 1 month ago
parent
commit
03e7f91fc2
  1. 97
      pages/home/home.vue
  2. 10
      pages/login/login.vue
  3. 289
      pages/register/register.vue
  4. 8
      static/iconfont.css
  5. BIN
      static/iconfont.ttf
  6. 33
      styles/global.scss
  7. 12
      subpkg/pages/reader-card/reader-card.vue

97
pages/home/home.vue

@ -1,12 +1,13 @@
<template>
<view style="padding-bottom: 20px;">
<view class="top-bar">
<uni-icons class="erweima-top" custom-prefix="iconfont" type="icon-erweima" size="22" color="#fff" @click="showTopImgPopup"></uni-icons>
<image class="top-bar-bg" src="@/static/images/mingqi-beij@2x.png" mode="aspectFill"></image>
<view class="library-info">
<image class="avatar" src="@/static/images/logo.jpg" mode="aspectFill"></image>
<view class="library-name">葛店经济技术开发区图书馆</view>
</view>
<uni-icons class="search-icon" type="search" size="30" @click="onToSearch"></uni-icons>
<uni-icons class="search-icon" type="search" size="24" @click="onToSearch"></uni-icons>
</view>
<view class="status-cards">
@ -99,7 +100,7 @@
</view>
<view class="menu-item" @click="goRegister">
<view class="menu-icon">
<uni-icons custom-prefix="iconfont" type="icon-yonghuxinxi-gerenxinxi" size="20"></uni-icons>
<uni-icons custom-prefix="iconfont" type="icon-a-28-banzhengjian" size="25"></uni-icons>
</view>
<view class="menu-label">在线办证</view>
</view>
@ -147,8 +148,7 @@
ref="popup"
type="center"
:mask-click="true"
@maskClick="closePopup"
:custom-style="popupFixedStyle"
@maskClick="closeAllPopup"
>
<view class="qrcode-popup">
<view class="qrcode-title">读者证二维码</view>
@ -159,8 +159,28 @@
foreground="#333"
background="#ffffff"
/>
<view class="qrcode-num">{{ qrcodeText }}</view>
<view class="close-btn" @click="closePopup">关闭</view>
<view class="qrcode-num" v-if="qrcodeText">{{ qrcodeText }}</view>
<!-- <view class="close-btn" @click="closeAllPopup" style="margin-top:15px;">关闭</view> -->
</view>
</uni-popup>
<uni-popup
ref="erweimapopup"
type="center"
:mask-click="true"
@maskClick="closeErweiPopup"
:custom-style="popupFixedStyle"
>
<view class="qrcode-popup" style="width: auto !important;">
<image
v-if="wecharQRCode"
:src="wecharQRCode"
style="width:200px;height:200px;"
mode="aspectFit"
:show-menu-by-longpress="true"
@longpress="onQRCodeLongPress"
></image>
<!-- <view class="qrcode-tip">长按二维码可识别</view> -->
</view>
</uni-popup>
</root-portal>
@ -196,7 +216,7 @@
</template>
<script>
import { FetchOpenId, FetchFindAllReaderBindByOpenId} from '@/api/user';
import { FetchInitScreenSetting, FetchOpenId, FetchFindAllReaderBindByOpenId} from '@/api/user';
import { FetchInitScreenBookRecommend } from '@/api/book';
import config from '@/utils/config';
import { STORAGE_KEYS } from '@/utils/storage';
@ -212,16 +232,42 @@ export default {
readerCardList: [], //
baseUrl: config.baseUrl,
qrcodeText: '', //
popupFixedStyle: 'position:fixed;top:0;left:0;right:0;bottom:0;'
popupFixedStyle: 'position:fixed;top:0;left:0;right:0;bottom:0;',
wecharQRCode: null
};
},
onLoad() {
this.getRecommendBooks();
this.getScreenSetting()
},
onShow() {
this.initUserAndCheckBind();
},
methods:{
async getScreenSetting() {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
if (res.data.wechar_qr_code && res.data.wechar_qr_code.context) {
const imageUrl = this.baseUrl + '/api/fileRelevant/getImg?imgType=1&imgId=' + res.data.wechar_qr_code.context;
try {
const base64 = await this.urlToBase64(imageUrl);
this.wecharQRCode = base64;
} catch (err) {
this.wecharQRCode = null;
}
} else {
this.wecharQRCode = null;
}
},
//
showTopImgPopup() {
if (!this.wecharQRCode) {
uni.showToast({ title: '暂无图片', icon: 'none' })
return
}
this.$refs.erweimapopup.open()
},
//
formatCardNo(cardNo) {
if (!cardNo) return '';
@ -448,10 +494,23 @@ export default {
this.qrcodeText = bindValue;
this.$refs.popup.open();
},
closePopup() {
closeAllPopup() {
this.qrcodeText = '';
this.$refs.popup.close();
},
closeErweiPopup() {
this.$refs.erweimapopup.close()
},
/**
* 二维码长按事件
*/
onQRCodeLongPress() {
// uni.showToast({
// title: '',
// icon: 'none',
// duration: 1500
// });
},
urlToBase64(url) {
return new Promise((resolve, reject) => {
uni.request({
@ -487,6 +546,12 @@ export default {
<style lang="scss" scoped>
.top-bar{
.erweima-top{
position: absolute;
left: 16px;
top: 15px;
z-index: 999;
}
.search-icon{
position: absolute;
right: 16px;
@ -734,4 +799,18 @@ swiper.menu-swiper{
color: #999 !important;
}
}
// .qrcode-popup {
// padding: 20px;
// border-radius: 12px;
// background: #fff;
// .qrcode-tip {
// text-align: center;
// font-size: 12px;
// color: #999;
// margin-top: 10px;
// }
// }
</style>

10
pages/login/login.vue

@ -31,7 +31,7 @@
<view class="item">
<uni-icons class="form-icon" type="locked" size="24"></uni-icons>
<input class="input" placeholder="请输入密码" :password="!showPwd" v-model="rdpasswd" />
<uni-icons class="form-right-icon" :type="showPwd ? 'eye-slash' : 'eye'" size="20"
<uni-icons class="form-right-icon" :type="showPwd ? 'eye' : 'eye-slash'" size="20"
@click="togglePwd"></uni-icons>
</view>
@ -362,12 +362,4 @@ export default {
margin-right: 10px;
}
}
.register-btn {
position: fixed;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
width: calc(100% - 40px);
}
</style>

289
pages/register/register.vue

@ -1,21 +1,23 @@
<template>
<view style="background-color: #fff; height: calc(100vh);">
<view class="page-container">
<!-- 顶部背景 + 标题 -->
<view class="top-bar">
<image class="top-bar-bg" src="@/static/images/mingqi-beij@2x.png" mode="aspectFill"></image>
<view class="library-info">
<image class="avatar" src="@/static/images/logo.jpg" mode="aspectFill"></image>
<view class="library-name">葛店经济技术开发区图书馆</view>
<view class="sub-title">读者证办理</view>
</view>
</view>
<!-- 表单区域 -->
<view class="form-box">
<!-- 表单卡片 -->
<view class="form-card">
<!-- 姓名 -->
<view class="form-item">
<uni-icons class="form-icon" custom-prefix="iconfont" type="icon-user" size="24"></uni-icons>
<input
class="input"
placeholder="请输入姓名"
placeholder="请输入真实姓名"
v-model="formData.name"
maxlength="20"
/>
@ -26,7 +28,7 @@
<uni-icons class="form-icon" custom-prefix="iconfont" type="icon-shenfen" size="24"></uni-icons>
<input
class="input"
placeholder="请输入身份证号"
placeholder="请输入18位身份证号"
v-model="formData.idCard"
maxlength="18"
/>
@ -43,7 +45,7 @@
maxlength="11"
/>
<button class="get-phone-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
获取手机号
一键获取
</button>
</view>
@ -52,14 +54,14 @@
<uni-icons class="form-icon" type="locked" size="24"></uni-icons>
<input
class="input"
placeholder="请输入密码"
placeholder="请设置6-20位密码"
:password="!showPwd"
v-model="formData.password"
maxlength="20"
/>
<uni-icons
class="pwd-icon"
:type="showPwd ? 'eye-slash' : 'eye'"
:type="showPwd ? 'eye' : 'eye-slash'"
size="20"
@click="togglePwd"
></uni-icons>
@ -70,14 +72,14 @@
<uni-icons class="form-icon" type="locked" size="24"></uni-icons>
<input
class="input"
placeholder="请再次输入密码"
placeholder="请再次确认密码"
:password="!showConfirmPwd"
v-model="formData.confirmPassword"
maxlength="20"
/>
<uni-icons
class="pwd-icon"
:type="showConfirmPwd ? 'eye-slash' : 'eye'"
:type="showConfirmPwd ? 'eye' : 'eye-slash'"
size="20"
@click="toggleConfirmPwd"
></uni-icons>
@ -85,19 +87,19 @@
<!-- 提交按钮 -->
<button class="submit-btn" type="primary" @click="submit" :loading="loading">
{{ loading ? '提交中...' : '提交办证' }}
{{ loading ? '提交中...' : '确认办理' }}
</button>
</view>
<!-- 温馨提示 -->
<!-- <view class="tips">
<text class="tips-title">温馨提示</text>
<view class="tips-content">
<text>1请确保填写的信息真实准确</text>
<text>2密码建议设置为6-20位数字和字母组合</text>
<text>3提交后工作人员将在1-3个工作日内审核</text>
<view class="tips-card">
<view class="tips-title">温馨提示</view>
<view class="tips-text">
1. 请填写真实身份信息用于办理读者证<br>
2. 密码请牢记用于登录和借阅查询<br>
<!-- 3. 提交后工作人员将尽快审核 -->
</view>
</view> -->
</view>
</view>
</template>
@ -121,24 +123,17 @@ export default {
};
},
onLoad() {
},
onLoad() {},
methods: {
/**
* 获取手机号通过后端接口解密
*/
getPhoneNumber(e) {
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
uni.showToast({ title: '取消授权', icon: 'none' });
return;
}
// #ifdef MP-WEIXIN
// login code
uni.login({
success: (loginRes) => {
//
uni.request({
url: config.baseUrl + '/api/wx/decryptPhone',
method: 'POST',
@ -148,154 +143,143 @@ export default {
iv: e.detail.iv
},
success: (res) => {
if (res.data && res.data.code === 200) {
if (res.data?.code === 200) {
this.formData.phone = res.data.data.phoneNumber || '';
} else {
uni.showToast({
title: res.data?.message || '获取手机号失败',
icon: 'none'
});
uni.showToast({ title: res.data?.message || '获取失败', icon: 'none' });
}
},
fail: () => {
uni.showToast({
title: '获取手机号失败',
icon: 'none'
});
}
fail: () => uni.showToast({ title: '获取手机号失败', icon: 'none' })
});
},
fail: () => {
uni.showToast({
title: '获取手机号失败',
icon: 'none'
});
}
fail: () => uni.showToast({ title: '登录失败', icon: 'none' })
});
// #endif
// #ifndef MP-WEIXIN
uni.showToast({ title: '该功能仅支持微信小程序', icon: 'none' });
uni.showToast({ title: '仅支持微信小程序', icon: 'none' });
// #endif
},
/**
* 切换密码显示
*/
togglePwd() {
this.showPwd = !this.showPwd;
},
/**
* 切换确认密码显示
*/
toggleConfirmPwd() {
this.showConfirmPwd = !this.showConfirmPwd;
},
/**
* 验证身份证号
*/
//
validateIdCard(idCard) {
const reg = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
return reg.test(idCard);
if (!reg.test(idCard)) return false;
const year = +idCard.substring(6, 10);
const month = +idCard.substring(10, 12);
const day = +idCard.substring(12, 14);
const date = new Date(year, month - 1, day);
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return false;
const weights = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
const codes = ['1','0','X','9','8','7','6','5','4','3','2'];
let sum = 0;
for (let i=0;i<17;i++) sum += +idCard[i] * weights[i];
return idCard[17].toUpperCase() === codes[sum % 11];
},
/**
* 验证手机号
*/
//
validatePhone(phone) {
const reg = /^1[3-9]\d{9}$/;
return reg.test(phone);
return /^1[3-9]\d{9}$/.test(phone);
},
/**
* 表单验证
*/
//
validateForm() {
const { name, idCard, phone, password, confirmPassword } = this.formData;
if (!name || name.trim().length === 0) {
// 1. trim
if (!name || name.trim() === '') {
uni.showToast({ title: '请输入姓名', icon: 'none' });
return false;
}
if (!idCard || idCard.trim().length === 0) {
// 2. +
if (!idCard || idCard.trim() === '') {
uni.showToast({ title: '请输入身份证号', icon: 'none' });
return false;
}
if (!this.validateIdCard(idCard)) {
if (!this.validateIdCard(idCard.trim())) {
uni.showToast({ title: '身份证号格式不正确', icon: 'none' });
return false;
}
if (!phone || phone.trim().length === 0) {
// 3. +
if (!phone || phone.trim() === '') {
uni.showToast({ title: '请输入手机号', icon: 'none' });
return false;
}
if (!this.validatePhone(phone)) {
if (!this.validatePhone(phone.trim())) {
uni.showToast({ title: '手机号格式不正确', icon: 'none' });
return false;
}
// 4. 6
if (!password || password.length < 6) {
uni.showToast({ title: '密码至少需要6位', icon: 'none' });
uni.showToast({ title: '密码至少6位', icon: 'none' });
return false;
}
// 5.
if (password !== confirmPassword) {
uni.showToast({ title: '两次输入的密码不一致', icon: 'none' });
uni.showToast({ title: '两次密码不一致', icon: 'none' });
return false;
}
//
return true;
},
/**
* 提交表单
*/
async submit() {
//
if (this.loading) return;
// input data
await this.$nextTick();
// return
if (!this.validateForm()) {
return;
}
this.loading = true;
try {
const openId = await getOpenId();
if (!openId) {
uni.showToast({ title: '获取用户信息失败', icon: 'none' });
this.loading = false;
return;
}
const res = await uni.request({
url: config.baseUrl + '/api/reader/register',
method: 'POST',
data: {
name: this.formData.name,
idCard: this.formData.idCard,
phone: this.formData.phone,
password: this.formData.password,
openId: openId,
libcode: config.LIB_CODE
}
});
if (res.data && res.data.code === 200) {
uni.showToast({ title: '提交成功', icon: 'success' });
setTimeout(() => {
uni.navigateBack();
}, 1500);
} else {
uni.showToast({ title: res.data?.message || '提交失败', icon: 'none' });
}
} catch (error) {
console.error('注册失败:', error);
uni.showToast({ title: '提交失败', icon: 'none' });
uni.showToast({ title: '后续流程正在研发中~', icon: 'none' });
// setTimeout(() => uni.navigateBack(), 1500);
// trim
// const res = await uni.request({
// url: config.baseUrl + '/api/reader/register',
// method: 'POST',
// data: {
// name: this.formData.name.trim(),
// idCard: this.formData.idCard.trim(),
// phone: this.formData.phone.trim(),
// password: this.formData.password,
// openId,
// libcode: config.LIB_CODE
// }
// });
// if (res.data?.code === 200) {
// uni.showToast({ title: '', icon: 'success' });
// setTimeout(() => uni.navigateBack(), 1500);
// } else {
// uni.showToast({ title: res.data?.message || '', icon: 'none' });
// }
} catch (err) {
console.error('提交异常', err);
uni.showToast({ title: '网络异常,请重试', icon: 'none' });
} finally {
this.loading = false;
}
@ -305,71 +289,83 @@ export default {
</script>
<style lang="scss" scoped>
page {
background-color: #f5f7fa;
}
.page-container {
min-height: 100vh;
background-color: #f5f7fa;
padding-bottom: 20px;
}
/* 顶部 */
.top-bar {
position: relative;
width: 100%;
height: 180px;
.top-bar-bg {
width: 100%;
height: 100%;
}
.page-title {
position: absolute;
bottom: 20px;
left: 20px;
font-size: 28px;
font-weight: bold;
height: 210px;
.library-info {
position: relative;
z-index: 2;
color: #fff;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
}
.form-box {
padding: 20px 15px;
/* 表单卡片 */
.form-card {
margin: -30px 12px 12px;
background: #fff;
border-radius: 12px;
padding: 20px 16px;
box-shadow: 0 4px 15px rgba(0,0,0,0.08);
position: relative;
z-index: 3;
}
.form-item {
position: relative;
display: flex;
align-items: center;
height: 44px;
border-bottom: 1px solid #f0f0f0;
margin-bottom: 10px;
border-bottom: 1rpx solid #f2f3f5;
margin-bottom: 4px;
.form-icon {
margin-right: 12px;
font-size: 14px;
color: #01a4fe;
margin-right: 10px;
}
.input {
flex: 1;
height: 100%;
font-size: 14px;
color: #333;
}
.pwd-icon {
margin-left: 10px;
color: #999;
padding: 5px;
}
.get-phone-btn {
background-color: #01a4fe;
color: #fff;
font-size: 12px;
color: #fff;
background-color: #01a4fe;
border-radius: 20px;
padding: 6px 10px;
border: none;
line-height: 1.2;
&::after {
border: none;
}
}
}
/* 提交按钮 */
.submit-btn {
width: 100%;
height: 48px;
height: 44px;
background-color: #01a4fe;
color: #fff;
border-radius: 24px;
font-size: 16px;
border-radius: 22px;
font-size: 15px;
margin-top: 20px;
border: none;
@ -378,28 +374,25 @@ export default {
}
}
.tips {
/* 温馨提示 */
.tips-card {
margin: 0 12px;
background: #fff;
border-radius: 10px;
padding: 15px;
background-color: #fff;
margin: 0 15px;
border-radius: 12px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
.tips-title {
font-size: 14px;
font-weight: bold;
font-size: 13px;
color: #333;
display: block;
font-weight: 500;
margin-bottom: 8px;
}
.tips-content {
text {
display: block;
font-size: 13px;
color: #999;
line-height: 1.8;
}
.tips-text {
font-size: 12px;
color: #666;
line-height: 1.6;
}
}
</style>
</style>

8
static/iconfont.css

@ -11,6 +11,14 @@
-moz-osx-font-smoothing: grayscale;
}
.icon-daohang-banzhengxuzhi:before {
content: "\e614";
}
.icon-a-28-banzhengjian:before {
content: "\e6a4";
}
.icon-yihuifu1:before {
content: "\e676";
}

BIN
static/iconfont.ttf

33
styles/global.scss

@ -77,8 +77,15 @@
margin-bottom: 10px;
}
.library-name {
font-size: 14px;
text-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.2);
font-size: 16px;
font-weight: bold;
margin-top: 8px;
text-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.sub-title {
font-size: 12px;
opacity: 0.9;
margin-top: 4px;
}
}
}
@ -259,7 +266,7 @@
}
.qrcode-popup {
width: 300px;
width: 240px;
padding: 20px;
background: #fff;
border-radius: 12px;
@ -284,4 +291,24 @@
border-radius: 20px;
font-size: 14px;
padding: 5px 20px;
}
.register-btn {
position: fixed;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
width: calc(100% - 40px);
height: 44px;
line-height: 44px;
border-radius: 24px;
background-color: #fff !important;
color: #01a4fe !important;
border: 1px solid #01a4fe !important;
font-size: 16px;
font-weight: 500;
&::after {
border: none !important;
}
}

12
subpkg/pages/reader-card/reader-card.vue

@ -33,7 +33,7 @@
<view class="add-card-btn" @click="toAddReaderCard" v-if="!isEditMode">
<uni-icons type="plus" size="20" color="#01a4fe"></uni-icons>
<text>新增读者证</text>
<text>绑定读者证</text>
</view>
</view>
@ -60,9 +60,11 @@
background="#f5f5f5"
/>
<view class="qrcode-num">{{ qrcodeText }}</view>
<view class="close-btn" @click="closePopup">关闭</view>
<!-- <view class="close-btn" @click="closePopup">关闭</view> -->
</view>
</uni-popup>
<button class="register-btn" type="primary" @click="goRegister">在线办证</button>
</view>
</template>
@ -239,6 +241,12 @@ export default {
toAddReaderCard() {
uni.navigateTo({ url: "/pages/login/login" });
},
// 线
goRegister() {
uni.navigateTo({
url: '/pages/register/register'
});
}
}
}
</script>

Loading…
Cancel
Save