ContentLayout.vue 4.8 KB

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