Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
这我不会
uni-starter
提交
710a0132
U
uni-starter
项目概览
这我不会
/
uni-starter
与 Fork 源项目一致
Fork自
DCloud / uni-starter
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-starter
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
710a0132
编写于
7月 19, 2021
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. 强制登陆配置,新增白名单模式 2. 强制登陆配置,支持正则表达式
上级
59eb3a0b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
587 addition
and
524 deletion
+587
-524
changelog.md
changelog.md
+3
-0
common/appInit.js
common/appInit.js
+431
-387
manifest.json
manifest.json
+129
-111
package.json
package.json
+1
-1
pages/grid/grid.vue
pages/grid/grid.vue
+1
-16
pages/ucenter/about/about.vue
pages/ucenter/about/about.vue
+0
-1
pages/ucenter/login-page/pwd-retrieve/pwd-retrieve.vue
pages/ucenter/login-page/pwd-retrieve/pwd-retrieve.vue
+1
-1
uni-starter.config.js
uni-starter.config.js
+21
-7
未找到文件。
changelog.md
浏览文件 @
710a0132
## 1.0.39(2021-07-19)
1.
强制登陆配置,新增白名单模式
2.
强制登陆配置,支持正则表达式
## 1.0.38(2021-07-17)
## 1.0.38(2021-07-17)
删除多余文件
删除多余文件
## 1.0.37(2021-07-14)
## 1.0.37(2021-07-14)
...
...
common/appInit.js
浏览文件 @
710a0132
import
uniStarterConfig
from
'
@/uni-starter.config.js
'
;
import
uniStarterConfig
from
'
@/uni-starter.config.js
'
;
import
store
from
'
@/store
'
import
store
from
'
@/store
'
//应用初始化页
//应用初始化页
// #ifdef APP-PLUS
// #ifdef APP-PLUS
import
checkUpdate
from
'
@/uni_modules/uni-upgrade-center-app/utils/check-update
'
;
import
checkUpdate
from
'
@/uni_modules/uni-upgrade-center-app/utils/check-update
'
;
import
callCheckVersion
from
'
@/uni_modules/uni-upgrade-center-app/utils/call-check-version
'
;
import
callCheckVersion
from
'
@/uni_modules/uni-upgrade-center-app/utils/call-check-version
'
;
import
interceptorChooseImage
from
'
@/uni_modules/json-interceptor-chooseImage/js_sdk/main.js
'
;
import
interceptorChooseImage
from
'
@/uni_modules/json-interceptor-chooseImage/js_sdk/main.js
'
;
// #endif
// #endif
const
db
=
uniCloud
.
database
()
const
db
=
uniCloud
.
database
()
export
default
async
function
()
{
export
default
async
function
()
{
let
loginConfig
=
uniStarterConfig
.
router
.
login
let
loginConfig
=
uniStarterConfig
.
router
.
login
//清除有配置但设备环境不支持的登陆项
//清除有配置但设备环境不支持的登陆项
// #ifdef APP-PLUS
// #ifdef APP-PLUS
await
new
Promise
((
callBack
)
=>
{
await
new
Promise
((
callBack
)
=>
{
plus
.
oauth
.
getServices
(
oauthServices
=>
{
plus
.
oauth
.
getServices
(
oauthServices
=>
{
loginConfig
=
loginConfig
.
filter
(
item
=>
{
loginConfig
=
loginConfig
.
filter
(
item
=>
{
if
([
"
univerify
"
,
"
weixin
"
,
"
apple
"
].
includes
(
item
)){
if
([
"
univerify
"
,
"
weixin
"
,
"
apple
"
].
includes
(
item
))
{
let
index
=
oauthServices
.
findIndex
(
e
=>
e
.
id
==
item
)
let
index
=
oauthServices
.
findIndex
(
e
=>
e
.
id
==
item
)
if
(
index
==-
1
){
if
(
index
==
-
1
)
{
return
false
return
false
}
else
{
}
else
{
return
oauthServices
[
index
].
nativeClient
return
oauthServices
[
index
].
nativeClient
}
}
else
{
return
true
}
})
if
(
loginConfig
.
includes
(
'
univerify
'
))
{
//一键登录 功能预登录
uni
.
preLogin
({
provider
:
'
univerify
'
,
complete
:
e
=>
{
console
.
log
(
e
);
}
})
}
callBack
()
},
err
=>
{
console
.
error
(
'
获取服务供应商失败:
'
+
JSON
.
stringify
(
err
));
})
})
// #endif
//非app移除:一键登录、苹果登陆;h5移除微信登陆,如果你做微信公众号登陆需要将此行移除
// #ifndef APP-PLUS
loginConfig
=
loginConfig
.
filter
(
item
=>
{
return
!
[
'
univerify
'
,
'
apple
'
,
// #ifdef H5
'
weixin
'
// #endif
].
includes
(
item
)
})
// #endif
uniStarterConfig
.
router
.
login
=
loginConfig
// uniStarterConfig挂载到getApp().globalData.config
setTimeout
(()
=>
{
getApp
({
allowDefault
:
true
}).
globalData
.
config
=
uniStarterConfig
;
},
1
)
// 初始化appVersion(仅app生效)
initAppVersion
();
// #ifdef APP-PLUS
// 实现,路由拦截。当应用无访问摄像头/相册权限,引导跳到设置界面
interceptorChooseImage
()
// #endif
//clientDB的错误提示
function
onDBError
({
code
,
// 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
message
})
{
console
.
log
(
'
onDBError
'
);
// 处理错误
console
.
log
(
code
,
message
);
if
([
'
TOKEN_INVALID_INVALID_CLIENTID
'
,
'
TOKEN_INVALID
'
,
'
TOKEN_INVALID_TOKEN_EXPIRED
'
,
'
TOKEN_INVALID_WRONG_TOKEN
'
,
'
TOKEN_INVALID_ANONYMOUS_USER
'
,
].
includes
(
code
))
{
uni
.
navigateTo
({
url
:
'
/pages/ucenter/login-page/index/index
'
})
}
}
// 绑定clientDB错误事件
db
.
on
(
'
error
'
,
onDBError
)
// 解绑clientDB错误事件
//db.off('error', onDBError)
db
.
on
(
'
refreshToken
'
,
function
({
token
,
tokenExpired
})
{
console
.
log
(
'
监听到clientDB的refreshToken
'
,
{
token
,
tokenExpired
});
store
.
commit
(
'
user/login
'
,
{
token
,
tokenExpired
})
})
const
Debug
=
true
;
//拦截器封装callFunction
let
callFunctionOption
;
uniCloud
.
addInterceptor
(
'
callFunction
'
,
{
async
invoke
(
option
)
{
// #ifdef APP-PLUS
// 判断如果是执行登陆(无论是哪种登陆方式),就记录用户的相关设备id
if
(
option
.
name
==
'
uni-id-cf
'
&&
(
option
.
data
.
action
==
'
register
'
||
option
.
data
.
action
.
slice
(
0
,
5
)
==
'
login
'
))
{
let
oaid
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
plus
.
device
.
getOAID
({
success
:
function
(
e
)
{
callBack
(
e
.
oaid
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
)
{
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
})
let
imei
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
plus
.
device
.
getInfo
({
success
:
function
(
e
)
{
callBack
(
e
.
imei
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
)
{
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
})
let
push_clientid
=
''
,
idfa
=
plus
.
storage
.
getItem
(
'
idfa
'
)
||
''
;
//idfa有需要的用户在应用首次启动时自己获取存储到storage中
try
{
push_clientid
=
plus
.
push
.
getClientInfo
().
clientid
}
catch
(
e
)
{
uni
.
showModal
({
content
:
'
获取推送标识失败。如果你的应用不需要推送功能,请注释掉本代码块
'
,
showCancel
:
false
,
confirmText
:
"
好的
"
});
console
.
log
(
e
)
}
let
deviceInfo
=
{
push_clientid
,
// 获取匿名设备标识符
imei
,
oaid
,
idfa
}
console
.
log
(
"
重新登陆/注册,获取设备id
"
,
deviceInfo
);
option
.
data
.
deviceInfo
=
deviceInfo
// #ifndef H5
//注册可能不仅仅走register接口,还有登陆并注册的接口
option
.
data
.
inviteCode
=
await
new
Promise
((
callBack
)
=>
{
uni
.
getClipboardData
({
success
:
function
(
res
)
{
if
(
res
.
data
.
slice
(
0
,
18
)
==
'
uniInvitationCode:
'
)
{
let
uniInvitationCode
=
res
.
data
.
slice
(
18
,
38
)
console
.
log
(
'
当前用户是其他用户推荐下载的,推荐者的code是:
'
+
uniInvitationCode
);
// uni.showModal({
// content: '当前用户是其他用户推荐下载的,推荐者的code是:'+uniInvitationCode,
// showCancel: false
// });
callBack
(
uniInvitationCode
)
//当前用户是其他用户推荐下载的。这里登记他的推荐者id 为当前用户的myInviteCode。判断如果是注册
}
else
{
callBack
(
false
)
}
},
fail
()
{
callBack
(
false
)
}
});
})
// #endif
}
// #endif
// console.log(JSON.stringify(option));
callFunctionOption
=
option
},
complete
(
e
)
{
// console.log(JSON.stringify(e));
},
fail
(
e
)
{
// 失败回调拦截
if
(
Debug
)
{
uni
.
showModal
({
content
:
JSON
.
stringify
(
e
),
showCancel
:
false
});
console
.
error
(
e
);
}
else
{
uni
.
showModal
({
content
:
"
系统错误请稍后再试!
"
,
showCancel
:
false
,
confirmText
:
"
知道了
"
});
}
//如果执行错误,检查是否断网
uni
.
getNetworkType
({
complete
:
res
=>
{
// console.log(res);
if
(
res
.
networkType
==
'
none
'
)
{
uni
.
showToast
({
title
:
'
手机网络异常
'
,
icon
:
'
none
'
});
console
.
log
(
'
手机网络异常
'
);
let
callBack
=
res
=>
{
console
.
log
(
res
);
if
(
res
.
isConnected
)
{
uni
.
showToast
({
title
:
'
恢复联网自动重新执行
'
,
icon
:
'
none
'
});
console
.
log
(
res
.
networkType
,
"
恢复联网自动重新执行
"
);
uni
.
offNetworkStatusChange
(
e
=>
{
console
.
log
(
"
移除监听成功
"
,
e
);
})
//恢复联网自动重新执行
uniCloud
.
callFunction
(
callFunctionOption
)
uni
.
offNetworkStatusChange
(
callBack
);
}
}
uni
.
onNetworkStatusChange
(
callBack
);
}
}
});
},
success
:
(
e
)
=>
{
console
.
log
(
e
);
const
{
token
,
tokenExpired
}
=
e
.
result
if
(
token
&&
tokenExpired
)
{
store
.
commit
(
'
user/login
'
,
{
token
,
tokenExpired
})
}
switch
(
e
.
result
.
code
)
{
case
403
:
uni
.
navigateTo
({
url
:
"
/pages/ucenter/login-page/index/index
"
})
break
;
case
30203
:
uni
.
navigateTo
({
url
:
"
/pages/ucenter/login-page/index/index
"
})
break
;
case
50101
:
uni
.
showToast
({
title
:
e
.
result
.
msg
,
icon
:
'
none
'
,
duration
:
2000
});
break
;
default
:
console
.
log
(
'
code的值是:
'
+
e
.
result
.
code
,
'
可以在这里插入,自动处理响应体
'
);
break
;
}
}
})
//自定义路由拦截
const
{
"
router
"
:
{
needLogin
,
visitor
,
login
}
}
=
uniStarterConfig
//需要登录的页面
let
list
=
[
"
navigateTo
"
,
"
redirectTo
"
,
"
reLaunch
"
,
"
switchTab
"
];
list
.
forEach
(
item
=>
{
//用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
uni
.
addInterceptor
(
item
,
{
invoke
(
e
)
{
// 调用前拦截
// console.log(e);
//获取用户的token
const
token
=
uni
.
getStorageSync
(
'
uni_id_token
'
),
//token是否已失效
tokenExpired
=
uni
.
getStorageSync
(
'
uni_id_token_expired
'
)
<
Date
.
now
(),
//获取要跳转的页面路径(url去掉"?"和"?"后的参数)
url
=
e
.
url
.
split
(
'
?
'
)[
0
],
//获取要前往的页面路径(即url去掉"?"和"?"后的参数)
pages
=
getCurrentPages
(),
fromUrl
=
pages
[
pages
.
length
-
1
].
route
;
let
inLoginPage
=
fromUrl
.
split
(
'
/
'
)[
2
]
==
'
login-page
'
//控制登录优先级
if
(
//判断当前窗口是否为登陆页面,如果是则不重定向路由
url
==
'
/pages/ucenter/login-page/index/index
'
&&
!
inLoginPage
)
{
// console.log(9527777,login);
//一键登录(univerify)、账号(username)、验证码登录(短信smsCode)
if
(
login
[
0
]
==
'
username
'
)
{
e
.
url
=
"
/pages/ucenter/login-page/pwd-login/pwd-login
"
}
else
{
if
(
e
.
url
==
url
)
{
e
.
url
+=
'
?
'
}
//添加参数之前判断是否带了`?`号如果没有就补上,因为当开发场景本身有参数的情况下是已经带了`?`号
e
.
url
+=
"
type=
"
+
login
[
0
]
}
}
}
else
{
}
else
{
return
true
//拦截强制登录页面
}
let
pass
=
true
})
//pattern
if
(
loginConfig
.
includes
(
'
univerify
'
)){
//一键登录 功能预登录
if
(
needLogin
)
{
uni
.
preLogin
({
pass
=
needLogin
.
every
((
item
)
=>
{
provider
:
'
univerify
'
,
if
(
item
.
slice
(
0
,
8
)
==
'
pattern:
'
)
{
complete
:
e
=>
{
return
!
eval
(
item
.
slice
(
8
,
item
.
length
)).
test
(
url
)
console
.
log
(
e
);
}
}
return
url
!=
item
})
}
callBack
()
},
err
=>
{
console
.
error
(
'
获取服务供应商失败:
'
+
JSON
.
stringify
(
err
));
})
})
// #endif
//非app移除:一键登录、苹果登陆;h5移除微信登陆,如果你做微信公众号登陆需要将此行移除
// #ifndef APP-PLUS
loginConfig
=
loginConfig
.
filter
(
item
=>
{
return
!
[
'
univerify
'
,
'
apple
'
,
// #ifdef H5
'
weixin
'
// #endif
].
includes
(
item
)
})
// #endif
uniStarterConfig
.
router
.
login
=
loginConfig
// uniStarterConfig挂载到getApp().globalData.config
setTimeout
(()
=>
{
getApp
({
allowDefault
:
true
}).
globalData
.
config
=
uniStarterConfig
;
},
1
)
// 初始化appVersion(仅app生效)
initAppVersion
();
// #ifdef APP-PLUS
// 实现,路由拦截。当应用无访问摄像头/相册权限,引导跳到设置界面
interceptorChooseImage
()
// #endif
//clientDB的错误提示
function
onDBError
({
code
,
// 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
message
})
{
console
.
log
(
'
onDBError
'
);
// 处理错误
console
.
log
(
code
,
message
);
if
([
'
TOKEN_INVALID_INVALID_CLIENTID
'
,
'
TOKEN_INVALID
'
,
'
TOKEN_INVALID_TOKEN_EXPIRED
'
,
'
TOKEN_INVALID_WRONG_TOKEN
'
,
'
TOKEN_INVALID_ANONYMOUS_USER
'
,
].
includes
(
code
)){
uni
.
navigateTo
({
url
:
'
/pages/ucenter/login-page/index/index
'
})
}
}
// 绑定clientDB错误事件
db
.
on
(
'
error
'
,
onDBError
)
// 解绑clientDB错误事件
//db.off('error', onDBError)
db
.
on
(
'
refreshToken
'
,
function
({
token
,
tokenExpired
})
{
console
.
log
(
'
监听到clientDB的refreshToken
'
,{
token
,
tokenExpired
});
store
.
commit
(
'
user/login
'
,
{
token
,
tokenExpired
})
})
const
Debug
=
true
;
//拦截器封装callFunction
let
callFunctionOption
;
uniCloud
.
addInterceptor
(
'
callFunction
'
,{
async
invoke
(
option
){
// #ifdef APP-PLUS
// 判断如果是执行登陆(无论是哪种登陆方式),就记录用户的相关设备id
if
(
option
.
name
==
'
uni-id-cf
'
&&
(
option
.
data
.
action
==
'
register
'
||
option
.
data
.
action
.
slice
(
0
,
5
)
==
'
login
'
)){
let
oaid
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
plus
.
device
.
getOAID
({
success
:
function
(
e
){
callBack
(
e
.
oaid
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
){
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
})
let
imei
=
await
new
Promise
((
callBack
,
fail
)
=>
{
if
(
uni
.
getSystemInfoSync
().
platform
==
"
android
"
)
{
plus
.
device
.
getInfo
({
success
:
function
(
e
){
callBack
(
e
.
imei
)
// console.log('getOAID success: '+JSON.stringify(e));
},
fail
:
function
(
e
){
callBack
()
console
.
log
(
'
getOAID failed:
'
+
JSON
.
stringify
(
e
));
}
});
}
else
{
callBack
()
}
})
let
push_clientid
=
''
,
idfa
=
plus
.
storage
.
getItem
(
'
idfa
'
)
||
''
;
//idfa有需要的用户在应用首次启动时自己获取存储到storage中
try
{
push_clientid
=
plus
.
push
.
getClientInfo
().
clientid
}
catch
(
e
){
uni
.
showModal
({
content
:
'
获取推送标识失败。如果你的应用不需要推送功能,请注释掉本代码块
'
,
showCancel
:
false
,
confirmText
:
"
好的
"
});
console
.
log
(
e
)
}
let
deviceInfo
=
{
push_clientid
,
// 获取匿名设备标识符
imei
,
oaid
,
idfa
}
console
.
log
(
"
重新登陆/注册,获取设备id
"
,
deviceInfo
);
option
.
data
.
deviceInfo
=
deviceInfo
// #ifndef H5
//注册可能不仅仅走register接口,还有登陆并注册的接口
option
.
data
.
inviteCode
=
await
new
Promise
((
callBack
)
=>
{
uni
.
getClipboardData
({
success
:
function
(
res
)
{
if
(
res
.
data
.
slice
(
0
,
18
)
==
'
uniInvitationCode:
'
){
let
uniInvitationCode
=
res
.
data
.
slice
(
18
,
38
)
console
.
log
(
'
当前用户是其他用户推荐下载的,推荐者的code是:
'
+
uniInvitationCode
);
// uni.showModal({
// content: '当前用户是其他用户推荐下载的,推荐者的code是:'+uniInvitationCode,
// showCancel: false
// });
callBack
(
uniInvitationCode
)
//当前用户是其他用户推荐下载的。这里登记他的推荐者id 为当前用户的myInviteCode。判断如果是注册
}
else
{
callBack
(
false
)
}
},
fail
()
{
callBack
(
false
)
}
});
})
})
// #endif
// console.log(pass)
}
}
// #endif
if
(
visitor
&&!
inLoginPage
)
{
// console.log(JSON.stringify(option));
pass
=
visitor
.
some
((
item
)
=>
{
callFunctionOption
=
option
if
(
item
.
slice
(
0
,
8
)
==
'
pattern:
'
)
{
},
return
eval
(
item
.
slice
(
8
,
item
.
length
)).
test
(
url
)
complete
(
e
){
}
// console.log(JSON.stringify(e));
return
url
==
item
},
fail
(
e
)
{
// 失败回调拦截
if
(
Debug
){
uni
.
showModal
({
content
:
JSON
.
stringify
(
e
),
showCancel
:
false
});
console
.
error
(
e
);
}
else
{
uni
.
showModal
({
content
:
"
系统错误请稍后再试!
"
,
showCancel
:
false
,
confirmText
:
"
知道了
"
});
}
//如果执行错误,检查是否断网
uni
.
getNetworkType
({
complete
:
res
=>
{
// console.log(res);
if
(
res
.
networkType
==
'
none
'
)
{
uni
.
showToast
({
title
:
'
手机网络异常
'
,
icon
:
'
none
'
});
console
.
log
(
'
手机网络异常
'
);
let
callBack
=
res
=>
{
console
.
log
(
res
);
if
(
res
.
isConnected
)
{
uni
.
showToast
({
title
:
'
恢复联网自动重新执行
'
,
icon
:
'
none
'
});
console
.
log
(
res
.
networkType
,
"
恢复联网自动重新执行
"
);
uni
.
offNetworkStatusChange
(
e
=>
{
console
.
log
(
"
移除监听成功
"
,
e
);
})
//恢复联网自动重新执行
uniCloud
.
callFunction
(
callFunctionOption
)
uni
.
offNetworkStatusChange
(
callBack
);
}
}
uni
.
onNetworkStatusChange
(
callBack
);
}
}
});
},
success
:(
e
)
=>
{
console
.
log
(
e
);
const
{
token
,
tokenExpired
}
=
e
.
result
if
(
token
&&
tokenExpired
)
{
store
.
commit
(
'
user/login
'
,
{
token
,
tokenExpired
})
}
switch
(
e
.
result
.
code
){
case
403
:
uni
.
navigateTo
({
url
:
"
/pages/ucenter/login-page/index/index
"
})
break
;
case
30203
:
uni
.
navigateTo
({
url
:
"
/pages/ucenter/login-page/index/index
"
})
break
;
case
50101
:
uni
.
showToast
({
title
:
e
.
result
.
msg
,
icon
:
'
none
'
,
duration
:
2000
});
break
;
default
:
console
.
log
(
'
code的值是:
'
+
e
.
result
.
code
,
'
可以在这里插入,自动处理响应体
'
);
break
;
}
}
})
//自定义路由拦截
const
{
"
router
"
:
{
needLogin
,
login
}
}
=
uniStarterConfig
//需要登录的页面
let
list
=
[
"
navigateTo
"
,
"
redirectTo
"
,
"
reLaunch
"
,
"
switchTab
"
];
list
.
forEach
(
item
=>
{
//用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
uni
.
addInterceptor
(
item
,
{
invoke
(
e
)
{
// 调用前拦截
// console.log(e);
//获取用户的token
const
token
=
uni
.
getStorageSync
(
'
uni_id_token
'
)
//token是否已失效
const
tokenExpired
=
uni
.
getStorageSync
(
'
uni_id_token_expired
'
)
<
Date
.
now
()
//获取当前页面路径(即url去掉"?"和"?"后的参数)
const
url
=
e
.
url
.
split
(
'
?
'
)[
0
]
//控制登录优先级
let
pages
=
getCurrentPages
();
if
(
//判断当前窗口是否为登陆页面,如果是则不重定向路由
url
==
'
/pages/ucenter/login-page/index/index
'
&&
pages
[
pages
.
length
-
1
].
route
.
split
(
'
/
'
)[
2
]
!=
'
login-page
'
)
{
console
.
log
(
9527777
,
login
);
//一键登录(univerify)、账号(username)、验证码登录(短信smsCode)
if
(
login
[
0
]
==
'
username
'
)
{
e
.
url
=
"
/pages/ucenter/login-page/pwd-login/pwd-login
"
}
else
{
if
(
e
.
url
==
url
)
{
e
.
url
+=
'
?
'
}
//添加参数之前判断是否带了`?`号如果没有就补上,因为当开发场景本身有参数的情况下是已经带了`?`号
e
.
url
+=
"
type=
"
+
login
[
0
]
}
}
else
{
//拦截强制登录页面
if
(
needLogin
.
includes
(
url
)
&&
(
token
==
''
||
tokenExpired
))
{
uni
.
showToast
({
title
:
'
请先登录
'
,
icon
:
'
none
'
})
uni
.
navigateTo
({
url
:
"
/pages/ucenter/login-page/index/index
"
})
})
return
false
console
.
log
(
pass
)
}
}
}
},
if
(
!
pass
&&
(
token
==
''
||
tokenExpired
))
{
fail
(
err
)
{
// 失败回调拦截
uni
.
showToast
({
console
.
log
(
err
);
title
:
'
请先登录
'
,
if
(
Debug
){
icon
:
'
none
'
console
.
log
(
err
);
})
uni
.
showModal
({
uni
.
navigateTo
({
content
:
JSON
.
stringify
(
err
),
url
:
"
/pages/ucenter/login-page/index/index
"
showCancel
:
false
})
});
return
false
}
}
},
}
})
return
e
})
},
// #ifdef APP-PLUS
fail
(
err
)
{
// 失败回调拦截
// 监听并提示设备网络状态变化
console
.
log
(
err
);
uni
.
onNetworkStatusChange
(
res
=>
{
if
(
Debug
)
{
console
.
log
(
res
.
isConnected
);
console
.
log
(
err
);
console
.
log
(
res
.
networkType
);
uni
.
showModal
({
if
(
res
.
networkType
!=
'
none
'
){
content
:
JSON
.
stringify
(
err
),
uni
.
showToast
({
showCancel
:
false
title
:
'
当前网络类型:
'
+
res
.
networkType
,
});
icon
:
'
none
'
,
}
duration
:
3000
}
})
})
}
else
{
})
uni
.
showToast
({
// #ifdef APP-PLUS
title
:
'
网络类型:
'
+
res
.
networkType
,
// 监听并提示设备网络状态变化
icon
:
'
none
'
,
uni
.
onNetworkStatusChange
(
res
=>
{
duration
:
3000
console
.
log
(
res
.
isConnected
);
})
console
.
log
(
res
.
networkType
);
}
if
(
res
.
networkType
!=
'
none
'
)
{
});
uni
.
showToast
({
// #endif
title
:
'
当前网络类型:
'
+
res
.
networkType
,
icon
:
'
none
'
,
duration
:
3000
})
}
else
{
uni
.
showToast
({
title
:
'
网络类型:
'
+
res
.
networkType
,
icon
:
'
none
'
,
duration
:
3000
})
}
});
// #endif
}
/**
* // 初始化appVersion
*/
function
initAppVersion
()
{
// #ifdef APP-PLUS
let
appid
=
plus
.
runtime
.
appid
;
plus
.
runtime
.
getProperty
(
appid
,
(
wgtInfo
)
=>
{
let
appVersion
=
plus
.
runtime
;
let
currentVersion
=
appVersion
.
versionCode
>
wgtInfo
.
versionCode
?
appVersion
:
wgtInfo
;
getApp
({
allowDefault
:
true
}).
appVersion
=
{
...
currentVersion
,
appid
,
hasNew
:
false
}
// 检查更新小红点
callCheckVersion
().
then
(
res
=>
{
// console.log('检查是否有可以更新的版本', res);
if
(
res
.
result
.
code
>
0
)
{
// 有新版本
getApp
({
allowDefault
:
true
}).
appVersion
.
hasNew
=
true
;
}
})
});
// 检查更新
checkUpdate
();
// #endif
}
}
/**
* // 初始化appVersion
*/
function
initAppVersion
()
{
// #ifdef APP-PLUS
let
appid
=
plus
.
runtime
.
appid
;
plus
.
runtime
.
getProperty
(
appid
,
(
wgtInfo
)
=>
{
let
appVersion
=
plus
.
runtime
;
let
currentVersion
=
appVersion
.
versionCode
>
wgtInfo
.
versionCode
?
appVersion
:
wgtInfo
;
getApp
({
allowDefault
:
true
}).
appVersion
=
{
...
currentVersion
,
appid
,
hasNew
:
false
}
// 检查更新小红点
callCheckVersion
().
then
(
res
=>
{
// console.log('检查是否有可以更新的版本', res);
if
(
res
.
result
.
code
>
0
)
{
// 有新版本
getApp
({
allowDefault
:
true
}).
appVersion
.
hasNew
=
true
;
}
})
});
// 检查更新
checkUpdate
();
// #endif
}
\ No newline at end of file
manifest.json
浏览文件 @
710a0132
{
{
"name"
:
"uni-starter"
,
"name"
:
"uni-starter"
,
"appid"
:
"__UNI__03B096E"
,
"appid"
:
"请点击重新获取"
,
"description"
:
"云端一体应用快速开发模版"
,
"description"
:
"云端一体应用快速开发模版"
,
"versionName"
:
"1.0.0"
,
"versionName"
:
"1.0.0"
,
"versionCode"
:
"100"
,
"versionCode"
:
"100"
,
"transformPx"
:
false
,
"transformPx"
:
false
,
"app-plus"
:
{
"app-plus"
:
{
"privacy"
:
{
"privacy"
:
{
"prompt"
:
"template"
,
"prompt"
:
"template"
,
"template"
:
{
"template"
:
{
"title"
:
"服务协议和隐私政策"
,
"title"
:
"服务协议和隐私政策"
,
"message"
:
" 请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/> 你可阅读<a href=
\"
https://ask.dcloud.net.cn/protocol.html
\"
>《服务协议》</a>和<a href=
\"
https://ask.dcloud.net.cn/protocol.html
\"
>《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。"
,
"message"
:
" 请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/> 你可阅读<a href=
\"
https://ask.dcloud.net.cn/protocol.html
\"
>《服务协议》</a>和<a href=
\"
https://ask.dcloud.net.cn/protocol.html
\"
>《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。"
,
"buttonAccept"
:
"同意"
,
"buttonAccept"
:
"同意"
,
"buttonRefuse"
:
"暂不同意"
"buttonRefuse"
:
"暂不同意"
}
}
},
},
"compatible"
:
{
"compatible"
:
{
"ignoreVersion"
:
true
"ignoreVersion"
:
true
},
"usingComponents"
:
true
,
"nvueStyleCompiler"
:
"uni-app"
,
"compilerVersion"
:
3
,
"splashscreen"
:
{
"alwaysShowBeforeRender"
:
true
,
"waiting"
:
true
,
"autoclose"
:
true
,
"delay"
:
0
},
"modules"
:
{
"Fingerprint"
:
{
},
"Share"
:
{
},
"OAuth"
:
{
},
"FaceID"
:
{
},
"Push"
:
{
}
},
"distribute"
:
{
"android"
:
{
"permissions"
:
[
"<uses-feature android:name=
\"
android.hardware.camera
\"
/>"
,
"<uses-feature android:name=
\"
android.hardware.camera.autofocus
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.ACCESS_NETWORK_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.ACCESS_WIFI_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.CAMERA
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.CHANGE_NETWORK_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.CHANGE_WIFI_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.FLASHLIGHT
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.GET_ACCOUNTS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.MODIFY_AUDIO_SETTINGS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.READ_LOGS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.READ_PHONE_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.USE_FINGERPRINT
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.VIBRATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.WAKE_LOCK
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.WRITE_SETTINGS
\"
/>"
],
"abiFilters"
:
[
"armeabi-v7a"
,
"arm64-v8a"
,
"x86"
]
},
"ios"
:
{
"capabilities"
:
{
"entitlements"
:
{
"com.apple.developer.associated-domains"
:
[
"applinks:static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com"
]
}
}
},
"sdkConfigs"
:
{
"oauth"
:
{
"apple"
:
{
},
"weixin"
:
{
"appid"
:
"wxffdd8fa6ec4ef2a0"
,
"appsecret"
:
""
,
"UniversalLinks"
:
"https://static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com/uni-universallinks/__UNI__03B096E"
},
"univerify"
:
{
}
},
},
"usingComponents"
:
true
,
"ad"
:
{
"nvueStyleCompiler"
:
"uni-app"
,
"compilerVersion"
:
3
,
"splashscreen"
:
{
"alwaysShowBeforeRender"
:
true
,
"waiting"
:
true
,
"autoclose"
:
true
,
"delay"
:
0
},
},
"modules"
:
{
"share"
:
{
"Fingerprint"
:
{},
"weixin"
:
{
"Share"
:
{},
"appid"
:
"wxffdd8fa6ec4ef2a0"
,
"OAuth"
:
{},
"UniversalLinks"
:
"https://static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com/uni-universallinks/__UNI__03B096E"
"FaceID"
:
{},
}
"Push"
:
{}
},
},
"distribute"
:
{
"geolocation"
:
{
"android"
:
{
"permissions"
:
[
"<uses-feature android:name=
\"
android.hardware.camera
\"
/>"
,
"<uses-feature android:name=
\"
android.hardware.camera.autofocus
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.ACCESS_NETWORK_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.ACCESS_WIFI_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.CAMERA
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.CHANGE_NETWORK_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.CHANGE_WIFI_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.FLASHLIGHT
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.GET_ACCOUNTS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.MODIFY_AUDIO_SETTINGS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.READ_LOGS
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.READ_PHONE_STATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.USE_FINGERPRINT
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.VIBRATE
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.WAKE_LOCK
\"
/>"
,
"<uses-permission android:name=
\"
android.permission.WRITE_SETTINGS
\"
/>"
],
"abiFilters"
:
[
"armeabi-v7a"
,
"arm64-v8a"
,
"x86"
]
},
"ios"
:
{
"capabilities"
:
{
"entitlements"
:
{
"com.apple.developer.associated-domains"
:
[
"applinks:static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com"
]
}
}
},
"sdkConfigs"
:
{
"oauth"
:
{
"apple"
:
{},
"weixin"
:
{
"appid"
:
"wxffdd8fa6ec4ef2a0"
,
"appsecret"
:
""
,
"UniversalLinks"
:
"https://static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com/uni-universallinks/__UNI__03B096E"
},
"univerify"
:
{}
},
"ad"
:
{},
"share"
:
{
"weixin"
:
{
"appid"
:
"wxffdd8fa6ec4ef2a0"
,
"UniversalLinks"
:
"https://static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com/uni-universallinks/__UNI__03B096E"
}
},
"geolocation"
:
{},
"push"
:
{
"unipush"
:
{}
},
"payment"
:
{}
}
},
},
"nvueLaunchMode"
:
""
"push"
:
{
},
"unipush"
:
{
"quickapp"
:
{},
}
"mp-weixin"
:
{
"appid"
:
"wx81dbb061d2258234"
,
"setting"
:
{
"urlCheck"
:
false
,
"es6"
:
false
},
},
"usingComponents"
:
true
,
"payment"
:
{
"betterScopedSlots"
:
true
}
},
}
"mp-alipay"
:
{
"usingComponents"
:
true
},
"mp-baidu"
:
{
"usingComponents"
:
true
},
"mp-toutiao"
:
{
"usingComponents"
:
true
},
"uniStatistics"
:
{
"enable"
:
false
},
},
"h5"
:
{
"nvueLaunchMode"
:
""
"template"
:
""
},
"quickapp"
:
{
},
"mp-weixin"
:
{
"appid"
:
""
,
"setting"
:
{
"urlCheck"
:
false
,
"es6"
:
false
},
},
"_spaceID"
:
"76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e"
"usingComponents"
:
true
,
}
"betterScopedSlots"
:
true
},
"mp-alipay"
:
{
"usingComponents"
:
true
},
"mp-baidu"
:
{
"usingComponents"
:
true
},
"mp-toutiao"
:
{
"usingComponents"
:
true
},
"uniStatistics"
:
{
"enable"
:
false
},
"h5"
:
{
"template"
:
""
},
"_spaceID"
:
"76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e"
}
\ No newline at end of file
package.json
浏览文件 @
710a0132
{
{
"id"
:
"uni-starter"
,
"id"
:
"uni-starter"
,
"displayName"
:
"uni-starter"
,
"displayName"
:
"uni-starter"
,
"version"
:
"1.0.3
8
"
,
"version"
:
"1.0.3
9
"
,
"description"
:
"云端一体应用快速开发基本项目模版"
,
"description"
:
"云端一体应用快速开发基本项目模版"
,
"keywords"
:
[
"keywords"
:
[
"uni-starter"
,
"uni-starter"
,
...
...
pages/grid/grid.vue
浏览文件 @
710a0132
<
template
>
<
template
>
<view
class=
"warp"
>
<view
class=
"warp"
>
<!-- 搜索 -->
<!-- #ifdef APP-PLUS -->
<!-- #ifdef APP-PLUS -->
<status-bar
/>
<status-bar
/>
<!-- #endif -->
<!-- #endif -->
<uni-search-bar
ref=
"searchBar"
style=
"flex:1;"
radius=
"100"
@
click.native=
"searchClick"
cancelButton=
"none"
disabled
/>
<!-- banner -->
<!-- banner -->
<unicloud-db
ref=
"bannerdb"
v-slot:default=
"
{data, loading, error, options}" collection="opendb-banner"
<unicloud-db
ref=
"bannerdb"
v-slot:default=
"
{data, loading, error, options}" collection="opendb-banner"
field="_id,bannerfile,open_url,title" @load="load">
field="_id,bannerfile,open_url,title" @load="load">
<uni-swiper-dot
class=
"uni-swiper-dot-box"
@
clickItem=
"clickItem"
:info=
"data || bannerFormate(data, loading)"
<uni-swiper-dot
class=
"uni-swiper-dot-box"
@
clickItem=
"clickItem"
:info=
"data || bannerFormate(data, loading)"
...
@@ -67,13 +65,6 @@
...
@@ -67,13 +65,6 @@
icon
:
'
none
'
icon
:
'
none
'
})
})
},
},
searchClick
()
{
uni
.
hideKeyboard
();
uni
.
navigateTo
({
url
:
'
/pages/list/search/search
'
,
animationType
:
'
fade-in
'
});
},
/**
/**
* banner加载后触发的回调
* banner加载后触发的回调
*/
*/
...
@@ -121,8 +112,6 @@
...
@@ -121,8 +112,6 @@
</
script
>
</
script
>
<
style
>
<
style
>
@charset
"UTF-8"
;
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
page
{
page
{
display
:
flex
;
display
:
flex
;
...
@@ -132,12 +121,10 @@
...
@@ -132,12 +121,10 @@
min-height
:
100%
;
min-height
:
100%
;
height
:
auto
;
height
:
auto
;
}
}
view
{
view
{
font-size
:
14px
;
font-size
:
14px
;
line-height
:
inherit
;
line-height
:
inherit
;
}
}
.example-body
{
.example-body
{
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
display
:
flex
;
display
:
flex
;
...
@@ -149,14 +136,12 @@
...
@@ -149,14 +136,12 @@
font-size
:
14px
;
font-size
:
14px
;
background-color
:
#ffffff
;
background-color
:
#ffffff
;
}
}
/* #endif */
/* #endif */
/* #ifdef APP-NVUE */
/* #ifdef APP-NVUE */
.warp
{
.warp
{
background-color
:
#fff
;
background-color
:
#fff
;
}
}
/* #endif */
/* #endif */
.example-body
{
.example-body
{
...
...
pages/ucenter/about/about.vue
浏览文件 @
710a0132
...
@@ -40,7 +40,6 @@ import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js';
...
@@ -40,7 +40,6 @@ import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js';
};
};
},
},
created
()
{
created
()
{
console
.
log
();
this
.
about
=
this
.
uniStarterConfig
.
about
this
.
about
=
this
.
uniStarterConfig
.
about
uni
.
setNavigationBarTitle
({
uni
.
setNavigationBarTitle
({
title
:
'
关于
'
+
this
.
about
.
appName
title
:
'
关于
'
+
this
.
about
.
appName
...
...
pages/ucenter/login-page/pwd-retrieve/pwd-retrieve.vue
浏览文件 @
710a0132
...
@@ -87,7 +87,7 @@
...
@@ -87,7 +87,7 @@
},
},
{
{
validateFunction
:
function
(
rule
,
value
,
data
,
callback
)
{
validateFunction
:
function
(
rule
,
value
,
data
,
callback
)
{
console
.
log
(
value
);
//
console.log(value);
if
(
value
!=
data
.
pwd
)
{
if
(
value
!=
data
.
pwd
)
{
callback
(
'
两次输入密码不一致
'
)
callback
(
'
两次输入密码不一致
'
)
};
};
...
...
uni-starter.config.js
浏览文件 @
710a0132
...
@@ -19,19 +19,33 @@ module.exports = {
...
@@ -19,19 +19,33 @@ module.exports = {
}
}
},
},
"
router
"
:
{
"
router
"
:
{
//needLogin:配置强制需要登陆的页面,在打开这些页面之前会自动检查(前端校验)uni_id_token的值是否有效,如果无效会自动跳转到登陆页面
/*
"
needLogin
"
:
[
名词解释:“强制登陆页”
"
/pages/ucenter/userinfo/userinfo
"
,
在打开定义的需强制登陆的页面之前会自动检查(前端校验)uni_id_token的值是否有效,
"
/uni_modules/uni-news-favorite/pages/uni-news-favorite/list
"
,
如果无效会自动跳转到登陆页面
"
/uni_modules/uni-feedback/pages/uni-feedback/add
"
两种模式:
1.needLogin:黑名单模式。枚举游客不可访问的页面。
2.visitor:白名单模式。枚举游客可访问的页面。
* 注意:黑名单与白名单模式二选一
*/
// "needLogin" : [
// "pattern:/^\\/pages\\/userinfo.*/", //支持正则表达式
// "/uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
// "/uni_modules/uni-feedback/pages/uni-feedback/add"
// ],
"
visitor
"
:
[
"
/
"
,
//注意入口页必须直接写 "/"
"
pattern:/^
\\
/pages
\\
/list.*/
"
,
//支持正则表达式
"
/pages/grid/grid
"
,
"
/pages/ucenter/ucenter
"
,
"
/pages/ucenter/about/about
"
,
],
],
/*
/*
login:配置登陆类型与优先级
login:配置登陆类型与优先级
未列举到的,或设备环境不支持的选项,将被隐藏。如果你需要在不同平台有不同的配置,直接用条件编译即可
未列举到的,或设备环境不支持的选项,将被隐藏。如果你需要在不同平台有不同的配置,直接用条件编译即可
根据数组的第0项,决定登录方式的第一优先级。
根据数组的第0项,决定登录方式的第一优先级。
*/
*/
// "login": ["username","smsCode","univerify", "weixin", "apple"],
"
login
"
:
[
"
weixin
"
,
"
username
"
,
"
univerify
"
,
"
smsCode
"
,
"
apple
"
]
"
login
"
:
[
"
weixin
"
,
"
smsCode
"
,
"
univerify
"
,
"
username
"
,
"
apple
"
],
},
},
//关于应用
//关于应用
"
about
"
:
{
"
about
"
:
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录