Apps.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="web-box">
  3. <navbar ref="navbar" :config="config" backColor="#1A1A1A" ></navbar>
  4. <web-view id="web-view" :src="path" @message="onMessage" @error="onError()" />
  5. </view>
  6. </template>
  7. <script>
  8. import {
  9. facParamsHandle
  10. } from '@/api/government'
  11. let app = getApp();
  12. export default {
  13. data() {
  14. return {
  15. title: '',
  16. navKey: 1,
  17. config: {
  18. back: true,
  19. web: true,
  20. closePath: '',
  21. title: '宜格服务',
  22. color: 'black',
  23. backgroundColor: [1, '#fff'],
  24. statusBarFontColor: 'black'
  25. },
  26. }
  27. },
  28. onReady() {
  29. // #ifdef APP
  30. const currentWebview = this.$scope.$getAppWebview()
  31. // this.pageTitle = uni.getAppBaseInfo().appName
  32. setTimeout(() => {
  33. const {
  34. statusBarHeight,
  35. screenHeight,
  36. navHeight
  37. } = app.globalData;
  38. const top = statusBarHeight + navHeight
  39. const wv = currentWebview.children()[0]
  40. wv.setStyle({
  41. top: top,
  42. bottom: 0
  43. })
  44. wv.addEventListener('titleUpdate', e => {
  45. if (e.title) {
  46. this.$set(this.config, 'title', this.title ||e.title || '');
  47. this.$refs.navbar.init()
  48. }
  49. })
  50. }, 10); //如果是页面初始化调用时,需要延时一下
  51. // #endif
  52. },
  53. onLoad(opt) {
  54. this.path = opt.path;
  55. this.title = opt.title
  56. },
  57. onShow() {
  58. },
  59. methods: {
  60. onError() {
  61. uni.redirectTo({
  62. url: '/pages/web-view/web-error'
  63. });
  64. },
  65. onMessage(e) {
  66. // e.detail.data 是一个数组
  67. if (e.detail.data) {
  68. // this.getCheck(e.detail.data)
  69. const data = e.detail.data[0];
  70. let {
  71. action
  72. } = data;
  73. switch (action) {
  74. case "auth":
  75. this.getCheck(data);
  76. break;
  77. case "map":
  78. this.openMap(data);
  79. break;
  80. case "fac":
  81. this.checkFac(data);
  82. break
  83. case "pay":
  84. this.goPayPage(data.orderNo);
  85. break
  86. case "openWechatApplet":
  87. this.onOpenWechatApplet(data);
  88. break
  89. }
  90. }
  91. },
  92. goPayPage(orderNo) {
  93. uni.redirectTo({
  94. url: "/pages/payPage/index?orderNo=" + orderNo
  95. })
  96. },
  97. getCheck(data) {
  98. console.log('e = ', data)
  99. this.$yghttp.post('/auth/before/check', data).then(res => {
  100. if (res.code == 200) {
  101. if (res.data.needConfirmAuth) {
  102. uni.setStorageSync('authInfo', data);
  103. uni.setStorageSync('checkInfo', res.data);
  104. uni.navigateTo({
  105. url: '/pages/login/service-auth'
  106. })
  107. } else {
  108. // console.log('res.data.redirect = ' , res.data.redirect)
  109. uni.redirectTo({
  110. url: `/pages/web-view/Apps?path=${encodeURIComponent(res.data.redirect)}`
  111. });
  112. }
  113. } else {
  114. uni.showToast({
  115. icon: 'none',
  116. title: res
  117. })
  118. }
  119. }).catch(err => {
  120. console.log('eeeeeee = ', err)
  121. // uni.showToast({
  122. // icon: '当前应用',
  123. // title: res
  124. // })
  125. })
  126. },
  127. openMap(data) {
  128. // data = {
  129. // latitude: 30.480535,
  130. // longitude: 114.42001,
  131. // name: '哗哗哗',
  132. // address: '啦啦啦啦啦'
  133. // }
  134. const {
  135. latitude,
  136. longitude,
  137. name,
  138. detailedAddress
  139. } = data
  140. uni.openLocation({
  141. latitude: parseFloat(latitude), // 要去的地址经度,浮点数
  142. longitude: parseFloat(longitude), // 要去的地址纬度,浮点数
  143. name: name, // 位置名
  144. address: detailedAddress, // 要去的地址详情说明
  145. scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
  146. });
  147. },
  148. checkFac(data) {
  149. // 将第三方h5传递的参数交于服务端进行加入处理并返回
  150. facParamsHandle(data).then(res => {
  151. if (res.code == 200) {
  152. this.$openWXminiprogram(res.data, 2)
  153. }
  154. })
  155. },
  156. onOpenWechatApplet(data = {}) {
  157. try {
  158. const {
  159. appletOriginalId,
  160. address,
  161. type
  162. } = data
  163. console.log("appletOriginalId= ", appletOriginalId)
  164. if (!appletOriginalId) {
  165. throw new Error("小程序ID错误")
  166. }
  167. if (!address) {
  168. throw new Error("小程序地址错误")
  169. }
  170. this.$openWXminiprogram(data, 0)
  171. } catch (e) {
  172. //TODO handle the exception
  173. if (e.message) {
  174. uni.showToast({
  175. title: e.message,
  176. icon: 'none'
  177. })
  178. }
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. </style>