基本成型
This commit is contained in:
@@ -11,19 +11,33 @@ App<IAppOption>({
|
||||
] ,
|
||||
processedCardsData: []
|
||||
},
|
||||
processedCardsData: [],
|
||||
onLaunch() {
|
||||
const token = wx.getStorageSync("token");
|
||||
const token = wx.getStorageSync("ttk_token");
|
||||
if (token) {
|
||||
this.globalData.token = token;
|
||||
}
|
||||
const userinfo = wx.getStorageSync("ttk_userInfo");
|
||||
console.log("系统重启获取userinfo2:",userinfo)
|
||||
if (userinfo) {
|
||||
// ⭐️ 核心修复:将缓存中的 JSON 字符串解析为对象
|
||||
try {
|
||||
this.globalData.userInfo = JSON.parse(userinfo);
|
||||
console.log("系统重启获取userinfo:", this.globalData.userInfo);
|
||||
} catch (e) {
|
||||
console.error("解析本地缓存的 userInfo 失败", e);
|
||||
this.globalData.userInfo = null; // 确保在解析失败时清空数据
|
||||
}
|
||||
}
|
||||
},
|
||||
fetchRawCardData(): Promise<CardData[]> {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: `${envConfig.apiBaseUrl}/article/get`,
|
||||
method: "POST",
|
||||
data: {
|
||||
uid: "1c3e5a7d-9b1f-4c3a-8e5f-7d9b1c3e5a7d"
|
||||
uid: this.globalData.userInfo.uid
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data && res.data.success && Array.isArray(res.data.data)) {
|
||||
@@ -32,6 +46,7 @@ App<IAppOption>({
|
||||
|
||||
const processedData = this.processVoteData(rawData);
|
||||
this.globalData.processedCardsData = processedData;
|
||||
this.processedCardsData = processedData;
|
||||
|
||||
console.log("成功获取文评列表:", processedData);
|
||||
resolve(processedData);
|
||||
@@ -47,29 +62,6 @@ App<IAppOption>({
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
getComments(articleId: number): Promise<Comment[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: `${envConfig.apiBaseUrl}/comment/get`,
|
||||
method: "POST",
|
||||
data: {
|
||||
articleId: articleId // int 类型
|
||||
},
|
||||
success: (res) => {
|
||||
const response = res.data as CommentResponse;
|
||||
|
||||
if (response.success && Array.isArray(response.data)) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || "获取评论失败"));
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(new Error("网络请求失败"));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
// 处理投票数据的方法
|
||||
processVoteData(rawData: CardData[]): CardData[] {
|
||||
|
||||
Reference in New Issue
Block a user