test.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div id="test">
  3. <div class="timeQuery" id="timeQuery">
  4. <div class="timeQuery-background" ></div>
  5. <div class="timeQuery-pointer">
  6. <div class="timeQuery-pointer-content" id="timeQueryPointer">
  7. <div class="timeQuery-pointer-handle" @mousedown.left="mousedownHandler" ></div>
  8. </div>
  9. </div>
  10. <div class="timeQuery-data" >
  11. <div class="timeQuery-data-cell" v-for="item of recordData" :style="'width:' + getDataWidth(item) + '%; left:' + getDataLeft(item) + '%'" ></div>
  12. <!-- <div class="timeQuery-data-cell" style="width: 30%; left: 20%" @click="timeChoose"></div>-->
  13. <!-- <div class="timeQuery-data-cell" style="width: 60%; left: 20%" @click="timeChoose"></div>-->
  14. </div>
  15. <div class="timeQuery-label" >
  16. <div class="timeQuery-label-cell" style="left: 0%">
  17. <div class="timeQuery-label-cell-label">0</div>
  18. </div>
  19. <div v-for="index of timeNode" class="timeQuery-label-cell" :style="'left:' + (100.0/timeNode*index).toFixed(4) + '%'">
  20. <div class="timeQuery-label-cell-label">{{24/timeNode * index}}</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. export default {
  28. name: "test",
  29. data() {
  30. return {
  31. mouseDown: false,
  32. timeNode: 24,
  33. recordData:[
  34. {
  35. startTime: "2021-04-18 00:00:00",
  36. endTime: "2021-04-18 00:00:09",
  37. },
  38. {
  39. startTime: "2021-04-18 00:00:09",
  40. endTime: "2021-04-18 01:00:05",
  41. },
  42. {
  43. startTime: "2021-04-18 02:00:01",
  44. endTime: "2021-04-18 04:25:05",
  45. },
  46. {
  47. startTime: "2021-04-18 05:00:01",
  48. endTime: "2021-04-18 20:00:05",
  49. },
  50. ]
  51. };
  52. },
  53. mounted() {
  54. document.body.addEventListener("mouseup", this.mouseupHandler, false)
  55. document.body.addEventListener("mousemove", this.mousemoveHandler, false)
  56. },
  57. methods:{
  58. getTimeNode(){
  59. let mine = 20
  60. let width = document.getElementById("timeQuery").offsetWidth
  61. if (width/20 > 24){
  62. return 24
  63. }else if (width/20 > 12) {
  64. return 12
  65. }else if (width/20 > 6) {
  66. return 6
  67. }
  68. },
  69. timeChoose(event){
  70. console.log(event)
  71. },
  72. getDataWidth(item){
  73. let startTime = new Date(item.startTime);
  74. let endTime = new Date(item.endTime);
  75. let result = parseFloat((endTime.getTime() - startTime.getTime())/(24*60*60*10))
  76. // console.log(result)
  77. return parseFloat((endTime.getTime() - startTime.getTime())/(24*60*60*10))
  78. },
  79. getDataLeft(item){
  80. let startTime = new Date(item.startTime);
  81. let differenceTime = startTime.getTime() - new Date(item.startTime.substr(0,10) + " 00:00:00").getTime()
  82. let result = differenceTime/(24*60*60*10)
  83. console.log(differenceTime)
  84. console.log(result)
  85. return parseFloat(differenceTime/(24*60*60*10));
  86. },
  87. mousedownHandler(event){
  88. this.mouseDown = true
  89. },
  90. mousemoveHandler(event){
  91. if (this.mouseDown){
  92. document.getElementById("timeQueryPointer").style.left = (event.clientX - 20)+ "px"
  93. }
  94. },
  95. mouseupHandler(event){
  96. this.mouseDown = false
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped>
  102. .timeQuery{
  103. width: 96%;
  104. margin-left: 2%;
  105. margin-right: 2%;
  106. margin-top: 20%;
  107. position: absolute;
  108. }
  109. .timeQuery-background{
  110. height: 16px;
  111. width: 100%;
  112. background-color: #ececec;
  113. position: absolute;
  114. left: 0;
  115. top: 0;
  116. z-index: 10;
  117. box-shadow: #9d9d9d 0px 0px 10px inset;
  118. }
  119. .timeQuery-data{
  120. height: 16px;
  121. width: 100%;
  122. position: absolute;
  123. left: 0;
  124. top: 0;
  125. z-index: 11;
  126. }
  127. .timeQuery-data-cell{
  128. height: 10px;
  129. background-color: #888787;
  130. position: absolute;
  131. z-index: 11;
  132. -webkit-box-shadow: #9d9d9d 0px 0px 10px inset;
  133. margin-top: 3px;
  134. top: 100%;
  135. }
  136. .timeQuery-label{
  137. height: 16px;
  138. width: 100%;
  139. position: absolute;
  140. pointer-events: none;
  141. left: 0;
  142. top: 0;
  143. z-index: 11;
  144. }
  145. .timeQuery-label-cell{
  146. height: 16px;
  147. position: absolute;
  148. z-index: 12;
  149. width: 0px;
  150. border-right: 1px solid #b7b7b7;
  151. }
  152. .timeQuery-label-cell-label {
  153. width: 23px;
  154. text-align: center;
  155. height: 18px;
  156. margin-left: -10px;
  157. margin-top: -30px;
  158. color: #444;
  159. }
  160. .timeQuery-pointer{
  161. width: 0px;
  162. height: 18px;
  163. position: absolute;
  164. left: 0;
  165. }
  166. .timeQuery-pointer-content{
  167. width: 0px;
  168. height: 70px;
  169. position: absolute;
  170. border-right: 2px solid #f60303;
  171. z-index: 14;
  172. top: -30px;
  173. }
  174. .timeQuery-pointer-handle {
  175. width: 0;
  176. height: 0;
  177. border-top: 12px solid transparent;
  178. border-right: 12px solid transparent;
  179. border-bottom: 20px solid #ff0909;
  180. border-left: 12px solid transparent;
  181. cursor: no-drop;
  182. position: absolute;
  183. left: -11px;
  184. top: 50px;
  185. }
  186. /*.timeQuery-cell:after{*/
  187. /* content: "";*/
  188. /* height: 14px;*/
  189. /* border: 1px solid #e70303;*/
  190. /* position: absolute;*/
  191. /*}*/
  192. </style>