小程序 - 页面固定文案全部改读后台配置(购买、登录、资料、首页、分享、介绍页),代码里不再硬编码 - 已拥有课程时在当前页提示,不再跳购买页再提示 - 介绍页正文由代码常量改为读 settings.page.formula.content 服务端 - 课程相关报错文案(不存在 / 已下架 / 课时不存在 / 未购买 / 已过期 / 重复购买 / 未配置支付商品)改读配置,代码保留默认值兜底 - 新增支付总开关 pay.blocked:打开即拦截下单并下发配置里的提示;开关存在数据库里,开发库与生产库各一份(开发库已开,生产库未设) 后台 - 系统配置页按页面分组折叠,默认收起;认不出来的配置归入「其他」 配套数据(不在代码里):对应的 settings 行已写入生产库与开发库
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
// pages/ChangeUserInfo/ChangeUserInfo.js
|
|
const api = require('../../utils/api');
|
|
const store = require('../../utils/store');
|
|
const config = require('../../config/index');
|
|
|
|
const app = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
// wxml 里直接用它拼头像路径,保持不变
|
|
BaseURL: config.STATIC_BASE_URL,
|
|
activeNames: [],
|
|
username: '',
|
|
HeadiconID: 0,
|
|
list: 50,
|
|
// 表单上的固定文案,全部来自后台配置
|
|
labelName: '',
|
|
placeholderName: '',
|
|
labelAvatar: '',
|
|
textSubmit: '',
|
|
},
|
|
|
|
onLoad() {
|
|
app.ready().then(() => this.applyUser());
|
|
},
|
|
|
|
onShow() {
|
|
this.applyUser();
|
|
},
|
|
|
|
applyUser() {
|
|
const user = store.getUser() || {};
|
|
this.setData({
|
|
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'),
|
|
});
|
|
},
|
|
|
|
onChange(event) {
|
|
let inputVal = event.detail;
|
|
// 只保留中英文与数字
|
|
inputVal = inputVal.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '');
|
|
// 去掉开头的数字
|
|
inputVal = inputVal.replace(/^[0-9]+/, '');
|
|
inputVal = inputVal.substring(0, 8);
|
|
this.setData({ username: inputVal });
|
|
},
|
|
|
|
selectHeadicon(event) {
|
|
this.setData({ HeadiconID: event.currentTarget.dataset.index });
|
|
},
|
|
|
|
onChange2(event) {
|
|
this.setData({ activeNames: event.detail });
|
|
},
|
|
|
|
onConfirm() {
|
|
const nickname = (this.data.username || '').trim();
|
|
if (!nickname) {
|
|
wx.showToast({ title: '请输入用户名', icon: 'none' });
|
|
return;
|
|
}
|
|
|
|
wx.showModal({
|
|
title: store.cfg('common.dialog.title'),
|
|
content: store.cfg('profile.confirm.save'),
|
|
confirmColor: '#ff0000',
|
|
success: (res) => {
|
|
if (!res.confirm) return;
|
|
wx.showLoading({ title: '提交中', mask: true });
|
|
|
|
api
|
|
.updateMe({ nickname: nickname, headiconId: this.data.HeadiconID })
|
|
.then((user) => {
|
|
store.setUser(user);
|
|
wx.hideLoading();
|
|
wx.showToast({ title: '成功', icon: 'success', mask: true, duration: 1500 });
|
|
setTimeout(() => wx.switchTab({ url: '/pages/wode/wode' }), 1500);
|
|
})
|
|
.catch((err) => {
|
|
wx.hideLoading();
|
|
wx.showToast({ title: err.message || '修改失败', icon: 'none', mask: true });
|
|
});
|
|
},
|
|
});
|
|
},
|
|
});
|
|
|