前后端分离计算器

前后端分离计算器
这个作业属于哪个课程https://bbs.csdn.net/forums/ssynkqtd-05
这个作业要求在哪里https://bbs.csdn.net/topics/617377308
这个作业的目标实现前后端分离计算器
其他参考文献

git仓库链接和代码规范链接

前端:https://github.com/zhironggu/cal_adv
后端:https://github.com/zhironggu/cal_advanced

PSP表格

PSPPersonal Software Process Stages预估耗时(分钟)实际耗时(分钟)
Planning计划3030
Estimate估计这个任务需要多少时间20003500
Development开发500800
Analysis需求分析 (包括学习新技术)300500
Design Spec生成设计文档4060
Design Review设计复审2020
Coding Standard代码规范 (为目前的开发制定合适的规范)2020
Design具体设计6080
Coding具体编码10001500
Code Review代码复审3030
Test测试(自我测试,修改代码,提交修改)6060
Reporting报告6060
Test Report测试报告3030
Size Measurement计算工作量1010
Postmortem & Process Improvement Plan事后总结, 并提出过程改进计划6060
合计30004000

成品展示

利率计算器:

video1

科学计算器:

计算过程:

video2

数据库历史记录:

video3

设计实现过程

前端:html+css+js 前端三件套。

后端:用nodejs 实现。

数据库:存历史记录以及利率表。

代码说明

1.科学计算器的运算功能

function compute(v) {
    if (v.innerText == "AC") {//清零
        willSum = "";
        idText.value = "0";

    } else if (v.innerText == "Back") {//回退
        if (idText.value.length > 0) {
            willSum = willSum.substring(0, willSum.length - 1);
            idText.value = willSum;
        }

    } else if (cheak(v.innerText) == true) {//小数点和运算符处理
        var ch;
        if (v.innerText == "X") {//乘法处理
            ch = "*";
        } else {
            ch = v.innerText
        }
        if (ch != willSum.charAt(willSum.length - 1) && !cheak(willSum.charAt(willSum.length - 1))) {
            willSum += ch;
            idText.value = willSum;
        }

    } else if (v.innerText == "=") {
        //求值
        window.eval("willSum = " + idText.value)

        idText.value = idText.value + "=" + willSum;
        willSum = "";
        axios.post("http://127.0.0.1:3000/addHistory", {"expression": idText.value}).then(res => {
            console.log(res)
        })

    } else {
        willSum += v.innerText;
        idText.value = willSum;
    }

}

2.存款计算

document.getElementById("calculate-deposit").onclick = () => {
    const amount = parseFloat(document.getElementById("amount").value);
    const time = parseFloat(document.getElementById("time").value);
    axios.get(`http://127.0.0.1:3000/getDepositInterestRate?time=${time}`)
        .then(res => {
            const rate = res.data.rate;
            const interest = amount * (rate / 100) * (time / 12);
            document.getElementById("result").textContent = `存款利息:${interest.toFixed(2)}`;
        });
};

3.贷款计算

ocument.getElementById("calculate-loan").onclick = () => {
    const amount = parseFloat(document.getElementById("amount").value);
    const time = parseFloat(document.getElementById("time").value);
    if (time < 6) {D

        alert("贷款时间不能低于6个月!")
        return;
    }
    axios.get(`http://127.0.0.1:3000/getLendingRate?time=${time}`)
        .then(res => {
            const rate = res.data.rate;
            const interest = amount * (rate / 100 / 12) * time;
            document.getElementById("result").textContent = `贷款利息:${interest.toFixed(2)}`;
        });
};

4.存款利率

router.get('/getDepositInterestRate', function (req, res) {
    let time = req.query.time;
    let sql
    if (time < 3) {
        sql = 'select * from deposit_rate where month = 0';
    } else if (time <= 6) {
        sql = 'select * from deposit_rate where month = 3';
    } else if (time <= 12) {
        sql = 'select * from deposit_rate where month = 6';
    } else if (time <= 24) {
        sql = 'select * from deposit_rate where month = 12';
    } else if (time <= 36) {
        sql = 'select * from deposit_rate where month = 24';
    } else if (time <= 60) {
        sql = 'select * from deposit_rate where month = 36';
    } else {
        sql = 'select * from deposit_rate where month = 60';
    }
    connection.query(sql, (err, result) => {
        if (err) {
            console.log(err.message);
            res.send(err.message);

        } else {
            res.send(result[0]);
        }
    })
})

5.贷款利率

router.get('/getLendingRate', function (req, res) {

    let time = req.query.time;
    let sql
    if (time > 6 && time<12) {
        sql = 'select * from lending_rate where month = 6';
    } else if (time == 12) {
        sql = 'select * from lending_rate where month = 12';
    } else if (time > 12 &&time < 36) {
        sql = 'select * from lending_rate where month = 36';
    } else if (time > 36 &&time < 60) {
        sql = 'select * from lending_rate where month = 60';
    } else  {
        sql = 'select * from lending_rate where month = -1';
    }
    connection.query(sql, (err, result) => {
        if (err) {
            console.log(err.message);
            res.send(err.message);

        } else {
            res.send(result[0]);
        }
    })
})

心路历程和收获

通过这次作业,我充分了解到了前后端开发的基本模式。我使用html,css,js来开发前端,通过nodejs实现前后端交互,学会连接数据库,受益匪浅,也让我认识到自己的不足,明确了今后的努力方向。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值