银联支付集成和购买插件;修改首页小区更改后获取数据;对接我的信息接口
This commit is contained in:
@@ -39,12 +39,14 @@
|
||||
onPullDownRefresh
|
||||
} from '@dcloudio/uni-app'
|
||||
import {
|
||||
authLogout, getUserProfile, getUserNotify, changeUserNotify
|
||||
authLogout, getUserProfile, getUserNotify, changeUserNotify, getAppVersion, checkAppUpdate, postUpdateLog
|
||||
} from '/pageSubPack/api/apiSub.js'
|
||||
|
||||
//
|
||||
const statusBarHeight = ref(20)
|
||||
const cacheSize = ref(0)
|
||||
const currentVersion = ref('1.0.0')
|
||||
const currentVersionCode = ref(1)
|
||||
const settingList = ref([{
|
||||
title: '更改手机号码',
|
||||
type: 'text',
|
||||
@@ -67,11 +69,142 @@
|
||||
{
|
||||
title: '升级版本',
|
||||
type: 'text',
|
||||
value: '当前版本 2.9.8',
|
||||
value: '当前版本 1.0.0',
|
||||
valueClass: 'item-version'
|
||||
}
|
||||
])
|
||||
|
||||
// 格式化字节大小
|
||||
const formatSize = (bytes) => {
|
||||
if (!bytes || bytes === 0) return '0B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'M', 'G']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + sizes[i]
|
||||
}
|
||||
|
||||
// 获取真实缓存大小
|
||||
const getCacheSizeData = () => {
|
||||
return new Promise((resolve) => {
|
||||
// #ifdef APP-PLUS
|
||||
// App 端获取完整缓存(含图片、文件等)
|
||||
plus.cache.calculate((size) => {
|
||||
resolve(formatSize(size))
|
||||
})
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
// 小程序/H5 端只能获取 storage 缓存
|
||||
const info = uni.getStorageInfoSync()
|
||||
const size = (info.currentSize || 0) * 1024 // currentSize 单位 KB
|
||||
resolve(formatSize(size))
|
||||
// #endif
|
||||
})
|
||||
}
|
||||
|
||||
// 获取当前运行版本号
|
||||
const initCurrentVersion = () => {
|
||||
// #ifdef APP-PLUS
|
||||
currentVersion.value = plus.runtime.version || '1.0.0'
|
||||
currentVersionCode.value = plus.runtime.versionCode || 1
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
const manifest = uni.getAppAuthorizeSetting ? uni.getAppAuthorizeSetting() : null
|
||||
if (manifest && manifest.version) {
|
||||
currentVersion.value = manifest.version
|
||||
}
|
||||
// #endif
|
||||
settingList.value[4].value = '当前版本 ' + currentVersion.value
|
||||
}
|
||||
|
||||
// 版本号比较:v1 > v2 返回 1,v1 = v2 返回 0,v1 < v2 返回 -1
|
||||
const compareVersion = (v1, v2) => {
|
||||
const arr1 = v1.split('.').map(Number)
|
||||
const arr2 = v2.split('.').map(Number)
|
||||
const len = Math.max(arr1.length, arr2.length)
|
||||
for (let i = 0; i < len; i++) {
|
||||
const n1 = arr1[i] || 0
|
||||
const n2 = arr2[i] || 0
|
||||
if (n1 > n2) return 1
|
||||
if (n1 < n2) return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// 检查版本更新
|
||||
const checkVersionUpdate = async () => {
|
||||
uni.showLoading({ title: '检查中...', mask: true })
|
||||
try {
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
const platform = systemInfo.platform === 'ios' ? 'ios' : 'android'
|
||||
const channel = 'resident'
|
||||
|
||||
// 1. 查询最新版本
|
||||
const versionRes = await getAppVersion(platform, channel)
|
||||
if (versionRes.code === 200 && versionRes.data) {
|
||||
const latestVersion = versionRes.data.versionName || ''
|
||||
const latestVersionCode = versionRes.data.versionCode || 0
|
||||
|
||||
// 2. 调 checkAppUpdate 检查是否需要更新
|
||||
const checkRes = await checkAppUpdate({
|
||||
platform: platform,
|
||||
channel: channel,
|
||||
currentVersionCode: currentVersionCode.value
|
||||
})
|
||||
uni.hideLoading()
|
||||
|
||||
if (checkRes.code === 200 && checkRes.data) {
|
||||
const needUpdate = checkRes.data.needUpdate !== false
|
||||
if (needUpdate) {
|
||||
const updateType = checkRes.data.updateType || versionRes.data.updateType || 'optional'
|
||||
const isForce = updateType === 'force'
|
||||
uni.showModal({
|
||||
title: isForce ? '强制更新' : '发现新版本',
|
||||
content: `当前版本:${currentVersion.value}\n最新版本:${latestVersion}${versionRes.data.releaseNotes || versionRes.data.updateDesc ? '\n\n更新内容:' + (versionRes.data.releaseNotes || versionRes.data.updateDesc) : ''}`,
|
||||
showCancel: !isForce,
|
||||
confirmText: '立即更新',
|
||||
cancelText: '稍后',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm && versionRes.data.downloadUrl) {
|
||||
// 记录更新日志
|
||||
const userId = uni.getStorageSync('userId')
|
||||
if (userId) {
|
||||
postUpdateLog({
|
||||
userId: userId,
|
||||
platform: platform,
|
||||
fromVersion: currentVersionCode.value,
|
||||
toVersion: latestVersionCode
|
||||
})
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.openURL(versionRes.data.downloadUrl)
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
uni.showToast({ title: '请在应用商店更新', icon: 'none' })
|
||||
// #endif
|
||||
} else if (isForce && !modalRes.confirm) {
|
||||
// 强制更新时用户点取消,退出应用
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.quit()
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showToast({ title: '已是最新版本', icon: 'success' })
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: '检查失败', icon: 'none' })
|
||||
}
|
||||
} else {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '检查失败', icon: 'none' })
|
||||
}
|
||||
} catch (err) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '检查失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
const onItemClick = (item) => {
|
||||
if (item.title == '更改手机号码') {
|
||||
@@ -84,7 +217,10 @@
|
||||
});
|
||||
} else if (item.title == '清除缓存') {
|
||||
uni.clearStorageSync();
|
||||
settingList.value[3].value = '0M'
|
||||
// #ifdef APP-PLUS
|
||||
plus.cache.clear(() => {})
|
||||
// #endif
|
||||
settingList.value[3].value = '0B'
|
||||
uni.showLoading({
|
||||
title: '清除中...',
|
||||
mask: true
|
||||
@@ -98,6 +234,8 @@
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 2500);
|
||||
} else if (item.title == '升级版本') {
|
||||
checkVersionUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +304,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
initCurrentVersion()
|
||||
settingList.value[3].value = await getCacheSizeData()
|
||||
getUserProfile().then(res => {
|
||||
if (res.code === 200 && res.data) {
|
||||
const phone = res.data.phone || ''
|
||||
|
||||
Reference in New Issue
Block a user