微信扫码进入小程序指定页面,然后无法跳转到index页面
发布于 5 年前 作者 dzhu 10348 次浏览 来自 问答

微信扫码进入某个指定页面后,我想跳转到index页面,但是无法跳转,使用switchTab也不行,但是可以跳转到其他页面

2 回复

// pay.js

var app = getApp();

var util = require(’…/…/utils/util.js’);

Page({

/**

  * 页面的初始数据

  */

data: {

minuteList: [

{ time: ‘’, money: ‘’, bgi: https://media.findpiano.cn/sharePiano/[email protected], bgi2: https://media.findpiano.cn/sharePiano/[email protected], className: ‘active’, recommend: false },

{ time: ‘’, money: ‘’, bgi: https://media.findpiano.cn/sharePiano/[email protected], bgi2: https://media.findpiano.cn/sharePiano/[email protected], className: ‘’, recommend: false },

{ time: ‘’, money: ‘’, bgi: https://media.findpiano.cn/sharePiano/[email protected], bgi2: https://media.findpiano.cn/sharePiano/[email protected], className: ‘’, recommend: true },

{ time: ‘’, money: ‘’, bgi: https://media.findpiano.cn/sharePiano/[email protected], bgi2: https://media.findpiano.cn/sharePiano/[email protected], className: ‘’, recommend: false },

],

flag: false,

experience: 1,

onTrialTime: ‘’,

},

/**

  * 生命周期函数–监听页面加载

  */

onLoad: function (options) {

var self = this;

setTimeout(function () {

self.getPayinfo();

}, 500);

},

close: function () {

this.setData({

experience: 1

});

},

choose: function (e) {

var money = e.currentTarget.dataset.money;

var minuteList = this.data.minuteList;

for (var i = 0; i < minuteList.length; i++) {

if (minuteList[i].money == money) {

minuteList[i].className = ‘active’;

} else {

minuteList[i].className = ‘’;

}

}

this.setData({

minuteList: minuteList

});

},

getState: function () {

var self = this

var data = util.getParameter(‘shareingPiano.getState’, {});

wx.request({

url: app.globalData.apiUrl,

method: ‘post’,

data: data,

success: function (res) {

console.log(‘state’,res);

if (res.statusCode !== 200 || res.data.header.code) {

wx.showToast({

title: res.data.header.desc,

})

} else {

let data = res.data.body

let currentTime = data.currentTime - 0

let startTime = data.startTime - 0

let paidTime = data.paidTime - 0

if (currentTime && startTime && paidTime) {

wx.navigateTo({

url: ‘…/index/index’,//这里无法跳转至index页面!!!

});

} else {

}

}

}

})

},

getPayinfo: function () {

var self = this

util.getParameter(‘shareingPiano.getPayInfo’, {}, function (res) {

console.log(‘heiehehehi’, res);

var data = res;

wx.request({

url: app.globalData.apiUrl,

method: ‘post’,

data: data,

success: function (res) {

console.log(‘payinfo:’, res);

if (res.statusCode == 200 && res.data.header.code == 0) {

var onTrialTime = res.data.body.onTrialTime;

self.setData({

experience: res.data.body.experience,

onTrialTime: res.data.body.onTrialTime

});

var payInfo = res.data.body.payInfo;

var payInfoArr = [];

for (var key in payInfo) {

payInfoArr.push({

time: key,

money: payInfo[key]

})

}

console.log(payInfoArr);

var minuteList = self.data.minuteList.map(function (item, index) {

console.log(index);

item.time = payInfoArr[index].time;

item.money = payInfoArr[index].money;

return item;

})

console.log(minuteList);

console.log(self.data.experience)

self.setData({

minuteList: minuteList

})

}

self.setData({

flag: true

})

}

})

});

},

// 试用

freeExperience: function () {

var data = util.getParameter(‘shareingPiano.onTrial’, {});

wx.request({

url: app.globalData.apiUrl,

method: ‘post’,

data: data,

success: function (res) {

console.log(res);

wx.navigateTo({

url: ‘…/endPractice/endPractice’

})

}

})

},

// 开始

start: function () {

var self = this;

var payTime;

var payMoney;

this.data.minuteList.forEach(function (item, index) {

if (item.className == ‘active’) {

payTime = item.time;

payMoney = item.money;

}

});

var data = util.getParameter(‘shareingPiano.start’, {

payTime: payTime - 0,

payMoney: parseFloat(payMoney)

});

wx.request({

url: app.globalData.apiUrl,

method: ‘post’,

data: data,

success: function (res) {

if (res.statusCode !== 200 || res.data.header.code) {

wx.showModal({

title: ‘提示’,

content: ‘无法开始,因为’+res.data.header.desc,

success: function (res) {

if (res.confirm) {

console.log(‘用户点击确定’)

} else if (res.cancel) {

console.log(‘用户点击取消’)

}

}

});

} else {

wx.showModal({

title: ‘提示’,

content: ‘成功开始,’+res.data.header.desc,

success: function (res) {

if (res.confirm) {

console.log(‘用户点击确定’)

} else if (res.cancel) {

console.log(‘用户点击取消’)

}

}

});

wx.navigateTo({

url: ‘…/endPractice/endPractice’

});

}

self.setData({

flag: true

});

}

})

},

recharge: function () {

if (!this.data.flag) {

wx.showToast({

title: ‘正在处理,请不要重复点击’,

})

return false;

} else {

this.setData({

flag: false

});

var self = this;

var orderAmount;

var time;

this.data.minuteList.forEach(function (item, index) {

if (item.className == ‘active’) {

orderAmount = item.money;

time = item.time;

}

});

wx.setStorage({

key: ‘buyInfo’,

data: {

money: orderAmount,

time: time

},

})

wx.login({

success: function (r) {

var data = util.getParameter(‘shareingPiano.getSmallRoutineTn’, {

“orderAmount”: orderAmount,

“orderCurrency”: “CNY”,

“paymentSchema”: “WX”,

“code”: r.code

});

wx.request({

url: app.globalData.apiUrl,

method: ‘post’,

data: data,

success: function (response) {

console.log(response.data.body);

wx.requestPayment({

timeStamp: response.data.body.timeStamp + ‘’,

nonceStr: response.data.body.nonceStr,

package: response.data.body.package + ‘’,

signType: response.data.body.signType,

paySign: response.data.body.paySign,

success: function (res) {

console.log(‘5566’, res);

self.start();

},

fail: function (res) {

console.log(res);

wx.showToast({

title: ‘支付失败,请重试’,

});

self.setData({

flag: true

});

},

complete: function (res) {

console.log(9999, res);

}

})

}

})

}

})

}

},

/**

  * 生命周期函数–监听页面初次渲染完成

  */

onReady: function () {

},

/**

  * 生命周期函数–监听页面显示

  */

onShow: function () {

},

/**

  * 生命周期函数–监听页面隐藏

  */

onHide: function () {

},

/**

  * 生命周期函数–监听页面卸载

  */

onUnload: function () {

},

/**

  * 页面相关事件处理函数–监听用户下拉动作

  */

onPullDownRefresh: function () {

},

/**

  * 页面上拉触底事件的处理函数

  */

onReachBottom: function () {

},

/**

  * 用户点击右上角分享

  */

onShareAppMessage: function () {

}

})

你好,请提供一下能复现问题的简单代码示例。

回到顶部