ContentLayout.vue 3.8 KB

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