| 12345678910111213141516171819202122232425262728 |
- import { REQUEST_CONFIG } from '../../../config';
- /** 获取小程序配置信息版本号,用于控制是否加载前端缓存更新 */
- export const useFrontEndConfigVersion = async () => {
- return new Promise((resolve) => {
- uni.request({
- url: `${REQUEST_CONFIG.BASE_URL}api/smallproFrontEndConfigVersion/localConfig.do`,
- method: 'GET',
- data: {},
- success(resp: any) {
- // 判断最新获取到的版本号是否与本地保持一致 保持一致修改缓存frontEndConfigRequest 用于判断当前是否要重新请求
- if (uni.getStorageSync('frontEndConfigVersion') == resp.data.frontEndConfigVersion) {
- uni.setStorageSync('frontEndConfigRequest', false);
- } else {
- // 不一致 代表当前前端配置信息更新
- uni.setStorageSync('frontEndConfigRequest', true);
- uni.setStorageSync('frontEndConfigVersion', resp.data.frontEndConfigVersion);
- }
- resolve(false);
- },
- fail(error) {
- // 如果是因为网络错误一律,前端配置信息一律都重新请求
- uni.setStorageSync('frontEndConfigRequest', true);
- resolve(false);
- },
- });
- });
- };
|