index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="pages" :style="{ height: screenHeight + 'px' }" v-if="dataList">
  3. <view class="pages-left" :style="{ height: screenHeight + 'px' }">
  4. <scroll-view :style="{ height: screenHeight + 'px' }" scroll-y class="pages-left" :show-scrollbar="false">
  5. <view class="pages-left-li" v-for="(item, index) in dataList" :key="index" @click="tabClick(item, index)">
  6. <text class="pages-left-li-txt" :class="{ 'pages-left-li-act': tabIndex == index }">{{ item.name }}</text>
  7. </view>
  8. </scroll-view>
  9. </view>
  10. <view class="pages-right">
  11. <scroll-view :style="{ height: screenHeight + 'px' }" scroll-y class="pages-right" :scroll-top="scrollTop" scroll-with-animation @scroll="scrollChange">
  12. <view class="pages-right-ul" ref="pagesRight" v-for="(item, index) in dataList" :key="index">
  13. <text class="pages-right-head">{{ item.name }}</text>
  14. <view class="pages-right-box">
  15. <view class="pages-right-box-div" v-for="(child, childIndex) in item.list" :key="childIndex" :style="{background:child.status == 1 ?'#F5FAFF' :'#F0F0F0'}" >
  16. <view class="pages-right-box-div-t">
  17. <text class="t1">{{child.modelName}}</text>
  18. <checkbox-group @change="(e) =>changeCheck(child,e)">
  19. <label>
  20. <checkbox style="transform: scale(0.6);" :value="child.robotNo" :checked="child.followed == 1" />
  21. </label>
  22. </checkbox-group>
  23. </view>
  24. <view style="display: flex;align-items: center;justify-content: center;">
  25. <view class="pages-right-box-div-img" :style="{background:child.status == 1 ?'#0581FD' :'#D5D5D5'}" >
  26. <image class="img" src="../../static/robot.png" mode=""></image>
  27. </view>
  28. </view>
  29. <text class="pages-right-box-div-name">{{child.robotName}}</text>
  30. <view class="pages-right-box-div-line">
  31. <text></text>
  32. <text class="t2" :style="{background:child.status == 1 ?'#449F34' :'#818181'}">{{child.status == 1 ? '在线' :'离线'}}</text>
  33. </view>
  34. </view>
  35. <!-- <view class="pages-right-li" :style="'width:' + 530 / 3 + 'rpx;'" v-for="(child, childIndex) in item.list" :key="childIndex">
  36. <image :src="child.image" class="pages-right-li-img" />
  37. <text class="pages-right-li-txt">{{ child.name }}</text>
  38. </view> -->
  39. </view>
  40. </view>
  41. <view :style="{ height: scrollHeight + 'px' }"></view>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {followRobot,unfollowRobot} from '@/common/api.js'
  48. // #ifdef APP-PLUS
  49. const dom = weex.requireModule('dom')
  50. // #endif
  51. /**
  52. * 兼容 nvue 获取节点信息
  53. * */
  54. function getNvueQuery(type) {
  55. return new Promise(resolve => {
  56. dom.getComponentRect(type, option => resolve(option))
  57. })
  58. }
  59. export default {
  60. data() {
  61. return {
  62. screenHeight: 0,
  63. tabIndex: 0,
  64. scrollTop: 0,
  65. scrollHeight: 0, // 计算末尾列表高度
  66. scrollList: [], // 记录右侧滚动距离
  67. viewModel: null,
  68. timer: null // scroll 滚动倒计时
  69. }
  70. },
  71. props:{
  72. dataList:{
  73. type:Array,
  74. default(){
  75. return []
  76. }
  77. }
  78. },
  79. created() {
  80. this.screenHeight = uni.getSystemInfoSync().windowHeight
  81. },
  82. mounted() {
  83. this.init()
  84. },
  85. methods: {
  86. changeCheck(child,e){
  87. if(child.followed == 0){
  88. followRobot({
  89. userId:this.$store.state.Token,
  90. robotId:child.robotId
  91. }).then(res =>{
  92. child.followed = 1
  93. uni.$emit("backhome")
  94. }).catch(e =>{
  95. child.followed = 0
  96. })
  97. }
  98. else{
  99. unfollowRobot({
  100. userId:this.$store.state.Token,
  101. robotId:child.robotId
  102. }).then(res =>{
  103. uni.$emit("backhome")
  104. child.followed = 0
  105. }).catch(e =>{
  106. child.followed = 1
  107. })
  108. }
  109. },
  110. init() {
  111. setTimeout(() => {
  112. this.getRightQuery()
  113. }, 100)
  114. },
  115. async getRightQuery() {
  116. // #ifdef APP-NVUE || APP-PLUS-NVUE
  117. let list = []
  118. for (let i in this.dataList) {
  119. let result = await getNvueQuery(this.$refs.pagesRight[i])
  120. list.push({
  121. top: Math.round(result.size.top),
  122. height: Math.round(result.size.height)
  123. })
  124. }
  125. this.scrollList = list
  126. // #endif
  127. // #ifndef APP-NVUE || APP-PLUS-NVUE
  128. var selectorQuery = uni.createSelectorQuery()
  129. selectorQuery.selectAll('.pages-right-ul').boundingClientRect(data => {
  130. this.scrollList = data.map(item => {
  131. return {
  132. top: Math.round(item.top),
  133. height: Math.round(item.height)
  134. }
  135. })
  136. }).exec()
  137. // #endif
  138. let listHeight = this.scrollList[this.scrollList.length - 1].height
  139. this.scrollHeight = this.screenHeight - listHeight
  140. },
  141. tabClick(item, index) {
  142. this.scrollTop = this.scrollList[index].top
  143. },
  144. scrollChange(ev) {
  145. var scorllTop = Math.round(ev.detail.scrollTop)
  146. for (var i = 0; i < this.scrollList.length; i++) {
  147. if (this.scrollList[i].top <= scorllTop && scorllTop < (this.scrollList[i].top + this.scrollList[i].height)) {
  148. this.tabIndex = i
  149. }
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .pages {
  157. display: flex;
  158. flex-direction: row;
  159. &-left {
  160. width: 220rpx;
  161. background-color: #E8E8E8;
  162. box-sizing: border-box;
  163. &-li {
  164. height: 95rpx;
  165. box-sizing: border-box;
  166. &-txt {
  167. line-height: 95rpx;
  168. text-align: center;
  169. color: #000000;
  170. font-size: 28rpx;
  171. }
  172. &-act {
  173. color: #0581FD;
  174. background-color: #ffffff;
  175. }
  176. }
  177. }
  178. &-right {
  179. width: 530rpx;
  180. background-color: #FFFFFF;
  181. box-sizing: border-box;
  182. &-ul {
  183. width: 530rpx;
  184. }
  185. &-head {
  186. font-size: 24rpx;
  187. padding: 20rpx 30rpx;
  188. color: #BBBBBB;
  189. }
  190. &-box {
  191. display: flex;
  192. flex-wrap: wrap;
  193. &-div{
  194. background: #F5FAFF;
  195. position: relative;
  196. border: 1px solid #44A2FF;
  197. padding: 30rpx;
  198. border-radius: 20rpx;
  199. margin:30rpx;
  200. &-t{
  201. display: flex;
  202. flex-direction: row;
  203. justify-content: space-between;
  204. .t1{
  205. font-size: 28rpx;
  206. color: #000000;
  207. }
  208. }
  209. &-img{
  210. background: #0581FD;
  211. width: 120rpx;
  212. height: 108rpx;
  213. display: flex;
  214. justify-content: center;
  215. margin:20rpx 0rpx;
  216. align-items: center;
  217. border-radius: 20rpx;
  218. .img{
  219. width: 86rpx;
  220. height: 86rpx;
  221. margin-top: -10rpx;
  222. }
  223. }
  224. &-name{
  225. font-size: 26rpx;
  226. text-align: center;
  227. color: #000000;
  228. }
  229. &-line{
  230. display: flex;
  231. flex-direction: row;
  232. justify-content: space-between;
  233. .t2{
  234. color: #fff;
  235. background: #449F34;
  236. border-radius: 8rpx;
  237. width: 70rpx;
  238. padding: 3rpx 0;;
  239. text-align: center;
  240. font-size: 20rpx;
  241. }
  242. }
  243. }
  244. }
  245. &-li {
  246. height: 200rpx;
  247. box-sizing: border-box;
  248. display: flex;
  249. flex-direction: column;
  250. align-items: center;
  251. justify-content: center;
  252. &-img {
  253. width: 120rpx;
  254. height: 120rpx;
  255. }
  256. &-txt {
  257. font-size: 28rpx;
  258. }
  259. }
  260. }
  261. }
  262. </style>