Browse Source

修改版本更新弹框功能

master
邓宏 7 months ago
parent
commit
e04e4034e3
  1. 45
      pages/home/login.vue

45
pages/home/login.vue

@ -71,13 +71,16 @@
:content="modalOptions.modalContent" :content="modalOptions.modalContent"
:show-confirm-button="true" :show-confirm-button="true"
:show-cancel-button="modalOptions.isShowCancel" :show-cancel-button="modalOptions.isShowCancel"
@close="!modalOptions.isDownApp && (isShowModal=false)" @close="modalOptions.isShowCancel&&(isShowModal=false)"
@cancel="isShowModal=false" @cancel="isShowModal=false"
@confirm="upgrade"/> @confirm="upgrade">
<text v-if="!modalOptions.isShowCancel&&modalOptions.asyncClose" style="width:200rpx;height:200rpx;background-size:contain" :style='{backgroundImage:`url("${icon}")`}'/>
</u-modal>
</view> </view>
</template> </template>
<script> <script>
import request,{host} from "@/common/request" import request,{host} from "@/common/request"
import {SVGToBase64} from 'black-knight/lib/config/tools'
export default { export default {
data(){ data(){
return{ return{
@ -94,22 +97,33 @@ export default {
isShowModal:false, isShowModal:false,
modalOptions:{ modalOptions:{
isShowCancel:true, isShowCancel:true,
isDownApp:false,
modalContent:"请升级app到最新版本!", modalContent:"请升级app到最新版本!",
process:0, process:0,
modalTitle:"测到有新版本", modalTitle:"测到有新版本",
okText:"立刻升级", okText:"立刻升级",
asyncClose:true, asyncClose:true,
}, },
} }
}, },
computed:{
icon(){
return SVGToBase64(`
<svg width="440" height="440">
<circle cx="220" cy="220" r="170" stroke-width="50" stroke="#D1D3D7" fill="none"></circle>
<circle cx="220" cy="220" r="170" stroke-width="50" stroke="#10C176" stroke-linecap="round" fill="none" transform="matrix(0,-1,1,0,0,440)" stroke-dasharray="${this.modalOptions.process/100*Math.PI*2*170} 1069"></circle>
<text x="220" y="240" font-size="75" text-anchor="middle">${this.modalOptions.process}%</text>
</svg>
`)
}
},
onLoad(options){ onLoad(options){
this.formData.username=options.phone||uni.getStorageSync('username')||"" this.formData.username=options.phone||uni.getStorageSync('username')||""
if(process.env.NODE_ENV === 'development'){ if(process.env.NODE_ENV === 'development'){
this.formData.username="18788469459" this.formData.username="18788469459"
this.formData.password="1qaz@WSX" this.formData.password="1qaz@WSX"
} }
//#ifdef APP-PLUS //#ifdef APP-PLUS
this.getVersion() this.getVersion()
plus.runtime.getProperty(plus.runtime.appid, async info=>{ plus.runtime.getProperty(plus.runtime.appid, async info=>{
@ -143,30 +157,26 @@ export default {
params:{type:1} params:{type:1}
}) })
if(res.statu){ if(res.statu){
console.log(res.data.appVersionCode,'当前运行版本号----') console.log(this.versionCode,'当前运行版本号----')
console.log(res.data.appVersionCode,'最新版本号----') console.log(res.data.appVersionCode,'最新版本号----')
if(res.data.appVersionCode > this.versionCode){
this.isShowModal=true this.appDownLoadUrl=host("version",res.data.appDownloadUrl)
this.appDownLoadUrl=host("version",res.data.appDownloadUrl) this.isShowModal=true//res.data.appVersionCode > this.versionCode
}
} }
}, },
//app //app
upgrade(){ upgrade(){
//#ifdef APP-PLUS
if(this.modalOptions.isShowCancel){ // #ifdef APP-PLUS
if(this.modalOptions.asyncClose){
this.modalOptions.modalTitle="开始下载" this.modalOptions.modalTitle="开始下载"
this.modalOptions.modalContent="下载中..."
this.modalOptions.isDownApp=true
this.modalOptions.isShowCancel=false this.modalOptions.isShowCancel=false
console.log(this.appDownLoadUrl,'-----url----')
var dtask=plus.downloader.createDownload(this.appDownLoadUrl,{ var dtask=plus.downloader.createDownload(this.appDownLoadUrl,{
filename: "_downloads/", filename: "_downloads/",
timeout:30, timeout:30,
retry:1 retry:1
},(d,status)=>{ },(d,status)=>{
console.log(d,status,'----111----')
this.modalOptions.isDownApp=false
this.modalOptions.asyncClose=false this.modalOptions.asyncClose=false
this.modalOptions.okText="确认" this.modalOptions.okText="确认"
this.$refs.modal.loading=false this.$refs.modal.loading=false
@ -180,7 +190,6 @@ export default {
this.modalOptions.modalContent="下载升级包失败!" this.modalOptions.modalContent="下载升级包失败!"
} }
}) })
console.log(dtask,'--dtask----')
if(dtask){ if(dtask){
dtask.addEventListener("statechanged",e=>{ dtask.addEventListener("statechanged",e=>{
// console.log(`totalSize:${e.totalSize};downloadedSize:${e.downloadedSize}`) // console.log(`totalSize:${e.totalSize};downloadedSize:${e.downloadedSize}`)

Loading…
Cancel
Save