热更新
BIN
certificate/book.keystore
Normal file
9
certificate/证书信息.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
证书指纹:
|
||||||
|
MD5: 9A:AD:4D:78:17:EE:17:D3:62:B2:6E:B2:56:0B:18:C3
|
||||||
|
SHA1: B1:1E:CE:4B:70:C7:88:B3:6E:8B:B9:05:98:4B:FD:67:81:C1:3A:8F
|
||||||
|
SHA256: A9:78:BD:BF:BB:DE:35:14:AA:5D:45:E9:6A:D0:E5:17:6D:BE:58:86:7A:1D:66:A2:F3:62:2F:E7:9C:9E:59:F6
|
||||||
|
|
||||||
|
|
||||||
|
别名: __uni__9f097f0
|
||||||
|
证书密码为:uZ6Stufj
|
||||||
|
包名:com.tianranqi.app
|
@ -2,13 +2,15 @@
|
|||||||
import { onLaunch, onShow, onHide, onLoad, onReady } from '@dcloudio/uni-app'
|
import { onLaunch, onShow, onHide, onLoad, onReady } from '@dcloudio/uni-app'
|
||||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||||
import { beforEach } from '@/router/index'
|
import { beforEach } from '@/router/index'
|
||||||
import { jurisdictionApi } from '@/api/system/login';
|
import { jurisdictionApi } from '@/api/system';
|
||||||
import { useAppStore } from '@/store'
|
import { useAppStore, useUpdateApp } from '@/store'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function (options) {
|
onLaunch: function (options) {
|
||||||
console.log('App Launch')
|
console.log('App Launch')
|
||||||
console.log('应用启动路径:', options.path)
|
console.log('应用启动路径:', options.path)
|
||||||
|
// 检查更新
|
||||||
|
useUpdateApp().checkAppUpdate()
|
||||||
},
|
},
|
||||||
onShow: function (options) {
|
onShow: function (options) {
|
||||||
console.log('App Show')
|
console.log('App Show')
|
||||||
|
@ -21,6 +21,18 @@ export function loginApi(config : LoginParams) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 热更新
|
||||||
|
* @param
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function upDateAppApi() {
|
||||||
|
return http({
|
||||||
|
url: '/sys/common/upDateApp',
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取是否灰化
|
* 获取是否灰化
|
||||||
* @param id 登录参数
|
* @param id 登录参数
|
||||||
@ -33,5 +45,6 @@ export function jurisdictionApi(id : string) { // 是否灰化
|
|||||||
data: {
|
data: {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
0
src/api/user/index.ts
Normal file
@ -69,7 +69,7 @@
|
|||||||
import { useRouter } from '@/plugin/uni-mini-router'
|
import { useRouter } from '@/plugin/uni-mini-router'
|
||||||
// import { useParamsStore } from '@/store/page-params'
|
// import { useParamsStore } from '@/store/page-params'
|
||||||
import Base64 from 'base-64';
|
import Base64 from 'base-64';
|
||||||
import { loginApi } from '@/api/system/login';
|
import { loginApi } from '@/api/system';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'login',
|
name: 'login',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { createPinia, defineStore } from 'pinia'
|
import { createPinia, defineStore } from 'pinia'
|
||||||
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
||||||
|
import { upDateAppApi } from '@/api/system';
|
||||||
|
import { hasNewVersion, onClickUpdate } from '@/utils/index';
|
||||||
const store = createPinia()
|
const store = createPinia()
|
||||||
store.use(
|
store.use(
|
||||||
createPersistedState({
|
createPersistedState({
|
||||||
@ -22,6 +23,66 @@ export const useAppStore = defineStore('app', {
|
|||||||
persist: true, // 启用持久化
|
persist: true, // 启用持久化
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const useUpdateApp = defineStore('updateApp', () => {
|
||||||
|
const updateOptions = reactive({
|
||||||
|
force: false,
|
||||||
|
hasNew: false,
|
||||||
|
content: '',
|
||||||
|
url: '',
|
||||||
|
apkUrl: '',
|
||||||
|
wgtUrl: ''
|
||||||
|
})
|
||||||
|
const systemInfo = uni.getSystemInfoSync()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前处于APP_PLUS时 检查是否有新版本
|
||||||
|
*
|
||||||
|
* @param to 是否跳转新页面显示更新 默认值false
|
||||||
|
*/
|
||||||
|
function checkAppUpdate(to = false) {
|
||||||
|
try {
|
||||||
|
upDateAppApi().then(async (res : any) => {
|
||||||
|
let {
|
||||||
|
result
|
||||||
|
} = res
|
||||||
|
result.apkUrl = import.meta.env.VITE_SERVER_BASEURL + '/sys/common/static/' + result.apkUrl;
|
||||||
|
result.wgtUrl = import.meta.env.VITE_SERVER_BASEURL + '/sys/common/static/' + result.wgtUrl
|
||||||
|
updateOptions.wgtUrl = result.wgtUrl
|
||||||
|
if (systemInfo.osName === 'android') {
|
||||||
|
// Android
|
||||||
|
updateOptions.apkUrl = result.apkUrl
|
||||||
|
// #ifdef APP_PLUS
|
||||||
|
updateOptions.hasNew = await hasNewVersion(result.versionCode, result.update == 'wgt') as boolean
|
||||||
|
// #endif
|
||||||
|
} else {
|
||||||
|
// IOS
|
||||||
|
updateOptions.url = `itms-apps://itunes.apple.com/cn/app/id${123456}?mt=8`
|
||||||
|
}
|
||||||
|
updateOptions.hasNew &&
|
||||||
|
uni.showModal({
|
||||||
|
title: '更新',
|
||||||
|
content: '发现新版本,请更新',
|
||||||
|
success(res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
onClickUpdate(result.update, result)
|
||||||
|
} else {
|
||||||
|
plus.runtime.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
updateOptions.hasNew = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
checkAppUpdate,
|
||||||
|
...toRefs(updateOptions),
|
||||||
|
systemInfo
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
export default store
|
export default store
|
||||||
|
|
||||||
// 模块统一导出
|
// 模块统一导出
|
||||||
|
@ -215,3 +215,106 @@ export function formatDate(value, fmt) {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有新版本
|
||||||
|
* @param version 接口返回的版本号
|
||||||
|
* @param isWgt 是否是热资源更新 默认不是
|
||||||
|
*/
|
||||||
|
export const hasNewVersion = (version, isWgt = false) => {
|
||||||
|
// #ifdef APP_PLUS
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const transfer = (str) => str.replace(/\./g, '')
|
||||||
|
if (isWgt) {
|
||||||
|
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||||
|
const currentVersion = widgetInfo.version
|
||||||
|
resolve(+transfer(version) > +transfer(currentVersion))
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const currentVersion = plus.runtime.version
|
||||||
|
resolve(+transfer(version) > +transfer(currentVersion))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onClickUpdate(updateType : string, url) {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
if (updateType != 'wgt') plus.runtime.openURL(url.apkUrl)
|
||||||
|
else downloadApp(url.wgtUrl)
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadApp(url : string) {
|
||||||
|
console.log('url', url);
|
||||||
|
var dtask = plus.downloader.createDownload(url, {
|
||||||
|
filename: `_downloads/wgt-${Date.now()}.wgt` //利用保存路径,实现下载文件的重命名
|
||||||
|
}, function (d, status) {
|
||||||
|
//d为下载的文件对象
|
||||||
|
if (status == 200) {
|
||||||
|
//下载成功,d.filename是文件在保存在本地的相对路径,使用下面的API可转为平台绝对路径
|
||||||
|
var fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename);
|
||||||
|
console.log('fileSaveUrl', fileSaveUrl);
|
||||||
|
installApp(fileSaveUrl)
|
||||||
|
} else {
|
||||||
|
//下载失败
|
||||||
|
plus.downloader.clear(); //清除下载任务
|
||||||
|
uni.showToast({
|
||||||
|
title: 'App下载失败!',
|
||||||
|
icon: 'error'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
let prg = 0
|
||||||
|
let showLoading = plus.nativeUI.showWaiting('正在下載')
|
||||||
|
dtask.start()
|
||||||
|
dtask.addEventListener('statechanged', (task) => {
|
||||||
|
// 给下载任务设置一个监听 并根据状态 做操作
|
||||||
|
switch (task.state) {
|
||||||
|
case 1:
|
||||||
|
showLoading.setTitle("正在下载")
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
showLoading.setTitle("已连接到服务器")
|
||||||
|
break
|
||||||
|
case 3: {
|
||||||
|
const downloaded = +task.downloadedSize; // 转为数字
|
||||||
|
const total = +task.totalSize; // 转为数字
|
||||||
|
prg = total > 0 ? Math.floor((downloaded / total) * 100) : 0;
|
||||||
|
showLoading.setTitle(`正在下载 ${prg}%`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
plus.nativeUI.closeWaiting()
|
||||||
|
//下载完成
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function installApp(tempFilePath : string) {
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
plus.runtime.install(
|
||||||
|
tempFilePath, {
|
||||||
|
force: true
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
uni.showModal({
|
||||||
|
title: '更新',
|
||||||
|
content: '更新成功,请点击确认后重启',
|
||||||
|
showCancel: false,
|
||||||
|
success(res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
plus.runtime.restart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
() =>
|
||||||
|
uni.showToast({
|
||||||
|
title: '安装失败!',
|
||||||
|
icon: 'error'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
// #endif
|
||||||
|
}
|
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 689 B |
Before Width: | Height: | Size: 971 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.2 KiB |