quickMark.vue 3.3 KB

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