index.nvue 7.2 KB

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