| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import { REQUEST_CONFIG, frontEndConfig } from '../../../config';
- import { common } from '../../../utils';
- // 获取前端统一缓存配置信息 并返回前端配置信息
- const frontEndConfigFn = () => {
- return new Promise(async (resolve) => {
- let accountInfo = getApp().globalData.accountInfo;
- // 判断正式版本获取线上配置数据
- if (accountInfo.miniProgram.envVersion == 'release') {
- // 获取小程序初始数据
- uni.request({
- url: `${REQUEST_CONFIG.BASE_URL}api/wechaSmallproFrontEndConfig/localConfig.do`,
- method: 'GET',
- data: {},
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- },
- success(resp: any) {
- // 小程登录初始化数据信息 从本地获取
- resp.data.fixedAppjsGlobalData = frontEndConfig.fixedAppjsGlobalData;
- uni.setStorageSync('frontEndConfig', resp.data);
- resolve(resp.data);
- },
- fail(error) {
- resolve(false);
- },
- });
- } else {
- // 否则都取本地数据
- uni.setStorageSync('frontEndConfig', frontEndConfig);
- resolve(frontEndConfig);
- }
- });
- };
- /** 设置前端配置信息处理 */
- export const useSetFrontEndConfig = async () => {
- let has = false;
- let frontEndConfigs: any;
- if (
- uni.getStorageSync('frontEndConfigRequest') ||
- common.isEmpty(uni.getStorageSync('frontEndConfig'))
- ) {
- frontEndConfigs = await frontEndConfigFn();
- } else {
- frontEndConfigs = uni.getStorageSync('frontEndConfig');
- }
- return new Promise(async (resolve) => {
- // 判断是否配置了小程序登录初始化数据信息
- if (!frontEndConfigs.appjsGlobalData) {
- common.showModal('小程序登录初始化数据信息未配置');
- has = true;
- } else {
- /**版本信息 */
- getApp().globalData = Object.assign(getApp().globalData, {
- smallPro_version: getApp().globalData.accountInfo.miniProgram.version || '0.0.0', // 登录请求时版本信息, 本地和体验版本都是0.0.0,正式线用获取的
- ...frontEndConfigs.fixedAppjsGlobalData,
- ...frontEndConfigs.appjsGlobalData,
- });
- }
- // 判断是否配置了前端webUiDiy配置信息
- if (!frontEndConfigs.webUiDiy) {
- common.showModal(
- frontEndConfigs === false ? '网络请求异常,请切换网络重新进入!' : 'webUiDiy配置信息未配置'
- );
- uni.hideLoading();
- has = true;
- } else {
- let config = frontEndConfigs.webUiDiy;
- getApp().globalData.config = frontEndConfigs.webUiDiy;
- /**如果配置了院区并且有区分院区 将院区ID设置为第一个院区的ID */
- let distric =
- config && config.pageConfiguration && config.pageConfiguration.hospitalDistrict_config;
- if (
- getApp().globalData.hasDistrict &&
- distric &&
- distric.districtList instanceof Array &&
- distric.districtList[0].districtId
- ) {
- getApp().globalData.districtId = distric.districtList[0].districtId;
- }
- }
- // 判断当前服务器在更新 跳转温馨提示页
- if (frontEndConfigs.appjsGlobalData.updateOrNot) {
- uni.redirectTo({
- url: `pages/st1/business/otherService/building/building`,
- });
- has = true;
- }
- resolve(has);
- });
- };
|