|
|
@@ -200,6 +200,98 @@ watch(locale, () => {
|
|
|
// });
|
|
|
}, { immediate: true })
|
|
|
|
|
|
+// 检测版本号更新
|
|
|
+const checkWgtUpdate = async () => {
|
|
|
+ try {
|
|
|
+ const currentVersion = await getCurrentVersion()
|
|
|
+ const res = await uni.request({
|
|
|
+ url: `https://ucard.44a5c8109e4.com/wgt/list.json?_t=${Date.now()}`,
|
|
|
+ method: 'GET',
|
|
|
+ timeout: 5000
|
|
|
+ })
|
|
|
+ const files = res.data?.files || []
|
|
|
+ if (!files.length) return
|
|
|
+ const latestFile = files[files.length - 1]
|
|
|
+ const latestVersion = latestFile
|
|
|
+ if (!latestFile) return
|
|
|
+ const lastInstalled = uni.getStorageSync('lastWgtVersion')
|
|
|
+ console.log(lastInstalled,'lastInstalled');
|
|
|
+ if (latestVersion === lastInstalled) return
|
|
|
+ if (compareVersion(latestVersion, currentVersion) > 0) {
|
|
|
+ downloadAndInstall(latestVersion)
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.log('[wgt] update check failed', e)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 下载并安装
|
|
|
+const downloadAndInstall=(version) => {
|
|
|
+ //TODO: 需要根据版本来确定url
|
|
|
+ const url = `https://ucard.44a5c8109e4.com/wgt/__UNI__EFA7490.wgt`
|
|
|
+ console.log(url,'downloadurl');
|
|
|
+
|
|
|
+ uni.downloadFile({
|
|
|
+ url,
|
|
|
+ success: (res) => {
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ const filePath = res.tempFilePath
|
|
|
+ plus.runtime.install(
|
|
|
+ filePath, {
|
|
|
+ force: true
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ uni.setStorageSync('lastWgtVersion', version)
|
|
|
+ console.log('[wgt] install success:', version)
|
|
|
+ uni.setStorageSync('wgtNeedRestart', true)
|
|
|
+ },
|
|
|
+ (err) => {
|
|
|
+ console.error('[wgt] install failed:', err)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ console.error('[wgt] download status error:', res.statusCode)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('[wgt] download failed:', err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+// 获取当前版本
|
|
|
+const getCurrentVersion = async () => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ try {
|
|
|
+ plus.runtime.getProperty(plus.runtime.appid, (info) => {
|
|
|
+ resolve(info.version)
|
|
|
+ }, (error) => {
|
|
|
+ reject(error)
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ reject(error)
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ // #ifndef APP-PLUS
|
|
|
+ reject(new Error('Not in APP-PLUS environment'))
|
|
|
+ // #endif
|
|
|
+ })
|
|
|
+}
|
|
|
+// 对比版本号
|
|
|
+const compareVersion = (v1, v2) => {
|
|
|
+ const s1 = v1.split('.').map(Number)
|
|
|
+ const s2 = v2.split('.').map(Number)
|
|
|
+ const len = Math.max(s1.length, s2.length)
|
|
|
+
|
|
|
+ for (let i = 0; i < len; i++) {
|
|
|
+ const n1 = s1[i] || 0
|
|
|
+ const n2 = s2[i] || 0
|
|
|
+ if (n1 > n2) return 1
|
|
|
+ if (n1 < n2) return -1
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
const sysInfo = uni.getSystemInfoSync();
|
|
|
globalStore.setBarHeight(sysInfo.statusBarHeight || 60);
|