吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1606|回复: 33
上一主题 下一主题
收起左侧

[其他原创] AI写的《个性计算器》

  [复制链接]
跳转到指定楼层
楼主
快乐的小驹 发表于 2025-5-1 06:18 回帖奖励
本帖最后由 快乐的小驹 于 2025-5-10 08:56 编辑

用AI写的计算器,因为有些时候计算的结果需要记录,使用用ai写了一个自动记录计算过程的计算器。

这是HTML和js写的,必须下载附件!
必须下载附件!必须下载附件!
如果你要是喜欢

免费的评分给点吧。



[JavaScript] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// 获取DOM元素
const display = document.getElementById('display');
const equation = document.getElementById('equation');
const buttons = document.querySelectorAll('.btn');
const historyTable = document.getElementById('historyTable').querySelector('tbody');
const clearBtn = document.getElementById('clearBtn');
const downloadBtn = document.getElementById('downloadBtn');
const calculationType = document.getElementById('calculationType');
const dimensionInputs = document.querySelectorAll('.dimension-input');
 
// 键盘按键映射
const keyMap = {
    '0': '0', '1': '1', '2': '2', '3': '3', '4': '4',
    '5': '5', '6': '6', '7': '7', '8': '8', '9': '9',
    '.': '.', '+': '+', '-': '-', '*': '*', '/': '/',
    'Enter': '=', '=': '=', 'Backspace': '⌫', 'Escape': 'C',
    '%': '%'
};
 
// 添加键盘事件监听
document.addEventListener('keydown', (e) => {
    // 如果当前焦点在输入框上,则不处理键盘事件
    if (e.target.tagName === 'INPUT' && e.target.type === 'text') {
        return;
    }
     
    const key = keyMap[e.key];
    if (key) {
        const button = document.querySelector(`.btn[value="${key}"]`);
        if (button) {
            button.click();
        }
    }
});
 
// 计算器状态
let currentInput = '0';
let equationStr = '';
let result = null;
 
// 更新显示
function updateDisplay() {
    display.textContent = currentInput;
    equation.textContent = equationStr;
}
 
// 处理数字输入
function handleNumber(number) {
    if (currentInput === '0' && number !== '.') {
        currentInput = number;
    } else {
        currentInput += number;
    }
    updateDisplay();
}
 
// 处理运算符
function handleOperator(operator) {
    if (operator === 'C') {
        currentInput = '0';
        equationStr = '';
        result = null;
    } else if (operator === '⌫') {
        currentInput = currentInput.slice(0, -1) || '0';
    } else if (operator === '+/-') {
        currentInput = (parseFloat(currentInput) * -1).toString();
    } else if (operator === '%') {
        currentInput = (parseFloat(currentInput) / 100).toString();
    } else {
        equationStr += currentInput + operator;
        currentInput = '0';
    }
    updateDisplay();
}
 
// 计算等式
function calculate() {
    try {
        equationStr += currentInput;
        result = eval(equationStr);
        currentInput = result.toString();
         
        // 添加到历史记录
        history.push({
            equation: equationStr,
            result: result
        });
        updateHistoryTable();
         
        equationStr = '';
        updateDisplay();
    } catch (e) {
        currentInput = 'Error';
        updateDisplay();
    }
}
 
// 更新历史记录表格
// 初始化时加载历史记录
let history = JSON.parse(localStorage.getItem('calcHistory') || '[]');
updateHistoryTable();
 
// 更新历史记录时保存到localStorage
function updateHistoryTable() {
    localStorage.setItem('calcHistory', JSON.stringify(history));
    historyTable.innerHTML = '';
    history.forEach((item, index) => {
        const row = document.createElement('tr');
        row.innerHTML = `
            <td>${index + 1}</td>
            <td>${item.equation}</td>
            <td>${item.result}</td>
        `;
        historyTable.appendChild(row);
    });
}
 
// 修改清除历史函数
function clearHistory() {
    history = [];
    localStorage.removeItem('calcHistory');
    updateHistoryTable();
}
 
// 修改下载功能读取localStorage
function downloadHistory() {
    const savedHistory = JSON.parse(localStorage.getItem('calcHistory') || '[]');
    const wb = XLSX.utils.book_new();
    const ws = XLSX.utils.json_to_sheet(savedHistory.map((item, index) => ({
        '序号': index + 1,
        '计算式': item.equation,
        '结果': item.result
    })));
    XLSX.utils.book_append_sheet(wb, ws, '计算历史');
    XLSX.writeFile(wb, '计算历史.xlsx');
}
 
