Assignment2-Separate front and rear end Calculator

Basic information

The Link Your Class2301-MUSE社区-CSDN社区云
The Link of Requirement of This Assignment**Second assignment-- Back-end separation calculator programming-CSDN社区
The Aim of This AssignmentDevelop a front - end separate calculator to achieve scientific calculation and history access
MU STU ID and FZU STU ID21125422_832101225

Introduction

This blog mainly introduces me in the first job Wechat small program calculator on the basis of adding back-end functions. To achieve basic operations, including addition, subtraction, multiplication, division, power sum and scientific calculation, in the following will introduce some related background and design process and code, and finally the product display.
Link to the finished project code:jolinYao/EE301-Assignment2: EE301 | Assignment2 Separate front and rear end Calculator (github.com)

PSP Table

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning2025
• Estimate2025
Development435675
• Analysis3030
• Design Spec55
• Design Review1010
• Coding Standard4040
• Design6080
• Coding200400
• Code Review6080
• Test3030
Reporting100125
• Test Repor6075
• Size Measurement1020
• Postmortem & Process Improvement Plan3030
Sum555825

Work Present

1. Four basic operations

Four Arithmetic Operations and Remainder,Implement bracket computation
在这里插入图片描述

2. Access historical data

Reading History Records
在这里插入图片描述

3.Realize scientific computing

在这里插入图片描述

Design implementation Process

1. Flow chart

On the basis of the last wechat mini program native, add history access. The back end can be processed with the cloud development that comes with the wechat mini program. Only slightly more cumbersome is the need to write a user login to implement historical computation data storage.
在这里插入图片描述

2.Function realization

  • Front-end development:
    I used wechat mini program framework for front-end development, WXML and WXSS to build the user interface, and JavaScript to handle user interaction. I wrote event handlers to capture the user’s input and perform the corresponding calculations.

  • Back-end development:
    For back-end development, I used wechat cloud development. Wechat Cloud Development provides built-in back-end support for small programs, including cloud functions and databases, without the need to configure your own server. I wrote cloud functions to handle front-end requests, perform related calculations, and then return the results to the front-end.

  • The use of wechat cloud development makes the backend development of small programs more simplified, without having to build their own servers or maintain complex backend architecture. It provides powerful features and a convenient way to handle back-end logic and data storage. This integration helps to quickly build feature-rich wechat mini program applications.

Code specification

1. Front end

In this operation, the main change of the front end is to add two independent event keys, namely, the data upload cloud key and the key to jump to the historical data interface. Then I made some simple Settings for the historical data interface.

Historical data interface:

WXSS: Historical data style file

/* pages/sujv/sujv.wxss */
.line{

  width:100%;
  
  height:2rpx;
  
  background:#aaa;
  
  }

WXML:Historical data configuration file

<!--pages/sujv/sujv.wxml-->
<view wx:for="{{strArr}}" wx:for-item="items" wx:for-index="indexs" wx:key="indexs">
 <view>
  {{items.str}}
 </view>
 <view class="line"></view>
</view>

JS: Historical data configuration file

// pages/sujv/sujv.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    strArr:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(){
    let that= this
    //固定写法,用于获取当前数据库中goods这个表的实例对象
    wx.cloud.database().collection('jilu')
    //查询操作
    .get({
      //请求成功
      success(res){
        console.log('请求成功',res)
        let result =  res.data
        that.setData({
          strArr:result
       })
       
        console.log(result);
      },
      //请求失败
      fail(err){
        console.log('请求失败',err)
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})

New buttons are added on the home screen:

WXML: New button configuration on the home screen

<view style="position: absolute; top: 0; right: 0; background-color: bisque; border-radius: 20rpx; padding: 10rpx; opacity: 0.8; color: royalblue; font-weight: 800;"  bindtap="lishi">历史</view>

<image style="position: absolute; top: 350rpx; right: 0; width: 100rpx; height: 100rpx;" bindtap="suby"  src="/asset/images/a.png" mode=""/>

JS: New button logic on the home screen

onsole.log(this.data.inputs);
if(!this.data.inputs){
  wx.showModal({
    title: '提示',
    content: '您没有输入内容哦~',
  })
  return
}
if(!this.data.answer){
  wx.showModal({
    title: '提示',
    content: '您还没有计算结果,无法上传到云端',
  })
  return
}
userCollection.add({
	data: {
    	str: this.data.inputs+"="+this.data.answer,
    }
}).then(res => {
  console.log('添加成功',res)
  wx.showModal({
    title: '提示',
    content: '已成功上传云端~',
  })

}).catch(err => {
	console.log('添加失败',err)//失败提示错误信息
})

2. Rear-End

Cloud development is more convenient than traditional on-premises backend development and can eliminate the hassle of configuring the environment.
First of all, in the small program management background, open the cloud development function. In the applet management background, create a cloud development environment. Each environment has its own database and cloud functions. In a cloud development environment, you can create database collections, define data models, and add, modify, query, and delete data. Develop cloud functions to handle requests and business logic on the applet side. Cloud functions can be activated by triggers, HTTP requests, applets, etc.

JS: Write the corresponding logic in the corresponding JS file on the page to handle the back-end operation

// pages/sujv/sujv.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    strArr:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(){
    let that= this
    //固定写法,用于获取当前数据库中goods这个表的实例对象
    wx.cloud.database().collection('jilu')
    //查询操作
    .get({
      //请求成功
      success(res){
        console.log('请求成功',res)
        let result =  res.data
        that.setData({
          strArr:result
       })
       
        console.log(result);
      },
      //请求失败
      fail(err){
        console.log('请求失败',err)
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})
lishi:function(){
    wx.navigateTo({
      url: '/pages/sujv/sujv'
      })      
  },
  suby:function(){
    let db = wx.cloud.database() //设置数据库
let userCollection = db.collection('jilu') //单引号里为刚刚新建的集合名
console.log(this.data.inputs);
if(!this.data.inputs){
  wx.showModal({
    title: '提示',
    content: '您没有输入内容哦~',
  })
  return
}
if(!this.data.answer){
  wx.showModal({
    title: '提示',
    content: '您还没有计算结果,无法上传到云端',
  })
  return
}
userCollection.add({
	data: {
    	str: this.data.inputs+"="+this.data.answer,
    }
}).then(res => {
  console.log('添加成功',res)
  wx.showModal({
    title: '提示',
    content: '已成功上传云端~',
  })

}).catch(err => {
	console.log('添加失败',err)//失败提示错误信息
})

Background data access:
在这里插入图片描述
在这里插入图片描述

Summary

The process of developing a wechat mini program calculator project with front-end separation brought me a lot of gains and insights, both in terms of technology and understanding of the development process. Here are some takeaways and insights:

  • Technical Enhancement: Through practical projects, you can strengthen your front-end and back-end development skills. On the front end, you learned how to use small program frameworks to build user interfaces and handle user input; On the back end, you learn how to build services, process requests, and perform computational logic.
  • API design and communication: You learned how to design simple and effective API interfaces and how to communicate data between the front end and the back end. This is also very useful for building other projects.
  • Security and error handling: Learn about front-end and back-end security issues such as data validation, user authentication, and error handling. This helps improve the stability and security of your application.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值