diff --git a/pages.json b/pages.json index 6851892c646729cf073382961d74cab258510bb2..6103508de15ba914e46a6aa5f84e8b5e6752e1ea 100644 --- a/pages.json +++ b/pages.json @@ -1,91 +1,96 @@ { - "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/*" + ] + } +} diff --git a/uni_modules/uni-id-pages-x/config.uts b/uni_modules/uni-id-pages-x/config.uts index 5f91a06be42f54792d9ef2842420b5de4b7bb169..a310eff5d5687e2172dfd12f6ee08ebf947fc44c 100644 --- a/uni_modules/uni-id-pages-x/config.uts +++ b/uni_modules/uni-id-pages-x/config.uts @@ -12,9 +12,6 @@ export default { "register","login","realNameVerify" ] }, - "needLogin":[ - "/uni_modules/uni-id-pages-x/pages/userinfo/*" - ], "loginTypes":[ "username", "smsCode", diff --git a/uni_modules/uni-id-pages-x/init.uts b/uni_modules/uni-id-pages-x/init.uts index 5081b834d472bdd8a61843b399c11ee2be76f2fd..cfb473ca6da32d7a34ac37a706988ebc3d0195d6 100644 --- a/uni_modules/uni-id-pages-x/init.uts +++ b/uni_modules/uni-id-pages-x/init.uts @@ -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('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('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 + }