quickMark.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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, onShow } from '@dcloudio/uni-app'
  10. import { myRequest } from '@/utils/api.js'
  11. // 二维码信息内容
  12. const QRCodeUrl = ref('')
  13. // 屏幕亮度
  14. const brightness = ref(0)
  15. // 二维码自定义样式
  16. const options = {
  17. typeNumber: -1,
  18. foregroundImageBorderRadius: 5,
  19. foregroundImageSrc: '/static/images/school-logo.jpg'
  20. }
  21. const timer = ref(null)
  22. const timerCode = ref(null)
  23. onLoad((data) => {
  24. // 获取二维码信息内容
  25. QRCodeUrl.value = data.value
  26. // 监听用户截屏事件
  27. uni.onUserCaptureScreen(showTips)
  28. // 获取屏幕亮度
  29. getBrightness()
  30. // 设置屏幕亮度
  31. setBrightness(1)
  32. //开启定时器 监听ios用户是否录屏
  33. timer.value = setInterval(() => {
  34. uni.getScreenRecordingState({
  35. success: (res) => {
  36. if (res.state == 'on') {
  37. uni.showModal({
  38. title: '提示',
  39. content: '此页面不允许录屏',
  40. showCancel: false,
  41. success: () => {
  42. uni.redirectTo({
  43. url: '/pages/home/home'
  44. })
  45. }
  46. })
  47. }
  48. }
  49. })
  50. }, 1000)
  51. // 开启安卓用户禁止截屏
  52. if (wx.setVisualEffectOnCapture) {
  53. wx.setVisualEffectOnCapture({
  54. visualEffect: 'hidden',
  55. complete: function (res) {
  56. console.log('开启', res)
  57. }
  58. })
  59. }
  60. })
  61. onShow(() => {
  62. if (timerCode.value) {
  63. clearInterval(timerCode.value)
  64. }
  65. timerCode.value = setInterval(() => {
  66. getQrcode()
  67. }, 55000)
  68. })
  69. onUnload(() => {
  70. // 取消监听用户截屏事件
  71. uni.offUserCaptureScreen()
  72. // 恢复屏幕亮度
  73. setBrightness(brightness.value)
  74. // 清除定时器
  75. clearInterval(timer.value)
  76. // 关闭安卓用户禁止截屏
  77. if (wx.setVisualEffectOnCapture) {
  78. wx.setVisualEffectOnCapture({
  79. visualEffect: 'none',
  80. complete: function (res) {
  81. console.log('解除', res)
  82. }
  83. })
  84. }
  85. clearInterval(timerCode.value)
  86. })
  87. // 获取身份码信息
  88. const getQrcode = async () => {
  89. const res = await myRequest({
  90. url: '/wanzai/api/smartQrcode/generateQrcode',
  91. data: {
  92. userId: uni.getStorageSync('userInfo').id
  93. }
  94. })
  95. // console.log(res)
  96. QRCodeUrl.value = res.data.qrcode
  97. }
  98. // 获取屏幕亮度
  99. const getBrightness = () => {
  100. uni.getScreenBrightness({
  101. success: (res) => {
  102. brightness.value = res.value
  103. }
  104. })
  105. }
  106. // 设置屏幕亮度
  107. const setBrightness = (data) => {
  108. uni.setScreenBrightness({
  109. value: data
  110. })
  111. }
  112. // 提示信息函数
  113. const showTips = () => {
  114. uni.showToast({
  115. title: '不要把二维码给他人使用,否则将冻结账号',
  116. icon: 'none',
  117. duration: 3500
  118. })
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .container {
  123. display: flex;
  124. flex-direction: column;
  125. justify-content: space-evenly;
  126. align-items: center;
  127. min-height: 100vh;
  128. background-color: #f1f6fe;
  129. }
  130. </style>