Refactor: UI & Feature updates (Calculator, UnitConverter, Privacy, Cleanup)

This commit is contained in:
2026-02-09 01:15:19 +08:00
parent fa1a8e083e
commit 2c5d5b7505
52 changed files with 1351 additions and 2702 deletions

View File

@@ -1,5 +1,8 @@
{
"navigationBarTitleText": "科学计算器",
"navigationBarBackgroundColor": "#EBF4F8",
"navigationBarTextStyle": "black"
"navigationBarTextStyle": "black",
"usingComponents": {
"privacy-popup": "/components/privacy-popup/privacy-popup"
}
}

View File

@@ -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: '知道了'
});
}
}
});
}
})
});

View File

@@ -1,5 +1,6 @@
<!--pages/calculator/calculator.wxml-->
<view class="calculator-container">
<privacy-popup></privacy-popup>
<!-- 帮助说明面板 -->
<view class="history-panel {{showHelp ? 'show' : ''}}" catchtouchmove="preventTouchMove" style="z-index: 200;">
<view class="history-mask" bindtap="toggleHelp"></view>
@@ -70,14 +71,30 @@
<text class="{{isScientific ? 'active' : ''}}" bindtap="switchMode" data-mode="scientific">科学</text>
</view>
<view class="top-actions">
<view class="action-btn" bindtap="toggleHistory" hover-class="action-btn-hover" hover-stay-time="100">
<text class="action-icon">🕐</text>
</view>
<view class="action-btn" bindtap="copyResult" hover-class="action-btn-hover" hover-stay-time="100">
<!-- 复制结果按钮 (带文字) -->
<view class="action-btn copy-btn" bindtap="copyResult" hover-class="action-btn-hover" hover-stay-time="100">
<text class="action-icon">📋</text>
<text class="action-text">复制结果</text>
</view>
<view class="action-btn" bindtap="toggleHelp" hover-class="action-btn-hover" hover-stay-time="100">
<text class="action-icon">❓</text>
<!-- 设置按钮 (包含历史和帮助) -->
<view class="settings-container">
<view class="action-btn" bindtap="toggleSettings" hover-class="action-btn-hover" hover-stay-time="100">
<text class="action-icon">⚙️</text>
</view>
<!-- 下拉菜单 -->
<view class="dropdown-menu {{showSettingsMenu ? 'show' : ''}}">
<view class="menu-item" bindtap="toggleHistory">
<text class="menu-icon">🕐</text>
<text class="menu-text">历史记录</text>
</view>
<view class="menu-item" bindtap="toggleHelp">
<text class="menu-icon">❓</text>
<text class="menu-text">使用帮助</text>
</view>
</view>
<!-- 点击背景关闭菜单 -->
<view class="settings-mask" wx:if="{{showSettingsMenu}}" bindtap="closeSettings"></view>
</view>
</view>
</view>

View File

