index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <!-- 历史数据 -->
  3. <view>
  4. <view class="card_time_row" :style="{padding:'10rpx 10rpx'}">
  5. <view class="time_picker">
  6. <view class="time_title">开始时间</view>
  7. <uni-datetime-picker style="width: 210rpx;" type="datetime" :clear-icon="false" v-model="startTime"
  8. @change="maskClick" />
  9. </view>
  10. <view class="time_picker">
  11. <view class="time_title">结束时间</view>
  12. <uni-datetime-picker style="width: 210rpx;" type="datetime" :clear-icon="false" v-model="endTime"
  13. @change="maskClick" />
  14. </view>
  15. </view>
  16. <view class="card_layout">
  17. <view class="facility_card">
  18. <view class="card_title_name">名称</view>
  19. <scroll-view class="scroll-view" :style="{height:leftHeight + 'px'}" :scroll-y="true"
  20. @scrolltolower="loadMore">
  21. <view class="item_title_name" v-for="(item, index) in tableData" :key="index">
  22. {{item.name}}
  23. </view>
  24. </scroll-view>
  25. </view>
  26. <view class="table_card_data">
  27. <uni-table ref="table" :loading="loading" border emptyText="暂无更多数据">
  28. <uni-tr>
  29. <uni-th width="10" align="center"></uni-th>
  30. <uni-th align="center">名称</uni-th>
  31. <uni-th width="40" align="center">温度(℃)</uni-th>
  32. <uni-th width="40" align="center">湿度(℃)</uni-th>
  33. <uni-th align="center">保存时间</uni-th>
  34. </uni-tr>
  35. <uni-tr v-for="(item, index) in tableData" :key="index">
  36. <uni-td align="center">{{ index + 1 }}</uni-td>
  37. <uni-td align="center">{{ item.name }}</uni-td>
  38. <uni-td align="center">
  39. <view class="name">{{ item.name }}</view>
  40. </uni-td>
  41. <uni-td align="center">{{ item.name }}</uni-td>
  42. <uni-td align="center">{{ item.date }}</uni-td>
  43. </uni-tr>
  44. </uni-table>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import tablelist from './tableData.js'
  51. export default {
  52. data() {
  53. return {
  54. loading: false,
  55. tableData: tablelist,
  56. startTime: this.getDateTime(new Date()),
  57. endTime: this.getDateTime(new Date()),
  58. leftHeight: 0,
  59. }
  60. },
  61. watch: {
  62. // demo 是要深度监听的值
  63. // headHeight: {
  64. // handler(newVal, oldVal) {
  65. // if (newVal) {
  66. // this.$nextTick(() => {
  67. // let topHeight = 0
  68. // const navbar = uni.createSelectorQuery().select('.card_layout')
  69. // navbar.boundingClientRect(data => {
  70. // topHeight = data.height
  71. // }).exec()
  72. // let titleHeight = 0
  73. // const titleBar = uni.createSelectorQuery().select('.card_title_name')
  74. // titleBar.boundingClientRect(data => {
  75. // titleHeight = data.height
  76. // }).exec()
  77. // this.leftHeight = topHeight - titleHeight
  78. // })
  79. // }
  80. // },
  81. // immediate: true,
  82. // deep: true
  83. // }
  84. },
  85. mounted() {},
  86. methods: {
  87. maskClick(event) {
  88. console.log(event, 264)
  89. },
  90. // 滚动加载更多
  91. loadMore() {
  92. console.log(3214)
  93. },
  94. getDateTime(date, addZero = true) {
  95. return `${this.getDate(date, addZero)} ${this.getTime(date, addZero)}`
  96. },
  97. getDate(date, addZero = true) {
  98. date = new Date(date)
  99. const year = date.getFullYear()
  100. const month = date.getMonth() + 1
  101. const day = date.getDate()
  102. return `${year}-${addZero ? this.addZero(month) : month}-${addZero ? this.addZero(day) : day}`
  103. },
  104. getTime(date, addZero = true) {
  105. date = new Date(date)
  106. const hour = date.getHours()
  107. const minute = date.getMinutes()
  108. const second = date.getSeconds()
  109. return this.hideSecond ?
  110. `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}` :
  111. `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}:${addZero ? this.addZero(second) : second}`
  112. },
  113. addZero(num) {
  114. if (num < 10) {
  115. num = `0${num}`
  116. }
  117. return num
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss">
  123. .card_time_row {
  124. position: sticky;
  125. top: 0px;
  126. background-color: #fff;
  127. z-index: 2;
  128. display: flex;
  129. align-items: center;
  130. padding-bottom: 10rpx;
  131. }
  132. .time_picker {
  133. display: flex;
  134. align-items: center;
  135. margin-right: 20rpx;
  136. }
  137. .time_title {
  138. font-size: 8px;
  139. margin-right: 10rpx;
  140. }
  141. .card_layout {
  142. display: flex;
  143. margin-left: 10rpx;
  144. height: calc(100% - 20rpx);
  145. }
  146. .facility_card {
  147. width: 140rpx;
  148. height: 100%;
  149. flex: none;
  150. border: 1px solid #EBEEF5;
  151. }
  152. .scroll-view {
  153. overflow-y: auto;
  154. }
  155. .card_title_name {
  156. position: sticky;
  157. top: 23px;
  158. z-index: 1;
  159. padding: 8rpx;
  160. font-size: 8px;
  161. background-color: #EBEEF5;
  162. }
  163. .item_title_name {
  164. padding: 6rpx;
  165. font-size: 8px;
  166. border-bottom: 1px solid #EBEEF5;
  167. }
  168. .table_card_data {
  169. overflow-y: auto;
  170. width: 100%;
  171. height: 100%;
  172. border-top: 1px solid #EBEEF5;
  173. border-bottom: 1px solid #EBEEF5;
  174. }
  175. </style>