Files
gaoYuJournal/miniprogram/pages/index/index.ts
2025-12-08 17:14:00 +08:00

51 lines
1005 B
TypeScript

// index.ts
import config from "../../config/index"
import { JournalPage, JournalPageType } from "../../types/Journal";
interface IndexData {
key: string;
}
Page({
data: <IndexData>{
key: ""
},
onShow() {
const key = wx.getStorageSync("key");
if (key) {
this.setData({
key
});
}
},
navigateToMain() {
wx.request({
url: `${config.url}/journal/list`,
method: "POST",
header: {
Key: this.data.key
},
data: <JournalPage> {
index: 0,
size: 1,
type: JournalPageType.PREVIEW
},
success: (resp) => {
const data = resp.data as any;
if (data.code === 20000) {
wx.setStorageSync("key", this.data.key);
wx.switchTab({
url: "/pages/main/journal/index",
})
} else if (data.code === 40100) {
wx.showToast({ title: "密码错误", icon: "error" });
} else {
wx.showToast({ title: "服务异常", icon: "error" });
}
},
fail: () => wx.showToast({ title: "验证失败", icon: "error" })
});
}
})