From 6a433eb27d65bd2da3f1e1ab3dd6256cb5ee489e Mon Sep 17 00:00:00 2001 From: guoshuang Date: Mon, 17 Jan 2022 22:23:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=87=AA=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/lang/cn.ts | 3 ++ src/i18n/lang/en.ts | 3 ++ src/pages/login/login/index.vue | 50 ++++++++++++++++++++++++++++----- src/store/modules/session.ts | 10 ++++++- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/i18n/lang/cn.ts b/src/i18n/lang/cn.ts index 9830668..c0502d9 100644 --- a/src/i18n/lang/cn.ts +++ b/src/i18n/lang/cn.ts @@ -24,6 +24,9 @@ export default { success: '操作成功', error: '操作失败', operation: '操作', + //版本更新 + updatePrompt: '更新提示', + Tip1: '检测到有新版本,是否更新?', //服务器设置 ServerSetting: '服务器设置', PleaseInputIPAddress: '请输入IP地址', diff --git a/src/i18n/lang/en.ts b/src/i18n/lang/en.ts index f84290d..1cdbccf 100644 --- a/src/i18n/lang/en.ts +++ b/src/i18n/lang/en.ts @@ -27,6 +27,9 @@ export default { error: 'Error', successful: 'query was successful', operation: 'operation', + //版本更新 + updatePrompt: 'Update tips', + Tip1: 'New version detected, update?', //服务器设置 ServerSetting: 'Server Setting', PleaseInputIPAddress: 'Please input IP address', diff --git a/src/pages/login/login/index.vue b/src/pages/login/login/index.vue index 24c8e89..a7f0d9e 100644 --- a/src/pages/login/login/index.vue +++ b/src/pages/login/login/index.vue @@ -85,6 +85,7 @@ import { session } from '@/store/modules/session'; import { BasePage } from '@/components/base/page'; import { VForm } from 'vue/types/form'; import { Lang } from '@/i18n'; +import { url } from '@/utils/url'; // import { any } from 'lodash/fp'; @Component({ @@ -138,21 +139,54 @@ export default class LoginPage extends BasePage { this.$form.setRules(this.rules); console.log('image', this.image); } - Version: string = '1.0.0'; + Version = '1.0.0'; async update() { await session.QueryVersion(); if (this.Version != session.Version) { - await uni.downloadFile({ - url: 'http://106.13.174.133:5210/HaierWMS.apk', - success: (res) => { - console.log('res.statusCode', res.statusCode); - console.log('res.tempFilePath', res.tempFilePath); + //alert('版本更新啦!'); + // 版本更新提示 + uni.showModal({ + //title: this.$t('message.updatePrompt') as string, + content: this.$t('message.Tip1') as string, + confirmText: this.$t('message.workArea_Confirm') as string, + cancelText: this.$t('message.Cancel') as string, + success: function (res) { + if (res.confirm) { + //确定执行下载 + let downloadApkUrl = session.url; + // uni.downloadFile({ + // url: downloadApkUrl, + // }); + var dtask = plus.downloader.createDownload(downloadApkUrl, {}, function (d, status) { + if (status == 200) { + console.log('Download success: ' + d.filename); + uni.showToast({ + icon: 'none', + title: d.filename, + }); + } else { + console.log('Download failed: ' + status); + } + }); + dtask.start(); + } else if (res.cancel) { + //console.log('用户点击取消'); + } }, }); + + //dtask.addEventListener("statechanged", onStateChanged, false); + // await uni.downloadFile({ + // url: session.url, + // success: (res) => { + // console.log('res.statusCode', res.statusCode); + // console.log('res.tempFilePath', res.tempFilePath); + // console.log("url,url,url",session.url); + // }, + // }); } } login(): void { - // this.update(); this.$form.validate(async (valid: boolean) => { if (valid) { if (!server.isServerAddressSet) { @@ -185,6 +219,8 @@ export default class LoginPage extends BasePage { icon: 'success', title: this.$t('message.LoginSuccessful') as string, }); + //debugger; + this.update(); uni.navigateTo({ url: page.login.area, }); diff --git a/src/store/modules/session.ts b/src/store/modules/session.ts index 60308c8..39ec4f8 100644 --- a/src/store/modules/session.ts +++ b/src/store/modules/session.ts @@ -32,6 +32,7 @@ class SessionService extends VuexModule { */ user: User | null = null; Version: string = ''; + url: string = ''; /** * 当前工作区 @@ -162,7 +163,14 @@ class SessionService extends VuexModule { async QueryVersion() { let res: any = await request.get('http://seamom.haier.net/sgNginxDownload/Debug/setup.json'); let Version = res.version; - return { Version }; + let url = res.url + res.file; + return { Version, url }; + } + //直接下载 + @MutationAction + async xiazai() { + let url: any = await request.get(this.url); + return { url }; } }