在别的机子测试是正常的;
有两处:
1、wx.showToast 在iPhone se 13.0+版本上弹不出来,没有其他弹框,延时操作在真机调试时可行,可是正式上线后还是不行;
这是页面的代码:
/**
* 页面的初始数据
*/
data: {
examName:"高考",//考试科目
examDate:"2020-7-7",//考试时间
examTime:"08:00",//考试时间
},
// 输入框的input事件的执行逻辑
nameHandleInput(e) {
this.setData({
examName: e.detail.value
})
},
bindDateChange(e) {
this.setData({
examDate: e.detail.value
})
},
bindTimeChange(e) {
this.setData({
examTime: e.detail.value
})
},
reset(){
//重置数据为高考时间
this.setData({
examName: '高考',
examDate: '2020-7-7',
examTime: '08:00',
})
},
save(){
//保存
try {
wx.setStorageSync('examName', this.data.examName);
wx.setStorageSync('examDate', this.data.examDate);
wx.setStorageSync('examTime', this.data.examTime);
} catch (e) {
console.log(e);
}
setTimeout(function () {
wx.showToast({
title: '设置成功',
icon: 'success',
duration: 2000,
fail:function(e){
console.log(e);
},
success:function(e){
console.log("e");
console.log(e);
},
})
}, 100)
wx.navigateBack({
delta: 1
})
},
2、有一个时间相减函数,调试时也是没有问题,正式上线后得出NAN,操作是将值存入wx.setStorageSync(第一个问题的代码),在主页面取出值后为NAN;
这是主页面代码:
data: {
motto: '',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
yuer: 0,//考试剩余天数
examName:"高考",//考试科目
examtime:"2020/7/7 08:00:00",//考试时间
endtime:"",//剩余时间
},
//事件处理函数
bindViewTap: function () {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
this.daojishi();
this.getSetData();
},
getSetData(){
//获取自定义设置的信息
try {
var examName = wx.getStorageSync('examName');
var examDate = wx.getStorageSync('examDate');
var examTime = wx.getStorageSync('examTime');
if (examName && examDate && examTime) {
this.setData({
examName: examName,
examtime: examDate + ' '+examTime+':00',
})
var endDate = new Date(this.data.examtime);
this.data.endtime = endDate.getTime();
}
} catch (e) {
console.log("error");
// Do something when catch error
}
},
getUserInfo: function (e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
},
daojishi() {
//计算倒计时
var t = null;
var that = this;
t = setTimeout(time, 1000); //開始运行
//设置截止时间
var endDate = new Date(this.data.examtime);
this.data.endtime = endDate.getTime();
function addZero(i) {
return i < 10 ? "0" + i : i + "";
}
function time() {
clearTimeout(t); //清除定时器
var dt = new Date();
var now = dt.getTime();
//时间差
var minustime = that.data.endtime - now;
if(minustime <= 0){
minustime = 0;
}
var lefttime = parseInt(minustime / 1000);//正式上线后重置that.data.endtime从storage取出,得出NAN;
var leftTimeday = parseInt(lefttime / (24 * 60 * 60))
var leftTimeh = parseInt(lefttime / (60 * 60) % 24);
var leftTimem = parseInt(lefttime / 60 % 60);
var leftTimes = parseInt(lefttime % 60);
leftTimeday = addZero(leftTimeday)
leftTimeh = addZero(leftTimeh);
leftTimem = addZero(leftTimem);
leftTimes = addZero(leftTimes);
var y = dt.getFullYear();
var mt = dt.getMonth() + 1;
var day = dt.getDate();
var h = dt.getHours(); //获取时
var m = dt.getMinutes(); //获取分
var s = dt.getSeconds(); //获取秒
var yuer = leftTimeday + "天 " + leftTimeh + "时" + leftTimem + "分" + leftTimes + "秒";
var shishitime =
y +
"年" +
mt +
"月" +
day +
"日 " +
h +
"时" +
m +
"分" +
s +
"秒";
that.setData({
motto: shishitime,
yuer: yuer
})
t = setTimeout(time, 1000); //设定定时器,循环运行
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
console.log("onShow");
this.getSetData();
},
你好,请更新微信版本后重试。若还有问题,麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)