小程序 - 页面固定文案全部改读后台配置(购买、登录、资料、首页、分享、介绍页),代码里不再硬编码 - 已拥有课程时在当前页提示,不再跳购买页再提示 - 介绍页正文由代码常量改为读 settings.page.formula.content 服务端 - 课程相关报错文案(不存在 / 已下架 / 课时不存在 / 未购买 / 已过期 / 重复购买 / 未配置支付商品)改读配置,代码保留默认值兜底 - 新增支付总开关 pay.blocked:打开即拦截下单并下发配置里的提示;开关存在数据库里,开发库与生产库各一份(开发库已开,生产库未设) 后台 - 系统配置页按页面分组折叠,默认收起;认不出来的配置归入「其他」 配套数据(不在代码里):对应的 settings 行已写入生产库与开发库
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
// pages/IndexNewCourseDetails/IndexNewCourseDetails.js
|
|
const api = require('../../utils/api');
|
|
const store = require('../../utils/store');
|
|
|
|
const app = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
html: ' ',
|
|
courseCode: '',
|
|
courseTitle: '',
|
|
priceYuan: '',
|
|
buyText: '',
|
|
contactText: '',
|
|
/** 是否已拥有这门课:已拥有时按钮就在本页提示,不再跳购买页 */
|
|
owned: false,
|
|
},
|
|
|
|
onLoad(options) {
|
|
const id = options.id;
|
|
if (!id) return;
|
|
|
|
api
|
|
.getHomeCourses()
|
|
.then((list) => {
|
|
const item = (list || []).filter((c) => String(c.id) === String(id))[0];
|
|
if (!item) return;
|
|
this.setData({
|
|
html: item.content || ' ',
|
|
courseCode: item.courseCode || '',
|
|
courseTitle: item.courseTitle || '',
|
|
});
|
|
this.refreshOwned();
|
|
})
|
|
.catch((err) => console.error('[IndexNewCourseDetails] 加载失败', err));
|
|
},
|
|
|
|
onShow() {
|
|
app.ready().then(() => {
|
|
this.applyConfig();
|
|
// 买完回来要立刻变成「已拥有」,所以每次显示都重新问一次
|
|
this.refreshOwned();
|
|
});
|
|
},
|
|
|
|
/** 查这门课的拥有状态。拿不到就按未拥有处理,不影响正常购买。 */
|
|
refreshOwned() {
|
|
const code = this.data.courseCode;
|
|
if (!code) return;
|
|
api
|
|
.getCourse(code)
|
|
.then((course) => this.setData({ owned: !!course.owned }))
|
|
.catch((err) => console.warn('[IndexNewCourseDetails] 拥有状态加载失败', err));
|
|
},
|
|
|
|
/** 按钮文案取自后台配置,后台改完小程序下拉刷新即可生效。 */
|
|
applyConfig() {
|
|
this.setData({
|
|
buyText: store.cfg('course.button.buy'),
|
|
contactText: store.cfg('course.button.contact'),
|
|
});
|
|
},
|
|
|
|
/** 购买统一走商业化页面。 */
|
|
toBuy() {
|
|
if (!this.data.courseCode) return;
|
|
// 已经拥有就不必再跳过去了:原地提示一句
|
|
if (this.data.owned) {
|
|
wx.showToast({ title: store.cfg('course.tip.owned'), icon: 'none' });
|
|
return;
|
|
}
|
|
wx.navigateTo({ url: '/pages/buy/buy?code=' + this.data.courseCode });
|
|
},
|
|
});
|