index.nvue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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+1 + '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. onTab:false,
  69. timer: null // scroll 滚动倒计时
  70. }
  71. },
  72. props:{
  73. dataList:{
  74. type:Array,
  75. default(){
  76. return []
  77. }
  78. }
  79. },
  80. created() {
  81. },
  82. mounted() {
  83. this.screenHeight = uni.getSystemInfoSync().windowHeight
  84. this.$nextTick(() =>{
  85. this.init()
  86. })
  87. },
  88. methods: {
  89. changeCheck(child,e){
  90. if(child.followed == 0){
  91. followRobot({
  92. userId:this.$store.state.Token,
  93. robotId:child.robotId
  94. }).then(res =>{
  95. child.followed = 1
  96. uni.$emit("backhome")
  97. }).catch(e =>{
  98. child.followed = 0
  99. })
  100. }
  101. else{
  102. unfollowRobot({
  103. userId:this.$store.state.Token,
  104. robotId:child.robotId
  105. }).then(res =>{
  106. uni.$emit("backhome")
  107. child.followed = 0
  108. }).catch(e =>{
  109. child.followed = 1
  110. })
  111. }
  112. },
  113. init() {
  114. setTimeout(async() => {
  115. await this.getRightQuery()
  116. }, 100)
  117. },
  118. async getRightQuery() {
  119. // #ifdef APP-NVUE || APP-PLUS-NVUE
  120. let list = []
  121. for (let i in this.dataList) {
  122. let result = await getNvueQuery(this.$refs.pagesRight[i])
  123. list.push({
  124. top: Math.round(result.size.top),
  125. height: Math.round(result.size.height)
  126. })
  127. }
  128. this.scrollList = list
  129. // #endif
  130. // #ifndef APP-NVUE || APP-PLUS-NVUE
  131. var selectorQuery = uni.createSelectorQuery()
  132. selectorQuery.selectAll('.pages-right-ul').boundingClientRect(data => {
  133. this.scrollList = data.map(item => {
  134. return {
  135. top: Math.round(item.top),
  136. height: Math.round(item.height)
  137. }
  138. })
  139. }).exec()
  140. // #endif
  141. let listHeight = this.scrollList[this.scrollList.length - 1].height
  142. this.scrollHeight = this.screenHeight - listHeight
  143. },
  144. tabClick(item, index) {
  145. console.log(this.scrollList)
  146. this.onTab = true
  147. this.scrollTop = this.scrollList[index].top
  148. },
  149. scrollChange(ev) {
  150. var scorllTop = Math.round(ev.detail.scrollTop)
  151. var index = null
  152. for (var i = 0; i < this.scrollList.length; i++) {
  153. if (this.scrollList[i].top <= scorllTop && scorllTop < (this.scrollList[i].top + this.scrollList[i].height)) {
  154. index = i
  155. }
  156. }
  157. this.tabIndex = index
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .pages {
  164. display: flex;
  165. flex-direction: row;
  166. &-left {
  167. width: 220rpx;
  168. background-color: #E8E8E8;
  169. box-sizing: border-box;
  170. &-li {
  171. height: 95rpx;
  172. box-sizing: border-box;
  173. &-txt {
  174. line-height: 95rpx;
  175. text-align: center;
  176. color: #000000;
  177. font-size: 28rpx;
  178. }
  179. &-act {
  180. color: #0581FD;
  181. background-color: #ffffff;
  182. }
  183. }
  184. }
  185. &-right {
  186. width: 530rpx;
  187. background-color: #FFFFFF;
  188. box-sizing: border-box;
  189. &-ul {
  190. width: 530rpx;
  191. }
  192. &-head {
  193. font-size: 24rpx;
  194. padding: 20rpx 30rpx;
  195. color: #BBBBBB;
  196. }
  197. &-box {
  198. display: flex;
  199. flex-wrap: wrap;
  200. &-div{
  201. background: #F5FAFF;
  202. position: relative;
  203. border: 1px solid #44A2FF;
  204. padding: 30rpx;
  205. border-radius: 20rpx;
  206. margin:30rpx;
  207. &-t{
  208. display: flex;
  209. flex-direction: row;
  210. justify-content: space-between;
  211. .t1{
  212. font-size: 28rpx;
  213. color: #000000;
  214. }
  215. }
  216. &-img{
  217. background: #0581FD;
  218. width: 120rpx;
  219. height: 108rpx;
  220. display: flex;
  221. justify-content: center;
  222. margin:20rpx 0rpx;
  223. align-items: center;
  224. border-radius: 20rpx;
  225. .img{
  226. width: 86rpx;
  227. height: 86rpx;
  228. margin-top: -10rpx;
  229. }
  230. }
  231. &-name{
  232. font-size: 26rpx;
  233. text-align: center;
  234. color: #000000;
  235. }
  236. &-line{
  237. display: flex;
  238. flex-direction: row;
  239. justify-content: space-between;
  240. .t2{
  241. color: #fff;
  242. background: #449F34;
  243. border-radius: 8rpx;
  244. width: 70rpx;
  245. padding: 3rpx 0;;
  246. text-align: center;
  247. font-size: 20rpx;
  248. }
  249. }
  250. }
  251. }
  252. &-li {
  253. height: 200rpx;
  254. box-sizing: border-box;
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. justify-content: center;
  259. &-img {
  260. width: 120rpx;
  261. height: 120rpx;
  262. }
  263. &-txt {
  264. font-size: 28rpx;
  265. }
  266. }
  267. }
  268. }
  269. </style>