index.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. import { REQUEST_CONFIG } from '../../config';
  2. /** 获取小程序配置信息版本号,用于控制是否加载前端缓存更新 */
  3. export const useFrontEndConfigVersion = async () => {
  4. return new Promise((resolve) => {
  5. uni.request({
  6. url: `${REQUEST_CONFIG.BASE_URL}api/smallproFrontEndConfigVersion/localConfig.do`,
  7. method: 'GET',
  8. data: {},
  9. success(resp: any) {
  10. // 判断最新获取到的版本号是否与本地保持一致 保持一致修改缓存frontEndConfigRequest 用于判断当前是否要重新请求
  11. if (uni.getStorageSync('frontEndConfigVersion') == resp.data.frontEndConfigVersion) {
  12. uni.setStorageSync('frontEndConfigRequest', false);
  13. } else {
  14. // 不一致 代表当前前端配置信息更新
  15. uni.setStorageSync('frontEndConfigRequest', true);
  16. uni.setStorageSync('frontEndConfigVersion', resp.data.frontEndConfigVersion);
  17. }
  18. resolve(false);
  19. },
  20. fail(error) {
  21. // 如果是因为网络错误一律,前端配置信息一律都重新请求
  22. uni.setStorageSync('frontEndConfigRequest', true);
  23. resolve(false);
  24. },
  25. });
  26. });
  27. };