Initial commit
Made-with: Cursor
This commit is contained in:
49
srde/miniprogram/pages/profile/profile.ts
Normal file
49
srde/miniprogram/pages/profile/profile.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { mockAccount } from '../../services/api';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
account: mockAccount,
|
||||
capital: '',
|
||||
saving: false,
|
||||
resetting: false,
|
||||
},
|
||||
onLoad() {
|
||||
const app = getApp<IAppOption>();
|
||||
const acc = app.globalData.account || mockAccount;
|
||||
this.setData({ account: acc, capital: String(acc.total_capital) });
|
||||
},
|
||||
onCapitalInput(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ capital: e.detail.value as string });
|
||||
},
|
||||
onSaveCapital() {
|
||||
const cap = parseFloat(this.data.capital);
|
||||
if (!cap || cap <= 0) {
|
||||
wx.showToast({ title: '请输入有效金额', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.setData({ saving: true });
|
||||
setTimeout(() => {
|
||||
const acc = { ...mockAccount, total_capital: cap, current_capital: cap };
|
||||
getApp<IAppOption>().globalData.account = acc;
|
||||
this.setData({ saving: false, account: acc });
|
||||
wx.showToast({ title: '已保存' });
|
||||
}, 500);
|
||||
},
|
||||
onReset() {
|
||||
wx.showModal({
|
||||
title: '确认重置',
|
||||
content: '将清空所有交易数据,确定吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.setData({ resetting: true });
|
||||
setTimeout(() => {
|
||||
const acc = { ...mockAccount, current_capital: mockAccount.total_capital, consecutive_losses: 0, trading_locked_until: null, status: 'tradable' as const };
|
||||
getApp<IAppOption>().globalData.account = acc;
|
||||
this.setData({ resetting: false, account: acc });
|
||||
wx.showToast({ title: '已重置' });
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user