提交 70e37cfc 编写于 作者: DCloud_JSON's avatar DCloud_JSON

去掉配置项config.needLogin,并提示

上级 bec2bb35
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-id-pages-x"
}
}, {
"path": "uni_modules/uni-id-pages-x/pages/login/login",
"style": {
"navigationBarTitleText": "登录账号",
"enablePullDownRefresh": false
}
}, {
"path": "uni_modules/uni-id-pages-x/pages/userinfo/userinfo",
"style": {
"navigationBarTitleText": "我的资料",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/register/register",
"style": {
"navigationBarTitleText": "注册",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/retrieve/retrieve",
"style": {
"navigationBarTitleText": "重置密码",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/common/webview/webview",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/deactivate/deactivate",
"style": {
"navigationBarTitleText": "注销账号",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/bindMobile/bindMobile",
"style": {
"navigationBarTitleText": "绑定手机号码",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/setNickname/setNickname",
"style": {
"navigationBarTitleText": "设置昵称",
"enablePullDownRefresh": false,
"navigationStyle": "custom"
// "app-plus": {
// "titleNView": {
// "buttons": [
// {
// "color": "#fff",
// "text": "完成",
// "float": "right",
// "fontWeight": "normal"
// }
// ]
// }
// }
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/realnameAuth/realnameAuth",
"style": {
"navigationBarTitleText": "实名认证",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"uniIdRouter": {}
}
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-id-pages-x"
}
}, {
"path": "uni_modules/uni-id-pages-x/pages/login/login",
"style": {
"navigationBarTitleText": "登录账号",
"enablePullDownRefresh": false
}
}, {
"path": "uni_modules/uni-id-pages-x/pages/userinfo/userinfo",
"style": {
"navigationBarTitleText": "我的资料",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/register/register",
"style": {
"navigationBarTitleText": "注册",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/retrieve/retrieve",
"style": {
"navigationBarTitleText": "重置密码",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/common/webview/webview",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/deactivate/deactivate",
"style": {
"navigationBarTitleText": "注销账号",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/bindMobile/bindMobile",
"style": {
"navigationBarTitleText": "绑定手机号码",
"enablePullDownRefresh": false
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/setNickname/setNickname",
"style": {
"navigationBarTitleText": "设置昵称",
"enablePullDownRefresh": false,
"navigationStyle": "custom"
// "app-plus": {
// "titleNView": {
// "buttons": [
// {
// "color": "#fff",
// "text": "完成",
// "float": "right",
// "fontWeight": "normal"
// }
// ]
// }
// }
}
},
{
"path": "uni_modules/uni-id-pages-x/pages/userinfo/realnameAuth/realnameAuth",
"style": {
"navigationBarTitleText": "实名认证",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"uniIdRouter": {
"loginPage": "/uni_modules/uni-id-pages-x/pages/login/login",
"needLogin": [
"/uni_modules/uni-id-pages-x/pages/userinfo/*"
]
}
}
......@@ -12,9 +12,6 @@ export default {
"register","login","realNameVerify"
]
},
"needLogin":[
"/uni_modules/uni-id-pages-x/pages/userinfo/*"
],
"loginTypes":[
"username",
"smsCode",
......
......@@ -52,7 +52,7 @@ export default async function () {
console.error(
`错误:前端启用的登录方式:${list?.join(',')};没有在服务端完成配置。配置文件路径:"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json"`
)
}
}
}
// #ifdef UNI-APP-X
......@@ -80,44 +80,55 @@ export default async function () {
// }
// // 解绑clientDB错误事件
// // db.off('error', onDBError)
const checkNeedLogin = (url:string):boolean=>{
if(state.isLogin){
return false
}
const needLogin = config.getArray<string>('needLogin')
if (needLogin != null) {
return needLogin.every((item:string):boolean => {
return item == url || new RegExp(item).test(url)
})
}else{
return false
}
}
uni.addInterceptor('navigateTo',{
invoke:(e:NavigateToOptions)=>{
if (checkNeedLogin(e.url)) {
uni.showToast({
title: '请先登录',
icon: 'none'
})
e.url = "/uni_modules/uni-id-pages-x/pages/login/login?uniIdRedirectUrl=" + encodeURIComponent(e.url)
// needLogin相关代码-start(此代码仅为版本兼容提示使用,如已知晓可删除)
const needLogin = config.getArray<string>('needLogin')
const uniCompileVersionCode = uni.getSystemInfoSync().get('uniCompileVersionCode') as number
if(needLogin != null && (uniCompileVersionCode > 3.99 || uniCompileVersionCode == 3.99) ){
const tipText = "uni-id-pages x v1.0.4+ 不再支持配置项config.needLogin,请升级HBuilderX 版本为3.99+,使用更强大 uni-id-router替代。详情查看:https://uniapp.dcloud.net.cn/uniCloud/uni-id/summary.html#uni-id-router"
console.error(tipText)
uni.showModal({
content: tipText,
showCancel: false,
confirmText:"知道了"
});
}else{
const checkNeedLogin = (url:string):boolean=>{
if(state.isLogin){
return false
}
}
})
uni.addInterceptor('redirectTo',{
invoke:(e:RedirectToOptions)=>{
if (checkNeedLogin(e.url)) {
uni.showToast({
title: '请先登录',
icon: 'none'
if (needLogin != null) {
return needLogin.every((item:string):boolean => {
return item == url || new RegExp(item).test(url)
})
e.url = "/uni_modules/uni-id-pages-x/pages/login/login?uniIdRedirectUrl=" + encodeURIComponent(e.url)
}else{
return false
}
}
})
uni.addInterceptor('navigateTo',{
invoke:(e:NavigateToOptions)=>{
if (checkNeedLogin(e.url)) {
uni.showToast({
title: '请先登录',
icon: 'none'
})
e.url = "/uni_modules/uni-id-pages-x/pages/login/login?uniIdRedirectUrl=" + encodeURIComponent(e.url)
}
}
})
uni.addInterceptor('redirectTo',{
invoke:(e:RedirectToOptions)=>{
if (checkNeedLogin(e.url)) {
uni.showToast({
title: '请先登录',
icon: 'none'
})
e.url = "/uni_modules/uni-id-pages-x/pages/login/login?uniIdRedirectUrl=" + encodeURIComponent(e.url)
}
}
})
}
// needLogin相关代码-end
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册