TimeoutNoOps.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <van-dialog v-model="noOperationSetTimeoutTimeVisible" title="提示" show-cancel-button
  3. :message="levitatedSphereContent" :confirm-button-text="confirmButtonText"
  4. confirm-button-color="#3cc51f" cancel-button-text="继续操作" @cancel="noOperationSetTimeout('cancel')"
  5. @confirm="noOperationSetTimeout('cancel'), exit(), noOperationSetTimeoutTimeVisible = false">
  6. </van-dialog>
  7. </template>
  8. <script>
  9. /**
  10. * 超时无操作
  11. * 弹窗提示
  12. * 弹窗倒计时无操作则自动退出
  13. */
  14. export default {
  15. name: 'TimeoutNoOps',
  16. data() {
  17. return {
  18. // 后台查询,是否是启动不操作自动退出云机功能
  19. isFiringNoOperationSetTimeout: false,
  20. // 超过指定触碰时间的弹窗是否显示
  21. noOperationSetTimeoutTimeVisible: false,
  22. // 弹窗提示内容
  23. levitatedSphereContent: '由于您长时间未操作,将自动断开视频链接(不影响云手机内应用运行)',
  24. // 间隔无操作时间
  25. noOperationSetTimeoutTime: 300000,
  26. // 超过指定触碰时间的弹窗文案
  27. confirmButtonText: '',
  28. // 超过指定触碰时间的弹窗定时器
  29. noOperationSetTimeoutTimeInterval: null,
  30. // 弹窗后的倒计时定时器
  31. noOperationSetIntervalTimeInterval: null,
  32. }
  33. },
  34. methods: {
  35. // 查询超过指定触碰时间是否提示关闭弹窗
  36. pushflowPopup(){
  37. this.$axios.get('/public/v5/pushflow/popup').then(res => {
  38. if (res.success) {
  39. this.isFiringNoOperationSetTimeout = res.data;
  40. this.noOperationSetTimeout();
  41. }
  42. })
  43. },
  44. // 不触碰屏幕显示退出链接弹窗
  45. noOperationSetTimeout(key) {
  46. if (!this.isFiringNoOperationSetTimeout) return
  47. clearTimeout(this.noOperationSetTimeoutTimeInterval);
  48. if (key === 'cancel') {
  49. clearInterval(this.noOperationSetIntervalTimeInterval);
  50. // 关闭弹窗
  51. this.noOperationSetTimeoutTimeVisible = false;
  52. this.noOperationSetTimeout();
  53. return;
  54. }
  55. // 超过指定触碰时间的弹窗定时器
  56. this.noOperationSetTimeoutTimeInterval = setTimeout(() => {
  57. let index = 9;
  58. this.confirmButtonText = '退出(10秒)';
  59. // 超过指定触碰时间的弹窗定时器
  60. this.noOperationSetTimeoutTimeVisible = true;
  61. // 弹窗后的倒计时定时器
  62. this.noOperationSetIntervalTimeInterval = setInterval(() => {
  63. this.confirmButtonText = `退出${index ? `(${index}秒)` : ''}`
  64. index--;
  65. if (index < 0) {
  66. // 关闭弹窗, 并清空倒计时定时器
  67. this.noOperationSetTimeout('cancel')
  68. // 退出云手机
  69. this.exit();
  70. }
  71. }, 1000);
  72. }, this.noOperationSetTimeoutTime)
  73. },
  74. // 退出
  75. exit() {
  76. this.$emit('exit');
  77. },
  78. }
  79. }
  80. </script>
  81. <style>
  82. </style>