quickMark.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="container">
  3. <uv-qrcode ref="qrcodeRef" size="400rpx" :value="QRCodeUrl" :options="options"></uv-qrcode>
  4. <view class="tips">不要把二维码给他人使用,否则冻结账号</view>
  5. </view>
  6. </template>
  7. <script setup>
  8. import { ref } from 'vue'
  9. import { onLoad, onUnload } from '@dcloudio/uni-app'
  10. // 二维码信息内容
  11. const QRCodeUrl = ref('')
  12. // 屏幕亮度
  13. const brightness = ref(0)
  14. // 二维码自定义样式
  15. const options = {
  16. typeNumber: 4,
  17. foregroundImageBorderRadius: 5,
  18. foregroundImageSrc: '/static/images/school-logo.png'
  19. }
  20. onLoad((data) => {
  21. // 监听用户截屏事件
  22. uni.onUserCaptureScreen(showTips)
  23. // 获取二维码信息内容
  24. QRCodeUrl.value = data.value
  25. // 获取屏幕亮度
  26. getBrightness()
  27. // 设置屏幕亮度
  28. setBrightness(1)
  29. })
  30. onUnload(() => {
  31. // 取消监听用户截屏事件
  32. uni.offUserCaptureScreen()
  33. // 恢复屏幕亮度
  34. setBrightness(brightness.value)
  35. })
  36. // 获取屏幕亮度
  37. const getBrightness = () => {
  38. uni.getScreenBrightness({
  39. success: (res) => {
  40. brightness.value = res.value
  41. }
  42. })
  43. }
  44. // 设置屏幕亮度
  45. const setBrightness = (data) => {
  46. uni.setScreenBrightness({
  47. value: data
  48. })
  49. }
  50. // 提示信息函数
  51. const showTips = () => {
  52. uni.showToast({
  53. title: '不要把二维码给他人使用,否则将冻结账号',
  54. icon: 'none',
  55. duration: 3500
  56. })
  57. }
  58. </script>
  59. <style lang="scss" scoped>
  60. .container {
  61. display: flex;
  62. flex-direction: column;
  63. justify-content: space-evenly;
  64. align-items: center;
  65. min-height: 100vh;
  66. background-color: #f1f6fe;
  67. }
  68. </style>