index.vue 4.2 KB

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