展品维保小程序前端代码接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
4.9 KiB

2 weeks ago
  1. <template>
  2. <view class="page">
  3. <!-- 活动信息卡片 -->
  4. <view class="activity-card">
  5. <image class="activity-image" :src="activityInfo.image" mode="aspectFill"></image>
  6. <view class="activity-info">
  7. <view class="title-row">
  8. <view class="activity-badge">
  9. <text class="badge-text">{{ activityInfo.score }}</text>
  10. </view>
  11. <text class="activity-title">{{ activityInfo.title }}</text>
  12. </view>
  13. <view class="activity-location">
  14. <uv-icon name="map-fill" size="14" color="#999"></uv-icon>
  15. <text class="location-text">{{ activityInfo.address }}</text>
  16. </view>
  17. <view class="activity-time">
  18. <uv-icon name="calendar" size="14" color="#999"></uv-icon>
  19. <text class="time-text">{{ activityInfo.activityTime }}</text>
  20. </view>
  21. <view class="activity-participants">
  22. <uv-icon name="account-fill" size="14" color="#999"></uv-icon>
  23. <text class="participants-text">{{ activityInfo.numActivity }}/{{ activityInfo.numLimit }}人已报名</text>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 二维码区域 -->
  28. <view class="qrcode-container">
  29. <view class="qrcode-wrapper">
  30. <!-- <uv-qrcode ref="qrcode" size="300px" value="https://h5.uvui.cn"></uv-qrcode> -->
  31. <uv-qrcode
  32. ref="qrcode"
  33. :value="qrcodeValue"
  34. size="500rpx"
  35. @complete="onQRCodeComplete"
  36. ></uv-qrcode>
  37. </view>
  38. </view>
  39. <!-- 保存按钮 -->
  40. <view class="save-container">
  41. <uv-button
  42. type="primary"
  43. text="保存到手机"
  44. size="large"
  45. shape="circle"
  46. @click="saveQRCode"
  47. ></uv-button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import utils from '@/utils/index'
  53. export default {
  54. data() {
  55. return {
  56. activityInfo: {
  57. },
  58. qrcodeValue: 'https://h5.uvui.cn',
  59. qrCodeReady: false
  60. }
  61. },
  62. async onLoad(options) {
  63. // 获取传递的参数
  64. if (options.id) {
  65. await this.getActiviyDetail(options.id)
  66. }
  67. // 生成签到码
  68. this.generateQRCode()
  69. },
  70. methods: {
  71. async getActiviyDetail(id) {
  72. const res = await this.$api.activity.queryActivityById({
  73. activityId: id
  74. })
  75. this.activityInfo = res.result
  76. },
  77. // 生成二维码内容
  78. generateQRCode() {
  79. // 生成包含活动信息的二维码内容
  80. const qrData = {
  81. activityId: this.activityInfo.id,
  82. activityTitle: this.activityInfo.title,
  83. type: 'checkin',
  84. timestamp: Date.now()
  85. }
  86. this.qrcodeValue = JSON.stringify(qrData)
  87. },
  88. // 二维码生成完成事件
  89. onQRCodeComplete(result) {
  90. if (result.success) {
  91. this.qrCodeReady = true
  92. console.log('二维码生成成功')
  93. } else {
  94. console.log('二维码生成失败')
  95. }
  96. },
  97. // 保存二维码到手机
  98. saveQRCode() {
  99. if (!this.qrCodeReady) {
  100. uni.showToast({
  101. title: '二维码还未生成完成',
  102. icon: 'none'
  103. })
  104. return
  105. }
  106. this.$refs.qrcode.save({
  107. success: (res) => {
  108. uni.showToast({
  109. title: '保存成功',
  110. icon: 'success'
  111. })
  112. },
  113. fail: (err) => {
  114. console.log('保存失败:', err)
  115. // 用uniapp获取保存权限
  116. utils.authoriza({
  117. scope: 'writePhotosAlbum',
  118. successfn: () => {
  119. // 保存二维码
  120. this.$refs.qrcode.save({
  121. success: (res) => {
  122. uni.showToast({
  123. title: '保存成功',
  124. icon: 'success'
  125. })
  126. },
  127. fail: (err) => {
  128. console.log('保存失败:', err)
  129. uni.showToast({
  130. title: '保存失败',
  131. icon: 'none'
  132. })
  133. }
  134. })
  135. },
  136. failfn: () => {
  137. uni.showToast({
  138. title: '保存失败',
  139. icon: 'none'
  140. })
  141. }
  142. })
  143. }
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .page {
  151. background-color: #f5f5f5;
  152. min-height: 100vh;
  153. padding: 20rpx;
  154. }
  155. .activity-card {
  156. display: flex;
  157. background: #fff;
  158. border-radius: 12rpx;
  159. padding: 20rpx;
  160. margin-bottom: 40rpx;
  161. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  162. }
  163. .activity-image {
  164. width: 180rpx;
  165. height: 180rpx;
  166. border-radius: 8rpx;
  167. margin-right: 20rpx;
  168. }
  169. .activity-info {
  170. flex: 1;
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: space-between;
  174. }
  175. .title-row {
  176. display: flex;
  177. align-items: center;
  178. margin-bottom: 10rpx;
  179. }
  180. .activity-badge {
  181. width: 31px;
  182. height: 20px;
  183. background: #218cdd;
  184. border-radius: 3.5px;
  185. margin-right: 7rpx;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. }
  190. .badge-text {
  191. font-size: 18rpx;
  192. color: #fff;
  193. }
  194. .activity-title {
  195. font-size: 28rpx;
  196. font-weight: bold;
  197. color: #333;
  198. line-height: 1.4;
  199. }
  200. .activity-location, .activity-time, .activity-participants {
  201. display: flex;
  202. align-items: center;
  203. margin-bottom: 6rpx;
  204. }
  205. .location-text, .time-text, .participants-text {
  206. font-size: 24rpx;
  207. color: #999;
  208. margin-left: 6rpx;
  209. }
  210. .qrcode-container {
  211. display: flex;
  212. justify-content: center;
  213. margin-bottom: 60rpx;
  214. }
  215. .qrcode-wrapper {
  216. background: #fff;
  217. border-radius: 12rpx;
  218. padding: 40rpx;
  219. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  220. }
  221. .save-container {
  222. padding: 0 40rpx;
  223. }
  224. </style>