index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="content" :style="{paddingBottom: paddingBottom}">
  3. <view class="item" v-for="(item, index) in json" :class="item.classText.join(' ')" @click="click(item)">
  4. <p v-if="item.type == 'h5-text'" :style="item.style">{{item.content}}</p>
  5. <img :ref="'myImage' + index" @load="handleImageLoad(index, item)" v-if="item.type == 'h5-image'" :src="item.url"></p>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. import Clipboard from 'clipboard'; // 引入Clipboard
  11. import {getTemplateByNo,getTemplateById,callback,youkuClickCallback, iqiyiClickCallback} from '../../api/api.js'
  12. import {clicks} from '../../common/common.js'
  13. export default {
  14. data() {
  15. return {
  16. images: [],
  17. site: {},
  18. data: {},
  19. json: {},
  20. vid: '',
  21. click_id: '',
  22. aid: '',
  23. id: null,
  24. no: null,
  25. type: 0,
  26. show: false,
  27. name: '',
  28. tel: '',
  29. accountId: '',
  30. ip: '',
  31. paddingBottom: 0,
  32. order_plan_id: "",
  33. creative_id: "",
  34. impress_id: "",
  35. sign: "",
  36. }
  37. },
  38. mounted() {
  39. window.vueInstance = this; // 将 Vue 实例暴露到全局
  40. },
  41. onLoad(option) {
  42. this.no = option.no;
  43. this.id = option.tid;
  44. if((this.id == null || this.id == "" || this.id == undefined) && (this.no == null || this.no == "" || this.no == undefined)){
  45. uni.showToast({
  46. icon:'none',
  47. title: '推广链接错误',
  48. });
  49. return;
  50. }
  51. this.accountId = option.accountId;
  52. this.type = option.type;
  53. this.no = option.no;
  54. // 百度
  55. if(this.type == 0){
  56. this.vid = option.bd_vid;
  57. }
  58. // 优酷
  59. if(this.type == 1){
  60. this.vid = option.bd_vid;
  61. this.aid = option.aid;
  62. this.click_id = option.click_id;
  63. this.ip = option.ip;
  64. }
  65. // 爱奇艺
  66. if(this.type == 2){
  67. this.order_plan_id = option.order_plan_id;
  68. this.creative_id = option.creative_id;
  69. this.impress_id = option.impress_id;
  70. this.sign = option.sign;
  71. }
  72. if(this.id){
  73. getTemplateById(this.id).then(e => {
  74. this.data = e.data;
  75. this.site = e.site;
  76. this.json = JSON.parse(e.data.json)
  77. })
  78. }else if(this.no){
  79. getTemplateByNo(this.no).then(e => {
  80. this.data = e.data;
  81. this.json = JSON.parse(e.data.json)
  82. })
  83. }
  84. // callback({vid: this.vid}).then(e => {
  85. // console.info(e)
  86. // })
  87. },
  88. methods: {
  89. handleImageLoad(index, item){
  90. if(item.classText.indexOf("footer") != -1){
  91. const imgElement = this.$refs["myImage" + index];
  92. // 获取真实高度(包含以下两种方式)
  93. const naturalHeight = imgElement[0].naturalHeight; // 原始高度
  94. const clientHeight = imgElement[0].clientHeight; // 渲染高度
  95. this.paddingBottom = clientHeight + "px";
  96. }
  97. },
  98. confirm() {
  99. this.show = false;
  100. },
  101. clickToWx(workUrl){
  102. // 百度
  103. if(this.type == 0){
  104. let data = {
  105. accountId: this.accountId,
  106. url: window.location.href,
  107. no: this.no,
  108. bdVid: this.vid,
  109. t: 67,
  110. };
  111. callback(data).then(e => {
  112. window.location.href = workUrl + "?customer_channel=" + this.vid;
  113. })
  114. }
  115. // 优酷
  116. if(this.type == 1){
  117. let data = {
  118. accountId: this.accountId,
  119. deeplink_url: window.location.href,
  120. no: this.no,
  121. bd_vid: this.vid,
  122. aid: this.aid,
  123. click_id: this.click_id,
  124. ip: this.ip,
  125. };
  126. youkuClickCallback(data).then(e => {
  127. window.location.href = workUrl + "?customer_channel=" + this.vid;
  128. })
  129. }
  130. // 优酷
  131. if(this.type == 2){
  132. let data = {
  133. accountId: this.accountId,
  134. url: window.location.href,
  135. no: this.no,
  136. order_plan_id: this.order_plan_id,
  137. creative_id: this.creative_id,
  138. impress_id: this.impress_id,
  139. sign: this.sign,
  140. clickType: "200"
  141. };
  142. iqiyiClickCallback(data).then(e => {
  143. window.location.href = workUrl + "?customer_channel=" + this.impress_id;
  144. })
  145. }
  146. },
  147. click(item){
  148. if(!item.addWxFun){
  149. return;
  150. }
  151. this.clickToWx(item.workUrl);
  152. },
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .item{
  158. display: flex;
  159. flex-direction: column;
  160. flex: 1;
  161. margin: 0;
  162. width: 100%;
  163. img{
  164. width: 100%;
  165. }
  166. p{
  167. white-space: pre-line;
  168. }
  169. }
  170. .footer{
  171. position: fixed;
  172. bottom: 0;
  173. left: 0;
  174. }
  175. </style>