fix: 优化版本升级,在作业页面新增版本校验
This commit is contained in:
parent
113910a0a3
commit
3ba6221bd2
2
.env
2
.env
@ -2,6 +2,6 @@ VITE_WS_URL = wss://ai.lingxixue.com/ws/device
|
||||
VITE_OSS_URL = https://lxx-web-1313840333.cos.ap-chengdu.myqcloud.com
|
||||
VITE_CDN_URL = https://dmgcdn-1313840333.cos.ap-guangzhou.myqcloud.com
|
||||
VITE_SERVER_URL = https://ai.lingxixue.com/api/main
|
||||
VITE_XXL_VERSION = 2.13.5
|
||||
VITE_XXL_VERSION=2.13.6
|
||||
VITE_INIT_VCONSOLE = 0
|
||||
VITE_TEACHER_ADMIN_URL = https://edu.lingxixue.com
|
||||
|
||||
@ -4,6 +4,6 @@ VITE_OSS_URL = https://lxx-web-1313840333.cos.ap-chengdu.myqcloud.com
|
||||
VITE_CDN_URL = https://dmgcdn-1313840333.cos.ap-guangzhou.myqcloud.com
|
||||
VITE_SERVER_URL = http://127.0.0.1:9053/api/main
|
||||
# VITE_SERVER_URL = http://test.web.xuexiaole.com/api/main
|
||||
VITE_XXL_VERSION = 2.13.2
|
||||
VITE_XXL_VERSION=2.13.6
|
||||
VITE_INIT_VCONSOLE = 0
|
||||
VITE_TEACHER_ADMIN_URL = https://test.edu.xuexiaole.com
|
||||
|
||||
@ -17,7 +17,6 @@ import { debounce } from 'lodash-es'
|
||||
import { isShufaAccount, SHUFA_PATH } from '@/page/app/app.ts'
|
||||
import { useHomeRedPointStore } from '@/stores/home-red-point'
|
||||
import hud from '@/utils/hud'
|
||||
import { compareVersions } from 'compare-versions'
|
||||
|
||||
defineOptions({
|
||||
name: 'Home',
|
||||
|
||||
@ -3,6 +3,7 @@ import LoadIcon from '@/page/system/mailbox/components/LoadIcon.vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { $XXL } from '@/utils'
|
||||
import { globalStore } from '@/stores'
|
||||
import homeworkApi, { type PaperRecord, type SubjectPaperRecord } from '@/api/subject/homework'
|
||||
import { resource_type_homework } from '@/page/subject/doWork'
|
||||
|
||||
@ -11,6 +12,7 @@ defineOptions({
|
||||
})
|
||||
|
||||
const router = useRouter()
|
||||
const { checkUpdate } = globalStore()
|
||||
|
||||
const OSS_URL = import.meta.env.VITE_OSS_URL
|
||||
|
||||
@ -47,6 +49,7 @@ const pageLoading = ref(false)
|
||||
const pageError = ref(false)
|
||||
|
||||
onMounted(async () => {
|
||||
checkUpdate()
|
||||
pageLoading.value = true
|
||||
listLoading.value = true
|
||||
$XXL.setScreenOn(1)
|
||||
|
||||
@ -76,6 +76,16 @@ const blackPkgPrefixes = [
|
||||
]
|
||||
|
||||
let vConsole: VConsole
|
||||
|
||||
/** 供 compare-versions 使用:去空白,空串用 0 占位避免抛错 */
|
||||
function semverArg(v: unknown) {
|
||||
return (
|
||||
String(v ?? '')
|
||||
.trim()
|
||||
.replace(/^\uFEFF/, '') || '0'
|
||||
)
|
||||
}
|
||||
|
||||
export const globalStore = defineStore('global', () => {
|
||||
const systemDict = {
|
||||
os: '',
|
||||
@ -189,13 +199,17 @@ export const globalStore = defineStore('global', () => {
|
||||
const diffApkVersion = computed(
|
||||
() =>
|
||||
compareVersions(
|
||||
String(system.latestVersion.apk?.versionNum || 0),
|
||||
String(getVersion() || 0),
|
||||
semverArg(system.latestVersion.apk?.versionNum || 0),
|
||||
semverArg(getVersion() || 0),
|
||||
) === 1,
|
||||
)
|
||||
// WEB版本差异
|
||||
const diffWebVersion = computed(
|
||||
() => compareVersions(String(system.latestVersion.web?.versionNum || 0), getVersion(1)) === 1,
|
||||
() =>
|
||||
compareVersions(
|
||||
semverArg(system.latestVersion.web?.versionNum || 0),
|
||||
semverArg(getVersion(1) || 0),
|
||||
) === 1,
|
||||
)
|
||||
// 检测更新
|
||||
const checkStudyMachineUpdate = async (checkWeb = true) => {
|
||||
@ -288,9 +302,9 @@ export const globalStore = defineStore('global', () => {
|
||||
updateType: 1,
|
||||
})
|
||||
.then((res: any) => {
|
||||
const newVersion = res?.rows?.[0]?.versionNum
|
||||
if (!newVersion) return
|
||||
const curVersion = getVersion(1)
|
||||
const newVersion = semverArg(res?.rows?.[0]?.versionNum)
|
||||
if (!newVersion || newVersion === '0') return
|
||||
const curVersion = semverArg(getVersion(1))
|
||||
if (compareVersions(newVersion, curVersion) !== 1) return
|
||||
hud.alert({
|
||||
title: '更新提示',
|
||||
|
||||
@ -43,11 +43,17 @@ export const getManufacturer = () => {
|
||||
// 获取版本号
|
||||
export const getVersion = (type = 0) => {
|
||||
if (type === 1) {
|
||||
// web版本
|
||||
return import.meta.env.VITE_XXL_VERSION
|
||||
// web版本(.env 里 `KEY = value` 等号旁空格可能让值带前导空格,compare-versions 会报非法 semver)
|
||||
const v = import.meta.env.VITE_XXL_VERSION
|
||||
return String(v ?? '')
|
||||
.trim()
|
||||
.replace(/^\uFEFF/, '')
|
||||
}
|
||||
if (native_api?.getVersionCode) {
|
||||
return JSON.parse(native_api.getVersionCode()).data
|
||||
const data = JSON.parse(native_api.getVersionCode()).data
|
||||
return String(data ?? '')
|
||||
.trim()
|
||||
.replace(/^\uFEFF/, '')
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user