Showing
2 changed files
with
50 additions
and
10 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2023-03-23 11:17:54 | 2 | * @Date: 2023-03-23 11:17:54 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-03-24 16:04:21 | 4 | + * @LastEditTime: 2023-04-17 16:01:15 |
| 5 | * @FilePath: /custom_form/src/app.js | 5 | * @FilePath: /custom_form/src/app.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -19,15 +19,15 @@ const App = createApp({ | ... | @@ -19,15 +19,15 @@ const App = createApp({ |
| 19 | const code = getUrlParams(location.href) | 19 | const code = getUrlParams(location.href) |
| 20 | ? getUrlParams(location.href).code | 20 | ? getUrlParams(location.href).code |
| 21 | : '' | 21 | : '' |
| 22 | - const store = mainStore(); | 22 | + const store = mainStore() |
| 23 | // 数据收集设置 | 23 | // 数据收集设置 |
| 24 | - const { data } = await getFormSettingAPI({ form_code: code }); | 24 | + const { data } = await getFormSettingAPI({ form_code: code }) |
| 25 | - const form_setting = {}; | 25 | + const form_setting = {} |
| 26 | if (data.length) { | 26 | if (data.length) { |
| 27 | - Object.assign(form_setting, data[0]['property_list'], data[0]['extend']); | 27 | + Object.assign(form_setting, data[0]['property_list'], data[0]['extend']) |
| 28 | } | 28 | } |
| 29 | // 缓存表单设置 | 29 | // 缓存表单设置 |
| 30 | - store.changeFormSetting(form_setting); | 30 | + store.changeFormSetting(form_setting) |
| 31 | } | 31 | } |
| 32 | }, | 32 | }, |
| 33 | 33 | ||
| ... | @@ -46,11 +46,10 @@ const App = createApp({ | ... | @@ -46,11 +46,10 @@ const App = createApp({ |
| 46 | }, | 46 | }, |
| 47 | 47 | ||
| 48 | // 对应 onShow | 48 | // 对应 onShow |
| 49 | - onShow(options) { | 49 | + onShow(options) {}, |
| 50 | - }, | ||
| 51 | 50 | ||
| 52 | // 对应 onHide | 51 | // 对应 onHide |
| 53 | - onHide() { }, | 52 | + onHide() {}, |
| 54 | 53 | ||
| 55 | // 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖 | 54 | // 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖 |
| 56 | }) | 55 | }) | ... | ... |
| ... | @@ -16,7 +16,7 @@ import { apiList } from '@/api/wx/jsApiList.js' | ... | @@ -16,7 +16,7 @@ import { apiList } from '@/api/wx/jsApiList.js' |
| 16 | import { styleColor } from "@/constant.js"; | 16 | import { styleColor } from "@/constant.js"; |
| 17 | import { mainStore } from '@/stores' | 17 | import { mainStore } from '@/stores' |
| 18 | import { getFormSettingAPI } from '@/api/form.js' | 18 | import { getFormSettingAPI } from '@/api/form.js' |
| 19 | -import Taro from '@tarojs/taro' | 19 | +import Taro, { useReady } from '@tarojs/taro' |
| 20 | 20 | ||
| 21 | // TAG: 自定义主题颜色 | 21 | // TAG: 自定义主题颜色 |
| 22 | const themeVars = { | 22 | const themeVars = { |
| ... | @@ -114,6 +114,47 @@ onMounted(async () => { | ... | @@ -114,6 +114,47 @@ onMounted(async () => { |
| 114 | }) | 114 | }) |
| 115 | }); | 115 | }); |
| 116 | 116 | ||
| 117 | +// 对应 onReady | ||
| 118 | +useReady(() => { | ||
| 119 | + if (!Taro.canIUse('getUpdateManager')) { | ||
| 120 | + Taro.showModal({ | ||
| 121 | + title: '提示', | ||
| 122 | + content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试', | ||
| 123 | + showCancel: false, | ||
| 124 | + }) | ||
| 125 | + return | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + // https://developers.weixin.qq.com/miniprogram/dev/api/base/update/UpdateManager.html | ||
| 129 | + const updateManager = Taro.getUpdateManager() | ||
| 130 | + | ||
| 131 | + updateManager.onCheckForUpdate((res) => { | ||
| 132 | + // 请求完新版本信息的回调 | ||
| 133 | + if (res.hasUpdate) { | ||
| 134 | + updateManager.onUpdateReady(function () { | ||
| 135 | + Taro.showModal({ | ||
| 136 | + title: '更新提示', | ||
| 137 | + content: '新版本已经准备好,是否重启应用?', | ||
| 138 | + success: function (res) { | ||
| 139 | + if (res.confirm) { | ||
| 140 | + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 | ||
| 141 | + updateManager.applyUpdate() | ||
| 142 | + } | ||
| 143 | + }, | ||
| 144 | + }) | ||
| 145 | + }) | ||
| 146 | + | ||
| 147 | + updateManager.onUpdateFailed(function () { | ||
| 148 | + // 新版本下载失败 | ||
| 149 | + Taro.showModal({ | ||
| 150 | + title: '更新提示', | ||
| 151 | + content: '新版本已上线,请删除当前小程序,重新搜索打开', | ||
| 152 | + }) | ||
| 153 | + }) | ||
| 154 | + } | ||
| 155 | + }) | ||
| 156 | +}) | ||
| 157 | + | ||
| 117 | </script> | 158 | </script> |
| 118 | 159 | ||
| 119 | <style lang="less"> | 160 | <style lang="less"> | ... | ... |
-
Please register or login to post a comment