index.vue 2.95 KB
Newer Older
程智春 committed
1
<template>
李嘉林 committed
2 3
    <div class="text" v-if="pageType == 0">
        <div v-if="loadFlag <= 1">正在跳转到其他小程序...</div>
4
        <div v-else class="toMini" @click="toMini">点击跳转到其他小程序</div>
程智春 committed
5 6
    </div>
</template>
李嘉林 committed
7
  
程智春 committed
8
<script>
李嘉林 committed
9 10 11 12 13 14
export default {
    data() {
        return {
            loadFlag: 0,
            options: "",
            pageType: 0, // 0默认 1打开地图
李嘉林 committed
15
            isOpenLocation: false,
李嘉林 committed
16 17 18 19 20 21 22
        }
    },
    onLoad(options) {
        this.options = options;
        console.log("onLoad", this.loadFlag, this.options)
        if (this.options && this.options.type == 1) {
            this.pageType = 1;
李嘉林 committed
23
            this.isOpenLocation = false
李嘉林 committed
24 25
            this.openLocation();
        } else {
26
            this.toMini();
李嘉林 committed
27 28 29 30 31 32
        }
    },
    onShow() {
        this.loadFlag++;
        console.log("onShow", this.loadFlag)
        this.toMini();
李嘉林 committed
33 34
        console.log('this.isOpenLocation', this.isOpenLocation)
        if (this.isOpenLocation) {
李嘉林 committed
35 36 37 38 39
            wx.navigateBack();
        }
    },
    methods: {
        openLocation() {
李嘉林 committed
40
            const _this = this
李嘉林 committed
41 42 43 44 45 46
            wx.openLocation({
                latitude: this.options.latitude - 0,
                longitude: this.options.longitude - 0,
                address: this.options.address,
                scale: 18,
                success(res) {
李嘉林 committed
47 48 49
                    _this.$nextTick(() => {
                        _this.isOpenLocation = true
                    })
李嘉林 committed
50 51 52 53 54 55 56 57
                },
                fail(res) {
                    console.log("fail", res)
                },
                complete(res) {
                    console.log("complete", res)
                }
            })
58
        },
李嘉林 committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        toMini() {
            let _this = this;
            wx.navigateToMiniProgram({
                appId: _this.options.weappAppId,
                path: decodeURIComponent(_this.options.weappPage),
                // envVersion: 'release',
                extraData: _this.options.extraData && JSON.parse(_this.options.extraData),
                success(res) {
                    console.log(res, '--------打开成功')
                    // 打开成功
                },
                complete(res) {
                    console.log(res, '------------------38')
                    if (res.errMsg == 'navigateToMiniProgram:fail cancel') {
                        // 点击了取消
                        _this.loadFlag++;
                    } else if (res.errMsg == 'navigateToMiniProgram:ok') {
                        // 点击了跳转
                        wx.navigateBack();
78
                    }
李嘉林 committed
79 80
                }
            })
程智春 committed
81 82
        }
    }
李嘉林 committed
83
}
程智春 committed
84
</script>
李嘉林 committed
85
  
程智春 committed
86
<style lang="scss" scoped>
李嘉林 committed
87
.text {
88 89 90 91 92
    text-align: center;
    margin-top: 30px;
    font-size: 16px;
    color: #333;
}
李嘉林 committed
93 94

.toMini {
95 96 97 98 99 100 101 102 103 104
    width: 60%;
    margin: 0 auto;
    margin-top: 40vh;
    height: 40px;
    line-height: 40px;
    padding: 0 30px;
    color: #fff;
    background: #41c867;
    border-radius: 40px;
}
李嘉林 committed
105 106
</style>