Browse Source

登录 版本验证

master
邓宏 2 years ago
parent
commit
6adc544527
  1. 5
      common/request.js
  2. 111
      pages/home/login.vue
  3. 114
      pages/home/my.vue

5
common/request.js

@ -5,8 +5,7 @@ export function host(host='default',suffix='/plant_manage'){
// default:`http://i5skii.natappfree.cc` //陈
// default:`http://jjytvc.natappfree.cc` //马
// default:`http://6exd5b.natappfree.cc` //何
default:`http://192.168.0.116:8080` //孙
// default:"http://192.168.0.14:7000"
default:"http://192.168.0.14:7000"
}:{
default:``
}
@ -65,7 +64,7 @@ const request=async function(url,param={}){
}
},600)
if(res){
if(res.data.code==401){
if(res.data.code==401&&!param.skipToken){
store.commit('outLogin')
return{statu:false, msg:"登录超时!"}
}

111
pages/home/login.vue

@ -56,6 +56,32 @@
<button class="cu-btn round bg-green shadow submit" @click="login">登录</button>
<view class="res">还没有账号?<text @click="$u.route({url:'pages/home/register'})">立即注册</text></view>
<!-- 升级模态框 -->
<u-modal
:show="isShowModal"
ref="modal"
closeOnClickOverlay
:confirm-text="modalOptions.okText"
cancel-text="暂不升级"
:async-close="modalOptions.asyncClose"
:title="modalOptions.modalTitle"
:content="modalOptions.modalContent"
:show-confirm-button="true"
:show-cancel-button="modalOptions.isShowCancel"
@close="!modalOptions.isDownApp && (isShowModal=false)"
@cancel="isShowModal=false"
@confirm="upgrade">
<template v-if="modalOptions.isDownApp">
<u-circle-progress active-color="#2979ff" :percent="modalOptions.process" style="display:flex;margin:50rpx auto;">
<view class="u-progress-content">
<view class="u-progress-dot"></view>
<text class='u-progress-info'>{{modalOptions.process}}%</text>
</view>
</u-circle-progress>
</template>
</u-modal>
</view>
</template>
<script>
@ -69,17 +95,34 @@ export default {
password:"",
username:"",
loginType:"mobile",
}
},
appVersion:"",
appDownLoadUrl:"",
isShowModal:false,
modalOptions:{
isShowCancel:true,
isDownApp:false,
modalContent:"请升级app到最新版本!",
process:0,
modalTitle:"监测到有新版本",
okText:"立刻升级",
asyncClose:true,
},
}
},
onLoad(){
uni.navigateTo({
url:"/pages/demo"
})
if(process.env.NODE_ENV === 'development'){
this.formData.username="13383434048"//"18636155239"
this.formData.password="1qaz@WSX"
}
this.getVersion()
//#ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, async info=>{
this.appVersion = info.version
})
//#endif
},
methods:{
async login(){
@ -97,7 +140,67 @@ export default {
showCancel:false,
})
}
},
async getVersion(){
var res=await request("/api/appVersion/getAppVersion",{
skipToken:true,
params:{type:2}
})
if(res.statu){
if(res.data.appVersion!=this.appVersion){
this.isShowModal=true
this.appDownLoadUrl=res.data.appDownloadUrl
}
}
},
//app
upgrade(){
//#ifdef APP-PLUS
if(this.modalOptions.isShowCancel){
this.modalOptions.modalTitle="开始下载"
this.modalOptions.isDownApp=true
this.modalOptions.isShowCancel=false
var dtask=plus.downloader.createDownload(this.appDownLoadUrl,{
filename: "_downloads/",
timeout:30,
retry:1
},(d,status)=>{
this.modalOptions.isDownApp=false
this.modalOptions.asyncClose=false
this.modalOptions.okText="确认"
this.$refs.modal.clearLoading()
if(status == 200){
plus.runtime.install(d.filename,{force:true},()=>plus.runtime.restart(), e=>{
this.modalOptions.modalTitle="提示"
this.modalOptions.modalContent="安装升级包失败!"
})
}else{
this.modalOptions.modalTitle="提示"
this.modalOptions.modalContent="下载升级包失败!"
}
})
console.log(dtask,'--dtask---')
if(dtask){
dtask.addEventListener("statechanged",e=>{
if(e&&e.totalSize>0){
// console.log("state",e.state,"::::","--------statechanged-----------",e.downloadedSize)
this.modalOptions.process=Math.floor((e.downloadedSize/e.totalSize)*10000)/100
}
},false)
dtask.start();
}else{
this.isShowModal=false
this.modalOptions=this.$options.data().modalOptions
uni.showModal({
title:"提示",
content:"下载最新版本失败!",
showCancel:false,
})
}
}
//#endif
},
},
}
</script>

