index.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { REQUEST_CONFIG, frontEndConfig } from '../../../config';
  2. import { common } from '../../../utils';
  3. // 获取前端统一缓存配置信息 并返回前端配置信息
  4. const frontEndConfigFn = () => {
  5. return new Promise(async (resolve) => {
  6. let accountInfo = getApp().globalData.accountInfo;
  7. // 判断正式版本获取线上配置数据
  8. if (accountInfo.miniProgram.envVersion == 'release') {
  9. // 获取小程序初始数据
  10. uni.request({
  11. url: `${REQUEST_CONFIG.BASE_URL}api/wechaSmallproFrontEndConfig/localConfig.do`,
  12. method: 'GET',
  13. data: {},
  14. header: {
  15. 'content-type': 'application/x-www-form-urlencoded',
  16. },
  17. success(resp: any) {
  18. // 小程登录初始化数据信息 从本地获取
  19. resp.data.fixedAppjsGlobalData = frontEndConfig.fixedAppjsGlobalData;
  20. uni.setStorageSync('frontEndConfig', resp.data);
  21. resolve(resp.data);
  22. },
  23. fail(error) {
  24. resolve(false);
  25. },
  26. });
  27. } else {
  28. // 否则都取本地数据
  29. uni.setStorageSync('frontEndConfig', frontEndConfig);
  30. resolve(frontEndConfig);
  31. }
  32. });
  33. };
  34. /** 设置前端配置信息处理 */
  35. export const useSetFrontEndConfig = async () => {
  36. let has = false;
  37. let frontEndConfigs: any;
  38. if (
  39. uni.getStorageSync('frontEndConfigRequest') ||
  40. common.isEmpty(uni.getStorageSync('frontEndConfig'))
  41. ) {
  42. frontEndConfigs = await frontEndConfigFn();
  43. } else {
  44. frontEndConfigs = uni.getStorageSync('frontEndConfig');
  45. }
  46. return new Promise(async (resolve) => {
  47. // 判断是否配置了小程序登录初始化数据信息
  48. if (!frontEndConfigs.appjsGlobalData) {
  49. common.showModal('小程序登录初始化数据信息未配置');
  50. has = true;
  51. } else {
  52. /**版本信息 */
  53. getApp().globalData = Object.assign(getApp().globalData, {
  54. smallPro_version: getApp().globalData.accountInfo.miniProgram.version || '0.0.0', // 登录请求时版本信息, 本地和体验版本都是0.0.0,正式线用获取的
  55. ...frontEndConfigs.fixedAppjsGlobalData,
  56. ...frontEndConfigs.appjsGlobalData,
  57. });
  58. }
  59. // 判断是否配置了前端webUiDiy配置信息
  60. if (!frontEndConfigs.webUiDiy) {
  61. common.showModal(
  62. frontEndConfigs === false ? '网络请求异常,请切换网络重新进入!' : 'webUiDiy配置信息未配置'
  63. );
  64. uni.hideLoading();
  65. has = true;
  66. } else {
  67. let config = frontEndConfigs.webUiDiy;
  68. getApp().globalData.config = frontEndConfigs.webUiDiy;
  69. /**如果配置了院区并且有区分院区 将院区ID设置为第一个院区的ID */
  70. let distric =
  71. config && config.pageConfiguration && config.pageConfiguration.hospitalDistrict_config;
  72. if (
  73. getApp().globalData.hasDistrict &&
  74. distric &&
  75. distric.districtList instanceof Array &&
  76. distric.districtList[0].districtId
  77. ) {
  78. getApp().globalData.districtId = distric.districtList[0].districtId;
  79. }
  80. }
  81. // 判断当前服务器在更新 跳转温馨提示页
  82. if (frontEndConfigs.appjsGlobalData.updateOrNot) {
  83. uni.redirectTo({
  84. url: `pages/st1/business/otherService/building/building`,
  85. });
  86. has = true;
  87. }
  88. resolve(has);
  89. });
  90. };