index.nvue 7.2 KB

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