114
pages/home/my.vue

@ -79,39 +79,11 @@
<view class="item" @click="$u.route({url:'/pages/home/news'})">
<text class="plant-xitongxiaoxi"/> <text>系统消息</text> <text class="number">{{$store.state.sysMsgNum}}</text> <text class="plant-youbian"/>
</view>
<view class="item" @click="getVersion">
<text class="plant-banbenhao"/> <text>检测更新</text> <text class="number">{{appVersion}}</text> <text class="plant-youbian"/>
</view>
<view class="item" @click="outLogin">
<text class="plant-tuichu"/> <text>退出</text> <text class="plant-youbian"/>
</view>
</view>
<!-- 升级模态框 -->
<u-modal
:show="isShowModal"
ref="modal"
closeOnClickOverlay
:confirm-text="modalOptions.okText"
cancel-text="暂不升级"
:async-close="modalOptions.asyncClose"
:title="modalOptions.modalTitle"
:content="modalOptions.modalContent"
:show-confirm-button="true"
:show-cancel-button="modalOptions.isShowCancel"
@close="!modalOptions.isDownApp && (isShowModal=false)"
@cancel="isShowModal=false"
@confirm="upgrade">
<template v-if="modalOptions.isDownApp">
<u-circle-progress active-color="#2979ff" :percent="modalOptions.process" style="display:flex;margin:50rpx auto;">
<view class="u-progress-content">
<view class="u-progress-dot"></view>
<text class='u-progress-info'>{{modalOptions.process}}%</text>
</view>
</u-circle-progress>
</template>
</u-modal>
</view>
</template>
<script>
@ -120,18 +92,6 @@ import request,{host} from '@/common/request'
data(){
return{
host,
appVersion:"",
appDownLoadUrl:"",
isShowModal:false,
modalOptions:{
isShowCancel:true,
isDownApp:false,
modalContent:"请升级app到最新版本!",
process:0,
modalTitle:"监测到有新版本",
okText:"立刻升级",
asyncClose:true,
},
}
},
onLoad(options){
@ -140,12 +100,6 @@ import request,{host} from '@/common/request'
uni.navigateTo({url:`/pages/purchase/${options.toPage}`})
}
})
//#ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, async info=>{
this.appVersion = info.version
})
//#endif
},
onShow(){
this.$store.commit("setSysMsgShow",false)
@ -168,74 +122,6 @@ import request,{host} from '@/common/request'
}
})
},
async getVersion(){
var res=await request("/appVersion/plantAppVersion/getAppVersion")
if(res.statu){
if(res.data.appVersion!=this.appVersion){
this.isShowModal=true
this.appDownLoadUrl=res.data.appDownloadUrl
}else{
uni.showModal({
title:"提示",
content:"当前版本已是最新版本!",
showCancel:false,
})
}
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取版本号失败!",
showCancel:false,
})
}
},
//app
upgrade(){
//#ifdef APP-PLUS
if(this.modalOptions.isShowCancel){
this.modalOptions.modalTitle="开始下载"
this.modalOptions.isDownApp=true
this.modalOptions.isShowCancel=false
var dtask=plus.downloader.createDownload(this.appDownLoadUrl,{
filename: "_downloads/",
timeout:30,
retry:1
},(d,status)=>{
this.modalOptions.isDownApp=false
this.modalOptions.asyncClose=false
this.modalOptions.okText="确认"
this.$refs.modal.clearLoading()
if(status == 200){
plus.runtime.install(d.filename,{force:true},()=>plus.runtime.restart(), e=>{
this.modalOptions.modalTitle="提示"
this.modalOptions.modalContent="安装升级包失败!"
})
}else{
this.modalOptions.modalTitle="提示"
this.modalOptions.modalContent="下载升级包失败!"
}
})
console.log(dtask,'--dtask---')
if(dtask){
dtask.addEventListener("statechanged",e=>{
if(e&&e.totalSize>0){
// console.log("state",e.state,"::::","--------statechanged-----------",e.downloadedSize)
this.modalOptions.process=Math.floor((e.downloadedSize/e.totalSize)*10000)/100
}
},false)
dtask.start();
}else{
this.isShowModal=false
this.modalOptions=this.$options.data().modalOptions
uni.showModal({
title:"提示",
content:"下载最新版本失败!",
showCancel:false,
})
}
}
//#endif
},
},
}
</script>
Loading…
Cancel
Save