Update evolution indices and enhance user experience in mini program

- Added new entries for content ranking algorithm adjustments and cross-platform reuse in the evolution indices for backend, team, and mini program development.
- Improved user interface elements in the mini program, including the addition of a hidden settings entry and refined guidance for profile modifications.
- Enhanced reading statistics display with formatted numbers for better clarity and user engagement.
- Updated reading tracker logic to prevent duplicate duration accumulation and ensure accurate reporting of reading progress.
This commit is contained in:
Alex-larget
2026-03-14 17:13:06 +08:00
parent c936371165
commit 1edceda4db
33 changed files with 773 additions and 75 deletions

View File

@@ -217,16 +217,16 @@ App({
return isDefaultNickname || noAvatar
},
// 登录后若资料未完善,引导跳转到资料编辑
// 登录后若资料未完善,引导跳转到头像昵称引导
_ensureProfileCompletedAfterLogin(user) {
try {
if (!user || !this._isProfileIncomplete(user)) return
const pages = getCurrentPages()
const current = pages[pages.length - 1]
// 避免在资料页内重复跳转
if (current && current.route === 'pages/profile-edit/profile-edit') return
// 避免在头像昵称页或资料编辑页内重复跳转
if (current && (current.route === 'pages/avatar-nickname/avatar-nickname' || current.route === 'pages/profile-edit/profile-edit')) return
wx.showToast({ title: '请先完善头像和昵称', icon: 'none', duration: 2000 })
wx.navigateTo({ url: '/pages/profile-edit/profile-edit' })
wx.navigateTo({ url: '/pages/avatar-nickname/avatar-nickname' })
} catch (e) {
console.warn('[App] 跳转资料编辑页失败:', e)
}

View File

@@ -21,7 +21,8 @@
"pages/mentors/mentors",
"pages/mentor-detail/mentor-detail",
"pages/profile-show/profile-show",
"pages/profile-edit/profile-edit"
"pages/profile-edit/profile-edit",
"pages/avatar-nickname/avatar-nickname"
],
"window": {
"backgroundTextStyle": "light",

View File

@@ -0,0 +1,155 @@
/**
* Soul创业派对 - 头像昵称引导页
* 登录后资料未完善时引导用户修改默认头像和昵称,仅包含头像+昵称两项
*/
const app = getApp()
Page({
data: {
statusBarHeight: 44,
avatar: '',
nickname: '',
saving: false,
showAvatarModal: false,
},
onLoad() {
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 44 })
this.loadFromUser()
},
loadFromUser() {
const user = app.globalData.userInfo
if (!app.globalData.isLoggedIn || !user?.id) {
wx.showToast({ title: '请先登录', icon: 'none' })
setTimeout(() => getApp().goBackOrToHome(), 1500)
return
}
const nickname = (user.nickname || user.nickName || '').trim()
const avatar = user.avatar || user.avatarUrl || ''
this.setData({ nickname, avatar })
},
goBack() {
getApp().goBackOrToHome()
},
onNicknameInput(e) {
this.setData({ nickname: e.detail.value })
},
onNicknameChange(e) {
this.setData({ nickname: e.detail.value })
},
onAvatarTap() {
wx.showActionSheet({
itemList: ['使用微信头像', '从相册选择'],
success: (res) => {
if (res.tapIndex === 0) {
this.setData({ showAvatarModal: true })
} else if (res.tapIndex === 1) {
this.chooseAvatarFromAlbum()
}
},
})
},
closeAvatarModal() {
this.setData({ showAvatarModal: false })
},
chooseAvatarFromAlbum() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
success: async (res) => {
const tempPath = res.tempFiles[0].tempFilePath
await this.uploadAndSaveAvatar(tempPath)
},
})
},
async onChooseAvatar(e) {
const tempAvatarUrl = e.detail?.avatarUrl
this.setData({ showAvatarModal: false })
if (!tempAvatarUrl) return
await this.uploadAndSaveAvatar(tempAvatarUrl)
},
async uploadAndSaveAvatar(tempPath) {
wx.showLoading({ title: '上传中...', mask: true })
try {
const uploadRes = await new Promise((resolve, reject) => {
wx.uploadFile({
url: app.globalData.baseUrl + '/api/miniprogram/upload',
filePath: tempPath,
name: 'file',
formData: { folder: 'avatars' },
success: (r) => {
try {
const data = JSON.parse(r.data)
if (data.success) resolve(data)
else reject(new Error(data.error || '上传失败'))
} catch {
reject(new Error('解析失败'))
}
},
fail: reject,
})
})
const avatarUrl = app.globalData.baseUrl + uploadRes.data.url
this.setData({ avatar: avatarUrl })
await app.request({
url: '/api/miniprogram/user/profile',
method: 'POST',
data: { userId: app.globalData.userInfo?.id, avatar: avatarUrl },
})
if (app.globalData.userInfo) {
app.globalData.userInfo.avatar = avatarUrl
wx.setStorageSync('userInfo', app.globalData.userInfo)
}
wx.hideLoading()
wx.showToast({ title: '头像已更新', icon: 'success' })
} catch (e) {
wx.hideLoading()
wx.showToast({ title: e.message || '上传失败', icon: 'none' })
}
},
async saveProfile() {
const userId = app.globalData.userInfo?.id
if (!userId) {
wx.showToast({ title: '请先登录', icon: 'none' })
return
}
const nickname = (this.data.nickname || '').trim()
const avatar = (this.data.avatar || '').trim()
if (!nickname) {
wx.showToast({ title: '请输入昵称', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await app.request({
url: '/api/miniprogram/user/profile',
method: 'POST',
data: { userId, avatar: avatar || undefined, nickname },
})
if (app.globalData.userInfo) {
if (nickname) app.globalData.userInfo.nickname = nickname
if (avatar) app.globalData.userInfo.avatar = avatar
wx.setStorageSync('userInfo', app.globalData.userInfo)
}
wx.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => getApp().goBackOrToHome(), 800)
} catch (e) {
wx.showToast({ title: e.message || '保存失败', icon: 'none' })
}
this.setData({ saving: false })
},
goToFullProfile() {
wx.navigateTo({ url: '/pages/profile-edit/profile-edit' })
},
})

