3 changed files with 378 additions and 43 deletions
@ -1,22 +1,141 @@ |
|||||
// pages/qrcode/index.js
|
// pages/qrcode/index.js
|
||||
|
const API = require('../../utils/api.js'); |
||||
|
|
||||
Page({ |
Page({ |
||||
data: { |
data: { |
||||
qrCodeUrl: '' // 二维码图片URL
|
qrCodeUrl: '', // 二维码图片URL
|
||||
|
userInfo: { |
||||
|
projectName: '未登录', |
||||
|
name: '未登录', |
||||
|
phoneNumber: '未登录' |
||||
|
}, |
||||
|
imageLoading: false, |
||||
|
imageError: false |
||||
}, |
}, |
||||
|
|
||||
onLoad: function (options) { |
onLoad: function (options) { |
||||
// 页面加载时的初始化逻辑
|
// 页面加载时的初始化逻辑
|
||||
console.log('二维码页面加载'); |
console.log('二维码页面加载'); |
||||
// 这里可以添加生成或获取二维码的逻辑
|
// 加载用户信息
|
||||
|
this.loadUserInfo(); |
||||
}, |
}, |
||||
|
|
||||
onShow: function () { |
onShow: function () { |
||||
// 页面显示时的逻辑
|
// 页面显示时的逻辑
|
||||
|
// 重新加载用户信息,确保信息是最新的
|
||||
|
this.loadUserInfo(); |
||||
}, |
}, |
||||
|
|
||||
// 示例:生成二维码的函数
|
// 加载用户信息
|
||||
|
loadUserInfo: function () { |
||||
|
// 从本地存储获取用户信息
|
||||
|
const userInfo = wx.getStorageSync('userInfo') || {}; |
||||
|
const phoneNumber = userInfo.phoneNumber || wx.getStorageSync('phoneNumber') || ''; |
||||
|
|
||||
|
if (phoneNumber) { |
||||
|
// 根据电话号码查询personnel表
|
||||
|
API.request('/api/personnel/get', 'POST', { phone: phoneNumber }).then(res => { |
||||
|
console.log('查询personnel表结果:', res); |
||||
|
if (res && res.success && res.data && res.data.length > 0) { |
||||
|
const personnelInfo = res.data[0]; |
||||
|
this.setData({ |
||||
|
userInfo: { |
||||
|
projectName: personnelInfo.projectName || '未提供', |
||||
|
name: personnelInfo.name || '未提供', |
||||
|
phoneNumber: phoneNumber |
||||
|
} |
||||
|
}); |
||||
|
} else { |
||||
|
// 如果查询失败,使用本地存储的用户信息
|
||||
|
this.setData({ |
||||
|
userInfo: { |
||||
|
projectName: '未提供', |
||||
|
name: userInfo.nickName || userInfo.name || '未提供', |
||||
|
phoneNumber: phoneNumber |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
}).catch(err => { |
||||
|
console.error('查询personnel表失败:', err); |
||||
|
// 如果查询失败,使用本地存储的用户信息
|
||||
|
this.setData({ |
||||
|
userInfo: { |
||||
|
projectName: '未提供', |
||||
|
name: userInfo.nickName || userInfo.name || '未提供', |
||||
|
phoneNumber: phoneNumber |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} else { |
||||
|
// 如果没有电话号码,提示用户登录
|
||||
|
wx.showToast({ |
||||
|
title: '请先登录', |
||||
|
icon: 'none', |
||||
|
duration: 2000 |
||||
|
}); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
// 生成二维码的函数
|
||||
generateQRCode: function () { |
generateQRCode: function () { |
||||
// 这里可以添加生成二维码的逻辑
|
// 设置图片加载状态
|
||||
// 例如,调用API生成二维码并获取URL
|
this.setData({ |
||||
|
imageLoading: true, |
||||
|
imageError: false |
||||
|
}); |
||||
|
|
||||
|
// 生成包含会话ID的URL
|
||||
|
const sessionId = 'session_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9); |
||||
|
|
||||
|
// 获取用户信息
|
||||
|
const { userInfo } = this.data; |
||||
|
let inviterName = userInfo.name || ''; |
||||
|
let inviterPhone = userInfo.phoneNumber || ''; |
||||
|
let inviterProjectName = userInfo.projectName || ''; |
||||
|
|
||||
|
// 构建邀请URL,包含会话ID和邀请者信息
|
||||
|
const inviteUrl = `http://8.137.125.67:3008/certificate.html?sessionId=${encodeURIComponent(sessionId)}&inviter=${encodeURIComponent(inviterName)}&inviterPhone=${encodeURIComponent(inviterPhone)}&inviterProjectName=${encodeURIComponent(inviterProjectName)}`; |
||||
|
|
||||
|
// 使用api.qrserver.com生成二维码
|
||||
|
const qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=${encodeURIComponent(inviteUrl)}`; |
||||
|
|
||||
|
console.log('生成的二维码URL:', qrCodeUrl); |
||||
|
|
||||
|
// 更新二维码图片
|
||||
|
this.setData({ |
||||
|
qrCodeUrl: qrCodeUrl |
||||
|
}, () => { |
||||
|
console.log('二维码URL已更新:', this.data.qrCodeUrl); |
||||
|
// 显示成功提示
|
||||
|
wx.showToast({ |
||||
|
title: '邀请二维码生成成功!', |
||||
|
icon: 'success', |
||||
|
duration: 2000 |
||||
|
}); |
||||
|
}); |
||||
|
}, |
||||
|
|
||||
|
// 图片加载成功事件
|
||||
|
onImageLoad: function () { |
||||
|
console.log('二维码图片加载成功'); |
||||
|
this.setData({ |
||||
|
imageLoading: false, |
||||
|
imageError: false |
||||
|
}); |
||||
|
}, |
||||
|
|
||||
|
// 图片加载失败事件
|
||||
|
onImageError: function (e) { |
||||
|
console.error('二维码图片加载失败:', e); |
||||
|
this.setData({ |
||||
|
imageLoading: false, |
||||
|
imageError: true |
||||
|
}); |
||||
|
wx.showToast({ |
||||
|
title: '二维码图片加载失败,请重试', |
||||
|
icon: 'none', |
||||
|
duration: 2000 |
||||
|
}); |
||||
} |
} |
||||
|
|
||||
}); |
}); |
||||
@ -1,14 +1,58 @@ |
|||||
<view class="container"> |
<view class="container"> |
||||
<view class="qrcode-container"> |
<view class="user-info"> |
||||
<text class="qrcode-title">二维码</text> |
<view class="user-info-header"> |
||||
<view class="qrcode-content"> |
<text class="user-info-title">登录信息</text> |
||||
<!-- 这里可以添加二维码图片 --> |
</view> |
||||
<view wx:if="{{qrCodeUrl}}" class="qrcode-image"> |
<view class="user-info-content"> |
||||
<image src="{{qrCodeUrl}}" mode="aspectFit"></image> |
<text class="user-info-item">职位:<text class="user-info-value">{{userInfo.projectName}}</text></text> |
||||
|
<text class="user-info-item">姓名:<text class="user-info-value">{{userInfo.name}}</text></text> |
||||
|
<text class="user-info-item">电话:<text class="user-info-value">{{userInfo.phoneNumber}}</text></text> |
||||
|
</view> |
||||
|
</view> |
||||
|
|
||||
|
<view class="header"> |
||||
|
<text class="header-title">生成邀请二维码</text> |
||||
|
<text class="header-subtitle">创建一个二维码,邀请他人填写合格证信息</text> |
||||
|
</view> |
||||
|
|
||||
|
<view class="info-box"> |
||||
|
<text class="info-box-title">使用说明</text> |
||||
|
<text class="info-box-item">1. 点击下方按钮生成邀请二维码</text> |
||||
|
<text class="info-box-item">2. 将生成的二维码分享给需要填写信息的人</text> |
||||
|
<text class="info-box-item">3. 对方扫描二维码后,填写完整的合格证信息并提交</text> |
||||
|
<text class="info-box-item">4. 您可以扫描下方二维码查看和导出已填写的信息</text> |
||||
|
</view> |
||||
|
|
||||
|
<view class="qr-container"> |
||||
|
<text class="qr-container-title">📝 邀请二维码</text> |
||||
|
<view wx:if="{{qrCodeUrl}}" class="qrcode-image"> |
||||
|
<image |
||||
|
src="{{qrCodeUrl}}" |
||||
|
mode="aspectFit" |
||||
|
bindload="onImageLoad" |
||||
|
binderror="onImageError" |
||||
|
></image> |
||||
|
<view wx:if="{{imageLoading}}" class="image-loading"> |
||||
|
<text>加载中...</text> |
||||
</view> |
</view> |
||||
<view wx:else class="qrcode-placeholder"> |
<view wx:if="{{imageError}}" class="image-error"> |
||||
<text class="placeholder-text">二维码将显示在这里</text> |
<text>加载失败,请重试</text> |
||||
</view> |
</view> |
||||
</view> |
</view> |
||||
|
<view wx:else class="qrcode-placeholder"> |
||||
|
<text class="placeholder-text">二维码将显示在这里</text> |
||||
|
</view> |
||||
|
<view class="qr-info"> |
||||
|
<text class="qr-info-title">作用:邀请他人填写合格证信息</text> |
||||
|
<text class="qr-info-subtitle">扫描此二维码进入信息填写页面</text> |
||||
|
</view> |
||||
|
</view> |
||||
|
|
||||
|
<view class="action-buttons"> |
||||
|
<button class="action-btn primary" bindtap="generateQRCode">生成邀请二维码</button> |
||||
|
</view> |
||||
|
|
||||
|
<view class="footer"> |
||||
|
<text class="footer-text">技术支持:四川又鸟蛋贸易有限公司</text> |
||||
</view> |
</view> |
||||
</view> |
</view> |
||||
Loading…
Reference in new issue