123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <template>
- <view class="web-box">
- <navbar ref="navbar" :config="config" backColor="#1A1A1A" ></navbar>
- <web-view id="web-view" :src="path" @message="onMessage" @error="onError()" />
- </view>
- </template>
- <script>
- import {
- facParamsHandle
- } from '@/api/government'
- let app = getApp();
- export default {
- data() {
- return {
- title: '',
- navKey: 1,
- config: {
- back: true,
- web: true,
- closePath: '',
- title: '宜格服务',
- color: 'black',
- backgroundColor: [1, '#fff'],
- statusBarFontColor: 'black'
- },
- }
- },
- onReady() {
- // #ifdef APP
- const currentWebview = this.$scope.$getAppWebview()
- // this.pageTitle = uni.getAppBaseInfo().appName
- setTimeout(() => {
- const {
- statusBarHeight,
- screenHeight,
- navHeight
- } = app.globalData;
- const top = statusBarHeight + navHeight
- const wv = currentWebview.children()[0]
- wv.setStyle({
- top: top,
- bottom: 0
- })
- wv.addEventListener('titleUpdate', e => {
- if (e.title) {
- this.$set(this.config, 'title', this.title ||e.title || '');
- this.$refs.navbar.init()
- }
- })
- }, 10); //如果是页面初始化调用时,需要延时一下
- // #endif
- },
- onLoad(opt) {
- this.path = opt.path;
- this.title = opt.title
-
- },
- onShow() {
- },
- methods: {
- onError() {
- uni.redirectTo({
- url: '/pages/web-view/web-error'
- });
- },
- onMessage(e) {
- // e.detail.data 是一个数组
- if (e.detail.data) {
- // this.getCheck(e.detail.data)
- const data = e.detail.data[0];
- let {
- action
- } = data;
- switch (action) {
- case "auth":
- this.getCheck(data);
- break;
- case "map":
- this.openMap(data);
- break;
- case "fac":
- this.checkFac(data);
- break
- case "pay":
- this.goPayPage(data.orderNo);
- break
- case "openWechatApplet":
- this.onOpenWechatApplet(data);
- break
- }
- }
- },
- goPayPage(orderNo) {
- uni.redirectTo({
- url: "/pages/payPage/index?orderNo=" + orderNo
- })
- },
- getCheck(data) {
- console.log('e = ', data)
- this.$yghttp.post('/auth/before/check', data).then(res => {
- if (res.code == 200) {
- if (res.data.needConfirmAuth) {
- uni.setStorageSync('authInfo', data);
- uni.setStorageSync('checkInfo', res.data);
- uni.navigateTo({
- url: '/pages/login/service-auth'
- })
- } else {
- // console.log('res.data.redirect = ' , res.data.redirect)
- uni.redirectTo({
- url: `/pages/web-view/Apps?path=${encodeURIComponent(res.data.redirect)}`
- });
- }
- } else {
- uni.showToast({
- icon: 'none',
- title: res
- })
- }
- }).catch(err => {
- console.log('eeeeeee = ', err)
- // uni.showToast({
- // icon: '当前应用',
- // title: res
- // })
- })
- },
- openMap(data) {
- // data = {
- // latitude: 30.480535,
- // longitude: 114.42001,
- // name: '哗哗哗',
- // address: '啦啦啦啦啦'
- // }
- const {
- latitude,
- longitude,
- name,
- detailedAddress
- } = data
- uni.openLocation({
- latitude: parseFloat(latitude), // 要去的地址经度,浮点数
- longitude: parseFloat(longitude), // 要去的地址纬度,浮点数
- name: name, // 位置名
- address: detailedAddress, // 要去的地址详情说明
- scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
- });
- },
- checkFac(data) {
- // 将第三方h5传递的参数交于服务端进行加入处理并返回
- facParamsHandle(data).then(res => {
- if (res.code == 200) {
- this.$openWXminiprogram(res.data, 2)
- }
- })
- },
- onOpenWechatApplet(data = {}) {
- try {
- const {
- appletOriginalId,
- address,
- type
- } = data
- console.log("appletOriginalId= ", appletOriginalId)
- if (!appletOriginalId) {
- throw new Error("小程序ID错误")
- }
- if (!address) {
- throw new Error("小程序地址错误")
- }
- this.$openWXminiprogram(data, 0)
- } catch (e) {
- //TODO handle the exception
- if (e.message) {
- uni.showToast({
- title: e.message,
- icon: 'none'
- })
- }
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- </style>
|