trace.js 1.8 KB
// pages/trace/trace.js
const WXRequest = require('../../utils/wxrequest.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        url: '',
        init: false,
        lat: '',
        lng: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        this.setData({
            lng: options.lng,
            lat: options.lat
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let _this = this;
        if (this.data.init) {
            wx.navigateBack()
            return false;
        }
        wx.getLocation({
            success: function (res) {
                /*that.setData({
                  url: `${WXRequest.domain}h5/dist/trace.html?originLat=${res.latitude}&originLng=${res.longitude}`
                });*/
                wx.openLocation({
                    latitude: Number(_this.data.lat),
                    longitude: Number(_this.data.lng)
                });
            },
            fail(res) {
                console.log(res)
            }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.setData({
            init: true
        });
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})