floorList.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /**
  2. *@author:Guoxiaohuan
  3. *@date:2020.06.02
  4. *@info:楼层列表
  5. */
  6. <template>
  7. <div class='floor-box'>
  8. <div class='floor-list'>
  9. <div class='icon-top' v-if='floorsArr.length>8'>
  10. <img
  11. :class='{disabled:currentFloorId == floorsArr[0].seq }'
  12. v-if='showT'
  13. @click='changeFloor(1)'
  14. @mousedown='mousedown'
  15. @mouseup='mouseup'
  16. src='@/assets/imgs/iconBlackTop.png'
  17. alt
  18. />
  19. <img :class='{disabled:currentFloorId == floorsArr[0].seq }' v-else src='@/assets/imgs/iconLightTop.png' alt />
  20. </div>
  21. <div class='floor-out'>
  22. <!-- :style='{ marginTop : marginTop }' -->
  23. <div class='floor-center'>
  24. <div
  25. class='floor-item'
  26. :class='item.seq == currentFloorId?"isActive":""'
  27. @click='tabFloor(item,index)'
  28. v-for='(item,index) in floorsArr'
  29. :key='index'
  30. >{{item.code}}</div>
  31. </div>
  32. </div>
  33. <div class='icon-bottom' v-if='floorsArr.length>8'>
  34. <img
  35. :class='{disabled:currentFloorId == floorsArr[floorsArr.length-1].seq }'
  36. v-if='showB'
  37. @click='changeFloor(-1)'
  38. src='@/assets/imgs/iconBlackBottom.png'
  39. alt
  40. />
  41. <img :class='{disabled:currentFloorId == floorsArr[floorsArr.length-1].seq }' v-else src='@/assets/imgs/iconLightBottom.png' alt />
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. floorId: 'F1',
  51. showT: true,
  52. showB: true,
  53. num: 0,
  54. floorMapIdName: '',
  55. floor: {
  56. code: 'F1',
  57. gcode: '1F',
  58. gname: 'f1',
  59. name: '第1层',
  60. seq: 100
  61. },
  62. currentFloorId: null,
  63. marginTop: 0,
  64. startTime: '',
  65. endTime: ''
  66. }
  67. },
  68. props: {
  69. floorsArr: {
  70. type: Array,
  71. default: () => {
  72. ;[]
  73. }
  74. }
  75. },
  76. mounted() {
  77. this.init()
  78. },
  79. watch: {
  80. // 监听floorsArr的变化
  81. // '$store.state.floorsArr': {
  82. // handler(newV, oldV) {
  83. // newV && this.init()
  84. // },
  85. // deep: true
  86. // }
  87. },
  88. methods: {
  89. mousedown() {
  90. this.startTime = new Date()
  91. },
  92. mouseup() {
  93. this.endTime = new Date()
  94. if (this.endTime - this.startTime < 200) {
  95. return false
  96. }
  97. },
  98. init() {
  99. if (!this.floorsArr.length) {
  100. return false
  101. }
  102. this.floorIdArr = []
  103. this.floorsArr.map(item => {
  104. this.floorIdArr.push(item.seq)
  105. })
  106. this.currentFloorId = Number(this.$cookie.get('currentFloorId') || 100)
  107. this.changeFloor(0)
  108. },
  109. /**
  110. * @name changeFloor
  111. * @param {Number} flag 1:向上滚动楼层, -1向下滚动 , 0:进入页面初始化时,执行位置处理
  112. * @description 点击图例下方的,上下切换按钮
  113. */
  114. changeFloor(flag) {
  115. const len = this.floorIdArr.length
  116. let index = this.floorIdArr.findIndex(item => item === this.currentFloorId)
  117. // 点击上箭头
  118. if (flag === 1) {
  119. index--
  120. this.currentFloorId = this.floorIdArr[index]
  121. } else if (flag === -1) {
  122. //点击下箭头
  123. index++
  124. this.currentFloorId = this.floorIdArr[index]
  125. }
  126. // 数据处理
  127. this.handleCookie()
  128. // 楼层位置动画处理
  129. this.handlePosition(flag, index, len)
  130. // 处理上下按钮禁用逻辑
  131. this.handleUpDownStatus(index, len)
  132. },
  133. /**
  134. * @name handleUpDownStatus
  135. * @param { Number } index 当前楼层在floorIdArr中的下标
  136. * @param { Number } len floorIdArr的长度
  137. * @description 处理上下按钮禁用逻辑
  138. */
  139. handleUpDownStatus(index, len) {
  140. switch (index) {
  141. // 第一条的上箭头禁用
  142. case 0:
  143. this.currentFloorId = this.floorIdArr[0]
  144. this.showT = false
  145. this.showB = true
  146. break
  147. // 最后一条的 下箭头设置为禁用
  148. case len - 1:
  149. this.currentFloorId = this.floorIdArr[len - 1]
  150. this.showT = true
  151. this.showB = false
  152. break
  153. // 默认都可以点击
  154. default:
  155. this.showT = true
  156. this.showB = true
  157. break
  158. }
  159. },
  160. /**
  161. * @name handleCookie
  162. * @description cookie数据处理
  163. */
  164. handleCookie() {
  165. // return true
  166. let currentFloor = this.floorsArr.filter(item => item.seq == this.currentFloorId)[0]
  167. if (currentFloor) {
  168. this.$cookie.set('floorNow', currentFloor.code || '', 3)
  169. this.$cookie.set('floorMapId', currentFloor.gname, 3)
  170. this.$cookie.set('currentFloorId', currentFloor.seq, 3)
  171. this.floorId = this.$cookie.get('floorNow') || currentFloor.code
  172. this.floorMapIdName = this.$cookie.get('floorMapId') || currentFloor.gname
  173. this.$emit('emitFloor', currentFloor)
  174. }
  175. },
  176. /**
  177. * @name tabFloor
  178. * @param {Object} 选中的楼层信息
  179. * @param {Number} 楼层信息在floorsArr数组中的位置
  180. */
  181. tabFloor(item, index) {
  182. this.currentFloorId = this.floorIdArr[index]
  183. this.handleCookie()
  184. this.handlePosition(1, index, this.floorIdArr.length)
  185. this.handleUpDownStatus(index, this.floorIdArr.length)
  186. },
  187. /**
  188. * @description 楼层位置动画处理
  189. * @param flag 是否启用动画时长 0:不启用 其他 启动
  190. * @param index 楼层 在floorIdArr中的下标
  191. * @param len floorIdArr长度
  192. */
  193. handlePosition(flag, index, len) {
  194. //楼层位置处理
  195. // 页面显示5条,当第五条以上,进行marginTop修改
  196. // index从0开始
  197. // TODO: 需要修改可以修改这里,配置页面样式,修改showNumber和height
  198. let showNumber = 5, //页面中展示的楼层条数
  199. height = 32, //一个楼层的div标签高度
  200. timer = 500 //动画时长
  201. // flag 为0时,timer设置为0
  202. flag === 0 && (timer = 0)
  203. if (index >= showNumber - 1) {
  204. if (index < len - 1) {
  205. this.marginTop = -height * (index - (showNumber - 2)) + 'px'
  206. } else if ((index = len - 1)) {
  207. this.marginTop = -height * (index - (showNumber - 1)) + 'px'
  208. }
  209. } else {
  210. // 前 showNumber 条的margin-top设置为0
  211. this.marginTop = 0
  212. }
  213. }
  214. }
  215. }
  216. </script>
  217. <style lang="less" scoped>
  218. .floor-box {
  219. position: fixed;
  220. right: 32px;
  221. top: 196px;
  222. z-index: 2;
  223. .floor-list {
  224. width: 44px;
  225. // height: 212px;
  226. background: rgba(255, 255, 255, 1);
  227. box-shadow: 0px 2px 15px 0px rgba(31, 36, 41, 0.08);
  228. border-radius: 2px;
  229. position: relative;
  230. padding: 6px 4px;
  231. text-align: center;
  232. .floor-out {
  233. // max-height: 260px;
  234. overflow: hidden;
  235. // overflow-y: auto;
  236. position: relative;
  237. // &::-webkit-scrollbar {
  238. // display: none;
  239. // }
  240. .floor-center {
  241. transition: all linear 0.8s;
  242. .floor-item {
  243. // border: 1px solid blue;
  244. // width: 36px;
  245. line-height: 28px;
  246. height: 28px;
  247. cursor: pointer;
  248. position: relative;
  249. &::after {
  250. position: absolute;
  251. left: 50%;
  252. margin-left: -20%;
  253. bottom: -6px;
  254. content: '';
  255. width: 14px;
  256. height: 1px;
  257. background: rgba(195, 199, 203, 1);
  258. border: 0px solid rgba(228, 229, 231, 1);
  259. }
  260. & + .floor-item {
  261. margin-top: 10px;
  262. }
  263. }
  264. }
  265. }
  266. .icon-top {
  267. height: 18px;
  268. img {
  269. width: 18px;
  270. height: 100%;
  271. margin-top: -10px;
  272. }
  273. }
  274. .icon-bottom {
  275. height: 18px;
  276. img {
  277. width: 18px;
  278. height: 100%;
  279. margin-top: -10px;
  280. }
  281. }
  282. .isActive {
  283. border-radius: 4px;
  284. color: #025baa;
  285. background: #e1f2ff;
  286. }
  287. }
  288. .disabled {
  289. cursor: not-allowed !important;
  290. }
  291. }
  292. </style>