test_opreation.blade.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. padding: 0;
  10. margin: 0;
  11. }
  12. #main {
  13. padding: 0 .4rem;
  14. }
  15. #main .bianhao {
  16. font-size: 0.5rem;
  17. font-weight: bold;
  18. color: black;
  19. padding: .4rem;
  20. }
  21. button {
  22. width: 2.3rem;
  23. background-color: #fff;
  24. outline: none;
  25. border: 0.01rem solid #efefef;
  26. padding: 0.2rem;
  27. margin-top: 0.3rem;
  28. }
  29. .redbtn {
  30. background-color: red !important;
  31. color: white !important;
  32. }
  33. .whitebtn {
  34. background-color: white;
  35. color: black;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <div id="main">
  41. <nav class="bianhao">
  42. 设备编号:{{$device->device_name}}
  43. </nav>
  44. <article>
  45. <div class="bianhao" style="padding-top: 0;">
  46. 全部锁位
  47. </div>
  48. <div class="bianhao" style="padding-top: 0; border-bottom: 0.01rem solid #efefef;">
  49. <button @click="startbtn()" :class="classbtn" :disabled="startbtndib">@{{mssage}}</button>
  50. <button v-preventclick @click="dingshi()" class="" :disabled="dingshibtn">@{{time}}s定时</button>
  51. </div>
  52. @foreach( $box as $key=>$bn)
  53. <div :key="{{$key}}">
  54. <div class="bianhao" style="font-size: 0.4rem;">
  55. {{$bn}}
  56. </div>
  57. <div class="bianhao" style="padding-top: 0;">
  58. <button @click="suowei" :data-name="'box'+{{$key+1}}" v-preventclick class="suoweiList" :disabled="allbtn">180s定时</button>
  59. </div>
  60. </div>
  61. @endforeach
  62. </article>
  63. </div>
  64. <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
  65. <script src="./js/auto-size.js"></script>
  66. <script>
  67. Vue.directive('preventclick', {
  68. inserted: function (button, bind) {
  69. button.addEventListener('click', () => {
  70. let time = 180
  71. if (!button.disabled) {
  72. button.disabled = true;
  73. setTimeout(() => {
  74. button.disabled = false
  75. vm.startbtndib= false
  76. vm.dingshibtn = false
  77. }, 181000)
  78. let timer=setInterval(()=>{
  79. button.innerHTML = time+"s定时"
  80. time--
  81. if (time<=0){
  82. clearInterval(timer)
  83. button.innerHTML = "180s定时"
  84. }
  85. },1000)
  86. }
  87. })
  88. }
  89. })
  90. const vm = new Vue({
  91. el: '#main',
  92. data: {
  93. isstart: false,
  94. mssage: "开始测试",
  95. classbtn: "",
  96. time: 180,
  97. allbtn: false,
  98. startbtndib: false,
  99. dingshibtn: false,
  100. },
  101. methods: {
  102. startbtn(e) {
  103. //开始测试
  104. this.isstart = !this.isstart
  105. this.allbtn = !this.allbtn
  106. this.dingshibtn = !this.dingshibtn
  107. if (this.isstart) {
  108. var type = 1;
  109. this.mssage = "停止测试"
  110. this.classbtn = "redbtn"
  111. } else {
  112. var type = 2;
  113. this.mssage = "开始测试"
  114. this.classbtn = ""
  115. }
  116. },
  117. dingshi() {
  118. this.startbtndib = true
  119. this.allbtn = true
  120. let timestop = setInterval(() => {
  121. this.time--
  122. if (this.time == 0) {
  123. clearInterval(timestop)
  124. this.time = 180
  125. this.startbtndib = false
  126. this.allbtn = false
  127. }
  128. }, 1000)
  129. },
  130. suowei(e){
  131. this.startbtndib = true
  132. this.dingshibtn = true
  133. console.log(e.currentTarget.dataset.name)
  134. }
  135. },
  136. })
  137. </script>
  138. </body>
  139. </html>