3***@qq.com
3***@qq.com
  • 发布:2019-11-01 11:16
  • 更新:2020-05-22 11:47
  • 阅读:1367

按手机2次物理返回键,再进去程序就白屏了,必须把程序全部杀掉才能显示。

分类:uni-app

麻烦问一下,为什么按手机上的返回键2次退出程序后,再进去就白屏了,必须把程序全部杀掉才能显示,跪求解决方案!谢谢


安卓手机型号:华为 meta 20 X,安卓版本:9.1.0
测试实例:第一次正常打开程序正常,按Home键返回到桌面再打开也正常。但是如果按物理返回键2次退出程序后,再打开程序就是白屏,只有完全从后台删掉程序再打开就正常。

如下代码:

<template>
<view class="page">
<view v-if="hasLogin" class="menu">
<view v-for="(item,index) in menuList" :key="index">
<view class="flex padding">
<image :src="item.icon" mode="aspectFit" style="width: 40upx;height: 40upx;margin-right: 10upx;"></image>
<text class="text-grey">{{item.name}}</text>
</view>
<view class="grid col-4 padding-sm">
<view class="padding-sm" v-for="(child,cindex) in item.children" :key="cindex">
<view class="radius text-center shadow-blur bg-white" @tap="toMenu(child.default_url)">
<view class="text-lg"><image :src="child.icon" mode="aspectFit" style="width: 100upx;height: 100upx;"></image></view>
<view class="text-Abc text-small text-cyan">{{child.name}}</view>
</view>
</view>
</view>
</view>
</view>
<view v-if="!hasLogin" class="hello">
<view class="title">
您好 游客。
</view>
<view class="ul">
<view>在 “我的” 中点击 “登录” 可以 “登录您的账户”</view>
</view>
</view>
</view>
</template>

<script>
//import uniGrid from "../../components/uni-grid.vue"
import {mapMutations,mapState} from 'vuex';
import service from 'service.js';
import menus from '../api/menu.js';
export default {
//components: {uniGrid},
computed: mapState(['requestUrl','forcedLogin', 'hasLogin']),
data(){
return {
menuList:[]
}
},
onLoad(e) {
plus.webview.currentWebview().setStyle({render: 'always'});
/ uni.showLoading({
title: '加载中...',
mask: true
});
/
let user=service.getLogin();
let vm = this;
//手动登录
if(e.account!=undefined){
/本地测试*/
// this.menuList = menus.menus
// return;
/****
/
uni.request({
url: this.requestUrl + 'GetMainDirectoryListServer',
method: 'GET',
dataType:'json',
data: {
userName:e.account
},
success: res => {
// console.log('menu',JSON.stringify(res));
this.menuList = res.data[1].menuList;
}
});
//自动登录
}else if(user.account){
/*本地测试
/
vm.login(user);
// this.menuList = menus.menus
// return;
/**/
uni.request({
url: this.requestUrl + 'CheckUserLoginServer',
method: 'GET',
data: {
userName: user.account,
passWord: user.password
},
success: res => {
if(res.data.length>0&&res.data[0].result==0){
vm.login(user);
uni.request({
url: this.requestUrl + 'GetMainDirectoryListServer',
method: 'GET',
dataType:'json',
data: {
userName:user.account
},
success: res => {
console.log("测试每次加载菜单2222"+res);
this.menuList = res.data[1].menuList;
}
});
}else{
uni.showModal({
title: '提示',
content: '登录失效,请重新登录',
showCancel: false,
success:res=> {
// uni.reLaunch({
// url: '../login/login',
// });
uni.redirectTo({
url: '../login/login'
})
}
});
}
}
});
//未登录
}else{
uni.showModal({
title: '未登录',
content: '您未登录,需要登录后才能继续',
showCancel:false,
success: (res) => {
if (res.confirm) {
uni.redirectTo({
url: '../login/login'
})
// uni.reLaunch({
// url: '../login/login'
// });
}
}
});
}
plus.key.addEventListener('backbutton', handleBack);
},
methods: {
...mapMutations(['login']),
toMenu(url){
uni.showLoading({
title: '加载中'
});
uni.navigateTo({
url: url,
success: () => {
uni.hideLoading();
},
fail() {
uni.hideLoading();
uni.showModal({
title: '错误',
content: '未找到指定界面',
showCancel: false
});
}
});
}
}
}
</script>

<style>
.page{
background-color: #fff;
padding: 10upx;
width: 100%;
}
.hello {
display: flex;
flex: 1;
flex-direction: column;
}
.title {

}  

.ul {
font-size: 30upx;
color: #8f8f94;
margin-top: 50upx;
}

.ul>view {  
    line-height: 50upx;  
}   
.menuGrid{  
    background-color: #DD514C;  
    color: #39B54A;  
    height: 200upx;  
    border: 1px dotted #39B54A;  
}  
.menuGrid image{  
    height: 100upx;  
}  
.text-small{  
    font-size:2vh;  
    font-weight: 900;  
    word-break:keep-all;       /* 不换行 */  
    white-space:nowrap;        /* 不换行 */  
    overflow: inherit;  
}  

</style>

2019-11-01 11:16 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

是cli创建的还是HBuilderX创建的工程?
HBuilderX版本多少?
其他机型是否正常?

  • 3***@qq.com (作者)


    1. HBuilderX创建的工程

    2. 2.3.6.20191021

    3. 测试其他机型也是同样情况

    2019-11-01 16:23

DCloud_UNI_GSQ

DCloud_UNI_GSQ

上传一下复现问题的示例工程

  • 3***@qq.com (作者)

    代码已上传

    2019-11-03 09:37

3***@qq.com

3***@qq.com (作者) - 80后IT男

@DCloud_UNI_GSQ 已上传示例工程

3***@qq.com

3***@qq.com

解决了嘛,我这个按两次物理返回键退出APP。在进入APP的时候,我一直卡在启动图的界面。

该问题目前已经被锁定, 无法添加新回复