floorListDark.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. <!-- @click='changeFloor(1,currIndex)' -->
  11. <img
  12. v-show="parseInt(marginTop) !== 0"
  13. v-repeat-click="increase"
  14. src="@/assets/imgs/iconBlackTop.png"
  15. alt
  16. />
  17. <img
  18. class="disabled"
  19. v-show="parseInt(marginTop) === 0"
  20. src="@/assets/imgs/iconLightTop.png"
  21. alt
  22. />
  23. </div>
  24. <div class="floor-out" :style="{ height: conHeight + 'px' }">
  25. <!-- 放开marginTop样式 -->
  26. <div class="floor-center" :style="{ marginTop: marginTop }">
  27. <div
  28. class="floor-item"
  29. :class="item.seq == currentFloorId ? 'isActive' : ''"
  30. @click="tabFloor(item, index)"
  31. v-for="(item, index) in floorsArr"
  32. :key="index"
  33. >
  34. {{ item.code }}
  35. </div>
  36. </div>
  37. </div>
  38. <div class="icon-bottom" v-if="floorsArr.length > 8">
  39. <!-- v-repeat-click='decrease' -->
  40. <img
  41. v-show="parseInt(marginTop) !== marginTopMax"
  42. v-repeat-click="decrease"
  43. src="@/assets/imgs/iconBlackBottom.png"
  44. alt
  45. />
  46. <img
  47. class="disabled"
  48. v-show="parseInt(marginTop) === marginTopMax"
  49. src="@/assets/imgs/iconLightBottom.png"
  50. alt
  51. />
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import store from "../store";
  58. import { mapGetters } from "vuex";
  59. import RepeatClick from "@/directives/repeat-click";
  60. export default {
  61. directives: {
  62. repeatClick: RepeatClick,
  63. },
  64. data() {
  65. return {
  66. floorId: "F1",
  67. showT: true,
  68. showB: true,
  69. num: 0,
  70. floorMapIdName: "",
  71. floor: {},
  72. currentFloorId: null,
  73. marginTop: 0,
  74. marginTopMax: 0,
  75. startTime: "",
  76. endTime: "",
  77. floorObj2: {},
  78. showNumber: 8, //需要展示的楼层数
  79. height: 39, //一个楼层的高度
  80. currIndex: 0, //当前楼层在 楼层数组中的下标,上下箭头使用
  81. conHeight: 0, // floor-out 的高度
  82. };
  83. },
  84. props: {
  85. floorsArr: {
  86. type: Array,
  87. default: () => {
  88. return [];
  89. },
  90. },
  91. // 默认true,
  92. // 1. 切换楼层后,是否触发 cookie,vuex数据修改,
  93. // 2. 在fenbuPic组件中为false, 1)不触发cookie,vuex , 2) 选中的楼层ID,为楼层列表数组floorIdArr的第0个
  94. changeDataFlag: {
  95. type: Boolean,
  96. default: true,
  97. },
  98. },
  99. computed: {
  100. ...mapGetters(["legendTable", "floorObj"]),
  101. },
  102. mounted() {
  103. this.init();
  104. },
  105. methods: {
  106. /**
  107. * @description 点击上箭头,marginTop<0时执行楼层滚动
  108. */
  109. increase() {
  110. let marginTop = parseInt(this.marginTop);
  111. marginTop < 0 && this.changeFloor(1, this.currIndex);
  112. },
  113. /**
  114. * @description 点击下箭头,marginTop小于最大值marginTopMax时,执行楼层滚动
  115. */
  116. decrease() {
  117. let marginTop = Math.abs(parseInt(this.marginTop)),
  118. marginTopMax = Math.abs(parseInt(this.marginTopMax));
  119. marginTop < marginTopMax && this.changeFloor(-1, this.currIndex);
  120. },
  121. init() {
  122. if (!this.floorsArr.length) {
  123. return false;
  124. }
  125. this.floorIdArr = [];
  126. this.floorsArr.map((item) => {
  127. this.floorIdArr.push(item.seq);
  128. if (item.seq == this.$cookie.get("currentFloorId")) {
  129. this.floor = item;
  130. } else {
  131. this.floor = this.floorObj;
  132. }
  133. });
  134. this.currentFloorId = Number(
  135. this.$cookie.get("currentFloorId") || this.floor.seq
  136. );
  137. // bug fix 修复 fenbuPic 弹窗中,楼层不能选中的问题
  138. // 如果 floorIdArr 不在 floorIdArr数组中,或者changeDataFlag为false(弹窗组件中的楼层组件),使用 floorIdArr[0], 而不使用 cookie
  139. let index = this.floorIdArr.findIndex(
  140. (item) => item === this.currentFloorId
  141. );
  142. if (index === -1 || !this.changeDataFlag) {
  143. this.currentFloorId = this.floorIdArr[0];
  144. }
  145. // 修复在设备设施页面中,楼层组件不够 8个楼层时,出现的样式问题,
  146. this.conHeight = this.floorsArr.length * 37.5;
  147. this.conHeight = this.conHeight >= 300 ? 300 : this.conHeight;
  148. this.showNumber = this.floorsArr.length > 8 ? 8 : this.floorsArr.length;
  149. this.marginTopMax =
  150. -(this.floorIdArr.length - this.showNumber) * this.height;
  151. this.changeFloor(0, index);
  152. },
  153. /**
  154. * @name changeFloor
  155. * @param {Number} flag 1:向上滚动楼层, -1向下滚动 , 0:进入页面初始化时,执行位置处理
  156. * @description 点击图例下方的,上下切换按钮
  157. */
  158. changeFloor(flag, index) {
  159. const len = this.floorIdArr.length;
  160. // let index = this.floorIdArr.findIndex(item => item === this.currentFloorId)
  161. this.currIndex = index;
  162. // 点击上箭头
  163. if (flag === 1) {
  164. index--;
  165. this.currIndex = index;
  166. } else if (flag === -1) {
  167. //点击下箭头
  168. index++;
  169. this.currIndex = index;
  170. }
  171. // FEAT: 点击上下箭头,不触发cookie更改 , 只有初始化时,才进行选中的楼层 状态更新
  172. if (flag === 0) {
  173. this.handleCookie();
  174. }
  175. this.handlePosition(flag, index, len);
  176. },
  177. handleCookie() {
  178. let currentFloor = this.floorsArr.filter(
  179. (item) => item.seq == this.currentFloorId
  180. )[0];
  181. if (currentFloor) {
  182. // 如果 changeDataFlag为true(不是在 分布图弹窗组件中的 楼层组件),设置cookie,vuex
  183. if (this.changeDataFlag) {
  184. this.$cookie.set("floorNow", currentFloor.code || "", 3);
  185. this.$cookie.set("floorMapId", currentFloor.gname, 3);
  186. this.$cookie.set("currentFloorId", currentFloor.seq, 3);
  187. this.floorId = this.$cookie.get("floorNow") || currentFloor.code;
  188. this.floorMapIdName =
  189. this.$cookie.get("floorMapId") || currentFloor.gname;
  190. store.commit("SETCURRENTFLOOR", currentFloor);
  191. }
  192. this.$emit("emitFloor", currentFloor);
  193. }
  194. },
  195. /**
  196. * @name tabFloor
  197. * @param {Object} item 选中的楼层信息
  198. * @param {Number} index 楼层信息在floorsArr数组中的位置
  199. */
  200. tabFloor(item, index) {
  201. this.currentFloorId = this.floorIdArr[index];
  202. this.handleCookie();
  203. this.handlePosition(2, index, this.floorIdArr.length);
  204. this.viewLengend();
  205. },
  206. viewLengend() {
  207. if (this.legendTable.length > 0) {
  208. this.$store.commit("SETSHOWVIEW", 1);
  209. } else {
  210. this.$store.commit("SETSHOWVIEW", 0);
  211. }
  212. },
  213. /**
  214. * @description 楼层位置动画处理
  215. * @param flag 1:向上滚动楼层, -1向下滚动 , 0:进入页面初始化时,执行位置处理 2:直接点击楼层
  216. * @param index 楼层 在floorIdArr中的下标
  217. * @param len floorIdArr长度
  218. */
  219. handlePosition(flag, index, len) {
  220. // 取出当前 marginTop
  221. let marginTop = parseInt(this.marginTop);
  222. switch (flag) {
  223. // 初始化进入页面,位置处理
  224. case 0:
  225. // 直接点击楼层,滚动楼层
  226. case 2:
  227. // 将 marginTop 设置为对应的index 应滚动的距离
  228. marginTop = -index * this.height;
  229. // marginTop 过大时,取最大值marginTopMax
  230. if (Math.abs(marginTop) >= Math.abs(this.marginTopMax)) {
  231. marginTop = parseInt(this.marginTopMax);
  232. }
  233. // marginTop>0时,取0,防止楼层上边出现空白
  234. marginTop = marginTop >= 0 ? 0 : marginTop;
  235. // index为0,marginTop设置为0
  236. index == 0 && (marginTop = 0);
  237. // index为最后一个,设置为最大marginTopMax
  238. index == len - 1 && (marginTop = parseInt(this.marginTopMax));
  239. this.marginTop = marginTop + "px";
  240. break;
  241. // 1:向上滚动楼层
  242. case 1:
  243. this.marginTop = marginTop + this.height + "px";
  244. break;
  245. // -1向下滚动楼层
  246. case -1:
  247. this.marginTop = marginTop + this.height * -1 + "px";
  248. break;
  249. default:
  250. break;
  251. }
  252. },
  253. },
  254. };
  255. </script>
  256. <style lang="less" scoped>
  257. .floor-box {
  258. .floor-list {
  259. width: 44px;
  260. // height: 212px;
  261. box-shadow: 0px 2px 15px 0px rgba(31, 36, 41, 0.08);
  262. border-radius: 2px;
  263. position: relative;
  264. padding: 6px 4px;
  265. text-align: center;
  266. background: rgba(22,73,206,0.36);
  267. border: 1px solid rgba(105,207,234,0.36);
  268. .floor-out {
  269. // max-height: 300px; //TODO:
  270. min-height: 38px;
  271. overflow: hidden;
  272. position: relative;
  273. overflow-y: auto;
  274. &::-webkit-scrollbar {
  275. display: none;
  276. }
  277. .floor-center {
  278. transition: all linear 0.5s;
  279. .floor-item {
  280. line-height: 28px;
  281. height: 28px;
  282. cursor: pointer;
  283. position: relative;
  284. color: #69cfea;
  285. &::after {
  286. position: absolute;
  287. left: 50%;
  288. margin-left: -20%;
  289. bottom: -6px;
  290. content: "";
  291. width: 14px;
  292. height: 1px;
  293. background: rgba(195, 199, 203, 1);
  294. border: 0px solid rgba(228, 229, 231, 1);
  295. }
  296. & + .floor-item {
  297. margin-top: 10px;
  298. }
  299. }
  300. }
  301. }
  302. .icon-top {
  303. cursor: pointer;
  304. height: 18px;
  305. img {
  306. width: 18px;
  307. height: 100%;
  308. margin-top: -10px;
  309. }
  310. }
  311. .icon-bottom {
  312. cursor: pointer;
  313. height: 18px;
  314. img {
  315. width: 18px;
  316. height: 100%;
  317. margin-top: -10px;
  318. }
  319. }
  320. .isActive {
  321. background: rgba(98, 196, 221, 0.3);
  322. border-radius: 4px;
  323. border: 1px solid #62c4dd;
  324. }
  325. }
  326. .disabled {
  327. cursor: not-allowed !important;
  328. }
  329. }
  330. </style>