box.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <div class="contact">
  3. <div class="navlist" v-show="navList" v-if="isShownav">
  4. <div class="nav" v-for="(n,index) in navList.list" :class="{navC: index == navChoose}" @click="navC(index,n)">
  5. <div class="title" :title="n.title">
  6. {{ n.title }}
  7. </div>
  8. <div class="you" style="">
  9. >
  10. </div>
  11. </div>
  12. </div>
  13. <div class="right">
  14. <div class="head nawarp" v-if="isShowHeader">
  15. 当前位置:
  16. <div @click="urlTo('index')">首页</div>
  17. >
  18. <div @click="listBack">
  19. {{ navList.title }}
  20. > {{ navList.list[navChoose].title }}
  21. </div>
  22. <span v-show="!(!content) && this.navList.listinlist"> > 信息详情</span>
  23. </div>
  24. <div class="head" v-else>
  25. 当前位置:<div @click="urlTo('index')">首页</div>
  26. >
  27. <div @click="listBack">
  28. {{ navList.title }}
  29. </div>
  30. <span v-show="!(!content) && this.navList.listinlist"> > 信息详情</span>
  31. </div>
  32. <slot v-if="!isShowSon"></slot>
  33. <div class="contentbox">
  34. <div class="content">
  35. <div class="load" v-show="loadingType == 'loadmore'">
  36. ----- 加载中 -----
  37. </div>
  38. <div v-html="content" v-show="isShowSon" class="text">
  39. </div>
  40. <div class="contentList chooseitem" v-show="!isShowSon">
  41. <div class="item" v-for="c in contentList" @click="listChoose(c)" :title="c.title">
  42. <span class="title-icon"></span>
  43. <div class="title nawarp">
  44. <div class="">
  45. </div>
  46. <div class="">
  47. {{ c.title }}
  48. </div>
  49. </div>
  50. <div class="time">
  51. {{ getTime(c.releasetime) }}
  52. </div>
  53. </div>
  54. <!-- 页数大于一时显示分页 -->
  55. <div class="pagec" v-if="totalPage >1">
  56. <div class="fristPage" @click="page = 1">
  57. 第一页
  58. </div>
  59. <div class="pagetoomuch" v-show="totalPage>10">
  60. <div class="nextPage" v-show="page-4>0">
  61. ...
  62. </div>
  63. <div class="pageNum" v-for="count in totalPage" @click="pageChoose(count)"
  64. :class="{isChoose:count == page}" v-if="count>page-5&&count<page+4 &&count!=totalPage">
  65. {{ count }}
  66. </div>
  67. <div class="nextPage" v-show="page+4<totalPage">
  68. ...
  69. </div>
  70. <div class="pageNum" v-for="count in totalPage" @click="pageChoose(count)"
  71. :class="{isChoose:count == page}" v-show="totalPage>2" v-if="count==totalPage">
  72. {{ count }}
  73. </div>
  74. </div>
  75. <div class="pageNum" v-for="count in totalPage" @click="pageChoose(count)"
  76. :class="{isChoose:count == page}" v-show="totalPage<=10">
  77. {{ count }}
  78. </div>
  79. <div class="nextPage" @click='nextPage'>
  80. 下一页
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { details,getArticList } from '@/request/api.js'
  91. export default {
  92. props: ['navList'],
  93. data() {
  94. return {
  95. page: 1, // 当前页
  96. limit: 10, // 每页数量
  97. sum: 0, // 文章列表总数
  98. loadingType: 'loadmore', // 是否在加载
  99. path: this.$route.path, // 路由
  100. navChoose: this.$route.params.navChoose || this.$route.query.navChoose || 0, //左侧导航栏选择
  101. timeOut: '',// 不断获取初始显示数据直至显示
  102. content: '', // 文章
  103. contentList: [], // 二级列表
  104. contentId: this.$route.params.contentId || this.$route.query.contentId || 0, // 文章详情id
  105. isShowSon: true, // 是否显示文章而不显示列表
  106. pageId: 0, //文章列表id
  107. }
  108. },
  109. mounted() {
  110. if(this.isShowContent) {
  111. this.init()
  112. }
  113. },
  114. methods: {
  115. // 查询数据默认
  116. init() {
  117. this.navC(this.navChoose,this.navList.list[this.navChoose])
  118. },
  119. navC(index,data) {
  120. // 组织介绍中各区县红十字会单独页面
  121. const pd1 = this.path == '/introduce' && index == 2
  122. if (pd1) {
  123. this.isShowSon = false
  124. this.content = ''
  125. this.loadingType == 'nomore'
  126. this.contentList = []
  127. } else{
  128. this.loadingType = 'loadmore' // 加载中
  129. this.page = 1
  130. this.isShowSon = true
  131. this.content = ''
  132. this.contentList = []
  133. this.pageId = data.id
  134. this.getlistslist()
  135. }
  136. this.navChoose = index
  137. this.$emit('navListC',index)
  138. },
  139. listChoose(data) {
  140. this.loadingType = 'loadmore'
  141. this.isShowSon = true
  142. this.contentId = data.id
  143. this.getData()
  144. },
  145. getData() {
  146. details({},this.contentId).then(({data}) => {
  147. if (data.url == '') {
  148. this.content = data.content
  149. this.contentId = 0
  150. } else{
  151. this.originalText(data.url)
  152. this.contentId = 0
  153. this.isShowSon = false
  154. }
  155. this.loadingType = 'nomore'
  156. })
  157. },
  158. // 获取文章列表
  159. getlistslist() {
  160. getArticList({page: this.page,limit: this.limit},this.pageId).then(res => {
  161. this.sum = res.data.count
  162. if(res.data.count > 0) {
  163. // 但文章数量为一时显示第一篇文章
  164. if(res.data.count == 1 ) {
  165. this.isShowSon = true
  166. this.contentId = res.data.list[0].id
  167. this.getData()
  168. // 但点进页面时有指定文章跳至文章详情
  169. }else if(this.contentId != 0) {
  170. this.isShowSon = true
  171. this.getData()
  172. // 但文章数量大于一时显示列表
  173. }else if(res.data.count > 1) {
  174. this.isShowSon = false
  175. this.loadingType = 'nomore'
  176. }
  177. this.contentList = res.data.list
  178. }else {
  179. this.loadingType = 'nomore'
  180. }
  181. })
  182. },
  183. // 改变当前页
  184. pageChoose(page) {
  185. this.page = page
  186. },
  187. // 文章详情转文章列表
  188. listBack() {
  189. if (this.path == '/introduce' && this.navChoose == 2) {
  190. }else {
  191. this.loadingType = 'nomore'
  192. this.content = ''
  193. this.isShowSon = false
  194. }
  195. },
  196. // 下一页
  197. nextPage() {
  198. this.page++
  199. if (this.page > this.totalPage) {
  200. this.page = this.totalPage
  201. }
  202. },
  203. // 跳转页面
  204. urlTo(name,navChoose) {
  205. this.$router.push({
  206. name: name
  207. })
  208. },
  209. // 时间戳准换
  210. getTime(time) {
  211. return time.substring(0,10)
  212. },
  213. // 查看原文
  214. originalText(url) {
  215. window.open(url)
  216. }
  217. },
  218. computed: {
  219. // 总页数
  220. totalPage() {
  221. return Math.ceil(this.sum/this.limit)
  222. },
  223. // 是否有文章列表
  224. isShownav() {
  225. return !(!this.navList.list)
  226. },
  227. // 文章列表是否大于数量一
  228. isShowHeader() {
  229. if(this.isShownav) {
  230. if (this.navList.list.length > 1) {
  231. return true
  232. } else{
  233. return false
  234. }
  235. }
  236. },
  237. isShowContent() {
  238. if (!this.navList.list) {
  239. return false
  240. } else{
  241. return this.navList.list.length > 0
  242. }
  243. },
  244. },
  245. watch: {
  246. isShowContent() {
  247. if(this.isShowContent) {
  248. this.init()
  249. }
  250. },
  251. page() {
  252. this.getlistslist()
  253. }
  254. },
  255. }
  256. </script>
  257. <style lang="scss" scoped>
  258. $red: #D82020;
  259. .contact {
  260. display: flex;
  261. height: 100%;
  262. .navlist,.right {
  263. box-shadow: 1px 1px 6px #e1e1e1;
  264. height: 100%;
  265. }
  266. .navlist {
  267. flex: 2;
  268. margin-right: 20px;
  269. .title {
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. display: -webkit-box;
  273. -webkit-box-orient: vertical;
  274. -webkit-line-clamp: 1;
  275. }
  276. }
  277. .nav {
  278. font-size: 16px;
  279. font-family: PingFang-SC-Medium;
  280. font-weight: Medium;
  281. color: #333333;
  282. background-color: #fff;
  283. display: flex;
  284. justify-content: space-between;
  285. padding: 10px 20px;
  286. .you {
  287. color: #333333;
  288. }
  289. }
  290. .navC {
  291. background-color: #F7DFDF;
  292. color: $red;
  293. .you {
  294. color: $red;
  295. }
  296. }
  297. .right {
  298. flex: 7;
  299. .head, {
  300. padding: 10px 20px;
  301. }
  302. .contentbox {
  303. overflow: hidden;
  304. height: 800px;
  305. }
  306. .content::-webkit-scrollbar {
  307. display: none;
  308. position: relative;
  309. }
  310. .content {
  311. position: relative;
  312. height: 800px;
  313. overflow: auto;
  314. padding: 25px 40px;
  315. background-color: #fff;
  316. .text {
  317. padding: 0 10px;
  318. padding-bottom: 30px;
  319. }
  320. .original {
  321. position: absolute;
  322. color: $red;
  323. top: 10px;
  324. left: 20px;
  325. }
  326. }
  327. .head {
  328. background-color: #F2F2F2;
  329. display: flex;
  330. }
  331. }
  332. }
  333. // 加载中
  334. .load {
  335. text-align: center;
  336. margin: 20px 0;
  337. color: #989898;
  338. }
  339. .contentList {
  340. .item {
  341. text-overflow:ellipsis;
  342. line-height: 40px;
  343. height: 40px;
  344. display: flex;
  345. justify-content: space-between;
  346. color: #666666;
  347. border-bottom: solid 1px #F2F2F2;
  348. overflow: hidden;
  349. img {
  350. width: 20px;
  351. height: 20px;
  352. margin: auto 0;
  353. }
  354. .title {
  355. width: calc(100% - 120px);
  356. text-overflow: ellipsis;
  357. display: -webkit-box;
  358. -webkit-box-orient: vertical;
  359. -webkit-line-clamp: 1;
  360. }
  361. .time {
  362. min-width: 100px;
  363. }
  364. }
  365. }
  366. .chooseitem {
  367. color: #666;
  368. .title-icon {
  369. display: inline-block;
  370. width: 0;
  371. height: 0;
  372. margin: auto 0;
  373. border-top: 6px solid transparent;
  374. border-left: 8px solid #d2d2d2;
  375. border-bottom: 6px solid transparent;
  376. }
  377. }
  378. .chooseitem :hover {
  379. color: #d8272a;
  380. .title-icon {
  381. border-left-color: #d8272a;
  382. }
  383. }
  384. .pagetoomuch {
  385. display: flex;
  386. }
  387. .pagec {
  388. color: #333333;
  389. display: flex;
  390. float: right;
  391. margin: 20px 30px;
  392. .fristPage,.pageNum,.nextPage {
  393. margin-left: 3px;
  394. border: solid 1px #F2F2F2;
  395. line-height: 30px;
  396. text-align: center;
  397. color: #333;
  398. }
  399. .fristPage,.nextPage {
  400. padding: 0 10px;
  401. }
  402. .pageNum {
  403. width: 30px;
  404. height: 30px;
  405. }
  406. .isChoose {
  407. background-color: $red;
  408. color: #fff;
  409. }
  410. }
  411. .pagec :hover {
  412. color: $red;
  413. }
  414. </style>