index.vue 5.0 KB

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