View File

@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "完善资料",
"usingComponents": {}
}

View File

@@ -0,0 +1,67 @@
<!--Soul创业派对 - 头像昵称引导页,仅头像+昵称-->
<view class="page">
<view class="nav-bar" style="padding-top: {{statusBarHeight}}px;">
<view class="nav-back" bindtap="goBack"><text class="back-icon"></text></view>
<text class="nav-title">完善资料</text>
<view class="nav-placeholder"></view>
</view>
<view style="height: {{statusBarHeight + 44}}px;"></view>
<view class="content">
<!-- 引导文案 -->
<view class="guide-card">
<text class="guide-icon">👋</text>
<text class="guide-title">完善头像和昵称</text>
<text class="guide-desc">让他人更好地认识你,展示更专业的形象</text>
</view>
<!-- 头像 -->
<view class="avatar-section">
<view class="avatar-wrap" bindtap="onAvatarTap">
<view class="avatar-inner">
<image wx:if="{{avatar}}" class="avatar-img" src="{{avatar}}" mode="aspectFill"/>
<view wx:else class="avatar-placeholder">{{nickname ? nickname[0] : '?'}}</view>
</view>
<view class="avatar-camera">📷</view>
</view>
<text class="avatar-change">点击更换头像</text>
</view>
<!-- 昵称 -->
<view class="form-section">
<text class="form-label">昵称</text>
<view class="form-input-wrap">
<input
class="form-input-inner"
type="nickname"
placeholder="请输入昵称"
value="{{nickname}}"
bindinput="onNicknameInput"
bindchange="onNicknameChange"
maxlength="20"
/>
</view>
<text class="input-tip">微信用户可点击输入框自动填充昵称,或手动输入</text>
</view>
<view class="save-btn" bindtap="saveProfile" disabled="{{saving}}">
{{saving ? '保存中...' : '完成'}}
</view>
<view class="link-row" bindtap="goToFullProfile">
<text class="link-text">完善更多资料</text>
<text class="link-arrow">→</text>
</view>
</view>
<!-- 头像弹窗:使用微信头像 -->
<view class="modal-overlay" wx:if="{{showAvatarModal}}" bindtap="closeAvatarModal">
<view class="modal-content avatar-modal" catchtap="stopPropagation">
<view class="modal-close" bindtap="closeAvatarModal">✕</view>
<text class="avatar-modal-title">使用微信头像</text>
<text class="avatar-modal-desc">点击下方按钮,一键同步当前微信头像</text>
<button class="btn-choose-avatar" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar">使用微信头像</button>
<view class="avatar-modal-cancel" bindtap="closeAvatarModal">取消</view>
</view>
</view>
</view>

