From d243cd46debbd5325a488ac117b8871c532c1eac Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Sat, 26 Aug 2023 18:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 13 +- api/config.js | 6 + pages.json | 20 +- pages/oaLogin/oaLogin.vue | 1 + store/modules/config.js | 41 +-- subpkg/blockTransaction/blockTransaction.vue | 18 +- uni_modules/guyue-updater/assets/bg1.png | Bin 0 -> 34588 bytes uni_modules/guyue-updater/assets/bg2.png | Bin 0 -> 12855 bytes uni_modules/guyue-updater/assets/close.png | Bin 0 -> 1343 bytes uni_modules/guyue-updater/changelog.md | 6 + uni_modules/guyue-updater/index.js | 24 ++ uni_modules/guyue-updater/interface.ts | 12 + uni_modules/guyue-updater/package.json | 82 +++++ uni_modules/guyue-updater/pages/updater.vue | 315 +++++++++++++++++++ uni_modules/guyue-updater/readme.md | 65 ++++ uni_modules/guyue-updater/updater.js | 30 ++ utils/oahttp.js | 1 + 17 files changed, 594 insertions(+), 40 deletions(-) create mode 100644 api/config.js create mode 100644 uni_modules/guyue-updater/assets/bg1.png create mode 100644 uni_modules/guyue-updater/assets/bg2.png create mode 100644 uni_modules/guyue-updater/assets/close.png create mode 100644 uni_modules/guyue-updater/changelog.md create mode 100644 uni_modules/guyue-updater/index.js create mode 100644 uni_modules/guyue-updater/interface.ts create mode 100644 uni_modules/guyue-updater/package.json create mode 100644 uni_modules/guyue-updater/pages/updater.vue create mode 100644 uni_modules/guyue-updater/readme.md create mode 100644 uni_modules/guyue-updater/updater.js diff --git a/App.vue b/App.vue index c3a1689..640bc25 100644 --- a/App.vue +++ b/App.vue @@ -1,10 +1,12 @@ + + diff --git a/uni_modules/guyue-updater/readme.md b/uni_modules/guyue-updater/readme.md new file mode 100644 index 0000000..ccb2b01 --- /dev/null +++ b/uni_modules/guyue-updater/readme.md @@ -0,0 +1,65 @@ +# App热更新 + +App热更新模块,支持apk安装以及wgt升级,支持显示弹窗升级、静默更新以及强制更新,支持进度显示,支持覆盖原生tabbar、原生导航栏。 +可用于自建热更新渠道,不依赖于云服务,无云服务费用支出,也可以适配官方更新中心。 + +## 使用说明 +### 1.将此项目导入自己的项目工程 +### 2.在page.json中注册页面,如下 + ```javascript + { + "path": "uni_modules/guyue-updater/pages/updater", + "style": { + "navigationStyle": "custom", + "backgroundColor": "transparent", + "disableScroll": true, + "app-plus": { + "backgroundColorTop": "transparent", + "background": "transparent", + "scrollIndicator": false, + "titleNView": false, + "popGesture": "none", + "bounce": "none", + "animationType": "fade-in", + "animationDuration": 200 + } + } + } + ``` +### 3.将版本检测函数导入需要使用的页面 + 一般在App.vue中的onLaunch导入或者首页导入,需要自行完成热更新检查,一般在APP启动时发起一个请求获取热更新数据,数据获取后,可以调用该组件完成更新。 + ```javascript + import Updater from '@/uni_modules/guyue-updater/index'; + + // 仅在app平台有效,其他平台调用无效 + Updater.update({ + title: '发现新版本', + content: '1. 我们更新了新的UI设计\n2. 我们更新了新的UI设计\n3. 我们更新了新的UI设计\n4. 我们更新了新的UI设计\n', + versionName: '1.3.6', + downUrl: 'https://cdn.xxx.cn/mp/__UNI__1F29D65.wgt', + force: false, + }) + ``` +## 参数说明 +```javascript +export type UpdateParams = { + content: string; // 必填,更新内容,内容中使用 \n 进行换行 + downUrl: string; // 必填,wgt热更新请给出 .wgt 的文件地址,APK整包更新请设置下载apk地址,ios请设置苹果商店的连接地址; + title?: string; // 用于显示弹窗标题,默认 发现新版本 + versionName?: string; // 版本名,用于显示更新版本,如 1.0.0 + quiet?: boolean; // 是否是静默更新,开启后,不会有弹窗,会在后台下载更新文件,在下次启动APP时使用更新 + force?: boolean; // 是否是强制更新,开启后,弹窗无法被关闭,必须更新 + updateBtnText?: string; // 升级按钮文字,默认 立即升级 + downMsgTip?: string; // 仅android,默认 下载中,请稍后 + downSucTip?: string; // 仅android,默认 下载完成,安装中 + downErrorTip?: string; // 仅android,默认 下载失败,请重试 +} +``` + +## Android如何跳转到应用市场更新 + +downUrl 设置为应用市场的地址即可,如: market://details?id={这里写你的应用包名} + +## iOS 如何跳转到AppStore + +downUrl 设置为AppStore的地址即可,如: itms-apps://itunes.apple.com/cn/app/hello-uni-app/id1417078253 \ No newline at end of file diff --git a/uni_modules/guyue-updater/updater.js b/uni_modules/guyue-updater/updater.js new file mode 100644 index 0000000..2adb9cc --- /dev/null +++ b/uni_modules/guyue-updater/updater.js @@ -0,0 +1,30 @@ + +export const download = ({ url, onProgress, onSuccess, onFail }) => { + const task = uni.downloadFile({ + url, + success(res) { + if (res.statusCode === 200) { + onSuccess && onSuccess(res.tempFilePath); + } + }, + fail() { + onFail && onFail(); + } + }); + task.onProgressUpdate(res => { + onProgress && onProgress(res.progress); + }); +}; + +export const install = (filePath, restart = false) => { + plus.runtime.install(filePath, { + force: true + }, () => { + console.log('install success...'); + if (restart) { + plus.runtime.restart(); + } + }, (e) => { + console.error('install fail...', e); + }); +}; \ No newline at end of file diff --git a/utils/oahttp.js b/utils/oahttp.js index d0ca0ab..d147d9f 100644 --- a/utils/oahttp.js +++ b/utils/oahttp.js @@ -38,6 +38,7 @@ function baseRequestTwo(url, method, data, { // if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token; if (store.state.app.token) header[TOKENNAME] = store.state.app.token; + // header[TOKENNAME] = 'Bearer sdjflidshjgfkbdasgjmasbgvhauuiavhkesvndkaesbvkjsdbv'; return new Promise((reslove, reject) => { // uni.showLoading({