floorList.vue 9.6 KB

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