speakerInvitation.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="container">
  3. <image class="bg" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/bg_invite.png" mode="aspectFill"></image>
  4. <!-- 状态栏占位(微信小程序原生适配) -->
  5. <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  6. <view class="return">
  7. <image class="return-img" @click="goBack" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/back_white.png" mode="aspectFill"></image>
  8. </view>
  9. <!-- 核心内容区:居中布局 -->
  10. <view class="main-content">
  11. <!-- 页面大标题:讲者邀请 -->
  12. <view class="page-title">
  13. <image class="title-img" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/img_title.png" mode="aspectFill"></image>
  14. <text class="title-txt">讲者邀请</text>
  15. <image class="title-img rotate180" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/img_title.png" mode="aspectFill"></image>
  16. </view>
  17. <!-- 邀请卡片:白色背景+圆角+轻微阴影(1:1匹配UI) -->
  18. <view class="invite-card">
  19. <!-- 邀请人信息区 -->
  20. <view class="inviter-section">
  21. <image class="inviter-avatar" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/my_heads_icon.png" mode="aspectFill"></image>
  22. <text class="inviter-name">王小明</text>
  23. <text class="invite-desc">邀请你成为讲者</text>
  24. </view>
  25. <!-- 二维码区域:白色边框+圆角 -->
  26. <view class="qrcode-box">
  27. <image class="qrcode-img" :src="qscode" @longpress="saveQrcode"></image>
  28. </view>
  29. <!-- 扫码提示文字 -->
  30. <view class="scan-tip">扫一扫,注册学苑</view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { inviteDoctor } from '@/api/speaker.js'
  37. export default {
  38. data() {
  39. return {
  40. // 仅获取微信小程序状态栏高度,无多余逻辑
  41. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  42. userInfo: {},
  43. qscode:''
  44. };
  45. },
  46. onLoad() {
  47. this.userInfo=uni.getStorageSync('userInfo')||{};
  48. this.inviteDoctor();
  49. },
  50. methods: {
  51. goBack() {
  52. uni.navigateBack({
  53. delta: 1
  54. });
  55. },
  56. saveQrcode() {
  57. if (!this.qscode) {
  58. uni.showToast({
  59. icon: 'none',
  60. title: '二维码未加载'
  61. });
  62. return;
  63. }
  64. uni.showLoading({
  65. title: '保存中...'
  66. });
  67. // 如果是base64格式的图片,需要先转换为临时文件
  68. if (this.qscode.startsWith('data:image')) {
  69. const base64Data = this.qscode.replace(/^data:image\/\w+;base64,/, '');
  70. const filePath = `${wx.env.USER_DATA_PATH}/qrcode_${Date.now()}.png`;
  71. const fs = wx.getFileSystemManager();
  72. try {
  73. fs.writeFileSync(filePath, base64Data, 'base64');
  74. uni.saveImageToPhotosAlbum({
  75. filePath: filePath,
  76. success: () => {
  77. uni.hideLoading();
  78. uni.showToast({
  79. icon: 'success',
  80. title: '保存成功'
  81. });
  82. },
  83. fail: (err) => {
  84. uni.hideLoading();
  85. if (err.errMsg.includes('auth')) {
  86. uni.showModal({
  87. title: '提示',
  88. content: '需要您授权保存图片到相册',
  89. success: (modalRes) => {
  90. if (modalRes.confirm) {
  91. uni.openSetting({
  92. success: (settingRes) => {
  93. if (settingRes.authSetting['scope.writePhotosAlbum']) {
  94. this.saveQrcode();
  95. }
  96. }
  97. });
  98. }
  99. }
  100. });
  101. } else {
  102. uni.showToast({
  103. icon: 'none',
  104. title: '保存失败'
  105. });
  106. }
  107. }
  108. });
  109. } catch (e) {
  110. uni.hideLoading();
  111. uni.showToast({
  112. icon: 'none',
  113. title: '保存失败'
  114. });
  115. }
  116. } else {
  117. // 如果是网络图片URL
  118. uni.downloadFile({
  119. url: this.qscode,
  120. success: (res) => {
  121. if (res.statusCode === 200) {
  122. uni.saveImageToPhotosAlbum({
  123. filePath: res.tempFilePath,
  124. success: () => {
  125. uni.hideLoading();
  126. uni.showToast({
  127. icon: 'success',
  128. title: '保存成功'
  129. });
  130. },
  131. fail: (err) => {
  132. uni.hideLoading();
  133. if (err.errMsg.includes('auth')) {
  134. uni.showModal({
  135. title: '提示',
  136. content: '需要您授权保存图片到相册',
  137. success: (modalRes) => {
  138. if (modalRes.confirm) {
  139. uni.openSetting({
  140. success: (settingRes) => {
  141. if (settingRes.authSetting['scope.writePhotosAlbum']) {
  142. this.saveQrcode();
  143. }
  144. }
  145. });
  146. }
  147. }
  148. });
  149. } else {
  150. uni.showToast({
  151. icon: 'none',
  152. title: '保存失败'
  153. });
  154. }
  155. }
  156. });
  157. }
  158. },
  159. fail: () => {
  160. uni.hideLoading();
  161. uni.showToast({
  162. icon: 'none',
  163. title: '下载失败'
  164. });
  165. }
  166. });
  167. }
  168. },
  169. inviteDoctor() {
  170. inviteDoctor(this.userInfo.userId,this.userInfo.companyId).then(res => {
  171. console.log('inviteDoctor返回数据:', res);
  172. if (res.code === 200) {
  173. // 将arraybuffer转换为base64
  174. const arrayBuffer = res.data;
  175. const base64 = uni.arrayBufferToBase64(arrayBuffer);
  176. this.qscode = 'data:image/png;base64,' + base64;
  177. } else {
  178. uni.showToast({
  179. icon: 'none',
  180. title: res.msg || '获取二维码失败'
  181. });
  182. }
  183. }).catch(err => {
  184. console.error('获取二维码失败:', err);
  185. uni.showToast({
  186. icon: 'none',
  187. title: '获取二维码失败'
  188. });
  189. });
  190. }
  191. }
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. /* 小程序页面全局重置:消除默认样式 */
  196. page {
  197. margin: 0;
  198. padding: 0;
  199. background-color: #F8F7F5;
  200. font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  201. }
  202. /* 根容器:全屏+垂直布局 */
  203. .container {
  204. min-height: 100vh;
  205. display: flex;
  206. flex-direction: column;
  207. background-color: #F8F7F5;
  208. position: relative;
  209. .bg {
  210. position: absolute;
  211. top: 0;
  212. width: 100%;
  213. height: 100%;
  214. }
  215. }
  216. /* 状态栏占位:透明背景,仅占高度 */
  217. .status-bar {
  218. width: 100%;
  219. background-color: transparent;
  220. }
  221. .return {
  222. position: relative;
  223. height: 88rpx;
  224. z-index: 2;
  225. line-height: 88rpx;
  226. .return-img {
  227. width: 40rpx;
  228. height: 40rpx;
  229. margin-left: 32rpx;
  230. }
  231. }
  232. /* 核心内容区:水平居中+顶部间距 */
  233. .main-content {
  234. width: 100%;
  235. display: flex;
  236. flex-direction: column;
  237. align-items: center;
  238. padding: 52rpx 74rpx 0;
  239. box-sizing: border-box;
  240. position: relative;
  241. z-index: 2;
  242. /* 页面大标题:讲者邀请(匹配UI字体/大小/颜色) */
  243. .page-title {
  244. font-weight: 600;
  245. font-size: 48rpx;
  246. color: #FFFFFF;
  247. margin-bottom: 124rpx;
  248. display: flex;
  249. align-items: center;
  250. .title-img {
  251. width: 134rpx;
  252. height: 12rpx;
  253. }
  254. .title-txt {
  255. margin: 0 20rpx;
  256. }
  257. .rotate180 {
  258. transform: rotate(180deg);
  259. }
  260. }
  261. /* 邀请卡片:白色背景+圆角+轻微阴影(1:1匹配) */
  262. .invite-card {
  263. width: 100%;
  264. background-color: #FFFFFF;
  265. border-radius: 32rpx;
  266. box-shadow: 0rpx 16rpx 28rpx 0rpx rgba(45, 109, 199, 0.37);
  267. padding: 60rpx 40rpx 80rpx;
  268. position: relative;
  269. box-sizing: border-box;
  270. /* 邀请人信息区:头像+文字横向布局 */
  271. .inviter-section {
  272. position: absolute;
  273. top: -72rpx;
  274. left: 50%;
  275. transform: translateX(-50%);
  276. display: flex;
  277. flex-direction: column;
  278. justify-content: center;
  279. align-items: center;
  280. .inviter-avatar {
  281. width: 144rpx;
  282. height: 144rpx;
  283. border-radius: 50%;
  284. margin-bottom: 18rpx;
  285. }
  286. /* 邀请人姓名 */
  287. .inviter-name {
  288. color: #000000;
  289. font-weight: 600;
  290. font-size: 36rpx;
  291. margin-bottom: 36rpx;
  292. }
  293. /* 邀请文案 */
  294. .invite-desc {
  295. font-size: 32rpx;
  296. color: #666666;
  297. }
  298. }
  299. .qrcode-box {
  300. width: 372rpx;
  301. height: 372rpx;
  302. background-color: #FFFFFF;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. margin: 200rpx auto 40rpx;
  307. .qrcode-img {
  308. width: 372rpx;
  309. height: 372rpx;
  310. }
  311. }
  312. /* 扫码提示文字:居中+浅灰色 */
  313. .scan-tip {
  314. text-align: center;
  315. font-size: 32rpx;
  316. color: #333333;
  317. }
  318. }
  319. }
  320. </style>