|
|
@@ -81,7 +81,10 @@
|
|
|
<script setup lang="uts">
|
|
|
import { ref, computed, onMounted } from 'vue'
|
|
|
import { loginByAccount, loginSSO, getUserInfo, resetPassword , getIsKey} from '../../api/auth/login'
|
|
|
- import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
|
|
|
+ // import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
|
|
|
+ import { getVersion } from '../../api/system/config.uts'
|
|
|
+ import { getBaseUrl } from '../../utils/request'
|
|
|
+
|
|
|
import {
|
|
|
saveAccessToken,
|
|
|
saveUserInfo,
|
|
|
@@ -105,11 +108,13 @@
|
|
|
const showNewPassword = ref<boolean>(false)
|
|
|
const showConfirmPassword = ref<boolean>(false)
|
|
|
const loading = ref<boolean>(false)
|
|
|
+ const isDownload = ref<boolean>(false)
|
|
|
const showPasswordPicker = ref<boolean>(false)
|
|
|
|
|
|
// 版本号
|
|
|
const manifestVersion = manifest.versionName as string | null
|
|
|
const version = ref<string>(manifestVersion != null ? manifestVersion : '1.0.0')
|
|
|
+ const versionServer = ref<string>('1.0.0')
|
|
|
|
|
|
// 是否可以登录
|
|
|
const canLogin = computed((): boolean => {
|
|
|
@@ -285,6 +290,129 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ const compareVersion = (newVersion: string, currentVersion: string): boolean => {
|
|
|
+ const newVer = newVersion.split('.').map(item => parseInt(item))
|
|
|
+ const currentVer = currentVersion.split('.').map(item => parseInt(item))
|
|
|
+
|
|
|
+ const maxLength = Math.max(newVer.length, currentVer.length)
|
|
|
+
|
|
|
+ for (let i = 0; i < maxLength; i++) {
|
|
|
+ const newNum = i < newVer.length ? newVer[i] : 0
|
|
|
+ const currentNum = i < currentVer.length ? currentVer[i] : 0
|
|
|
+
|
|
|
+ if (newNum > currentNum) {
|
|
|
+ return true
|
|
|
+ } else if (newNum < currentNum) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 安装APK的单独函数
|
|
|
+ const installApkFile = (filePath: string): void => {
|
|
|
+ uni.installApk({
|
|
|
+ filePath: filePath,
|
|
|
+ success: () => {
|
|
|
+ console.log('安装成功');
|
|
|
+ uni.showToast({
|
|
|
+ title: '安装成功',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (error) => {
|
|
|
+ console.error('安装失败:', error);
|
|
|
+ uni.showToast({
|
|
|
+ title: '安装失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ complete: (res) => {
|
|
|
+ console.log('安装完成:', res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const installApkWithProgress = (): void => {
|
|
|
+ // #ifdef APP-ANDROID
|
|
|
+ // 显示下载进度
|
|
|
+ uni.showLoading({
|
|
|
+ title: '下载中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ isDownload.value = true;
|
|
|
+ let donwloadUrl = '';
|
|
|
+ donwloadUrl = getBaseUrl() + '/profile/app/gxt-release-'+versionServer.value+'.apk'
|
|
|
+
|
|
|
+ // 下载APK
|
|
|
+ const downloadTask = uni.downloadFile({
|
|
|
+ url: donwloadUrl,
|
|
|
+ filePath: `${uni.env.USER_DATA_PATH}/${Date.now()}_test.apk`, // 使用时间戳防止重名
|
|
|
+ success: (downloadRes) => {
|
|
|
+ if (downloadRes.statusCode == 200) {
|
|
|
+ // 确认安装
|
|
|
+ uni.showModal({
|
|
|
+ title: '安装提示',
|
|
|
+ content: '下载完成,是否立即安装?',
|
|
|
+ success: (modalRes) => {
|
|
|
+ if (modalRes.confirm) {
|
|
|
+ installApkFile(downloadRes.tempFilePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: '下载失败',
|
|
|
+ icon: 'error'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ uni.hideLoading();
|
|
|
+ },
|
|
|
+ fail: (error) => {
|
|
|
+ uni.hideLoading();
|
|
|
+ uni.showToast({
|
|
|
+ title: '下载失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ console.error('下载失败:', error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 监听下载进度
|
|
|
+ downloadTask.onProgressUpdate((res) => {
|
|
|
+ console.log('下载进度:', res.progress + '%');
|
|
|
+ // 如果需要,可以更新UI显示进度
|
|
|
+ // uni.showLoading({
|
|
|
+ // title: `下载中...`,
|
|
|
+ // mask: true
|
|
|
+ // });
|
|
|
+ });
|
|
|
+ // #endif
|
|
|
+ // #ifdef APP-HARMONY
|
|
|
+ uni.showToast({
|
|
|
+ title: '请登录PC端,扫描二维码下载并安装',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ // #endif
|
|
|
+ // #ifdef APP-IOS
|
|
|
+ uni.showToast({
|
|
|
+ title: '请登录PC端,扫描二维码下载并安装',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ // #endif
|
|
|
+ }
|
|
|
+
|
|
|
+ const checkVersion = async (): Promise<void> => {
|
|
|
+ const versionJSON = await getVersion() as UTSJSONObject
|
|
|
+ versionServer.value = versionJSON['msg'] as string
|
|
|
+ const hasNewVersion = compareVersion(versionServer.value, version.value) // true
|
|
|
+ console.log("versionServer:"+versionServer.value)
|
|
|
+ console.log("hasNewVersion:"+hasNewVersion)
|
|
|
+ if(hasNewVersion){
|
|
|
+ installApkWithProgress();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
onLoad((options: UTSJSONObject | null) => {
|
|
|
console.log('URL参数:', options)
|
|
|
// 延迟一点执行,确保App.vue已保存到缓存
|
|
|
@@ -322,7 +450,8 @@
|
|
|
|
|
|
// 初始化:加载记住的账号密码
|
|
|
onMounted(() => {
|
|
|
- checkUpdate()
|
|
|
+ // checkUpdate()
|
|
|
+ checkVersion()
|
|
|
const remembered = getRememberedAccount()
|
|
|
if (remembered != null) {
|
|
|
username.value = remembered['username'] as string
|