index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <van-popup
  3. class="fbt-van-popup"
  4. v-model="showFlag"
  5. :lock-scroll="true"
  6. :close-on-click-overlay="false">
  7. <p>打开小程序</p>
  8. <div class="btns">
  9. <a
  10. href="javascript:;"
  11. @click="funJumpIndex">取消</a>
  12. <div>
  13. <a
  14. href="javascript:;">允许</a>
  15. <wx-open-launch-weapp
  16. ref="launchBtn"
  17. :username="accountId"
  18. :path="appPath"
  19. style="position: absolute;left:0;top:0;z-index:1;width: 100%;height: 100%;"
  20. @error="errorHandle">
  21. <script type="text/wxtag-template">
  22. <style>
  23. .jump-btn {
  24. position: absolute;
  25. left: 0;
  26. top: 0;
  27. width: 100%;
  28. height: 100%;
  29. line-height: 100%;
  30. text-align: center;
  31. font-size: 12px;
  32. opacity: 0;
  33. }
  34. </style>
  35. <div class="jump-btn">打开小程序</div>
  36. </script>
  37. </wx-open-launch-weapp>
  38. </div>
  39. </div>
  40. </van-popup>
  41. </template>
  42. <script>
  43. import { Toast, Popup, Dialog } from 'vant'
  44. import { getJumpConfig } from './api'
  45. import { isSupportJumpWXmini } from '../../../utils'
  46. export default {
  47. name: 'index',
  48. components: {
  49. 'van-popup': Popup
  50. },
  51. props: {
  52. redirectUrl: {
  53. type: String,
  54. default: ''
  55. }
  56. },
  57. data () {
  58. return {
  59. showFlag: false,
  60. accountId: '',
  61. appPath: '',
  62. toast: null
  63. }
  64. },
  65. methods: {
  66. init () {
  67. this.toast = Toast.loading({
  68. message: '加载中...',
  69. forbidClick: true,
  70. duration: 0
  71. })
  72. this.handleJump()
  73. },
  74. funJumpIndex () {
  75. const { name } = this.$route
  76. this.showFlag = false
  77. if (name === 'MarketingSave') {
  78. return
  79. }
  80. this.$nextTick(() => {
  81. this.$router.push({ name: 'MarketingSave' })
  82. })
  83. },
  84. async handleJump () {
  85. const linkUrl = this.redirectUrl.split('api/transfer/')
  86. try {
  87. const { status, data, msg } = await getJumpConfig(linkUrl[1])
  88. this.toast.clear()
  89. if (status) {
  90. // type 类型:1-h5 2-小程序
  91. const { type, url } = data
  92. this.accountId = data.app_id
  93. // this.appPath = data.page_path
  94. if (type === 2 && isSupportJumpWXmini()) {
  95. this.showFlag = true
  96. } else {
  97. top.location.href = url
  98. }
  99. } else {
  100. Toast(msg)
  101. }
  102. } catch (e) {
  103. this.toast.clear()
  104. }
  105. },
  106. errorHandle (err) {
  107. Dialog.alert({
  108. message: JSON.stringify(err)
  109. }).then(() => {
  110. // on close
  111. })
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .fbt-van-popup {
  118. display: flex;
  119. flex-direction: column;
  120. align-items: center;
  121. width: 273px;
  122. background: #fff;
  123. border-radius: 5px;
  124. p, a {
  125. line-height: 20px;
  126. font-size: 14px;
  127. }
  128. p {
  129. font-weight: bold;
  130. padding: 23px 0;
  131. color: #222;
  132. }
  133. a {
  134. padding: 13px 0;
  135. text-align: center;
  136. }
  137. .btns {
  138. display: flex;
  139. align-items: center;
  140. width: 100%;
  141. border-top: 1px solid #F3F3F3; /*no*/
  142. & > a {
  143. flex: 1;
  144. color: #999999;
  145. }
  146. & > div {
  147. position: relative;
  148. left: 0;
  149. top: 0;
  150. flex: 1;
  151. &:before {
  152. position: absolute;
  153. left: 0;
  154. top: 0;
  155. bottom: 0;
  156. height: 100%;
  157. content: '';
  158. border-left: 1px solid #F3F3F3;
  159. }
  160. a {
  161. display: block;
  162. width: 100%;
  163. font-weight: bold;
  164. color: #222;
  165. }
  166. }
  167. }
  168. }
  169. </style>