| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- <template>
- <view class="container">
- <image class="bg" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/bg_invite.png" mode="aspectFill"></image>
- <!-- 状态栏占位(微信小程序原生适配) -->
- <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
- <view class="return">
- <image class="return-img" @click="goBack" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/back_white.png" mode="aspectFill"></image>
- </view>
- <!-- 核心内容区:居中布局 -->
- <view class="main-content">
- <!-- 页面大标题:讲者邀请 -->
- <view class="page-title">
- <image class="title-img" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/img_title.png" mode="aspectFill"></image>
- <text class="title-txt">讲者邀请</text>
- <image class="title-img rotate180" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/img_title.png" mode="aspectFill"></image>
- </view>
- <!-- 邀请卡片:白色背景+圆角+轻微阴影(1:1匹配UI) -->
- <view class="invite-card">
- <!-- 邀请人信息区 -->
- <view class="inviter-section">
- <image class="inviter-avatar" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/my_heads_icon.png" mode="aspectFill"></image>
- <text class="inviter-name">王小明</text>
- <text class="invite-desc">邀请你成为讲者</text>
- </view>
- <!-- 二维码区域:白色边框+圆角 -->
- <view class="qrcode-box">
- <image class="qrcode-img" :src="qscode" @longpress="saveQrcode"></image>
- </view>
- <!-- 扫码提示文字 -->
- <view class="scan-tip">扫一扫,注册学苑</view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { inviteDoctor } from '@/api/speaker.js'
- export default {
- data() {
- return {
- // 仅获取微信小程序状态栏高度,无多余逻辑
- statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
- userInfo: {},
- qscode:''
- };
- },
- onLoad() {
- this.userInfo=uni.getStorageSync('userInfo')||{};
- this.inviteDoctor();
- },
- methods: {
- goBack() {
- uni.navigateBack({
- delta: 1
- });
- },
- saveQrcode() {
- if (!this.qscode) {
- uni.showToast({
- icon: 'none',
- title: '二维码未加载'
- });
- return;
- }
-
- uni.showLoading({
- title: '保存中...'
- });
-
- // 如果是base64格式的图片,需要先转换为临时文件
- if (this.qscode.startsWith('data:image')) {
- const base64Data = this.qscode.replace(/^data:image\/\w+;base64,/, '');
- const filePath = `${wx.env.USER_DATA_PATH}/qrcode_${Date.now()}.png`;
-
- const fs = wx.getFileSystemManager();
- try {
- fs.writeFileSync(filePath, base64Data, 'base64');
-
- uni.saveImageToPhotosAlbum({
- filePath: filePath,
- success: () => {
- uni.hideLoading();
- uni.showToast({
- icon: 'success',
- title: '保存成功'
- });
- },
- fail: (err) => {
- uni.hideLoading();
- if (err.errMsg.includes('auth')) {
- uni.showModal({
- title: '提示',
- content: '需要您授权保存图片到相册',
- success: (modalRes) => {
- if (modalRes.confirm) {
- uni.openSetting({
- success: (settingRes) => {
- if (settingRes.authSetting['scope.writePhotosAlbum']) {
- this.saveQrcode();
- }
- }
- });
- }
- }
- });
- } else {
- uni.showToast({
- icon: 'none',
- title: '保存失败'
- });
- }
- }
- });
- } catch (e) {
- uni.hideLoading();
- uni.showToast({
- icon: 'none',
- title: '保存失败'
- });
- }
- } else {
- // 如果是网络图片URL
- uni.downloadFile({
- url: this.qscode,
- success: (res) => {
- if (res.statusCode === 200) {
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: () => {
- uni.hideLoading();
- uni.showToast({
- icon: 'success',
- title: '保存成功'
- });
- },
- fail: (err) => {
- uni.hideLoading();
- if (err.errMsg.includes('auth')) {
- uni.showModal({
- title: '提示',
- content: '需要您授权保存图片到相册',
- success: (modalRes) => {
- if (modalRes.confirm) {
- uni.openSetting({
- success: (settingRes) => {
- if (settingRes.authSetting['scope.writePhotosAlbum']) {
- this.saveQrcode();
- }
- }
- });
- }
- }
- });
- } else {
- uni.showToast({
- icon: 'none',
- title: '保存失败'
- });
- }
- }
- });
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast({
- icon: 'none',
- title: '下载失败'
- });
- }
- });
- }
- },
- inviteDoctor() {
- inviteDoctor(this.userInfo.userId,this.userInfo.companyId).then(res => {
- console.log('inviteDoctor返回数据:', res);
- if (res.code === 200) {
- // 将arraybuffer转换为base64
- const arrayBuffer = res.data;
- const base64 = uni.arrayBufferToBase64(arrayBuffer);
- this.qscode = 'data:image/png;base64,' + base64;
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg || '获取二维码失败'
- });
- }
- }).catch(err => {
- console.error('获取二维码失败:', err);
- uni.showToast({
- icon: 'none',
- title: '获取二维码失败'
- });
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- /* 小程序页面全局重置:消除默认样式 */
- page {
- margin: 0;
- padding: 0;
- background-color: #F8F7F5;
- font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
- }
- /* 根容器:全屏+垂直布局 */
- .container {
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- background-color: #F8F7F5;
- position: relative;
- .bg {
- position: absolute;
- top: 0;
- width: 100%;
- height: 100%;
- }
- }
- /* 状态栏占位:透明背景,仅占高度 */
- .status-bar {
- width: 100%;
- background-color: transparent;
- }
- .return {
- position: relative;
- height: 88rpx;
- z-index: 2;
- line-height: 88rpx;
- .return-img {
- width: 40rpx;
- height: 40rpx;
- margin-left: 32rpx;
- }
- }
- /* 核心内容区:水平居中+顶部间距 */
- .main-content {
- width: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 52rpx 74rpx 0;
- box-sizing: border-box;
- position: relative;
- z-index: 2;
- /* 页面大标题:讲者邀请(匹配UI字体/大小/颜色) */
- .page-title {
- font-weight: 600;
- font-size: 48rpx;
- color: #FFFFFF;
- margin-bottom: 124rpx;
- display: flex;
- align-items: center;
- .title-img {
- width: 134rpx;
- height: 12rpx;
- }
- .title-txt {
- margin: 0 20rpx;
- }
- .rotate180 {
- transform: rotate(180deg);
- }
- }
- /* 邀请卡片:白色背景+圆角+轻微阴影(1:1匹配) */
- .invite-card {
- width: 100%;
- background-color: #FFFFFF;
- border-radius: 32rpx;
- box-shadow: 0rpx 16rpx 28rpx 0rpx rgba(45, 109, 199, 0.37);
- padding: 60rpx 40rpx 80rpx;
- position: relative;
- box-sizing: border-box;
- /* 邀请人信息区:头像+文字横向布局 */
- .inviter-section {
- position: absolute;
- top: -72rpx;
- left: 50%;
- transform: translateX(-50%);
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- .inviter-avatar {
- width: 144rpx;
- height: 144rpx;
- border-radius: 50%;
- margin-bottom: 18rpx;
- }
- /* 邀请人姓名 */
- .inviter-name {
- color: #000000;
- font-weight: 600;
- font-size: 36rpx;
- margin-bottom: 36rpx;
- }
- /* 邀请文案 */
- .invite-desc {
- font-size: 32rpx;
- color: #666666;
- }
- }
- .qrcode-box {
- width: 372rpx;
- height: 372rpx;
- background-color: #FFFFFF;
- display: flex;
- align-items: center;
- justify-content: center;
- margin: 200rpx auto 40rpx;
- .qrcode-img {
- width: 372rpx;
- height: 372rpx;
- }
- }
- /* 扫码提示文字:居中+浅灰色 */
- .scan-tip {
- text-align: center;
- font-size: 32rpx;
- color: #333333;
- }
- }
- }
- </style>
|