@@ -24,9 +24,9 @@ page {
justify-content: flex-end;
align-items: flex-end;
padding: 30rpx 40rpx 20rpx;
background: transparent; /* No more dark gradient */
background: transparent;
position: relative;
overflow: hidden;
overflow: visible; /* Limit overflow for dropdown but visible for popup */
}
/* 顶部工具栏 */
@@ -38,12 +38,13 @@ page {
display: flex;
justify-content: space-between;
align-items: center;
z-index: 10;
z-index: 100;
}
.top-actions {
display: flex;
gap: 20rpx;
align-items: center;
}
.action-btn {
@@ -57,11 +58,92 @@ page {
box-shadow: 0 4rpx 12rpx rgba(17, 97, 107, 0.15); /* Teal shadow */
}
.action-btn-hover {
background-color: #F0F0F0 !important;
transform: translateY(2rpx);
box-shadow: 0 2rpx 6rpx rgba(17, 97, 107, 0.1) !important;
}
/* 复制按钮特殊样式 */
.action-btn.copy-btn {
width: auto;
padding: 0 20rpx;
border-radius: 36rpx;
gap: 10rpx;
}
.copy-btn .action-text {
font-size: 24rpx;
color: #11616B;
font-weight: 500;
}
.action-icon {
font-size: 36rpx;
font-size: 34rpx;
color: #11616B; /* Color 01 */
}
/* Settings Dropdown Container */
.settings-container {
position: relative;
}
/* Dropdown Menu */
.dropdown-menu {
position: absolute;
top: 80rpx;
right: 0;
width: 240rpx;
background: #ffffff;
border-radius: 12rpx;
box-shadow: 0 8rpx 24rpx rgba(0,0,0,0.15);
padding: 10rpx 0;
opacity: 0;
visibility: hidden;
transform: translateY(-10rpx);
transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
z-index: 500;
}
.dropdown-menu.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.menu-item {
display: flex;
align-items: center;
padding: 20rpx 30rpx;
gap: 20rpx;
transition: background 0.1s;
}
.menu-item:active {
background-color: #f5f5f5;
}
.menu-icon {
font-size: 36rpx;
}
.menu-text {
font-size: 28rpx;
color: #333;
}
/* Mask for closing dropdown */
.settings-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 400;
background: transparent;
}
/* 模式切换 */
.mode-indicator {
display: flex;
@@ -98,165 +180,156 @@ page {
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
text-align: right;
width: 100%;
letter-spacing: 2rpx;
word-break: break-all;
}
/* 当前值 */
/* 当前值 */
.current-value {
font-size: 130rpx;
color: #11616B; /* Color 01 (Deep Teal) */
font-size: 96rpx;
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
font-weight: 300;
color: #11616B; /* Color 01 */
line-height: 1.1;
font-weight: 200;
word-break: break-all;
text-align: right;
width: 100%;
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
transition: font-size 0.2s;
}
.current-value.shrink {
font-size: 90rpx;
}
.current-value.shrink-more {
font-size: 62rpx;
}
.current-value.shrink { font-size: 72rpx; }
.current-value.shrink-more { font-size: 56rpx; }
/* ========== 键盘区域 ========== */
.keypad-area {
background: #EBF4F8; /* Color 03 */
padding: 16rpx 24rpx 24rpx;
background-color: #ffffff;
border-radius: 40rpx 40rpx 0 0;
padding: 30rpx 20rpx;
padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
box-shadow: 0 -4rpx 20rpx rgba(17, 97, 107, 0.05);
transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
z-index: 50;
display: flex;
flex-direction: column;
gap: 20rpx;
gap: 20rpx;
}
.keypad-area.scientific-pad {
gap: 14rpx;
padding-bottom: 20rpx;
/* 科学键盘模式 */
.scientific-pad {
/* 增加高度或者改变布局逻辑 if needed */
}
/* 行 */
.row {
display: flex;
justify-content: space-between;
gap: 20rpx;
}
.keypad-area.scientific-pad .row {
gap: 14rpx;
margin-bottom: 0;
}
.small-row {
justify-content: space-around;
gap: 8rpx;
justify-content: space-between;
gap: 16rpx;
}
/* ========== 按钮通用 ========== */
/* 按钮通用 */
.btn {
width: 152rpx;
height: 152rpx;
border-radius: 50%;
flex: 1;
height: 130rpx; /* Taller buttons */
border-radius: 30rpx; /* More rounded */
display: flex;
justify-content: center;
align-items: center;
font-size: 56rpx;
justify-content: center;
font-size: 48rpx;
font-weight: 400;
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
position: relative;
overflow: hidden;
box-shadow: 0 4rpx 10rpx rgba(17, 97, 107, 0.05); /* Very subtle shadow */
}
/* 数字键 */
.digit {
background-color: #ffffff;
background-color: #F8FBFC; /* Light gray-blue */
color: #11616B; /* Color 01 */
box-shadow: 0 4rpx 0 #E1E8EC;
transition: transform 0.1s, background-color 0.2s;
}
/* 功能键 (AC, +/-, %) */
.func {
background-color: #7BBDB6; /* Color 02 (Medium Teal) */
color: #ffffff;
font-size: 46rpx;
.btn-hover {
transform: translateY(4rpx);
box-shadow: none !important;
}
/* 功能键 (AC, Delete, +/-) */
.btn.func {
color: #DC8B70; /* Color 05 (Highlight) - Use Peach/Orange for clear/action */
font-weight: 500;
background-color: #FFF6F3; /* Light peach bg */
box-shadow: 0 4rpx 0 #FCEBE6;
}
.btn.func.btn-hover {
background-color: #FEDCC8 !important;
}
/* 运算符 */
.operator {
background-color: #FED9CD; /* Color 04 (Pale Pink/Peach) */
color: #DC8B70; /* Color 05 (Terracotta) for contrast */
font-size: 64rpx;
font-weight: 400;
.btn.operator {
background-color: #EBF4F8; /* Color 03 */
color: #11616B;
font-size: 56rpx;
}
/* 等号键:渐变突出 */
.equal {
background: #11616B; /* Color 01 (Deep Teal) */
.btn.operator.btn-hover {
background-color: #D3E7ED !important;
}
.btn.equal {
background-color: #11616B; /* Color 01 (Primary) */
color: #ffffff;
box-shadow: 0 6rpx 20rpx rgba(17, 97, 107, 0.3);
box-shadow: 0 4rpx 0 #0D4A52;
}
/* 0键 */
.zero {
width: 324rpx;
border-radius: 76rpx;
justify-content: flex-start;
padding-left: 62rpx;
box-sizing: border-box;
.btn.equal.btn-hover {
background-color: #167A85 !important;
}
/* 点击反馈 */
.btn-hover {
transform: scale(0.92);
opacity: 0.9;
/* 数字键 */
.btn.digit {
background-color: #ffffff;
color: #333;
font-weight: 500;
font-size: 52rpx;
box-shadow: 0 4rpx 0 #EAEAEA;
}
/* 科学模式缩放 */
.keypad-area.scientific-pad .btn {
width: 130rpx;
height: 130rpx;
font-size: 48rpx;
.btn.digit.btn-hover {
background-color: #E0E0E0 !important;
}
.keypad-area.scientific-pad .zero {
width: 274rpx;
border-radius: 65rpx;
.btn.zero {
flex: 2.2; /* Wider 0 button */
}
.keypad-area.scientific-pad .func {
font-size: 40rpx;
}
.keypad-area.scientific-pad .operator {
font-size: 54rpx;
}
/* 科学功能键 */
/* 科学按钮 */
.sci-btn {
width: 120rpx !important;
height: 120rpx !important;
font-size: 32rpx !important;
background: rgba(17, 97, 107, 0.05) !important; /* Very light teal bg */
color: #11616B !important; /* Color 01 */
border-radius: 50% !important;
font-weight: 500 !important;
letter-spacing: 1rpx;
height: 90rpx;
font-size: 32rpx;
border-radius: 20rpx;
background-color: #EBF4F8; /* Color 03 */
color: #7BBDB6; /* Color 02 */
box-shadow: 0 3rpx 0 #DEE9EE;
}
/* ========== 历史记录面板 ========== */
.sci-btn.btn-hover {
background-color: #D3E7ED !important;
}
/* ========== 面板 (历史/帮助) ========== */
.history-panel {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 100;
pointer-events: none;
width: 100%;
height: 100%;
z-index: 1000;
visibility: hidden;
opacity: 0;
transition: all 0.3s;
}
.history-panel.show {
pointer-events: auto;
visibility: visible;
opacity: 1;
}
@@ -264,171 +337,152 @@ page {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(17, 97, 107, 0.4); /* Color 01 dim */
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.4);
}
.history-content {
position: relative;
z-index: 101;
background: #EBF4F8; /* Color 03 */
border-radius: 0 0 16rpx 16rpx; /* Reduced radius */
max-height: 70vh;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 70%;
background-color: #ffffff;
border-radius: 40rpx 40rpx 0 0;
transform: translateY(100%);
transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
display: flex;
flex-direction: column;
box-shadow: 0 16rpx 48rpx rgba(17, 97, 107, 0.2);
padding-bottom: env(safe-area-inset-bottom);
}
.history-panel.show .history-content {
animation: histSlideDown 0.3s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}
@keyframes histSlideDown {
from { transform: translateY(-100%); }
to { transform: translateY(0); }
transform: translateY(0);
}
.history-header {
padding: 30rpx 40rpx;
display: flex;
justify-content: space-between;
align-items: center;
padding: 36rpx 40rpx;
border-bottom: 2rpx solid rgba(17, 97, 107, 0.1);
border-bottom: 1px solid #f0f0f0;
}
.history-title {
color: #11616B; /* Color 01 */
font-size: 34rpx;
font-weight: 600;
letter-spacing: 1rpx;
font-weight: bold;
color: #11616B;
}
.history-clear {
color: #DC8B70; /* Color 05 */
font-size: 28rpx;
padding: 8rpx 24rpx;
border-radius: 20rpx;
background: rgba(220, 139, 112, 0.15); /* Color 05 faint */
color: #999;
padding: 10rpx;
}
.history-list {
max-height: 58vh;
padding: 10rpx 0;
flex: 1;
padding: 20rpx 40rpx;
box-sizing: border-box;
}
.history-item {
padding: 28rpx 40rpx;
border-bottom: 1rpx solid rgba(17, 97, 107, 0.08); /* Darker border for light bg */
padding: 20rpx 0;
border-bottom: 1px solid #f8f8f8;
display: flex;
flex-direction: column;
align-items: flex-end;
}
.history-item:active {
background: rgba(17, 97, 107, 0.05); /* Dark interaction state */
.history-item-hover {
background-color: #f9f9f9;
}
.history-expr {
color: rgba(17, 97, 107, 0.6); /* Color 01 faded - Visible on light bg */
font-size: 26rpx;
margin-bottom: 8rpx;
font-family: -apple-system, 'SF Pro Display', monospace;
color: #999;
margin-bottom: 6rpx;
}
.history-result {
color: #11616B; /* Color 01 - Visible High Contrast */
font-size: 42rpx;
font-size: 36rpx;
color: #11616B;
font-weight: 500;
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
}
.history-empty {
text-align: center;
padding: 100rpx 0;
color: rgba(17, 97, 107, 0.4);
font-size: 28rpx;
height: 400rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #ccc;
gap: 20rpx;
}
.history-empty-icon {
font-size: 64rpx;
display: block;
margin-bottom: 16rpx;
font-size: 80rpx;
opacity: 0.5;
}
/* Help Panel Styles */
/* 帮助样式 */
.help-content {
height: 80%; /* Slightly taller */
}
.help-list {
padding: 0; /* padding moved to inner section to avoid scroll-view width issues */
padding: 10rpx 40rpx;
}
.help-section {
display: flex;
flex-direction: column;
gap: 40rpx;
padding: 30rpx 40rpx 60rpx; /* Apply padding here */
box-sizing: border-box;
padding-bottom: 60rpx;
}
.help-item {
display: flex;
gap: 24rpx;
align-items: flex-start;
display: flex;
gap: 24rpx;
margin-bottom: 40rpx;
align-items: flex-start;
}
.help-icon {
font-size: 44rpx;
width: 60rpx;
text-align: center;
padding-top: 4rpx;
font-size: 40rpx;
background: #EBF4F8;
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 20rpx;
color: #11616B;
}
.help-text {
flex: 1;
display: flex;
flex-direction: column;
flex: 1;
}
.help-h1 {
font-size: 30rpx;
font-weight: bold;
color: #11616B; /* Color 01 */
margin-bottom: 12rpx;
display: block;
font-size: 30rpx;
font-weight: bold;
color: #11616B;
margin-bottom: 8rpx;
}
.help-p {
font-size: 26rpx;
color: #2d3436;
line-height: 1.6;
opacity: 0.8;
display: block;
font-size: 26rpx;
color: #666;
line-height: 1.5;
text-align: justify;
}
.share-btn-large {
background-color: #11616B !important; /* Color 01 */
color: white !important;
border-radius: 16rpx !important; /* Unified radius */
font-size: 30rpx !important;
font-weight: 500 !important;
margin-top: 20rpx;
width: 100% !important;
box-shadow: 0 8rpx 20rpx rgba(17, 97, 107, 0.25);
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx 0;
}
/* ========== 小屏适配 ========== */
@media (max-width: 360px) {
.btn {
width: 140rpx;
height: 140rpx;
font-size: 50rpx;
}
.zero {
width: 300rpx;
}
.current-value {
font-size: 110rpx;
}
background-color: #11616B;
color: #fff;
border-radius: 50rpx;
font-weight: bold;
margin-top: 40rpx;
box-shadow: 0 4rpx 12rpx rgba(17, 97, 107, 0.3);
}