爱简收旧衣按件回收前端代码仓库
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.

271 lines
5.3 KiB

2 weeks ago
  1. <template>
  2. <!-- 客服二维码弹窗 -->
  3. <view v-if="showModal" class="qrcode-modal-mask" @click="closeModal">
  4. <view class="qrcode-modal-content" @click.stop>
  5. <view class="qrcode-modal-header">
  6. <text class="qrcode-modal-title">联系客服</text>
  7. <view class="qrcode-modal-close" @click="closeModal">
  8. <uni-icons type="close" size="24" color="#999"></uni-icons>
  9. </view>
  10. </view>
  11. <view class="qrcode-modal-body">
  12. <image
  13. v-if="serviceQrcodeUrl"
  14. :src="serviceQrcodeUrl"
  15. mode="aspectFit"
  16. class="qrcode-modal-img"
  17. :show-menu-by-longpress="true"
  18. @longpress="onQrcodeLongPress"
  19. ></image>
  20. <view v-else class="qrcode-placeholder">
  21. <text>二维码加载中...</text>
  22. </view>
  23. <text class="qrcode-modal-tip">长按识别二维码添加客服微信</text>
  24. <!-- <view class="qrcode-actions">
  25. <button class="save-btn" @click="saveQrcodeToAlbum" v-if="serviceQrcodeUrl">
  26. 保存到相册
  27. </button>
  28. </view> -->
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'ServiceQrcode',
  36. data() {
  37. return {
  38. showModal: false
  39. }
  40. },
  41. computed: {
  42. serviceQrcodeUrl() {
  43. const item = getApp().globalData.configData.find(i => i.keyName === 'kefu_code')
  44. return item ? item.keyContent : ''
  45. }
  46. },
  47. methods: {
  48. // 打开客服二维码弹窗
  49. open() {
  50. this.showModal = true
  51. },
  52. // 关闭客服二维码弹窗
  53. close() {
  54. this.showModal = false
  55. this.$emit('close')
  56. },
  57. // 关闭二维码弹窗(内部调用)
  58. closeModal() {
  59. this.close()
  60. },
  61. // 处理二维码长按事件
  62. onQrcodeLongPress() {
  63. console.log('长按二维码')
  64. // 在微信小程序中,show-menu-by-longpress="true" 会自动处理长按识别
  65. // 这里可以添加一些反馈提示
  66. uni.showToast({
  67. title: '长按识别二维码',
  68. icon: 'none',
  69. duration: 1500
  70. })
  71. },
  72. // 保存二维码到相册
  73. saveQrcodeToAlbum() {
  74. if (!this.serviceQrcodeUrl) {
  75. uni.showToast({
  76. title: '二维码还未加载完成',
  77. icon: 'none'
  78. })
  79. return
  80. }
  81. // 先授权相册权限
  82. uni.getSetting({
  83. success: (res) => {
  84. if (!res.authSetting['scope.writePhotosAlbum']) {
  85. // 没有权限,申请权限
  86. uni.authorize({
  87. scope: 'scope.writePhotosAlbum',
  88. success: () => {
  89. this.doSaveQrcodeImage()
  90. },
  91. fail: () => {
  92. // 权限被拒绝,引导用户手动开启
  93. uni.showModal({
  94. title: '提示',
  95. content: '需要您授权保存相册权限',
  96. showCancel: false,
  97. success: () => {
  98. uni.openSetting()
  99. }
  100. })
  101. }
  102. })
  103. } else {
  104. // 已有权限,直接保存
  105. this.doSaveQrcodeImage()
  106. }
  107. }
  108. })
  109. },
  110. // 执行保存二维码图片
  111. doSaveQrcodeImage() {
  112. uni.downloadFile({
  113. url: this.serviceQrcodeUrl,
  114. success: (res) => {
  115. if (res.statusCode === 200) {
  116. uni.saveImageToPhotosAlbum({
  117. filePath: res.tempFilePath,
  118. success: () => {
  119. uni.showToast({
  120. title: '保存成功',
  121. icon: 'success'
  122. })
  123. },
  124. fail: (err) => {
  125. console.log('保存失败', err)
  126. uni.showToast({
  127. title: '保存失败',
  128. icon: 'none'
  129. })
  130. }
  131. })
  132. }
  133. },
  134. fail: (err) => {
  135. console.log('下载失败', err)
  136. uni.showToast({
  137. title: '下载失败',
  138. icon: 'none'
  139. })
  140. }
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. // 客服二维码弹窗样式
  148. .qrcode-modal-mask {
  149. position: fixed;
  150. top: 0;
  151. left: 0;
  152. right: 0;
  153. bottom: 0;
  154. background: rgba(0, 0, 0, 0.6);
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. z-index: 9999;
  159. backdrop-filter: blur(5rpx);
  160. }
  161. .qrcode-modal-content {
  162. background: #fff;
  163. border-radius: 24rpx;
  164. width: 600rpx;
  165. max-width: 90vw;
  166. animation: fadeInScale 0.3s ease;
  167. overflow: hidden;
  168. }
  169. .qrcode-modal-header {
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. padding: 40rpx 40rpx 20rpx 40rpx;
  174. border-bottom: 1rpx solid #f0f0f0;
  175. }
  176. .qrcode-modal-title {
  177. font-size: 36rpx;
  178. font-weight: bold;
  179. color: #333;
  180. }
  181. .qrcode-modal-close {
  182. padding: 10rpx;
  183. margin: -10rpx;
  184. }
  185. .qrcode-modal-body {
  186. padding: 40rpx;
  187. display: flex;
  188. flex-direction: column;
  189. align-items: center;
  190. }
  191. .qrcode-modal-img {
  192. width: 400rpx;
  193. height: 400rpx;
  194. border-radius: 16rpx;
  195. margin-bottom: 30rpx;
  196. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  197. }
  198. .qrcode-placeholder {
  199. width: 400rpx;
  200. height: 400rpx;
  201. border-radius: 16rpx;
  202. margin-bottom: 30rpx;
  203. background: #f5f5f5;
  204. display: flex;
  205. justify-content: center;
  206. align-items: center;
  207. text {
  208. color: #999;
  209. font-size: 28rpx;
  210. }
  211. }
  212. .qrcode-modal-tip {
  213. font-size: 28rpx;
  214. color: #666;
  215. text-align: center;
  216. line-height: 1.4;
  217. margin-bottom: 20rpx;
  218. }
  219. .qrcode-actions {
  220. display: flex;
  221. justify-content: center;
  222. margin-top: 20rpx;
  223. }
  224. .save-btn {
  225. background: linear-gradient(90deg, #ff8917, #ffd01e);
  226. color: #fff;
  227. border: none;
  228. border-radius: 25rpx;
  229. padding: 16rpx 40rpx;
  230. font-size: 28rpx;
  231. font-weight: bold;
  232. &::after {
  233. border: none;
  234. }
  235. &:active {
  236. opacity: 0.8;
  237. }
  238. }
  239. @keyframes fadeInScale {
  240. from {
  241. opacity: 0;
  242. transform: scale(0.8);
  243. }
  244. to {
  245. opacity: 1;
  246. transform: scale(1);
  247. }
  248. }
  249. </style>