// 绑定按钮事件
buttons.forEach(button => {
    button.addEventListener('click', () => {
        const value = button.value;
         
        if (button.classList.contains('number')) {
            handleNumber(value);
        } else if (button.classList.contains('operator')) {
            if (value === '=') {
                calculate();
            } else {
                handleOperator(value);
            }
        }
    });
});
 
// 绑定功能按钮事件
clearBtn.addEventListener('click', clearHistory);
downloadBtn.addEventListener('click', downloadHistory);
 
// 初始化显示
updateDisplay();
 
// 监听计算类型变化
calculationType.addEventListener('change', function() {
    // 获取所有输入框
    const inputGroups = document.querySelectorAll('.input-group');
     
    // 默认隐藏所有输入框(从第二个开始,第一个是计算类型选择)
    for (let i = 1; i < inputGroups.length; i++) {
        inputGroups[i].style.display = 'none';
    }
     
    // 根据选择的值显示对应的输入框
    switch(this.value) {
        case 'area': // 长方形面积
            document.getElementById('lengthGroup').style.display = 'flex';
            document.getElementById('widthGroup').style.display = 'flex';
            break;
        case 'cylinder_area': // 圆柱体面积
            document.getElementById('radiusGroup').style.display = 'flex';
            document.getElementById('heightGroup').style.display = 'flex';
            break;
        case 'cone_area': // 圆锥体面积
            document.getElementById('radiusGroup').style.display = 'flex';
            document.getElementById('generatrixGroup').style.display = 'flex';
            break;
        case 'trapezoid_area': // 梯形面积
            document.getElementById('upperBaseGroup').style.display = 'flex';
            document.getElementById('lowerBaseGroup').style.display = 'flex';
            document.getElementById('heightGroup').style.display = 'flex';
            break;
        case 'rectangle_perimeter': // 长方形周长
            document.getElementById('lengthGroup').style.display = 'flex';
            document.getElementById('widthGroup').style.display = 'flex';
            break;
        case 'circle_perimeter': // 圆形周长
            document.getElementById('radiusGroup').style.display = 'flex';
            break;
        case 'cube_volume': // 立方体体积
            document.getElementById('lengthGroup').style.display = 'flex';
            document.getElementById('widthGroup').style.display = 'flex';
            document.getElementById('heightGroup').style.display = 'flex';
            break;
        case 'cylinder_volume': // 圆柱体体积
            document.getElementById('radiusGroup').style.display = 'flex';
            document.getElementById('heightGroup').style.display = 'flex';
            break;
        case 'triangle_area': // 三角形面积
            document.getElementById('baseGroup').style.display = 'flex';
            document.getElementById('height1Group').style.display = 'flex';
            break;
    }
});
 
// 初始隐藏所有输入框(从第二个开始)
const inputGroups = document.querySelectorAll('.input-group');
for (let i = 1; i < inputGroups.length; i++) {
    inputGroups[i].style.display = 'none';
}


个性计算器.zip (315.99 KB, 下载次数: 115)


《Excel文件比较器v1.3》
https://www.52pojie.cn/thread-2020893-1-1.html

没啥用软件 - 《Python库的批量安装》
https://www.52pojie.cn/thread-2030214-1-1.html

没啥用软件 - 《本地测试服务器》
https://www.52pojie.cn/thread-2030222-1-1.html

免费评分

参与人数 5吾爱币 +7 热心值 +4 收起 理由
lovepluto6 + 1 + 1 我很赞同!
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
yingzichuanshuo + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
pyjiujiu + 1 热心回复!
shisoro + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
mujita666 发表于 2025-5-1 07:29
界面看着还不错,新手学习
推荐
shutiao88888 发表于 2025-5-1 15:01
3#
安逸zzy 发表于 2025-5-1 06:32
4#
 楼主| 快乐的小驹 发表于 2025-5-1 06:33 |楼主
安逸zzy 发表于 2025-5-1 06:32
大佬,怎么运行的啊

在这个是html的~要下载的!
5#
ddfzl 发表于 2025-5-1 07:03
感谢分享,学习一下
6#
scxclzyzb 发表于 2025-5-1 07:43
确实有个性,第一次用这种形式的。
7#
52soft 发表于 2025-5-1 07:54
AI无所不能
8#
那些年打的飞机 发表于 2025-5-1 08:11
只给结果不说过程的吗?用啥AI写的,教一下呗……
9#
那些年打的飞机 发表于 2025-5-1 08:12
只给结果不说过程的吗?用啥AI写的,教一下呗……
10#
 楼主| 快乐的小驹 发表于 2025-5-1 08:16 |楼主
那些年打的飞机 发表于 2025-5-1 08:12
只给结果不说过程的吗?用啥AI写的,教一下呗……

用Trae CN 写的!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-28 07:54, Updated at 2025-05-28 07:54:31.

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表