Refactor: UI & Feature updates (Calculator, UnitConverter, Privacy, Cleanup)
This commit is contained in:
@@ -9,6 +9,7 @@ Page({
|
||||
isScientific: false,
|
||||
showHistory: false,
|
||||
showHelp: false,
|
||||
showSettingsMenu: false,
|
||||
historyList: [] as Array<{expression: string, result: string}>
|
||||
},
|
||||
|
||||
@@ -26,7 +27,21 @@ Page({
|
||||
},
|
||||
|
||||
toggleHelp() {
|
||||
this.setData({ showHelp: !this.data.showHelp });
|
||||
this.setData({
|
||||
showHelp: !this.data.showHelp,
|
||||
showSettingsMenu: false
|
||||
});
|
||||
},
|
||||
|
||||
toggleSettings() {
|
||||
this.vibrate();
|
||||
this.setData({ showSettingsMenu: !this.data.showSettingsMenu });
|
||||
},
|
||||
|
||||
closeSettings() {
|
||||
if (this.data.showSettingsMenu) {
|
||||
this.setData({ showSettingsMenu: false });
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -209,7 +224,7 @@ Page({
|
||||
this.setData({
|
||||
operator: nextOperator,
|
||||
// 更新历史记录中的符号
|
||||
history: `${firstOperand} ${nextOperator}`
|
||||
history: `${firstOperand} ${nextOperator}`
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -279,29 +294,52 @@ Page({
|
||||
},
|
||||
|
||||
toggleHistory() {
|
||||
this.setData({ showHistory: !this.data.showHistory });
|
||||
this.vibrate();
|
||||
this.setData({
|
||||
showHistory: !this.data.showHistory,
|
||||
showSettingsMenu: false
|
||||
});
|
||||
},
|
||||
|
||||
clearHistory() {
|
||||
this.setData({ historyList: [] });
|
||||
this.vibrate();
|
||||
wx.removeStorageSync('CALC_HISTORY');
|
||||
this.setData({ historyList: [] });
|
||||
},
|
||||
|
||||
useHistoryResult(e: any) {
|
||||
this.vibrate();
|
||||
const result = e.currentTarget.dataset.result;
|
||||
this.setData({
|
||||
displayValue: String(result),
|
||||
showHistory: false,
|
||||
waitingForSecondOperand: true
|
||||
displayValue: result,
|
||||
waitingForSecondOperand: false, // Treat as a fresh input that can be operated on
|
||||
showHistory: false
|
||||
});
|
||||
},
|
||||
|
||||
copyResult() {
|
||||
this.vibrate();
|
||||
const { displayValue } = this.data;
|
||||
wx.setClipboardData({
|
||||
data: this.data.displayValue,
|
||||
data: displayValue,
|
||||
success: () => {
|
||||
wx.showToast({ title: '已复制', icon: 'success', duration: 1000 });
|
||||
wx.showToast({
|
||||
title: '复制成功',
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('复制失败:', err);
|
||||
// 隐私协议未声明或用户拒绝会导致复制失败 (errno 112)
|
||||
if (err.errno === 112 || (err.errMsg && err.errMsg.indexOf('privacy') > -1)) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '无法自动复制,请长按显示区域手动复制',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user