文案配置化 + 支付开关

小程序
- 页面固定文案全部改读后台配置(购买、登录、资料、首页、分享、介绍页),代码里不再硬编码
- 已拥有课程时在当前页提示,不再跳购买页再提示
- 介绍页正文由代码常量改为读 settings.page.formula.content

服务端
- 课程相关报错文案(不存在 / 已下架 / 课时不存在 / 未购买 / 已过期 / 重复购买 / 未配置支付商品)改读配置,代码保留默认值兜底
- 新增支付总开关 pay.blocked:打开即拦截下单并下发配置里的提示;开关存在数据库里,开发库与生产库各一份(开发库已开,生产库未设)

后台
- 系统配置页按页面分组折叠,默认收起;认不出来的配置归入「其他」

配套数据(不在代码里):对应的 settings 行已写入生产库与开发库
This commit is contained in:
Yeomai committed 2026-10-01 11:28:29 +08:00
1 parent c45025fc86
commit 879e74ebda
21 files changed
+325 -103

No files matched your search

@@ -13,6 +13,11 @@ Page({
username: '',
HeadiconID: 0,
list: 50,
// 表单上的固定文案,全部来自后台配置
labelName: '',
placeholderName: '',
labelAvatar: '',
textSubmit: '',
},
onLoad() {
@@ -29,6 +34,10 @@ Page({
username: user.nickname || '',
HeadiconID: user.headiconId || 0,
list: parseInt(store.cfg('profile.headicon_count'), 10) || 0,
labelName: store.cfg('profile.form.name'),
placeholderName: store.cfg('profile.form.namePlaceholder'),
labelAvatar: store.cfg('profile.form.avatar'),
textSubmit: store.cfg('profile.form.submit'),
});
},
@@ -58,8 +67,8 @@ Page({
}
wx.showModal({
title: '提示',
content: '确定修改个人资料吗?',
title: store.cfg('common.dialog.title'),
content: store.cfg('profile.confirm.save'),
confirmColor: '#ff0000',
success: (res) => {
if (!res.confirm) return;
@@ -1,15 +1,15 @@
<van-cell-group>
<van-field
label="用户名"
label="{{labelName}}"
value="{{username}}"
placeholder="请输入用户名"
placeholder="{{placeholderName}}"
border="true"
bind:change="onChange"
/>
</van-cell-group>
<van-collapse value="{{ activeNames }}" bind:change="onChange2">
<van-collapse-item title="头像" name="1">
<van-collapse-item title="{{labelAvatar}}" name="1">
<view style="display: flex; justify-content: center; padding: 20rpx 0;">
<van-image width="120rpx" height="120rpx" src="{{BaseURL}}/Images/Headicons/Headicon{{HeadiconID}}.png" />
</view>
@@ -22,5 +22,5 @@
</van-collapse>
<view class="button-container" style="text-align: center;padding: 20rpx;">
<van-button type="primary" bind:click="onConfirm">确认修改</van-button>
</view>
<van-button type="primary" bind:click="onConfirm">{{textSubmit}}</van-button>
</view>
@@ -1,6 +1,7 @@
// pages/IndexFreeCourseDetails/IndexFreeCourseDetails.js
const api = require('../../utils/api');
const format = require('../../utils/format');
const store = require('../../utils/store');
Page({
data: {
@@ -9,6 +10,8 @@ Page({
VideoPlayerSrc: '',
HiddenVideoControl: true,
top: 0,
/** 列表上方的更新期数文案,整句来自后台配置 */
updatedText: '',
},
onLoad(options) {
@@ -32,6 +35,7 @@ Page({
this.setData({
playdata: rows,
VideoTitle: rows.length ? rows[0].videoTitle || '' : '',
updatedText: store.cfg('course.lesson.updated').replace('{n}', rows.length),
});
})
.catch((err) => {
@@ -43,14 +47,14 @@ Page({
onTapLesson(e) {
const item = this.data.playdata[e.currentTarget.dataset.index];
if (!item || !item.videoUrl) {
wx.showToast({ title: '该课时暂无视频', icon: 'none' });
wx.showToast({ title: store.cfg('course.tip.lessonNoVideo'), icon: 'none' });
return;
}
this.setData({ VideoPlayerSrc: item.videoUrl, HiddenVideoControl: false, top: 420 });
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
});
@@ -2,7 +2,7 @@
<scroll-view class="scrollarea" scroll-y type="list" style="top:{{top}}rpx;">
<view class="jieshao">
<text decode class="video_biaoti">&nbsp;&nbsp;{{VideoTitle}}</text>
<text decode class="video_info">&nbsp;&nbsp;已更新{{playdata.length}}期</text>
<text decode class="video_info">&nbsp;&nbsp;{{updatedText}}</text>
</view>
<view class="videolistcontainer" bind:tap="onTapLesson"
@@ -12,6 +12,8 @@ Page({
priceYuan: '',
buyText: '',
contactText: '',
/** 是否已拥有这门课:已拥有时按钮就在本页提示,不再跳购买页 */
owned: false,
},
onLoad(options) {
@@ -28,12 +30,27 @@ Page({
courseCode: item.courseCode || '',
courseTitle: item.courseTitle || '',
});
this.refreshOwned();
})
.catch((err) => console.error('[IndexNewCourseDetails] 加载失败', err));
},
onShow() {
app.ready().then(() => this.applyConfig());
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));
},
/** 按钮文案取自后台配置,后台改完小程序下拉刷新即可生效。 */
@@ -47,6 +64,11 @@ Page({
/** 购买统一走商业化页面。 */
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 });
},
});
@@ -17,7 +17,11 @@ Page({
data: {
userInfo: { avatarUrl: '', nickName: '' },
loginStatue: false,
LoginTag: '一键登录',
LoginTag: '',
// 页面固定文案,全部来自后台配置
pageTitle: '',
pageSubtitle: '',
logoutText: '',
},
onLoad() {
@@ -34,7 +38,10 @@ Page({
const registered = !!(user && user.isLogin === 1);
this.setData({
loginStatue: registered,
LoginTag: registered ? '退出登录' : '一键登录',
LoginTag: registered ? store.cfg('login.button.logout') : store.cfg('login.button.login'),
logoutText: store.cfg('login.button.logout'),
pageTitle: store.cfg('login.title'),
pageSubtitle: store.cfg('login.subtitle'),
userInfo: {
avatarUrl: config.STATIC_BASE_URL + config.PLACEHOLDER.WECHAT,
nickName: registered ? user.nickname : '',
@@ -82,8 +89,8 @@ Page({
onlogout() {
if (!this.data.loginStatue) return;
wx.showModal({
title: '提示',
content: '确定退出登录吗?',
title: store.cfg('common.dialog.title'),
content: store.cfg('login.confirm.logout'),
confirmColor: '#ff0000',
success: (res) => {
if (!res.confirm) return;
@@ -4,10 +4,10 @@
<image class="touxiang_img" src="{{userInfo.avatarUrl}}" mode="" />
</view>
<view class="imgview2">
<text class="imgtext2">叶雷讲数学</text>
<text class="imgtext2">{{pageTitle}}</text>
</view>
<view class="imgview3">
<text class="imgtext3">让数学不再难学</text>
<text class="imgtext3">{{pageSubtitle}}</text>
</view>
<view wx:if="{{!loginStatue}}" class="btn_wrapper">
@@ -17,9 +17,9 @@
</view>
<view wx:else="{{loginStatue}}" class="btn_wrapper">
<button plain class="btn2" bind:tap="onlogout">
<text class="btn_text">退出登录</text>
<text class="btn_text">{{logoutText}}</text>
</button>
</view>
</scroll-view>
</scroll-view>
+15 -4
View File
@@ -16,6 +16,8 @@ Page({
VideoDetails: '',
coverUrl: '',
playdata: [],
/** 列表上方的更新期数文案,整句来自后台配置 */
updatedText: '',
VideoPlayerSrc: '',
HiddenVideoControl: true,
top: 0,
@@ -59,7 +61,7 @@ Page({
})
.catch((err) => {
this.setData({ loading: false });
wx.showToast({ title: err.message || '课程加载失败', icon: 'none' });
wx.showToast({ title: err.message || store.cfg('course.tip.loadFailed'), icon: 'none' });
setTimeout(() => wx.switchTab({ url: '/pages/kecheng/kecheng' }), 1500);
});
},
@@ -77,7 +79,11 @@ Page({
publishedAt: format.toDateString(item.publishedAt),
coverUrl: item.coverUrl,
}));
this.setData({ playdata: rows });
// 期数文案整句来自后台配置,{n} 在这里替换成实际条数
this.setData({
playdata: rows,
updatedText: store.cfg('course.lesson.updated').replace('{n}', rows.length),
});
})
.catch((err) => {
this.setData({ playdata: [] });
@@ -99,18 +105,23 @@ Page({
})
.catch((err) => {
wx.hideLoading();
wx.showToast({ title: err.message || '无法播放', icon: 'none' });
wx.showToast({ title: err.message || store.cfg('course.tip.playFailed'), icon: 'none' });
});
},
/** 购买入口:详情页不做交易,统一跳商业化页面。 */
goBuy() {
if (!this.data.code) 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.code });
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
});
@@ -7,7 +7,7 @@
<view class="jieshao">
<text decode class="video_biaoti">&nbsp;&nbsp;{{VideoTitle}}</text>
<text decode class="video_miaoshu">&nbsp;&nbsp;{{VideoDetails}}</text>
<text decode class="video_info">&nbsp;&nbsp;已更新{{playdata.length}}期</text>
<text decode class="video_info">&nbsp;&nbsp;{{updatedText}}</text>
</view>
<view class="videolistcontainer" bind:tap="onTapLesson"
@@ -1,15 +1,8 @@
// pages/VideoDetailsPage/VideoDetailsPage.js
const htmlSnip =
`<p>
在初中数学的考试当中,解所有题型都需要用到公式,公式的重要性不言而喻!为了更好的帮助孩子们记住初中数学常用的公式、定理,在此老师给大家总结了初中三年所有的公式及定理!这份资料十分珍贵,每次考试都能用的上!
</p>
<p>
<img src="https://api.yeomai.site/WebPages/2/1.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/2.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/3.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/4.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/5.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/6.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/7.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/8.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/9.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/10.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/11.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/12.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/13.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/14.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/15.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/16.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/17.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/18.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/19.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/20.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/21.jpg"/>
</p>
<p>
<br/>
</p>
`
// 正文 HTML 放在后台配置里(settings.page.formula.content),这里只负责取出来交给 Parser 渲染。
const store = require('../../utils/store');
const app = getApp();
Page({
@@ -18,14 +11,15 @@ Page({
* 页面的初始数据
*/
data: {
htmlSnip,
htmlSnip: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 页面可能被直接打开(小程序码、搜一搜),等初始化把站点配置读回来
app.ready().then(() => this.setData({ htmlSnip: store.cfg('page.formula.content') }));
},
/**
@@ -80,4 +74,4 @@ Page({
onShareTimeline(){
}
})
})
@@ -1,6 +1,7 @@
// pages/WebPageDetails/WebPageDetails.js
const api = require('../../utils/api');
const format = require('../../utils/format');
const store = require('../../utils/store');
Page({
data: {
@@ -29,11 +30,11 @@ Page({
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
onShareTimeline() {
return { title: '叶雷讲数学' };
return { title: store.cfg('share.title') };
},
});
+32 -18
View File
@@ -10,8 +10,10 @@ const api = require('../../utils/api');
const format = require('../../utils/format');
const store = require('../../utils/store');
const app = getApp();
const POLL_INTERVAL = 1500;
// 微信的发货推送实测要 13~17 秒才到,原来只等 12 秒,用户多半看到「可能稍有延迟」而不是「购买成功」
// 微信的发货推送实测要 13~17 秒才到,原来只等 12 秒,用户多半先拿到兜底提示而不是成功提示
const POLL_MAX = 20;
/** iPhone 上跑 Apple 支付要求微信客户端 ≥ 这个版本 */
@@ -50,9 +52,17 @@ Page({
coverUrl: '',
priceYuan: '',
list: [],
// 页面上的固定文案全部来自后台配置,这里只放容器
textBuy: '',
textBuyList: '',
textPaying: '',
textOwned: '',
textEmpty: '',
},
onLoad(options) {
// 页面可能被直接打开(分享、扫码),先等初始化把站点配置读回来
app.ready().then(() => this.applyTexts());
const code = options && options.code;
if (code) {
this.setData({ code: code });
@@ -62,6 +72,16 @@ Page({
this.loadList();
},
applyTexts() {
this.setData({
textBuy: store.cfg('course.buy.button'),
textBuyList: store.cfg('course.buy.buttonList'),
textPaying: store.cfg('course.buy.paying'),
textOwned: store.cfg('course.buy.owned'),
textEmpty: store.cfg('course.buy.empty'),
});
},
load(code) {
api
.getCourse(code)
@@ -74,12 +94,12 @@ Page({
priceYuan: format.fenToYuan(course.priceFen),
});
// 已经拥有就不用再买了,避免重复下单
if (course.owned) this.rejectOut('你已经拥有这门课程');
if (course.owned) this.rejectOut(store.cfg('course.tip.owned'));
})
.catch((err) => {
this.setData({ loading: false });
// 课程被下架或课程号拼错,后端会返回错误,这里按同样的方式退出
this.rejectOut((err && err.message) || '课程不存在');
this.rejectOut((err && err.message) || store.cfg('course.tip.notFound'));
});
},
@@ -100,7 +120,7 @@ Page({
})
.catch((err) => {
this.setData({ loading: false });
wx.showToast({ title: (err && err.message) || '课程加载失败', icon: 'none' });
wx.showToast({ title: (err && err.message) || store.cfg('course.tip.loadFailed'), icon: 'none' });
});
},
@@ -131,9 +151,9 @@ Page({
// 购买的前置条件:用户主动使用过登录功能。静默登录不算。
if (!store.isLoggedIn()) {
wx.showModal({
title: '请先登录',
content: '使用微信登录后才能购买课程',
confirmText: '去登录',
title: store.cfg('course.login.title'),
content: store.cfg('course.login.desc'),
confirmText: store.cfg('course.login.confirm'),
success: (res) => {
if (res.confirm) {
wx.navigateTo({ url: '/pages/LoginOrOutDetails/LoginOrOutDetails' });
@@ -152,7 +172,7 @@ Page({
if (!this.checkIosVersion()) return;
this.setData({ buying: true });
wx.showLoading({ title: '发起支付', mask: true });
wx.showLoading({ title: store.cfg('course.loading.paying'), mask: true });
api
.createOrder(code)
@@ -188,13 +208,7 @@ Page({
if (!version || compareVersion(version, IOS_MIN_WECHAT) >= 0) return true;
wx.showModal({
title: '请先升级微信',
content:
'iPhone 上购买课程需要微信 ' +
IOS_MIN_WECHAT +
' 及以上版本,你当前是 ' +
version +
'。请到 App Store 更新微信后重试。',
content: '请先升级微信',
showCancel: false,
confirmText: '知道了',
});
@@ -212,7 +226,7 @@ Page({
return api.getOrder(outTradeNo).then((order) => {
if (order.status === 2) {
this.setData({ buying: false, owned: true });
wx.showToast({ title: '购买成功', icon: 'success', mask: true });
wx.showToast({ title: store.cfg('course.tip.buySuccess'), icon: 'success', mask: true });
// 单课程模式从详情页进来,买完退回去;列表模式留在原地刷新
if (this.data.code) {
setTimeout(() => this.back(), 1500);
@@ -223,7 +237,7 @@ Page({
}
if (attempts >= POLL_MAX || order.status === 3 || order.status === 4) {
this.setData({ buying: false });
wx.showToast({ title: '支付已提交,开通可能稍有延迟', icon: 'none', duration: 3000 });
wx.showToast({ title: store.cfg('course.tip.payPending'), icon: 'none', duration: 3000 });
return;
}
return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL)).then(poll);
@@ -233,6 +247,6 @@ Page({
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
});
+3 -3
View File
@@ -10,7 +10,7 @@
class="buy-btn"
disabled="{{buying || owned}}"
bindtap="buyNow"
>{{owned ? '已拥有' : (buying ? '支付中…' : '立即购买')}}</button>
>{{owned ? textOwned : (buying ? textPaying : textBuy)}}</button>
</view>
<view class="buy-list" wx:else>
@@ -25,10 +25,10 @@
disabled="{{buying || item.owned}}"
data-code="{{item.code}}"
bindtap="buyNow"
>{{item.owned ? '已拥有' : '购买'}}</button>
>{{item.owned ? textOwned : textBuyList}}</button>
</view>
<view class="buy-empty" wx:if="{{!loading && list.length === 0}}">
<text>暂无可购买的课程</text>
<text>{{textEmpty}}</text>
</view>
</view>
</view>
+4 -4
View File
@@ -111,9 +111,9 @@ Page({
updateManager.onCheckForUpdate(() => {});
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
title: store.cfg('app.update.title'),
showCancel: false,
content: '新版本已准备好,即将重启应用',
content: store.cfg('app.update.content'),
success: (res) => {
if (res.confirm) updateManager.applyUpdate();
},
@@ -174,10 +174,10 @@ Page({
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
onShareTimeline() {
return { title: '叶雷讲数学' };
return { title: store.cfg('share.title') };
},
});
+1 -1
View File
@@ -69,7 +69,7 @@ Page({
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
});
+7 -7
View File
@@ -10,8 +10,9 @@ Page({
showCode: false,
headiconUrl: '',
isLoggedIn: false,
userNameText: '未登录',
loginBtnText: '登录注册',
// 文字全部来自后台配置
userNameText: '',
loginBtnText: '',
version: '',
qrcodeUrl: '',
text2: '',
@@ -52,8 +53,8 @@ Page({
const registered = !!(user && user.isLogin === 1);
this.setData({
isLoggedIn: registered,
userNameText: registered ? user.nickname : '未登录',
loginBtnText: registered ? '退出登录' : '登录注册',
userNameText: registered ? user.nickname : store.cfg('profile.user.guest'),
loginBtnText: registered ? store.cfg('login.button.logout') : store.cfg('profile.button.login'),
// 未登录一律用默认头像:静默登录仍会带回上次设置的头像,
// 不挡住的话退出登录后还会显示用户自己的头像。
headiconUrl:
@@ -69,7 +70,7 @@ Page({
toChangeUserInfo() {
if (!this.data.isLoggedIn) {
wx.showToast({ mask: true, icon: 'error', title: '请先登录' });
wx.showToast({ mask: true, icon: 'error', title: store.cfg('profile.tip.needLogin') });
return;
}
wx.navigateTo({ url: '/pages/ChangeUserInfo/ChangeUserInfo' });
@@ -84,7 +85,6 @@ Page({
},
onShareAppMessage() {
return { title: '叶雷讲数学', path: '/pages/index/index' };
return { title: store.cfg('share.title'), path: '/pages/index/index' };
},
});