Refactor Date Calculator UI to Morandi theme and fix logic; fix Index page interaction
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"navigationBarTitleText": "计算器"
|
||||
"navigationBarTitleText": "科学计算器",
|
||||
"navigationBarBackgroundColor": "#1c1c1e",
|
||||
"navigationBarTextStyle": "white"
|
||||
}
|
||||
|
||||
@@ -6,14 +6,25 @@ Page({
|
||||
operator: null as string | null,
|
||||
firstOperand: null as number | null,
|
||||
waitingForSecondOperand: false,
|
||||
isScientific: false
|
||||
isScientific: false,
|
||||
showHistory: false,
|
||||
historyList: [] as Array<{expression: string, result: string}>
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 从本地存储恢复历史记录
|
||||
const saved = wx.getStorageSync('CALC_HISTORY');
|
||||
if (saved && Array.isArray(saved)) {
|
||||
this.setData({ historyList: saved });
|
||||
}
|
||||
},
|
||||
|
||||
vibrate() {
|
||||
// wx.vibrateShort({ type: 'light' });
|
||||
wx.vibrateShort({ type: 'light' }).catch(() => {});
|
||||
},
|
||||
|
||||
preventTouchMove() {
|
||||
// 阻止历史面板底层滚动
|
||||
},
|
||||
|
||||
toggleMode() {
|
||||
@@ -157,6 +168,8 @@ Page({
|
||||
history: desc,
|
||||
waitingForSecondOperand: true // 计算完后,下次输入数字是新数字
|
||||
});
|
||||
|
||||
this.addToHistory(desc, String(formatted));
|
||||
},
|
||||
|
||||
onOperator(e: any) {
|
||||
@@ -201,6 +214,7 @@ Page({
|
||||
|
||||
if (operator && firstOperand != null) {
|
||||
const result = this.performCalculation(operator, firstOperand, inputValue);
|
||||
const expression = `${firstOperand} ${operator} ${inputValue}`;
|
||||
|
||||
this.setData({
|
||||
displayValue: String(result),
|
||||
@@ -209,6 +223,8 @@ Page({
|
||||
waitingForSecondOperand: true,
|
||||
history: `${firstOperand} ${operator} ${inputValue} =`
|
||||
});
|
||||
|
||||
this.addToHistory(expression, String(result));
|
||||
}
|
||||
},
|
||||
|
||||
@@ -223,5 +239,42 @@ Page({
|
||||
}
|
||||
const precision = 10000000000;
|
||||
return Math.round(result * precision) / precision;
|
||||
},
|
||||
|
||||
// 历史记录相关方法
|
||||
addToHistory(expression: string, result: string) {
|
||||
const list = this.data.historyList.slice();
|
||||
list.unshift({ expression, result });
|
||||
// 最多保留50条
|
||||
if (list.length > 50) list.length = 50;
|
||||
this.setData({ historyList: list });
|
||||
wx.setStorageSync('CALC_HISTORY', list);
|
||||
},
|
||||
|
||||
toggleHistory() {
|
||||
this.setData({ showHistory: !this.data.showHistory });
|
||||
},
|
||||
|
||||
clearHistory() {
|
||||
this.setData({ historyList: [] });
|
||||
wx.removeStorageSync('CALC_HISTORY');
|
||||
},
|
||||
|
||||
useHistoryResult(e: any) {
|
||||
const result = e.currentTarget.dataset.result;
|
||||
this.setData({
|
||||
displayValue: String(result),
|
||||
showHistory: false,
|
||||
waitingForSecondOperand: true
|
||||
});
|
||||
},
|
||||
|
||||
copyResult() {
|
||||
wx.setClipboardData({
|
||||
data: this.data.displayValue,
|
||||
success: () => {
|
||||
wx.showToast({ title: '已复制', icon: 'success', duration: 1000 });
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,9 +1,44 @@
|
||||
<!--pages/calculator/calculator.wxml-->
|
||||
<view class="calculator-container">
|
||||
<!-- 历史记录面板 -->
|
||||
<view class="history-panel {{showHistory ? 'show' : ''}}" catchtouchmove="preventTouchMove">
|
||||
<view class="history-mask" bindtap="toggleHistory"></view>
|
||||
<view class="history-content">
|
||||
<view class="history-header">
|
||||
<text class="history-title">计算历史</text>
|
||||
<text class="history-clear" bindtap="clearHistory">清空</text>
|
||||
</view>
|
||||
<scroll-view scroll-y class="history-list" enhanced show-scrollbar="{{false}}">
|
||||
<block wx:if="{{historyList.length > 0}}">
|
||||
<view class="history-item" wx:for="{{historyList}}" wx:key="index"
|
||||
bindtap="useHistoryResult" data-result="{{item.result}}"
|
||||
hover-class="history-item-hover" hover-stay-time="100">
|
||||
<text class="history-expr">{{item.expression}}</text>
|
||||
<text class="history-result">= {{item.result}}</text>
|
||||
</view>
|
||||
</block>
|
||||
<view wx:else class="history-empty">
|
||||
<text class="history-empty-icon">📭</text>
|
||||
<text>暂无计算记录</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 显示区域 -->
|
||||
<view class="display-area">
|
||||
<view class="mode-indicator" bindtap="toggleMode">
|
||||
<text class="{{isScientific ? 'active' : ''}}">⚗️ 科学模式</text>
|
||||
<view class="display-top-bar">
|
||||
<view class="mode-indicator" bindtap="toggleMode">
|
||||
<text class="{{isScientific ? 'active' : ''}}">⚗️ 科学</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">
|
||||
<text class="action-icon">📋</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="history-text">{{history}}</view>
|
||||
<view class="current-value {{displayValue.length > 9 ? 'shrink' : ''}} {{displayValue.length > 15 ? 'shrink-more' : ''}}">{{displayValue}}</view>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/* pages/calculator/calculator.wxss */
|
||||
|
||||
/* ========== 全局 ========== */
|
||||
page {
|
||||
height: 100%;
|
||||
background-color: #000000;
|
||||
background-color: #1c1c1e;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
@@ -14,168 +16,330 @@ page {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
/* 显示区域 */
|
||||
/* ========== 显示区域 ========== */
|
||||
.display-area {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-end;
|
||||
padding: 40rpx;
|
||||
background-color: #000;
|
||||
padding: 30rpx 40rpx 20rpx;
|
||||
background: linear-gradient(180deg, #1c1c1e 0%, #2c2c2e 100%);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.mode-indicator {
|
||||
position: absolute;
|
||||
top: 40rpx;
|
||||
left: 40rpx;
|
||||
/* 顶部工具栏 */
|
||||
.display-top-bar {
|
||||
position: absolute;
|
||||
top: 20rpx;
|
||||
left: 30rpx;
|
||||
right: 30rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.top-actions {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
background: rgba(255,255,255,0.08);
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
/* 模式切换 */
|
||||
.mode-indicator text {
|
||||
color: #444;
|
||||
font-size: 24rpx;
|
||||
border: 1px solid #444;
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 30rpx;
|
||||
color: rgba(255,255,255,0.4);
|
||||
font-size: 24rpx;
|
||||
padding: 10rpx 24rpx;
|
||||
border-radius: 30rpx;
|
||||
background: rgba(255,255,255,0.06);
|
||||
border: none;
|
||||
}
|
||||
|
||||
.mode-indicator text.active {
|
||||
color: #ff9f0a;
|
||||
border-color: #ff9f0a;
|
||||
background: rgba(255, 159, 10, 0.1);
|
||||
color: #ff9f0a;
|
||||
background: rgba(255, 159, 10, 0.15);
|
||||
}
|
||||
|
||||
|
||||
/* 表达式行 */
|
||||
.history-text {
|
||||
font-size: 36rpx;
|
||||
color: #666;
|
||||
min-height: 50rpx;
|
||||
margin-bottom: 20rpx;
|
||||
font-family: monospace;
|
||||
font-size: 32rpx;
|
||||
color: rgba(255,255,255,0.35);
|
||||
min-height: 44rpx;
|
||||
margin-bottom: 12rpx;
|
||||
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
|
||||
text-align: right;
|
||||
width: 100%;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
|
||||
/* 当前值 */
|
||||
.current-value {
|
||||
font-size: 160rpx;
|
||||
color: #fff;
|
||||
line-height: 1;
|
||||
font-size: 130rpx;
|
||||
color: #ffffff;
|
||||
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;
|
||||
}
|
||||
|
||||
.current-value.shrink {
|
||||
font-size: 100rpx;
|
||||
}
|
||||
.current-value.shrink-more {
|
||||
font-size: 70rpx;
|
||||
font-size: 90rpx;
|
||||
}
|
||||
|
||||
/* 键盘区域 */
|
||||
.current-value.shrink-more {
|
||||
font-size: 62rpx;
|
||||
}
|
||||
|
||||
/* ========== 键盘区域 ========== */
|
||||
.keypad-area {
|
||||
background-color: #000;
|
||||
padding: 0 30rpx 30rpx 30rpx;
|
||||
background: #1c1c1e;
|
||||
padding: 16rpx 24rpx 24rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 30rpx;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
/* 科学模式适配 */
|
||||
.keypad-area.scientific-pad {
|
||||
gap: 20rpx;
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
|
||||
/* 统一圆形按钮 */
|
||||
.keypad-area.scientific-pad .btn {
|
||||
width: 130rpx;
|
||||
height: 130rpx;
|
||||
font-size: 50rpx;
|
||||
border-radius: 50%; /* 保持圆形 */
|
||||
}
|
||||
|
||||
.keypad-area.scientific-pad .zero {
|
||||
width: 280rpx; /* 适配新的宽度 */
|
||||
border-radius: 65rpx; /* 圆角为高度一半 */
|
||||
}
|
||||
|
||||
/* 科学功能键行 */
|
||||
.keypad-area.scientific-pad .sci-btn {
|
||||
width: 120rpx; /* 稍微大一点,填满宽度 */
|
||||
height: 120rpx; /* 正圆 */
|
||||
font-size: 36rpx;
|
||||
background: #222;
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.small-row {
|
||||
justify-content: space-around; /* 均匀分布 */
|
||||
gap: 10rpx;
|
||||
gap: 14rpx;
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
|
||||
/* 行 */
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 30rpx;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.keypad-area.scientific-pad .row {
|
||||
gap: 20rpx;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.small-row {
|
||||
justify-content: space-around;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
/* ========== 按钮通用 ========== */
|
||||
.btn {
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
border-radius: 75rpx; /* 圆形按钮 */
|
||||
width: 152rpx;
|
||||
height: 152rpx;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 60rpx;
|
||||
font-weight: 500;
|
||||
font-size: 56rpx;
|
||||
font-weight: 400;
|
||||
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 数字键 */
|
||||
.digit {
|
||||
background-color: #333333;
|
||||
color: #fff;
|
||||
background-color: #3a3a3c;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* 功能键 (AC, Del, +/-) */
|
||||
/* 功能键 */
|
||||
.func {
|
||||
background-color: #a5a5a5;
|
||||
color: #000;
|
||||
font-size: 50rpx;
|
||||
font-weight: 600;
|
||||
background-color: #636366;
|
||||
color: #ffffff;
|
||||
font-size: 46rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 运算符 */
|
||||
.operator {
|
||||
background-color: #ff9f0a;
|
||||
color: #fff;
|
||||
font-size: 70rpx;
|
||||
padding-bottom: 10rpx;
|
||||
padding: 0;
|
||||
color: #ffffff;
|
||||
font-size: 64rpx;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
/* 0键特殊处理 */
|
||||
/* 等号键:渐变突出 */
|
||||
.equal {
|
||||
background: linear-gradient(135deg, #ff9f0a 0%, #ff6723 100%);
|
||||
box-shadow: 0 6rpx 20rpx rgba(255, 159, 10, 0.35);
|
||||
}
|
||||
|
||||
/* 0键 */
|
||||
.zero {
|
||||
width: 330rpx;
|
||||
border-radius: 75rpx;
|
||||
width: 324rpx;
|
||||
border-radius: 76rpx;
|
||||
justify-content: flex-start;
|
||||
padding-left: 60rpx;
|
||||
padding-left: 62rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 点击反馈 */
|
||||
.btn-hover {
|
||||
opacity: 0.7;
|
||||
transform: scale(0.92);
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
/* 平板适配或小屏适配 */
|
||||
/* 科学模式缩放 */
|
||||
.keypad-area.scientific-pad .btn {
|
||||
width: 130rpx;
|
||||
height: 130rpx;
|
||||
font-size: 48rpx;
|
||||
}
|
||||
|
||||
.keypad-area.scientific-pad .zero {
|
||||
width: 274rpx;
|
||||
border-radius: 65rpx;
|
||||
}
|
||||
|
||||
.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(255,255,255,0.08) !important;
|
||||
color: #64d2ff !important;
|
||||
border-radius: 50% !important;
|
||||
font-weight: 500 !important;
|
||||
letter-spacing: 1rpx;
|
||||
}
|
||||
|
||||
/* ========== 历史记录面板 ========== */
|
||||
.history-panel {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 100;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.history-panel.show {
|
||||
pointer-events: auto;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.history-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.55);
|
||||
}
|
||||
|
||||
.history-content {
|
||||
position: relative;
|
||||
z-index: 101;
|
||||
background: #2c2c2e;
|
||||
border-radius: 0 0 36rpx 36rpx;
|
||||
max-height: 70vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 16rpx 48rpx rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
.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); }
|
||||
}
|
||||
|
||||
.history-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 36rpx 40rpx;
|
||||
border-bottom: 1rpx solid rgba(255,255,255,0.08);
|
||||
}
|
||||
|
||||
.history-title {
|
||||
color: #ffffff;
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
letter-spacing: 1rpx;
|
||||
}
|
||||
|
||||
.history-clear {
|
||||
color: #ff9f0a;
|
||||
font-size: 28rpx;
|
||||
padding: 8rpx 24rpx;
|
||||
border-radius: 20rpx;
|
||||
background: rgba(255, 159, 10, 0.1);
|
||||
}
|
||||
|
||||
.history-list {
|
||||
max-height: 58vh;
|
||||
padding: 10rpx 0;
|
||||
}
|
||||
|
||||
.history-item {
|
||||
padding: 28rpx 40rpx;
|
||||
border-bottom: 1rpx solid rgba(255,255,255,0.05);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.history-item:active {
|
||||
background: rgba(255,255,255,0.06);
|
||||
}
|
||||
|
||||
.history-expr {
|
||||
color: rgba(255,255,255,0.45);
|
||||
font-size: 26rpx;
|
||||
margin-bottom: 8rpx;
|
||||
font-family: -apple-system, 'SF Pro Display', monospace;
|
||||
}
|
||||
|
||||
.history-result {
|
||||
color: #ffffff;
|
||||
font-size: 42rpx;
|
||||
font-weight: 500;
|
||||
font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
|
||||
}
|
||||
|
||||
.history-empty {
|
||||
text-align: center;
|
||||
padding: 100rpx 0;
|
||||
color: rgba(255,255,255,0.25);
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.history-empty-icon {
|
||||
font-size: 64rpx;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
/* ========== 小屏适配 ========== */
|
||||
@media (max-width: 360px) {
|
||||
.btn {
|
||||
width: 140rpx;
|
||||
@@ -183,6 +347,9 @@ page {
|
||||
font-size: 50rpx;
|
||||
}
|
||||
.zero {
|
||||
width: 310rpx;
|
||||
width: 300rpx;
|
||||
}
|
||||
.current-value {
|
||||
font-size: 110rpx;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user