index.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const config_request = require("../../config/request.js");
  4. const config_frontEndConfig = require("../../config/frontEndConfig.js");
  5. const utils_common = require("../../utils/common.js");
  6. const frontEndConfigFn = () => {
  7. return new Promise(async (resolve) => {
  8. let accountInfo = getApp().globalData.accountInfo;
  9. if (accountInfo.miniProgram.envVersion == "release") {
  10. common_vendor.index.request({
  11. url: `${config_request.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) {
  18. resp.data.fixedAppjsGlobalData = config_frontEndConfig.frontEndConfig.fixedAppjsGlobalData;
  19. common_vendor.index.setStorageSync("frontEndConfig", resp.data);
  20. resolve(resp.data);
  21. },
  22. fail(error) {
  23. resolve(false);
  24. }
  25. });
  26. } else {
  27. common_vendor.index.setStorageSync("frontEndConfig", config_frontEndConfig.frontEndConfig);
  28. resolve(config_frontEndConfig.frontEndConfig);
  29. }
  30. });
  31. };
  32. const useSetFrontEndConfig = async () => {
  33. let has = false;
  34. let frontEndConfigs;
  35. if (common_vendor.index.getStorageSync("frontEndConfigRequest") || utils_common.isEmpty(common_vendor.index.getStorageSync("frontEndConfig"))) {
  36. frontEndConfigs = await frontEndConfigFn();
  37. } else {
  38. frontEndConfigs = common_vendor.index.getStorageSync("frontEndConfig");
  39. }
  40. return new Promise(async (resolve) => {
  41. if (!frontEndConfigs.appjsGlobalData) {
  42. utils_common.showModal("小程序登录初始化数据信息未配置");
  43. has = true;
  44. } else {
  45. getApp().globalData = Object.assign(getApp().globalData, {
  46. smallPro_version: getApp().globalData.accountInfo.miniProgram.version || "0.0.0",
  47. // 登录请求时版本信息, 本地和体验版本都是0.0.0,正式线用获取的
  48. ...frontEndConfigs.fixedAppjsGlobalData,
  49. ...frontEndConfigs.appjsGlobalData
  50. });
  51. }
  52. if (!frontEndConfigs.webUiDiy) {
  53. utils_common.showModal(
  54. frontEndConfigs === false ? "网络请求异常,请切换网络重新进入!" : "webUiDiy配置信息未配置"
  55. );
  56. common_vendor.index.hideLoading();
  57. has = true;
  58. } else {
  59. let config = frontEndConfigs.webUiDiy;
  60. getApp().globalData.config = frontEndConfigs.webUiDiy;
  61. let distric = config && config.pageConfiguration && config.pageConfiguration.hospitalDistrict_config;
  62. if (getApp().globalData.hasDistrict && distric && distric.districtList instanceof Array && distric.districtList[0].districtId) {
  63. getApp().globalData.districtId = distric.districtList[0].districtId;
  64. }
  65. }
  66. if (frontEndConfigs.appjsGlobalData.updateOrNot) {
  67. common_vendor.index.redirectTo({
  68. url: `pages/st1/business/otherService/building/building`
  69. });
  70. has = true;
  71. }
  72. resolve(has);
  73. });
  74. };
  75. exports.useSetFrontEndConfig = useSetFrontEndConfig;
  76. //# sourceMappingURL=../../../.sourcemap/mp-alipay/hook/use-front-end-config/index.js.map