speakerInvitation.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. // 检查返回数据的类型
  173. if (res && typeof res === 'object' && res.code === 200 && res.data) {
  174. // 如果是标准的API返回格式
  175. const arrayBuffer = res.data;
  176. const base64 = uni.arrayBufferToBase64(arrayBuffer);
  177. this.qscode = 'data:image/png;base64,' + base64;
  178. } else {
  179. // 如果直接返回arraybuffer
  180. try {
  181. const base64 = uni.arrayBufferToBase64(res);
  182. this.qscode = 'data:image/png;base64,' + base64;
  183. } catch (e) {
  184. console.error('二维码转换失败:', e);
  185. uni.showToast({
  186. icon: 'none',
  187. title: '二维码转换失败'
  188. });
  189. }
  190. }
  191. }).catch(err => {
  192. console.error('获取二维码失败:', err);
  193. uni.showToast({
  194. icon: 'none',
  195. title: '获取二维码失败'
  196. });
  197. });
  198. }
  199. }
  200. };
  201. </script>
  202. <style lang="scss" scoped>
  203. /* 小程序页面全局重置:消除默认样式 */
  204. page {
  205. margin: 0;
  206. padding: 0;
  207. background-color: #F8F7F5;
  208. font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  209. }
  210. /* 根容器:全屏+垂直布局 */
  211. .container {
  212. min-height: 100vh;
  213. display: flex;
  214. flex-direction: column;
  215. background-color: #F8F7F5;
  216. position: relative;
  217. .bg {
  218. position: absolute;
  219. top: 0;
  220. width: 100%;
  221. height: 100%;
  222. }
  223. }
  224. /* 状态栏占位:透明背景,仅占高度 */
  225. .status-bar {
  226. width: 100%;
  227. background-color: transparent;
  228. }
  229. .return {
  230. position: relative;
  231. height: 88rpx;
  232. z-index: 2;
  233. line-height: 88rpx;
  234. .return-img {
  235. width: 40rpx;
  236. height: 40rpx;
  237. margin-left: 32rpx;
  238. }
  239. }
  240. /* 核心内容区:水平居中+顶部间距 */
  241. .main-content {
  242. width: 100%;
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. padding: 52rpx 74rpx 0;
  247. box-sizing: border-box;
  248. position: relative;
  249. z-index: 2;
  250. /* 页面大标题:讲者邀请(匹配UI字体/大小/颜色) */
  251. .page-title {
  252. font-weight: 600;
  253. font-size: 48rpx;
  254. color: #FFFFFF;
  255. margin-bottom: 124rpx;
  256. display: flex;
  257. align-items: center;
  258. .title-img {
  259. width: 134rpx;
  260. height: 12rpx;
  261. }
  262. .title-txt {
  263. margin: 0 20rpx;
  264. }
  265. .rotate180 {
  266. transform: rotate(180deg);
  267. }
  268. }
  269. /* 邀请卡片:白色背景+圆角+轻微阴影(1:1匹配) */
  270. .invite-card {
  271. width: 100%;
  272. background-color: #FFFFFF;
  273. border-radius: 32rpx;
  274. box-shadow: 0rpx 16rpx 28rpx 0rpx rgba(45, 109, 199, 0.37);
  275. padding: 60rpx 40rpx 80rpx;
  276. position: relative;
  277. box-sizing: border-box;
  278. /* 邀请人信息区:头像+文字横向布局 */
  279. .inviter-section {
  280. position: absolute;
  281. top: -72rpx;
  282. left: 50%;
  283. transform: translateX(-50%);
  284. display: flex;
  285. flex-direction: column;
  286. justify-content: center;
  287. align-items: center;
  288. .inviter-avatar {
  289. width: 144rpx;
  290. height: 144rpx;
  291. border-radius: 50%;
  292. margin-bottom: 18rpx;
  293. }
  294. /* 邀请人姓名 */
  295. .inviter-name {
  296. color: #000000;
  297. font-weight: 600;
  298. font-size: 36rpx;
  299. margin-bottom: 36rpx;
  300. }
  301. /* 邀请文案 */
  302. .invite-desc {
  303. font-size: 32rpx;
  304. color: #666666;
  305. }
  306. }
  307. .qrcode-box {
  308. width: 372rpx;
  309. height: 372rpx;
  310. background-color: #FFFFFF;
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. margin: 200rpx auto 40rpx;
  315. .qrcode-img {
  316. width: 372rpx;
  317. height: 372rpx;
  318. }
  319. }
  320. /* 扫码提示文字:居中+浅灰色 */
  321. .scan-tip {
  322. text-align: center;
  323. font-size: 32rpx;
  324. color: #333333;
  325. }
  326. }
  327. }
  328. </style>