微信小程序从入门到放弃(七)
程序员文章站
2024-03-22 18:25:52
...
scroll-view不显示滚动条
新版本的微信小程序已经把scroll-view的滚动条默认为隐藏了,而有的业务逻辑需要把滚动条显示出来;所以:
本人查了好久终于找到了解决的方案,就是找到滚动条添加样式;加入如下代码:
::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: #fff;
border-radius: 0px;
}
::-webkit-scrollbar-thumb {
border-radius: 0px;
background: #999;
}
滚动条就可以显示出来了。
用户拒绝授权,再次授权;
这里吊起授权如果在使用wx.login,大家会发现,根本没有效果;这时候,仔细读一下api文档我们会发现有两个api分别为:
wx.openSetting(OBJECT)
和wx.getSetting(OBJECT)
;功能分别为:
wx.openSetting(OBJECT)
:调起客户端小程序设置界面,返回用户设置的操作结果。注:设置界面只会出现小程序已经向用户请求过的权限。示例代码:
wx.openSetting({
success: (res) => {
res.authSetting = {
"scope.userInfo": true, //用户信息
"scope.userLocation": true //地理位置
}
}
})
wx.getSetting(OBJECT)
:获取用户的当前设置。注:返回值中只会出现小程序已经向用户请求过的权限。示例代码:
wx.getSetting({
success: (res) => {
res.authSetting = {
"scope.userInfo": true, //用户信息
"scope.userLocation": true //地理位置
}
}
})
区别:两者都可以更改用户当前的设置;但是只有wx.openSetting()
点击操作之后,会返回是否同意或取消,而wx.getSetting()
只会出现小程序已经向用户请求过的权限;不能更改。
用户授权scope结果列表见下图
下面随手谢啦一个二次授权的函数;如下(true代表同意授权,false代表拒绝授权);
/**二次授权-函数 */
sedauthor:function(e){
var that=this;
wx.showModal({
title: '授权失败',
content: '无法获取您的公开信息,将不能给您进一步服务,请允许授权操作。',
showCancel: true, //显示取消按钮
confirmText: '允许',
cancelText: '拒绝',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
wx.openSetting({ //判断是否同意授权
success(res) {
console.log(1, res)
if (res.authSetting['scope.userInfo']) {
console.log('再次请求授权')
wx.login({
success: function (res) {
console.log(2, res)
that.data.author = true; //成功授权
wx.getUserInfo({
success: function (result) {
console.log(3, res)
var userinfo = result.userInfo;
wx.setStorageSync("userinfo", userinfo)
that.catchOpenid(res.code, userinfo);
that.data.author = true; //成功授权标识
},
fail: function (res) {
console.log('fail', res)
}
})
},
fail: function (res) {
that.data.author = false; //失败授权
console.log('fail', res)
}
});
} else {
console.log('再次拒绝授权')
}
},
fail: function (res) {
console.log('fail', res)
},
complete: (res) => {
console.log('complete', res)
}
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},