first commit

This commit is contained in:
Blizzard
2026-03-05 09:08:21 +08:00
commit 0a61c4ddec
2189 changed files with 38610 additions and 0 deletions
+116
View File
@@ -0,0 +1,116 @@
/**
* 收听历史 — 从后端获取历史列表
*/
const app = getApp()
const api = require('../../utils/api')
const util = require('../../utils/util')
Page({
data: {
filter: 'all',
cleared: false,
historyList: [],
isPlaying: false,
loading: true
},
onShow() {
this._refresh()
this._onPlayerChange = () => this._updatePlayState()
app.on('playerStateChange', this._onPlayerChange)
},
onHide() {
if (this._onPlayerChange) app.off('playerStateChange', this._onPlayerChange)
},
_refresh() {
if (this.data.cleared) return
const self = this
const gd = app.globalData
api.getHistoryList({ current: 1, pageSize: 30 }).then(function (res) {
if (res.code === 200 && res.data) {
var list = res.data.list || res.data || []
// 附带格式化信息
list = list.map(function (item) {
// 节目可能包含频道信息,根据后端返回结构适配
var channel = item.channel || item.program && item.program.channel || {}
var program = item.program || item
return Object.assign({}, program, {
_domainName: channel.name || program.channelName || '',
_icon: channel.icon || '🎵',
_bgColor: channel.bgColor || '#F0F0F0',
_coverUrl: (channel.cover && channel.cover.url) || channel.coverUrl || '',
_friendlyDate: util.getFriendlyDate(
program.createdAt ? program.createdAt.substring(0, 10) : ''
),
durationText: util.formatTime(program.duration || 0),
_isThisPlaying: gd.activeContent && gd.activeContent.id === program.id
})
})
self.setData({ historyList: list, isPlaying: gd.isPlaying, loading: false })
} else {
self.setData({ historyList: [], loading: false })
}
}).catch(function (err) {
console.error('[History] 加载历史失败:', err)
self.setData({ loading: false })
})
},
/**
* 仅更新播放状态
*/
_updatePlayState() {
var gd = app.globalData
var list = this.data.historyList.map(function (item) {
return Object.assign({}, item, {
_isThisPlaying: gd.activeContent && gd.activeContent.id === item.id
})
})
this.setData({ historyList: list, isPlaying: gd.isPlaying })
},
setFilter(e) {
this.setData({ filter: e.currentTarget.dataset.val })
},
onPlay(e) {
const id = e.currentTarget.dataset.id
const gd = app.globalData
// 从已加载数据中查找
var content = null
for (var i = 0; i < this.data.historyList.length; i++) {
if (this.data.historyList[i].id === id) {
content = this.data.historyList[i]
break
}
}
if (!content) return
if (gd.activeContent && gd.activeContent.id === id) {
app.togglePlay()
} else {
app.playContent(content)
}
},
onClear() {
const self = this
wx.showModal({
title: '提示',
content: '确定要清空所有收听历史吗?',
success(res) {
if (res.confirm) {
self.setData({ cleared: true, historyList: [] })
}
}
})
}
})
+6
View File
@@ -0,0 +1,6 @@
{
"usingComponents": {
"global-player": "/components/global-player/index"
},
"navigationBarTitleText": "收听历史"
}
+71
View File
@@ -0,0 +1,71 @@
<!-- 收听历史 —— 按日期倒序的已听列表 -->
<view class="history-page">
<!-- 筛选Tab + 清空按钮 -->
<view class="filter-header">
<view class="filter-tabs">
<text
class="tab {{filter === 'all' ? 'active' : ''}}"
bindtap="setFilter"
data-val="all"
>全部片段</text>
<text
class="tab {{filter === 'subscribed' ? 'active' : ''}}"
bindtap="setFilter"
data-val="subscribed"
>仅看已订阅</text>
</view>
<view class="clear-btn tap-active" bindtap="onClear">
<text class="clear-icon">🗑</text>
<text class="clear-text">清空</text>
</view>
</view>
<!-- 历史列表 -->
<view class="list-area">
<!-- 空状态 -->
<view wx:if="{{cleared || historyList.length === 0}}" class="empty-state">
<view class="empty-icon-wrap">
<text class="empty-emoji">📭</text>
</view>
<text class="empty-text">暂无收听历史</text>
</view>
<!-- 历史条目 -->
<view
wx:for="{{historyList}}"
wx:key="id"
class="history-item card"
bindtap="onPlay"
data-id="{{item.id}}"
>
<!-- 频道图标 -->
<view class="h-icon" style="background: {{item._bgColor}};">
<image wx:if="{{item._coverUrl}}" src="{{item._coverUrl}}" class="h-cover-img" mode="aspectFill" />
<text wx:else class="h-emoji">{{item._icon}}</text>
</view>
<!-- 信息 -->
<view class="h-info">
<text class="h-channel">{{item._domainName}}</text>
<text class="h-title {{item._isThisPlaying ? 'text-primary' : ''}}">{{item.title}}</text>
<text class="h-meta">{{item._friendlyDate}} · {{item.durationText}}</text>
</view>
<!-- 播放指示 -->
<view wx:if="{{item._isThisPlaying && isPlaying}}" class="playing-indicator">
<view class="bar bar-1"></view>
<view class="bar bar-2"></view>
<view class="bar bar-3"></view>
</view>
<view wx:else class="play-mini">
<image src="/assets/icons/play.svg" class="play-mini-icon" />
</view>
</view>
</view>
<view style="height: 200rpx;"></view>
<global-player />
</view>
+177
View File
@@ -0,0 +1,177 @@
/* 收听历史样式 */
.history-page {
min-height: 100vh;
background: var(--color-bg-page);
}
/* 筛选头部 */
.filter-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16rpx 32rpx;
background: #FFFFFF;
border-bottom: 1rpx solid #F5F5F5;
}
.clear-btn {
display: flex;
align-items: center;
}
.clear-icon {
font-size: 22rpx;
margin-right: 6rpx;
}
.clear-text {
font-size: 22rpx;
color: #999;
font-weight: 500;
}
/* 筛选Tab */
.filter-tabs {
display: flex;
gap: 32rpx;
}
.tab {
font-size: 26rpx;
font-weight: 700;
color: #999;
padding-bottom: 12rpx;
border-bottom: 4rpx solid transparent;
transition: all 0.2s;
}
.tab.active {
color: #333;
border-bottom-color: var(--color-primary);
}
/* 列表 */
.list-area {
padding: 20rpx 32rpx;
}
/* 空状态 */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
padding: 160rpx 0;
opacity: 0.5;
}
.empty-icon-wrap {
width: 128rpx;
height: 128rpx;
border-radius: 50%;
background: #F5F5F5;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 24rpx;
}
.empty-emoji {
font-size: 48rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
font-weight: 500;
}
/* 历史条目 */
.history-item {
display: flex;
align-items: center;
padding: 24rpx;
margin-bottom: 20rpx;
}
.history-item:active {
box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.06);
}
.h-icon {
width: 88rpx;
height: 88rpx;
border-radius: 24rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.h-emoji {
font-size: 40rpx;
}
.h-info {
flex: 1;
padding: 0 20rpx;
overflow: hidden;
}
.h-channel {
display: block;
font-size: 20rpx;
font-weight: 700;
color: #999;
letter-spacing: 2rpx;
margin-bottom: 6rpx;
}
.h-title {
display: block;
font-size: 26rpx;
font-weight: 700;
color: #333;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.h-title.text-primary {
color: var(--color-primary);
}
.h-meta {
display: block;
font-size: 20rpx;
color: #BBB;
margin-top: 6rpx;
font-weight: 500;
}
/* 播放指示器 */
.playing-indicator {
display: flex;
align-items: flex-end;
gap: 4rpx;
width: 48rpx;
height: 48rpx;
justify-content: center;
flex-shrink: 0;
}
.bar {
width: 6rpx;
border-radius: 4rpx;
background: var(--color-primary);
animation: bounce 0.6s ease-in-out infinite;
}
.bar-1 { height: 24rpx; animation-delay: 0s; }
.bar-2 { height: 40rpx; animation-delay: 0.1s; }
.bar-3 { height: 16rpx; animation-delay: 0.2s; }
@keyframes bounce {
0%, 100% { transform: scaleY(0.4); }
50% { transform: scaleY(1); }
}
.play-mini {
width: 56rpx;
height: 56rpx;
border-radius: 50%;
border: 2rpx solid #EEE;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.play-mini-icon {
width: 20rpx;
height: 20rpx;
opacity: 0.4;
}