QA-UniApp-wlaq/pages/index/index.vue

282 lines
7.7 KiB
Vue

<template>
<view>
<basics v-if="PageCur=='basics'" id="basics"></basics>
<application v-if="PageCur=='application'" id="application"></application>
<works v-if="PageCur=='works'" id = "works"></works>
<my v-if="PageCur=='my'" id = "my"></my>
<view class="cu-bar tabbar bg-white shadow foot">
<view class="action" @click="NavChange" data-cur="basics">
<view class='cuIcon-cu-image'>
<image :src="'/static/tabbar/basics' + [PageCur=='basics'?'_cur':''] + '.png'"></image>
</view>
<view :class="PageCur=='basics'?'text-blue':'text-gray'">首页</view>
</view>
<view class="action" @click="NavChange" data-cur="application">
<view class='cuIcon-cu-image'>
<image :src="'/static/tabbar/application' + [PageCur == 'application'?'_cur':''] + '.png'"></image>
</view>
<view :class="PageCur=='application'?'text-blue':'text-gray'">应用</view>
</view>
<view class="action" @click="NavChange" data-cur="works">
<view class='cuIcon-cu-image'>
<image :src="'/static/tabbar/works' + [PageCur == 'works'?'_cur':''] + '.png'"></image>
<view v-if="mesCount>0" class="cu-tag badge">{{mesCount}}</view>
</view>
<view :class="PageCur=='works'?'text-blue':'text-gray'">通知</view>
</view>
<view class="action" @click="NavChange" data-cur="my">
<view class='cuIcon-cu-image'>
<image :src="'/static/tabbar/my' + [PageCur == 'my'?'_cur':''] + '.png'"></image>
</view>
<view :class="PageCur=='my'?'text-blue':'text-gray'"></view>
</view>
</view>
</view>
</template>
<script>
import {
basePath,
isRest,
loginUserId,
formatDate,
loginUser,
setloginUserId,
setCorpinfoId,
setDeptId,
setloginUser,
setVersion,
corpinfoId,
setIsRest
} from '@/common/tool.js';
export default {
data() {
return {
initflag:false,
PageCur: 'basics',
wgtVer:'',
version:'',
brand:'other',
mesCount:0
}
},
onBackPress() {
//console.log("press back");
uni.showModal({
title: '是否退出',
confirmText: '退出',
success: function(res) {
if (res.confirm) {
setloginUserId(null);
setCorpinfoId(null);
setDeptId(null);
setloginUser(null);
uni.removeStorage({key: 'USER'});
uni.reLaunch({
url: '/pages/login/home'
});
}
}.bind(this)//此处bind是关键
})
return true;
},
onShow() {
var _this = this;
_this.$nextTick(() => { //等待组件渲染结束才调用
if(_this.initflag) {
console.info("index的initflag=="+_this.initflag);
if(_this.PageCur=='basics' || _this.PageCur=='message') {
var page = _this.selectComponent("#" + _this.PageCur);//按子组件ID 获取子组件对象
page.getData();//调用子组件init方法
}
if(_this.PageCur=='works') {
var page = _this.selectComponent("#" + _this.PageCur);//按子组件ID 获取子组件对象
page.getData();//调用子组件init方法
page.getPcData();//调用子组件init方法
}
if(_this.PageCur=='my') {
var page = _this.selectComponent("#" + _this.PageCur);//按子组件ID 获取子组件对象
page.getData();//调用子组件init方法
}
if(_this.PageCur=='application') {
var page = _this.selectComponent("#" + _this.PageCur);//按子组件ID 获取子组件对象
console.info(page)
page.getHidRedPoint();//调用子组件init方法
}
}
_this.initflag=false;//false;子组件调用跳转方法时设为true
});
_this.$nextTick(() => { //等待组件渲染结束才调用
if(_this.PageCur=='basics') {
var page = _this.selectComponent("#" + _this.PageCur);//按子组件ID 获取子组件对象
page.getData();//调用子组件init方法
}
});
this.getRedPoint();
},
onLoad() {
this.plusReady();
// this.checkPlatform();
// this.checkUpdate("android");
},
plusReady() {
uni.startPullDownRefresh();
},
onPullDownRefresh() {
var _this = this;
// console.info(_this.PageCur)
if(_this.PageCur=='basics' || _this.PageCur=='message' || _this.PageCur=='works') {
var page = _this.selectComponent("#" + _this.PageCur);//按子组件ID 获取子组件对象
page.getData();//调用子组件init方法
}
setTimeout(function () {
uni.stopPullDownRefresh();
}, 1000);
},
methods: {
getRedPoint() {
var _this = this;
uni.showLoading({
title: '请稍候'
})
uni.request({
url: basePath + '/app/notice/getRedPoint',
method: 'POST',
dataType: 'json',
header: {
'Content-type':'application/x-www-form-urlencoded'
},
data: {
USER_ID: loginUserId
},
success: (res) => {
if("success" == res.data.result){
uni.hideLoading();
_this.mesCount = res.data.count;
} else {
uni.showToast({
title: res.data.message,
duration: 2000
});
}
},
fail: (res) => {
uni.showToast({
icon: 'none',
title: "服务器正在升级,请稍后再试。",
duration: 2000
});
}
});
},
NavChange: function (e) {
this.PageCur = e.currentTarget.dataset.cur
},
setInit(flag) {//子组件调用init方法后 无需再执行onShow方法
this.initflag = flag;
},
// 获取当前版本号
plusReady() {
var that = this;
// 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid, function (inf) {
that.wgtVer = inf.version; //获取当前版本号
setVersion(that.wgtVer);
that.version = plus.runtime.version;
uni.getSystemInfo({
success(res) {
that.brand = res.brand.toUpperCase();
that.checkPlatform();
}
});
});
},
getBrand() {
var that = this;
uni.getSystemInfo({
success(res) {
that.brand = res.brand.toUpperCase();
console.log(that.brand) //手机牌子
console.log(res.model) //手机型号
console.log(res.screenWidth) //屏幕宽度
console.log(res.screenHeight) //屏幕高度
}
});
},
checkPlatform() {
var _this=this;
uni.getSystemInfo({
success: (res) => {
_this.checkUpdate(res.platform);
}
})
},
// 自动更新
checkUpdate(platform){
var that=this;
uni.request({
url: basePath + '/app/versionmanager/getVersion', //获取最新版本号
method: 'POST',
data: {FILETYPE:platform},
success: res => {
if(res.data.pd.VERSION>that.wgtVer){
if(platform=="android"){
plus.nativeUI.confirm( "请保持应用最新版本,否则将无法使用。", function(e){
if(e.index == 0){
var url2 = encodeURI('https://wlqy.zcloudchina.com/file/uploadFiles/wlaq/app.apk');
plus.runtime.openURL(url2, function(res) {
});
setTimeout(function() {
plus.runtime.quit();
}, 2000);
} else {
plus.runtime.quit();
}
}, "下载更新", ["下载"] );
} else {
plus.nativeUI.confirm( "请保持应用最新版本,否则将无法使用。", function(e){
if(e.index == 0){
var url='itms-apps://itunes.apple.com/cn/app/id1632574886?mt=8';// 应用在appstore的地址
plus.runtime.openURL(url);
setTimeout(function() {
const threadClass = plus.ios.importClass("NSThread");
const mainThread = plus.ios.invoke(threadClass, "mainThread");
plus.ios.invoke(mainThread, "exit");
}, 2000);
}
}, "下载更新", ["下载"] );
}
}
},
fail: (res) => {
uni.showToast({
icon: 'none',
title: "服务器正在升级,请稍后再试。",
duration: 2000
});
}
});
},
}
}
</script>
<style>
</style>