View File

@@ -0,0 +1,271 @@
/* Soul创业派对 - 头像昵称引导页 */
.page {
background: #050B14;
min-height: 100vh;
color: #fff;
width: 100%;
box-sizing: border-box;
}
.nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
align-items: center;
justify-content: space-between;
height: 44px;
padding: 0 24rpx;
background: rgba(5, 11, 20, 0.9);
backdrop-filter: blur(8rpx);
border-bottom: 1rpx solid rgba(255, 255, 255, 0.08);
}
.nav-back {
width: 60rpx;
padding: 16rpx 0;
}
.back-icon {
font-size: 44rpx;
color: #5EEAD4;
}
.nav-title {
font-size: 36rpx;
font-weight: 600;
}
.nav-placeholder {
width: 60rpx;
}
.content {
padding: 32rpx 24rpx;
box-sizing: border-box;
}
.guide-card {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
padding: 48rpx 32rpx;
background: rgba(94, 234, 212, 0.08);
border: 1rpx solid rgba(94, 234, 212, 0.25);
border-radius: 24rpx;
margin-bottom: 48rpx;
}
.guide-icon {
font-size: 64rpx;
margin-bottom: 16rpx;
}
.guide-title {
font-size: 36rpx;
font-weight: 700;
color: #5EEAD4;
margin-bottom: 12rpx;
}
.guide-desc {
font-size: 26rpx;
color: rgba(148, 163, 184, 0.95);
line-height: 1.5;
}
.avatar-section {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 48rpx;
}
.avatar-wrap {
position: relative;
width: 192rpx;
height: 192rpx;
border-radius: 50%;
border: 4rpx solid #5EEAD4;
box-shadow: 0 0 30rpx rgba(94, 234, 212, 0.3);
}
.avatar-inner {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
}
.avatar-img {
width: 100%;
height: 100%;
display: block;
}
.avatar-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 72rpx;
font-weight: bold;
color: #5EEAD4;
background: rgba(94, 234, 212, 0.2);
}
.avatar-camera {
position: absolute;
bottom: -8rpx;
right: -8rpx;
width: 56rpx;
height: 56rpx;
background: #5EEAD4;
color: #000;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 28rpx;
border: 4rpx solid #050B14;
box-sizing: border-box;
}
.avatar-change {
font-size: 28rpx;
color: #5EEAD4;
font-weight: 500;
margin-top: 16rpx;
}
.form-section {
margin-bottom: 32rpx;
}
.form-label {
display: block;
font-size: 24rpx;
color: #94A3B8;
margin-bottom: 12rpx;
margin-left: 8rpx;
}
.form-input-wrap {
padding: 24rpx 32rpx;
background: #17212F;
border: 1rpx solid rgba(255, 255, 255, 0.08);
border-radius: 24rpx;
box-sizing: border-box;
}
.form-input-inner {
width: 100%;
font-size: 28rpx;
color: #fff;
background: transparent;
box-sizing: border-box;
display: block;
}
.input-tip {
margin-top: 8rpx;
font-size: 22rpx;
color: #94A3B8;
margin-left: 8rpx;
display: block;
}
.save-btn {
width: 100%;
height: 96rpx;
line-height: 96rpx;
text-align: center;
background: #5EEAD4;
color: #050B14;
font-size: 36rpx;
font-weight: bold;
border-radius: 24rpx;
margin-top: 24rpx;
margin-bottom: 32rpx;
}
.save-btn[disabled] {
opacity: 0.6;
}
.link-row {
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
padding: 24rpx;
}
.link-text {
font-size: 28rpx;
color: #94A3B8;
}
.link-arrow {
font-size: 28rpx;
color: #5EEAD4;
}
/* 头像弹窗 */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(16rpx);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
padding: 48rpx;
box-sizing: border-box;
}
.modal-content {
width: 100%;
max-width: 640rpx;
background: #0b1220;
border-radius: 32rpx;
padding: 48rpx;
position: relative;
box-sizing: border-box;
}
.modal-close {
position: absolute;
top: 24rpx;
right: 24rpx;
width: 56rpx;
height: 56rpx;
border-radius: 50%;
background: rgba(255, 255, 255, 0.08);
display: flex;
align-items: center;
justify-content: center;
font-size: 28rpx;
color: rgba(255, 255, 255, 0.7);
}
.avatar-modal-title {
display: block;
font-size: 36rpx;
font-weight: 700;
text-align: center;
margin-bottom: 12rpx;
}
.avatar-modal-desc {
display: block;
font-size: 26rpx;
color: #94A3B8;
text-align: center;
margin-bottom: 32rpx;
}
.btn-choose-avatar {
width: 100%;
height: 88rpx;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
background: #5EEAD4;
color: #050B14;
font-size: 30rpx;
font-weight: 600;
border-radius: 44rpx;
border: none;
}
.btn-choose-avatar::after {
border: none;
}
.avatar-modal-cancel {
margin-top: 24rpx;
text-align: center;
font-size: 28rpx;
color: #9CA3AF;
}

