mobileBar.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div>
  3. <div id='mobilebarBox' class="overflow-hidden" :style="{height:detailHeight + 'px'}" >
  4. <div id="content">
  5. <!-- 1.滑动标识 -->
  6. <div class="gray" style="text-align:center" @click="changeExpandClass">
  7. <!-- 上滑标识 -->
  8. <b-icon style="margin:0 auto"
  9. icon='chevron-compact-up'
  10. font-scale="1.2"
  11. v-show="expandClass === 0"
  12. variant="secondary">
  13. </b-icon>
  14. <!-- 上下滑标识 -->
  15. <b-icon style="margin:0 auto"
  16. icon='dash'
  17. font-scale="1.2"
  18. v-show="expandClass === 1"
  19. variant="secondary">
  20. </b-icon>
  21. <!-- 下滑标识 -->
  22. <b-icon style="margin:0 auto"
  23. icon='chevron-compact-down'
  24. font-scale="1.2"
  25. v-show="expandClass === 2"
  26. variant="secondary">
  27. </b-icon>
  28. </div>
  29. <!-- 2.搜索栏 -->
  30. <!-- <b-input-group
  31. key="sm"
  32. v-show="(type !== 'noticeDetail' && type !== 'cultureDetail') || isExpand === false "
  33. size="sm"
  34. class="mb-2 pr-1 pl-1"
  35. >
  36. <b-input-group-prepend is-text>
  37. <b-icon icon="search"></b-icon>
  38. </b-input-group-prepend>
  39. <b-form-input
  40. placeholder="查找单位、地点、设施"
  41. >
  42. </b-form-input>
  43. </b-input-group> -->
  44. <!-- 3.伸展栏 -->
  45. <div>
  46. <!-- 通知列表 -->
  47. <div id="list-div">
  48. <b-list-group>
  49. <b-list-group-item
  50. style="font-size:10px"
  51. button
  52. v-for="item of reportData.reportList.slice((currentPage-1)*perPage,currentPage*perPage)"
  53. :key="item.id"
  54. @click="showReportDetail(item.id)"
  55. >
  56. <tr>
  57. <td class="font-weight-bold">
  58. <div class="text-truncate">{{item.title| ellipsis}}</div>
  59. </td>
  60. </tr>
  61. <div class="listTime">{{item.time}}</div>
  62. </b-list-group-item>
  63. </b-list-group>
  64. </div>
  65. <!-- 分页栏 -->
  66. <div class="mt-2" id='pagin-div'>
  67. <b-pagination
  68. v-model="currentPage"
  69. pills
  70. :total-rows="rows"
  71. :per-page="perPage"
  72. align="center">
  73. </b-pagination>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import bus from '../../static/js/eventBus'
  82. export default {
  83. name: 'MobileBar',
  84. data () {
  85. return {
  86. detailHeight: window.screen.height * 0.32, // 底部栏实际高度
  87. minHeight: 24, // 底部栏最小高度
  88. maxHeight: window.screen.height * 0.80, // 底部栏最大高度
  89. midHeight: window.screen.height * 0.32, // 底部栏中等高度
  90. isExpand: false, // 底部栏伸缩状态
  91. expandClass: 1, // 底部栏拉伸等级,0为最小,1为中,2为最大
  92. reportData: {
  93. reportList: [] // 通知列表数据
  94. },
  95. currentPage: 1, // 通知列表当前页数
  96. resetListener: true // 重置监听器的开关
  97. }
  98. },
  99. methods: {
  100. /**
  101. * @description:底部栏高度拉伸监听
  102. * @param {String} id:目标容器id值
  103. * @returns {void}
  104. */
  105. heightListener: function (id) {
  106. var that = this
  107. var resize = document.getElementById(id)
  108. var START_HEIGHT // 记录初始高度
  109. var START, END, LEN // 记录拉伸过程总起点、总终点、总长度
  110. var startY, endY, moveLen
  111. var min
  112. var max
  113. var touchStart = function (e) {
  114. // 获取开始坐标 clientY为鼠标的垂直坐标
  115. startY = e.touches[0].pageY
  116. START = startY
  117. START_HEIGHT = that.detailHeight
  118. e.stopPropagation()
  119. }
  120. var touchMove = function (e) {
  121. min = that.min
  122. max = that.max
  123. // 计算并应用位移量
  124. endY = e.touches[0].pageY
  125. moveLen = startY - endY
  126. startY = endY
  127. let tempHeight = that.detailHeight + moveLen
  128. // 高度限制处理
  129. if (tempHeight < min) {
  130. that.detailHeight = min
  131. } else if (tempHeight > max) {
  132. that.detailHeight = max
  133. } else {
  134. that.detailHeight = tempHeight
  135. }
  136. e.stopPropagation()
  137. }
  138. var touchEnd = function (e) {
  139. END = endY
  140. LEN = START - END
  141. // 上拉/下拉 响应
  142. if (LEN >= 100 && that.expandClass !== 2) {
  143. // that.isExpand = true
  144. if (that.expandClass !== 2) {
  145. that.resetListener = true
  146. that.expandClass += 1
  147. }
  148. } else if (LEN <= -100 && that.expandClass !== 0) {
  149. // that.isExpand = false
  150. if (that.expandClass !== 0) {
  151. that.resetListener = true
  152. that.expandClass -= 1
  153. }
  154. } else {
  155. that.detailHeight = START_HEIGHT
  156. return 0
  157. }
  158. e.stopPropagation()
  159. resize.removeEventListener('touchstart', touchStart)
  160. resize.removeEventListener('touchmove', touchMove)
  161. resize.removeEventListener('touchend', touchEnd)
  162. }
  163. resize.addEventListener('touchstart', touchStart, false)
  164. resize.addEventListener('touchmove', touchMove, false)
  165. resize.addEventListener('touchend', touchEnd, false)
  166. },
  167. /**
  168. * @description:获取报道列表数据
  169. * @returns {void}
  170. */
  171. getReportList: function () {
  172. var that = this
  173. this.$axios
  174. .get('/report/list')
  175. .then(function (response) {
  176. that.reportData.reportList = response.data
  177. })
  178. },
  179. /**
  180. * @description:将id值传给map.vue进行信息提取与渲染
  181. * @param {number} id:报道的id值
  182. */
  183. showReportDetail: function (id) {
  184. bus.$emit('showReportDetail', id)
  185. this.resetListener = false
  186. this.expandClass = 0
  187. },
  188. /**
  189. * @description:设置底部栏列表尺寸
  190. */
  191. setSize: function () {
  192. let max = this.maxHeight
  193. let el = document.getElementById('list-div')
  194. el.style.height = max - 24 - 34 - 16 + 'px'
  195. },
  196. /**
  197. * @description:改变底部栏扩张等级
  198. */
  199. changeExpandClass: function () {
  200. this.resetListener = false
  201. switch (this.expandClass) {
  202. case 0:
  203. this.expandClass += 1
  204. break
  205. case 1:
  206. this.expandClass += 1
  207. break
  208. case 2:
  209. this.expandClass -= 1
  210. break
  211. }
  212. }
  213. },
  214. watch: {
  215. /**
  216. * @description:底部栏显示、拉伸控制
  217. */
  218. expandClass () {
  219. switch (this.expandClass) {
  220. case 0:
  221. this.detailHeight = this.min
  222. break
  223. case 1:
  224. this.detailHeight = this.mid
  225. break
  226. case 2:
  227. this.detailHeight = this.max
  228. break
  229. }
  230. if (this.resetListener) {
  231. this.heightListener('mobilebarBox')
  232. }
  233. }
  234. },
  235. computed: {
  236. /**
  237. * @description:根据type值调整底部栏最大高度限制
  238. */
  239. max: function () {
  240. return this.maxHeight
  241. },
  242. /**
  243. * @description:根据type值调整底部栏最小高度限制
  244. */
  245. min: function () {
  246. return this.minHeight
  247. },
  248. /**
  249. * @description:根据type值调整底部栏中等高度限制
  250. */
  251. mid: function () {
  252. return this.midHeight
  253. },
  254. /**
  255. * @description: 通知列表总数目
  256. */
  257. rows: function () {
  258. return this.reportData.reportList.length
  259. },
  260. /**
  261. * @description: 最高伸展等级时通知列表每页显示数目
  262. */
  263. perPage: function () {
  264. return Math.floor((this.maxHeight - 34 - 16 - 24) / 42)
  265. },
  266. /**
  267. * @description: 中等伸展等级时通知列表单页显示数目
  268. */
  269. onePage: function () {
  270. return Math.floor((this.maxHeight - 34 - 16 - 24) / 42)
  271. }
  272. },
  273. filters: {
  274. /**
  275. * @description:过滤器,超过16位显示省略号
  276. */
  277. ellipsis: function (value) {
  278. if (!value) return ''
  279. if (value.length > 18) {
  280. return value.slice(0, 18) + '...'
  281. }
  282. return value
  283. }
  284. },
  285. mounted () {
  286. this.heightListener('mobilebarBox')
  287. this.getReportList()
  288. this.setSize()
  289. // this.busOnAction()
  290. }
  291. }
  292. </script>
  293. <!-- Add "scoped" attribute to limit CSS to this component only -->
  294. <style scoped>
  295. * {
  296. -webkit-text-size-adjust: none;
  297. }
  298. .text-truncate{
  299. margin-left:32px;
  300. border-bottom: 4px solid #87BF96;
  301. padding-bottom: 0px;
  302. font-size: 11px;
  303. -webkit-text-size-adjust: none;
  304. /*top:50%;*/
  305. /*transform: translateY(-50%);*/
  306. height:18px;
  307. }
  308. /*分页栏上的数字*/
  309. /deep/ .page-item.active .page-link{
  310. background-color: #87BF96!important;
  311. border-color: #87BF96!important;
  312. }
  313. .font-weight-bold{
  314. font-family: "Noto Sans SC";
  315. font-weight: 200;
  316. }
  317. .list-group-item {
  318. height:42px;
  319. padding: 0;
  320. border:none;
  321. }
  322. .listTime {
  323. position:absolute;
  324. top:50%;
  325. transform: translateY(-50%);
  326. right:32px;
  327. /* font-family: "Source Han Sans CN"; */
  328. font-family: 'Noto Sans SC';
  329. font-weight: 100;
  330. font-size: 11px;
  331. }
  332. #pagin-div {
  333. position: relative;
  334. /* bottom: 0; */
  335. left: 50%;
  336. transform: translateX(-50%);
  337. }
  338. #mobilebarBox {
  339. border-radius: 7px;
  340. }
  341. </style>