ContentLayout.vue 4.9 KB

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