View File

@@ -482,49 +482,24 @@ Page({
wx.switchTab({ url: '/pages/match/match' })
},
// 最新新增:用 latest-chapters 接口(后端按 updated_at 取前 N 条),不拉全量,支持万级文章
async loadLatestChapters() {
try {
const res = await app.request({ url: '/api/miniprogram/book/all-chapters', silent: true })
const chapters = (res && res.data) || (res && res.chapters) || []
const res = await app.request({ url: '/api/miniprogram/book/latest-chapters', silent: true })
const list = (res && res.data) ? res.data : []
const pt = (c) => (c.partTitle || c.part_title || '').toLowerCase()
const exclude = c => !pt(c).includes('序言') && !pt(c).includes('尾声') && !pt(c).includes('附录')
// stitch_soul优先取 isNew 标记的章节;若无则取最近更新的前 10 章(排除序言/尾声/附录)
let candidates = chapters.filter(c => (c.isNew || c.is_new) === true && exclude(c))
if (candidates.length === 0) {
candidates = chapters.filter(exclude)
}
// 解析「第X场」用于倒序最新场次大放在最上方
const sessionNum = (c) => {
const title = c.section_title || c.sectionTitle || c.title || c.chapterTitle || ''
const m = title.match(/第\s*(\d+)\s*场/) || title.match(/第(\d+)场/)
if (m) return parseInt(m[1], 10)
const id = c.id != null ? String(c.id) : ''
if (/^\d+$/.test(id)) return parseInt(id, 10)
return 0
}
const latest = candidates
.sort((a, b) => {
const na = sessionNum(a)
const nb = sessionNum(b)
if (na !== nb) return nb - na // 场次倒序:最新在上
return new Date(b.updatedAt || b.updated_at || 0) - new Date(a.updatedAt || a.updated_at || 0)
})
const latest = list
.filter(exclude)
.slice(0, 10)
.map(c => {
const d = new Date(c.updatedAt || c.updated_at || Date.now())
const title = c.section_title || c.sectionTitle || c.title || c.chapterTitle || ''
const rawContent = (c.content || '').replace(/<[^>]+>/g, '').trim()
// 描述仅用正文摘要,避免 #id 或标题重复;截取 36 字
let desc = ''
if (rawContent && rawContent.length > 0) {
const clean = rawContent.replace(/^#[\d.]+\s*/, '').trim()
desc = clean.length > 36 ? clean.slice(0, 36) + '...' : clean
}
return {
id: c.id,
mid: c.mid ?? c.MID ?? 0,
title,
desc,
desc: '', // latest-chapters 不返回 content避免大表全量加载
price: c.price ?? 1,
dateStr: `${d.getMonth() + 1}/${d.getDate()}`
}

View File

@@ -5,6 +5,7 @@
*/
const app = getApp()
const { formatStatNum } = require('../../utils/util.js')
Page({
data: {
@@ -28,6 +29,9 @@ Page({
// 阅读统计
totalReadTime: 0,
matchHistory: 0,
readCountText: '0',
totalReadTimeText: '0',
matchHistoryText: '0',
// 最近阅读
recentChapters: [],
@@ -128,25 +132,32 @@ Page({
earningsLoading: true,
recentChapters: [],
totalReadTime: 0,
matchHistory: 0
matchHistory: 0,
readCountText: '0',
totalReadTimeText: '0',
matchHistoryText: '0'
})
this.loadDashboardStats()
this.loadMyEarnings()
this.loadPendingConfirm()
this.loadVipStatus()
} else {
const guestReadCount = app.getReadCount()
this.setData({
isLoggedIn: false,
userInfo: null,
userIdShort: '',
readCount: app.getReadCount(),
readCount: guestReadCount,
readCountText: formatStatNum(guestReadCount),
referralCount: 0,
earnings: '-',
pendingEarnings: '-',
earningsLoading: false,
recentChapters: [],
totalReadTime: 0,
matchHistory: 0
matchHistory: 0,
totalReadTimeText: '0',
matchHistoryText: '0'
})
}
},
@@ -175,10 +186,16 @@ Page({
}))
: []
const readCount = Number(res.data.readCount || 0)
const totalReadTime = Number(res.data.totalReadMinutes || 0)
const matchHistory = Number(res.data.matchHistory || 0)
this.setData({
readCount: Number(res.data.readCount || 0),
totalReadTime: Number(res.data.totalReadMinutes || 0),
matchHistory: Number(res.data.matchHistory || 0),
readCount,
totalReadTime,
matchHistory,
readCountText: formatStatNum(readCount),
totalReadTimeText: formatStatNum(totalReadTime),
matchHistoryText: formatStatNum(matchHistory),
recentChapters
})
} catch (e) {

View File

@@ -46,7 +46,7 @@
</view>
<view class="profile-stats-row">
<view class="profile-stat" bindtap="goToChapters">
<text class="profile-stat-val">{{readCount}}</text>
<text class="profile-stat-val">{{readCountText}}</text>
<text class="profile-stat-label">已读章节</text>
</view>
<view class="profile-stat" bindtap="goToReferral">
@@ -94,17 +94,17 @@
<view class="stats-grid">
<view class="stat-box" bindtap="goToChapters">
<image class="stat-icon-img" src="/assets/icons/book-open-teal.svg" mode="aspectFit"/>
<text class="stat-num">{{readCount}}</text>
<text class="stat-num">{{readCountText}}</text>
<text class="stat-label">已读章节</text>
</view>
<view class="stat-box" bindtap="goToChapters">
<image class="stat-icon-img" src="/assets/icons/clock-teal.svg" mode="aspectFit"/>
<text class="stat-num">{{totalReadTime}}</text>
<text class="stat-num">{{totalReadTimeText}}</text>
<text class="stat-label">阅读分钟</text>
</view>
<view class="stat-box" bindtap="goToMatch">
<image class="stat-icon-img" src="/assets/icons/users-teal.svg" mode="aspectFit"/>
<text class="stat-num">{{matchHistory}}</text>
<text class="stat-num">{{matchHistoryText}}</text>
<text class="stat-label">匹配伙伴</text>
</view>
</view>
@@ -154,7 +154,7 @@
</view>
<text class="menu-arrow"></text>
</view>
<view class="menu-item" bindtap="handleMenuTap" data-id="settings">
<view class="menu-item" wx:if="{{false}}" bindtap="handleMenuTap" data-id="settings">
<view class="menu-left">
<view class="menu-icon-wrap icon-gray"><image class="menu-icon-img" src="/assets/icons/settings-gray.svg" mode="aspectFit"/></view>
<text class="menu-text">设置</text>

View File

@@ -95,6 +95,19 @@ Page({
goBack() { getApp().goBackOrToHome() },
onShareAppMessage() {
const ref = app.getMyReferralCode()
return {
title: 'Soul创业派对 - 编辑资料',
path: ref ? `/pages/profile-edit/profile-edit?ref=${ref}` : '/pages/profile-edit/profile-edit'
}
},
onShareTimeline() {
const ref = app.getMyReferralCode()
return { title: 'Soul创业派对 - 编辑资料', query: ref ? `ref=${ref}` : '' }
},
onNicknameInput(e) { this.setData({ nickname: e.detail.value }) },
onNicknameChange(e) { this.setData({ nickname: e.detail.value }) },
onRegionInput(e) { this.setData({ region: e.detail.value }) },

View File

@@ -163,8 +163,11 @@
.btn-choose-avatar {
width: 100%;
height: 88rpx;
line-height: 88rpx;
text-align: center;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
background: #5EEAD4;
color: #050B14;
font-size: 30rpx;

View File

@@ -170,10 +170,10 @@ class ReadingTracker {
const userId = app.globalData.userInfo?.id
if (!userId) return
// 计算本次上报的时长
// 计算本次上报的时长(仅发送增量 delta后端会累加避免重复累加导致阅读分钟数异常
const now = Date.now()
const duration = Math.round((now - this.activeTracker.lastScrollTime) / 1000)
this.activeTracker.totalDuration += duration
const delta = Math.round((now - this.activeTracker.lastScrollTime) / 1000)
this.activeTracker.totalDuration += delta
this.activeTracker.lastScrollTime = now
try {
@@ -183,7 +183,7 @@ class ReadingTracker {
userId,
sectionId: this.activeTracker.sectionId,
progress: this.activeTracker.maxProgress,
duration: this.activeTracker.totalDuration,
duration: Math.max(0, delta),
status: this.activeTracker.isCompleted ? 'completed' : 'reading',
completedAt: this.activeTracker.completedAt
}

View File

@@ -32,6 +32,18 @@ const formatMoney = (amount, decimals = 2) => {
return Number(amount).toFixed(decimals)
}
/**
* 格式化统计数字≥1万显示 x.xw≥1千显示 x.xk否则原样
* @param {number} n - 原始数字
* @returns {string}
*/
const formatStatNum = n => {
const num = Number(n) || 0
if (num >= 10000) return (num / 10000).toFixed(1).replace(/\.0$/, '') + 'w'
if (num >= 1000) return (num / 1000).toFixed(1).replace(/\.0$/, '') + 'k'
return String(num)
}
// 防抖函数
const debounce = (fn, delay = 300) => {
let timer = null
@@ -166,6 +178,7 @@ module.exports = {
formatTime,
formatDate,
formatMoney,
formatStatNum,
formatNumber,
debounce,
throttle,