2025/9/26/1:02

This commit is contained in:
2025-09-26 01:02:43 +08:00
parent c1b7a1174d
commit 578d49826b
10 changed files with 199 additions and 49 deletions

View File

@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@@ -0,0 +1,26 @@
Component({
data: {
},
lifetimes: {
attached() {
// 组件被挂载时执行
const id = this.properties.id; // 从 properties 获取
this.getCardDetail(id);
}
},
properties: {
id: {
type: String,
value: ''
}
},
methods: {
getCardDetail(id: string) {
console.log("切换到:", id);
},
getArticleComments(id:string){
}
}
})

View File

@@ -0,0 +1,3 @@
<view>
<a></a>
</view>

View File

@@ -1,50 +1,17 @@
Component({
data: {
rawCardData: [
{
"article_id": 123123148,
"article_title": "多选测试",
"vote_type": "multiple",
"total_voters": 3,
"end_time": "2025-10-22 00:59:59",
"is_ended": false,
"publisher_id": "xlsisanasifknfdg",
"create_time": "2025-09-24 23:10:22",
"options": [
{ "id": 69, "name": "Go", "votes": 1, "is_voted": false },
{ "id": 70, "name": "Python", "votes": 1, "is_voted": false },
{ "id": 71, "name": "Rust", "votes": 1, "is_voted": false }
],
"user_has_voted": false,
"user_voted_option_ids": null
},
{
"article_id": 123123149,
"article_title": "单选测试",
"vote_type": "single",
"total_voters": 5,
"end_time": "2025-10-25 12:00:00",
"is_ended": false,
"publisher_id": "another_user_id",
"create_time": "2025-09-25 10:00:00",
"options": [
{ "id": 72, "name": "JavaScript", "votes": 3, "is_voted": false },
{ "id": 73, "name": "TypeScript", "votes": 2, "is_voted": false },
{ "id": 74, "name": "Java", "votes": 0, "is_voted": false }
],
"user_has_voted": false,
"user_voted_option_ids": null
}
],
processedCardsData: [] as any[]
},
lifetimes: {
attached() {
const processedData = this.processVoteData(this.data.rawCardData);
this.setData({
processedCardsData: processedData
});
}
attached() {
// 从全局获取处理后的卡片数据
const app = getApp();
app.fetchRawCardData().then(cards => {
this.setData({ processedCardsData: cards });
}).catch(err => {
wx.showToast({ title: '加载失败', icon: 'none' });
});
},
},
methods: {
processVoteData(cards: any[]): any[] {
@@ -152,6 +119,13 @@ Component({
icon: 'success',
duration: 2000
});
},
goToDetail(e: { currentTarget: { dataset: { id: any; }; }; }) {
const id = e.currentTarget.dataset.id;
console.log(id)
wx.navigateTo({
url: `/pages/articledetail/articledetail?id=${id}`,
});
}
}
});

View File

@@ -9,8 +9,12 @@
>
<view class="cards-container">
<block wx:for="{{processedCardsData}}" wx:for-item="card" wx:key="article_id">
<view class="voting-card">
<view class="card-header">
<view class="voting-card"
>
<view class="card-header"
bindtap="goToDetail"
data-id="{{card.article_id}}"
>
<view class="user-info">
<image src="https://picsum.photos/id/100/200/200" mode="widthFix" class="avatar" alt="用户头像"></image>
<view class="user-details">
@@ -23,7 +27,8 @@
<view class="divider"></view>
<view class="vote-title-section">
<view class="vote-title-section" bindtap="goToDetail"
data-id="{{card.article_id}}">
<text class="vote-title">{{card.article_title}} ({{card.vote_type === 'single' ? '单选' : '多选'}})</text>
<text class="vote-desc"></text>
</view>
@@ -63,7 +68,10 @@
</block>
</view>
<view class="vote-stats">
<view class="vote-stats"
bindtap="goToDetail"
data-id="{{card.article_id}}"
>
<text class="stats-text">已有 {{card.total_voters}} 人参与投票</text>
<text class="stats-text">{{card.is_ended ? '已结束' : '剩余 ' + card.end_time}}</text>
</view>

View File

@@ -1,4 +1,7 @@
// index.ts
import { IAppOption } from "../../../typings";
// 获取应用实例
const app = getApp<IAppOption>()
Component({