|
|
@@ -22,7 +22,7 @@ onLoad((options) => {
|
|
|
onShow((options) => {
|
|
|
updateRoute();
|
|
|
// checkUpdate()
|
|
|
- handleSignupRoute(options)
|
|
|
+ handleSignupRoute(options)
|
|
|
})
|
|
|
|
|
|
// App.vue 或你的初始化文件中
|
|
|
@@ -74,7 +74,16 @@ onLaunch((options) => {
|
|
|
// 调用初始化
|
|
|
// initTheme()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ // #ifdef H5
|
|
|
// 处理 signup 路径
|
|
|
+ document.title = 'CWGMarkets'
|
|
|
+ // 防止后面又被改掉,再加个定时器兜底
|
|
|
+ setInterval(() => {
|
|
|
+ if (!document.title) document.title = 'CWGMarkets'
|
|
|
+ }, 500)
|
|
|
+ // #endif
|
|
|
|
|
|
})
|
|
|
|
|
|
@@ -141,7 +150,7 @@ const handleSignupRoute = (options) => {
|
|
|
if (query.path === 'signin') {
|
|
|
|
|
|
// 跳转到登录页面 有就携带 token 参数
|
|
|
- const loginUrl = query?.sysLoginToken?`/pages/login/index?sysLoginToken=${encodeURIComponent(query.sysLoginToken)}`:'/pages/login/index'
|
|
|
+ const loginUrl = query?.sysLoginToken ? `/pages/login/index?sysLoginToken=${encodeURIComponent(query.sysLoginToken)}` : '/pages/login/index'
|
|
|
console.log('跳转到登录页面:', loginUrl);
|
|
|
|
|
|
uni.reLaunch({
|
|
|
@@ -205,94 +214,94 @@ watch(locale, () => {
|
|
|
|
|
|
// 检测版本号更新
|
|
|
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)
|
|
|
- }
|
|
|
+ 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 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
|
|
|
- })
|
|
|
+ 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
|
|
|
+ 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(() => {
|