ContentLayout.vue 4.3 KB

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