提交 8673038e 编写于 作者: 芊里

Merge branch 'master' of https://gitee.com/dcloud/base-app

......@@ -8,12 +8,17 @@ export default function() {
initAppVersion();
//自定义路由拦截
const {"router":{needLogin,login}} = baseappConfig //需要登陆的页面
const {
"router": {
needLogin,
login
}
} = baseappConfig //需要登陆的页面
//uni.addInterceptor的写法
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach(item=>{
uni.addInterceptor(item,{
invoke(e){// 调用前拦截
list.forEach(item => {
uni.addInterceptor(item, {
invoke(e) { // 调用前拦截
//console.log(e);
const token = uni.getStorageSync('uni_id_token')
// console.log(token);
......@@ -21,50 +26,71 @@ export default function() {
//拦截强制登陆页面
if (needLogin.includes(url) && token == '') {
console.log('该页面需要登陆,即将跳转到login页面');
uni.showToast({title:'该页面需要登陆,即将跳转到login页面',icon:'none'})
uni.showToast({
title: '该页面需要登陆,即将跳转到login页面',
icon: 'none'
})
uni.navigateTo({
url:"/uni_modules/uni-login-page/pages/index/index"
url: "/uni_modules/uni-login-page/pages/index/index"
})
return false
}
//控制登陆优先级
if(url=='/uni_modules/uni-login-page/pages/index/index'){
if (url == '/uni_modules/uni-login-page/pages/index/index') {
//一键登录(univerify)、密码登陆(username)、快捷登录&验证码登陆(!univerify&password)
if(login[0]=='univerify'){
if (login[0] == 'univerify') {
// console.log(e.url,url);
if(e.url==url){ e.url+= '?' }
if (e.url == url) {
e.url += '?'
}
e.url += "univerify_first=true"
}else if(login[0]=='username'){
} else if (login[0] == 'username') {
e.url = "/uni_modules/uni-login-page/pages/pwd-login/pwd-login"
}else{
} else {
//默认即是
}
}
return true
},
success(){ // 成功回调拦截
},
fail(err){ // 失败回调拦截
fail(err) { // 失败回调拦截
console.log(err);
},
complete(e){ // 完成回调拦截
//console.log(e);
},
returnValue(){// 返回结果拦截
})
})
//当应用无访问摄像头/相册权限,引导跳到设置界面
uni.addInterceptor('chooseImage', {
fail(e) { // 失败回调拦截
console.log(e);
if (
e.errCode === 11 && uni.getSystemInfoSync().platform == "android" ||
e.errCode === 2 && uni.getSystemInfoSync().platform == "ios"
){
uni.showModal({
title:"无法访问摄像头",
content: "当前无摄像头访问权限,建议前往设置",
confirmText: "前往设置",
success(e) {
if (e.confirm) {
openAppPermissionSetting()
}
}
});
}
if(e.errCode === 12 && uni.getSystemInfoSync().platform == "android"){
uni.showModal({
title:"无法访问相册",
content: "当前无系统相册访问权限,建议前往设置",
confirmText: "前往设置",
success(e) {
if (e.confirm) {
openAppPermissionSetting()
}
}
});
}
}
})// 移除拦截器API removeInterceptor('request')
})
//提示网络变化
eventListenerNetwork()
/*
当某个权限调用失败
1.先检测手机的该模块是否打开
2.检测当前应用是否被授权了该模块对应的权限
提示,并点击跳转到设置
*/
}
/**
* // 初始化appVersion
......@@ -80,12 +106,12 @@ function initAppVersion() {
}).appVersion = {
...currentVersion,
appid,
hasNew:false
hasNew: false
}
// 检查更新小红点
callCheckVersion().then(res=>{
console.log('检查是否有可以更新的版本',res);
if(res.result.code>0){
callCheckVersion().then(res => {
console.log('检查是否有可以更新的版本', res);
if (res.result.code > 0) {
// 有新版本
getApp({
allowDefault: true
......@@ -93,14 +119,13 @@ function initAppVersion() {
}
})
});
// 检查更新
checkUpdate();
// #endif
}
// 设备网络状态变化事件
function eventListenerNetwork () {
function eventListenerNetwork() {
uni.onNetworkStatusChange(function(res) {
console.log(res.isConnected);
console.log(res.networkType);
......@@ -127,3 +152,45 @@ function eventListenerNetwork () {
}
});
}
function openAppPermissionSetting(){
// 跳转到**应用**的权限页面
if (uni.getSystemInfoSync().platform == "ios") {
var UIApplication = plus.ios.import("UIApplication");
var application2 = UIApplication.sharedApplication();
var NSURL2 = plus.ios.import("NSURL");
// var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
var setting2 = NSURL2.URLWithString("app-settings:");
application2.openURL(setting2);
plus.ios.deleteObject(setting2);
plus.ios.deleteObject(NSURL2);
plus.ios.deleteObject(application2);
} else {
// console.log(plus.device.vendor);
var Intent = plus.android.importClass("android.content.Intent");
var Settings = plus.android.importClass("android.provider.Settings");
var Uri = plus.android.importClass("android.net.Uri");
var mainActivity = plus.android.runtimeMainActivity();
var intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
intent.setData(uri);
mainActivity.startActivity(intent);
}
}
/*
uni.addInterceptor(item, {
invoke(e) { // 调用前拦截
},
success() { // 成功回调拦截
},
fail(err) { // 失败回调拦截
console.log(err);
},
complete(e) { // 完成回调拦截
//console.log(e);
},
returnValue() { // 返回结果拦截
}
}) // 移除拦截器API removeInterceptor('request')
*/
\ No newline at end of file
......@@ -101,6 +101,6 @@
"enable" : false
},
"h5" : {
"template" : "template.h5.html"
"template" : ""
}
}
......@@ -5,9 +5,23 @@
//#ifndef MP
"navigationStyle": "custom",
//#endif
"enablePullDownRefresh": true
"enablePullDownRefresh": true,
"app-plus":{
"subNVues":[
{
"id":"networkErr",
"path":"pages/list/networkErr/networkErr",
"style":{
"height":"0",
"width":"100%",
"background":"transparent"
}
}, {
}
]
}
}
},
{
"path": "pages/list/news-list",
"style": {
//#ifndef MP
......@@ -226,7 +240,6 @@
"path": "pages/ucenter/settings/settings"
}
],
"current": 0
},
"tabBar": {
......
......@@ -20,6 +20,7 @@
},
onLoad() {
checkIsAgree();
uni.getSubNVueById('networkErr').show()
},
onShow(options) {
this.searchText = getApp().globalData.searchText;
......
<template>
<view class="box" :style="{'padding-top':statusBarHeight}">
<text class="networkErr">网络连接不可用</text>
<text @click="toSet">去设置</text>
</view>
</template>
<script>
export default {
data() {
return {
statusBarHeight:0
}
},
mounted() {
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const getCurrentSubNVue = uni.getCurrentSubNVue();
getCurrentSubNVue.setStyle({
"height":this.statusBarHeight+60+'px'
})
uni.getNetworkType({
success:res=>{
console.log(res);
if(res.networkType!='none'){
getCurrentSubNVue.hide()
}else{
getCurrentSubNVue.show()
}
}
});
uni.onNetworkStatusChange(res=> {
console.log(res.isConnected);
console.log(res.networkType);
if(res.networkType!='none'){
uni.showToast({
title:'当前网络类型:'+res.networkType,
icon:'none',
duration:3000
})
if(this.old=='none'){
this.$parent.reLink();
}
getCurrentSubNVue.hide()
}else{
getCurrentSubNVue.show()
uni.showToast({
title:'网络类型:'+res.networkType,
icon:'none',
duration:3000
})
}
});
},
methods: {
toSet(){
if (uni.getSystemInfoSync().platform == "ios") {
plus.runtime.launchApplication({
action: 'App-Prefs:root=WIFI'
}, function(e) {
console.log(JSON.stringify(e));
});
} else {
var main = plus.android.runtimeMainActivity();
var Intent = plus.android.importClass("android.content.Intent");
var mIntent = new Intent('android.settings.DATA_ROAMING_SETTINGS');
main.startActivity(mIntent);
}
}
},
}
</script>
<style lang="scss" scoped>
.box{
background-color: #DD524D;
height:100%;
flex: 1;
}
</style>
......@@ -8,186 +8,32 @@
<text>应用相关权限</text>
<button type="default" @click="openAppPermissionSetting">打开</button>
<button type="default" @click="iosSetting">iosSetting</button> -->
<!-- <button type="default" @click="openCamera">打开相机</button> -->
<!-- <button type="default" @click="openGridPage">打开一个需要登陆的页面</button> -->
<button type="default" @click="showShare">打开分享</button>
<!-- <uni-bottom-menu ref="bottomMenu" @clickItem="clickItem" :list="menus"></uni-bottom-menu> -->
<button type="default" @click="openCamera">打开相机</button>
</view>
</template>
<script>
// import permision from '@/js_sdk/wa-permission/permission.js';
import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js';
export default {
data() {
return {
}
},
onLoad() {
/*
// uni.addInterceptor('showToast',{
// invoke(e){// 调用前拦截
// console.log(e)
// e.title = "645"
// },
// success(e){// 成功回调拦截
// console.log(e)
// },
// fail(e){// 失败回调拦截
// console.log(e)
// },
// complete(e){
// console.log(e)
// },
// returnValue(e){// 返回结果拦截
// console.log(e)
// }
// })
// return
//
// 当某个权限调用失败
// 1.先检测手机的该模块是否打开
// 2.检测当前应用是否被授权了该模块对应的权限
// 提示,并点击跳转到设置
//
// this.changeAction('chooseImage', {
// after_action: e => {
// console.log('changeAction', e);
// if(e.errCode === 11){
// uni.showModal({
// content: '无权限',
// confirmText:"前往设置",
// success(e) {
// if(e.confirm){
// permision.gotoAppPermissionSetting()
// }
// }
// });
// }
// }
// })
// this.changeAction(["navigateTo", "redirectTo", "reLaunch", "switchTab"], {
// before_action: e => {
// let needLoginUrls = ['/pages/grid/grid']//需要登陆的页面
// let token = uni.getStorageSync('uni-id-token')
// if (needLoginUrls.includes(e.url) && token == '') {
// console.log('该页面需要登陆,即将跳转到login页面');
// uni.showToast({title:'该页面需要登陆,即将跳转到login页面',icon:'none'})
// return false
// }
// return true
// }
// })
*/
},
methods: {
showShare(){
uniShare({
menus:[
{
"img": "/static/sharemenu/wechatfriend.png",
"text": "微信好友",
"share": {
"provider": "weixin",
"scene": "WXSceneSession"
}
},
{
"img": "/static/sharemenu/wechatmoments.png",
"text": "微信朋友圈",
"share": {
"provider": "weixin",
"scene": "WXSceneSession"
}
},
{
"img": "/static/sharemenu/weibo.png",
"text": "微博",
"share": {
"provider": "sinaweibo"
}
},
{
"img": "/static/sharemenu/qq.png",
"text": "QQ",
"share": {
"provider": "qq"
}
},
{
"img": "/static/sharemenu/copyurl.png",
"text": "复制",
"share": "copyurl"
},
{
"img": "/static/sharemenu/more.png",
"text": "更多",
"share": "shareSystem"
}
],
content:{
type: 0,
href: "https://uniapp.dcloud.io/api/plugins/share?id=share",
title: "主标题",
summary: "分享内容的摘要",
imageUrl: "https://uniapp.dcloud.io/api/plugins/share?id=share",
},
cancelText:"取消分享",
},e=>{ //callback
console.log(e);
})
},
clickItem(e){
console.log(e);
uni.showToast({
title: e
});
},
openCamera(){
uni.chooseImage({
sourceType: ["camera"],
sourceType: ["camera","album"],
complete: (e) => {
console.log(e);
}
})
},
openGridPage(){
uni.redirectTo({
url:'/pages/grid/grid'
})
},
changeAction(actions, {
before_action,
after_action
}) {
if(typeof actions == 'string'){
actions = [actions]
}
if (!before_action) {
before_action = () => true
}
actions.forEach(action=>{
let old_action = uni[action]
uni[action] = e => {
if (before_action(e)) {
console.log(after_action);
if (after_action) {
var compose = function(f, g) {
return function(x) {
return f(x,g(x));
};
};
e.complete = compose(e.complete,after_action)
}
old_action(e)
}
}
})
},
iosSetting() {
plus.runtime.launchApplication({
action: 'App-Prefs:root=WIFI'
......@@ -227,16 +73,6 @@
mainActivity.startActivity(intent);
}
},
fn1() {
let res = this.request('user-center/login_by_').then(e => {
console.log('then--1', e);
})
},
fn2() {
this.request('user-center/login_by_', {}, e => {
console.log('222', e);
})
}
}
}
</script>
......
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<!-- 正式发布的时候使用,开发期间不启用。↓ -->
<!-- <script src="/h5/touch-emulator.js"></script>
<script>
TouchEmulator();
if (document.documentElement.clientWidth > 1024) {
window.location.href = '/h5/pcguide.html#'+location.pathname+location.search;
}
</script>
<style>
::-webkit-scrollbar{
display: none;
}
</style>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?";// 百度统计key
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script> -->
<!-- 正式发布的时候使用,开发期间不启用。↑ -->
<script>
// document.addEventListener('DOMContentLoaded', function() {
// document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
// })
</script>
<link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
<style type="text/css">
#openApp{
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 999;
}
</style>
</head>
<body>
<!-- 该文件为 H5 平台的模板 HTML,并非应用入口。 -->
<!-- 请勿在此文件编写页面代码或直接运行此文件。 -->
<!-- 详见文档:https://uniapp.dcloud.io/collocation/manifest?id=h5-template -->
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div style="margin-top: 100px;" id="app"></div>
<!-- built files will be auto injected -->
<script>
/*BAIDU_STAT*/
</script>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册