ContentLayout.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="content-container v-w1200" :class="{ calc: conentCenter }">
  3. <div class="content-main">
  4. <slot name="default"></slot>
  5. </div>
  6. <div class="content-right ad-container" :class="{ nothing: adShow }">
  7. <slot name="right">
  8. <slot name="right-top"></slot>
  9. <slot name="right-main">
  10. <div class="ad-list" :id="adCodeMap[routerName] || routerName">
  11. <div
  12. class="ad-item-container"
  13. v-for="(item, index) in adList"
  14. :key="index"
  15. >
  16. <a
  17. :href="item.s_link"
  18. target="_blank"
  19. :id="(adCodeMap[routerName] || routerName) + '-' + index"
  20. >
  21. <img :src="item.s_pic" />
  22. </a>
  23. </div>
  24. </div>
  25. </slot>
  26. <slot name="right-bottom"></slot>
  27. </slot>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { getAdList } from '@/api/modules/'
  33. import { getRandomString } from '@/utils/'
  34. import { mapState } from 'vuex'
  35. export default {
  36. name: 'content-layout',
  37. props: {
  38. // 是否需要获取广告位列表(不获取则不会显示广告位)
  39. needAd: {
  40. type: Boolean,
  41. default: true
  42. },
  43. adCode: {
  44. type: String,
  45. default: ''
  46. },
  47. // 如果没有广告位,内容宽度状态(居中/自适应铺满)
  48. contentWithState: {
  49. type: String,
  50. default: 'center' // center/full
  51. }
  52. },
  53. computed: {
  54. ...mapState({
  55. loginFlag: (state) => state.user.loginFlag
  56. }),
  57. conentCenter() {
  58. // 已登录广告位无数据则隐藏右侧广告位布局并整体居中,未登录则右侧布局常在可插入相关内容
  59. return (
  60. this.adList.length === 0 &&
  61. this.contentWithState === 'center' &&
  62. this.loginFlag
  63. )
  64. },
  65. adShow() {
  66. return this.adList.length === 0 && this.contentWithState && this.loginFlag
  67. }
  68. },
  69. data() {
  70. return {
  71. routerName: '',
  72. adCodeMap: {
  73. article_detail: 'jy-pccontent-right', // 标讯详情页右侧广告位
  74. pro_follow_detail: 'jy-pc-bigmember-project-content-right', // 项目详情页右侧广告位code
  75. ent_portrait: 'jy-pc-bigmember-entportrayal-content-right', // 企业情报详情页右侧广告位code
  76. unit_portrayal: 'jy-pc-bigmember-unitportrayal-content-right', // 采购单位全景分析详情页右侧广告位code
  77. bigvip_subreport_month: 'jy-pc-bigmember-month-content-right', // 数据月报右侧
  78. bigvip_subreport_week: 'jy-pc-bigmember-week-content-right', // 数据周报右侧
  79. ent_ser_portrait: 'jy-pc-bigmember-entportrayal-content-right',
  80. custom_unit_portrayal: 'jy-pc-bigmember-unitportrayal-content-right',
  81. business_detail: 'jy-pc-bigmember-businessdetail-content-right' // 商机情报详情页右侧code
  82. },
  83. adList: [
  84. // {
  85. // s_link: 'https://web2-jytest.jydev.jianyu360.com/swordfish/docs/',
  86. // s_pic: 'https://web2-qmxtest.jydev.jianyu360.com/upload/2021/03/24/20210324164127003068k656W.png'
  87. // }
  88. ]
  89. }
  90. },
  91. created() {
  92. this.routerName = this.$route.name
  93. if (this.needAd) {
  94. this.getAdvertisementList()
  95. }
  96. },
  97. methods: {
  98. getRandomString,
  99. async getAdvertisementList() {
  100. const params = {
  101. code: this.adCode
  102. }
  103. if (!params.code) {
  104. // 先从props中取出参数,如果没取到,就从map中取
  105. const routeName = this.routerName
  106. params.code = this.adCodeMap[routeName]
  107. }
  108. if (!params.code) return console.warn('请传入adCode参数')
  109. const { data } = await getAdList(params)
  110. if (Array.isArray(data)) {
  111. this.adList = data
  112. }
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss">
  118. .content-container {
  119. display: flex;
  120. margin: 32px auto;
  121. padding-bottom: 60px;
  122. &.calc {
  123. display: block;
  124. .content-main {
  125. display: block;
  126. width: calc(100% - 264px);
  127. margin: 0 auto;
  128. }
  129. }
  130. .content-main {
  131. width: 100%;
  132. flex: 1;
  133. transition: 0.1s;
  134. }
  135. .content-right {
  136. width: 264px;
  137. margin-left: 16px;
  138. &.nothing {
  139. width: unset;
  140. margin-left: unset;
  141. }
  142. .ad-item-container {
  143. width: 100%;
  144. min-height: 120px;
  145. overflow: hidden;
  146. border-radius: 4px;
  147. // background-color: #C4C4C4;
  148. &:not(:last-of-type) {
  149. margin-bottom: 16px;
  150. }
  151. a,
  152. img {
  153. display: block;
  154. width: 100%;
  155. cursor: pointer;
  156. }
  157. }
  158. }
  159. }
  160. </style>