<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
- 发布:2023-04-20 18:10
- 更新:2023-07-06 18:22
- 阅读:568
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 3.7.13
手机系统: Android
手机系统版本号: Android 12
手机厂商: 华为
手机机型: HONOR 50 SE
页面类型: vue
vue版本: vue2
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
预期结果:
<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
实际结果:
<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
<template>
<view class="start" :style="{'width':bgWidth,'height':bgHeight}">
<view class="start_flex text-center">
<view class="flex row-center" style="padding-top: 300px;">
<view class="flex-none">
<u-image src="../../static/app_logo.png" width="100px" height="100px"></u-image>
</view>
</view>
<view class="flex row-center m-t-60">
<view class="flex-none">
<u-image src="../../static/start/start_text.png" width="300px" height="30px"></u-image>
</view>
</view>
</view>
</view>
</template>
<script>
import {connectWebSocket} from "@/common/websocket/useSocket.js";
import {mapState,mapMutations} from 'vuex'
export default {
computed:{
...mapState(['$systemInfo','$userTables','$Socket'])
},
data() {
return {
bgWidth:'',
bgHeight:''
}
},
onLoad() {
this.bgWidth=this.$systemInfo.windowWidth+'px';
this.bgHeight=this.$systemInfo.windowHeight+'px';
//this.check();
this.getDb();
},
methods: {
async getDb(){
var dbResult = await this.$sqlDb.isHasDb();
if(dbResult.ok){
var result = await this.$sqlDb.openOrCreate();
if(result.ok){
this.check();
}
}
},
check(){
var token=uni.getStorageSync('qianhe_im_token');
if(token){
this.$http(this.$api.check_login).then(async res=>{
if(res.data.is_login){
this.$store.commit('setUserInfo', res.data.user);
for (var i=0;i<this.$userTables.length;i++) {
var tabsName=this.$userTables[i].name+res.data.id;
var table = await this.$sqlDb.isHasTable(tabsName);
if(!table.isHasTable){
//不存在表
var create = await this.$sqlDb.createTable(tabsName,this.$userTables[i].colum);
}
}
connectWebSocket();
this.$Socket.eventPatch.onOpen((msg,sk)=>{ //监听是否连接成功
this.$store.commit('setIsLogin',2);
//获取离线消息
var user={
id:res.data.id
}
//获取本地数据库未读消息和离线消息
var cacheTime = uni.getStorageSync('chat_cache_time_'+res.data.id);
console.log('启动页');
console.log(cacheTime);
if(cacheTime){
//判断当前日期和记录时间之差,是否超过后台配置的缓存时间
//如果超过,则情况所有数据库
this.$http(this.$api.platform_config).then(async result=>{
if(result.code==200){
var nowTime=new Date().getTime();
console.log(nowTime);
var number=(nowTime-cacheTime)/1000
console.log(number);
console.log(result.data.clear_chatlog_time);
if(number>result.data.clear_chatlog_time){
for (var i=0;i<this.$userTables.length;i++) {
var tableName=this.$userTables[i].name+user.id;
var result = await this.$sqlDb.clearData(tableName);
}
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}else{
console.log('清除聊天缓存时间没过期');
this.$sqlDb.getHistoryAndOffline(user.id);
}
}else{
}
})
}else{
uni.setStorageSync('chat_cache_time_'+user.id,new Date().getTime())
this.$sqlDb.getHistoryAndOffline(user.id);
}
//关闭其他页面,进入url页面
if(res.data.is_teenager==0){
this.$u.sleep(1500).then(res=>{
uni.switchTab({
url:'/pages/tabbar/home/home'
});
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/user/setting_page/teenagers/teenagers',
type:'reLaunch'
})
})
}
});
}else{
uni.setStorageSync('qianhe_im_token','');
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
})
}else{
this.$u.sleep(1500).then(res=>{
this.$u.route({
url:'pages/login/login',
type:'reLaunch'
})
})
}
}
}
}
</script>
<style lang="scss">
.start{
background-image: url('../../static/start/start_bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
.start_flex{
height: 100%;
width: 100%;
}
}
</style>
bug描述:
uni-app离线打包后,用android调试或者打包APK,卡在启动页,进不去