react-app-shell
Version:
react打包脚本和example, 这里的版本请忽略
88 lines (80 loc) • 3.12 kB
JavaScript
// 功能方法>>>引用:
import {observable, action} from 'mobx';
// 服务接口>>>引用:
import {landingPageService} from '../service';
// 公用方法>>>引用:
import {message} from '../utils';
/**
* landing页面状态
*/
class LandingStore {
/**
* 数据源
*/
state = {
configId: '',
bannerImgUrl: '', // 首页banner
endTime: '', // 倒计时时间
nowTime: '', // 服务器现在时间
buttonImg: '', // 按钮图
productCourse: {
productId: '', // 生成订单id
productNum: '', // 约课数量
productOriginPrize: '', // 原价
productPrize: '', // 现价
productPeriod: '', // 有效期
},
mainImg: '', // 内容区域图
buyStatus: '', // 购买状态
activeState: '', // 活动状态
shareOptions: {
title: '', // 分享标题
desc: '', // 分享描述
imgUrl: '' // 分享图标
},
serviceError: false, // 获取信息时 接口是否发生异常或者超时
}
// 初始化页面数据方法
initData = async (id) => {
try {
// 展示loading
message.showLoading('加载中');
const landingPageConfig = await landingPageService.getLandingPageConfig(id);
// 数据赋值
this.state = {
...this.state,
configId: landingPageConfig.configId,
endTime: Date.parse(landingPageConfig.endTime.replace(/-/g, '/')),
nowTime: Date.parse(landingPageConfig.nowTime.replace(/-/g, '/')),
buttonImg: landingPageConfig.buttonImg,
productCourse: {
productId: landingPageConfig.productCourse.productId,
productNum: landingPageConfig.productCourse.productNum,
productOriginPrize: landingPageConfig.productCourse.productOriginPrize,
productPrize: landingPageConfig.productCourse.productPrize,
productPeriod: landingPageConfig.productCourse.productPeriod
},
bannerImgUrl: landingPageConfig.bannerImg,
mainImg: landingPageConfig.mainImg,
buyStatus: landingPageConfig.buyStatus,
activeState: landingPageConfig.activityProcessStatus,
shareOptions: {
title: landingPageConfig.shareTitle,
desc: landingPageConfig.shareContent,
imgUrl: landingPageConfig.shareImg
},
serviceError: false,
};
} catch (error) {
// 获取信息时 接口超时显示该页面 不把错误信息展示给用户
this.state = {
serviceError: true
};
// myToast.error(error && error.msg || '初始化数据失败');
} finally {
// 关闭loading
message.closeLoading();
}
}
}
export default new LandingStore();