MiniStar 1 year ago
commit
aea295cf9c
19 changed files with 1316 additions and 0 deletions
  1. 72 0
      LICENSE
  2. 23 0
      README.md
  3. 24 0
      README.zh-CN.md
  4. 20 0
      app.js
  5. 14 0
      app.json
  6. 9 0
      app.wxss
  7. 286 0
      pages/index/index.js
  8. 5 0
      pages/index/index.json
  9. 21 0
      pages/index/index.wxml
  10. 37 0
      pages/index/index.wxss
  11. 335 0
      pages/super/index.js
  12. 5 0
      pages/super/index.json
  13. 21 0
      pages/super/index.wxml
  14. 37 0
      pages/super/index.wxss
  15. 72 0
      project.config.json
  16. 7 0
      sitemap.json
  17. 183 0
      utils/calc.js
  18. 81 0
      utils/core.js
  19. 64 0
      utils/util.js

+ 72 - 0
LICENSE

@@ -0,0 +1,72 @@
+Apache License 
+Version 2.0, January 2004 
+http://www.apache.org/licenses/
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
+
+(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
+
+(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+
+(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
+
+Copyright 2022 liuyuqi.gov@msn.cn
+
+Licensed under the Apache License, Version 2.0 (the "License"); 
+you may not use this file except in compliance with the License. 
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software 
+distributed under the License is distributed on an "AS IS" BASIS, 
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+See the License for the specific language governing permissions and 
+limitations under the License.

+ 23 - 0
README.md

@@ -0,0 +1,23 @@
+# Calculator
+
+[![Version](https://img.shields.io/badge/version-v1.1.0-brightgreen)](https://git.yoqi.me/MiniStar/Calculator)
+[![.NET](https://img.shields.io/badge/wechatsdk-v2.12.2-brightgreen?style=plastic)](https://git.yoqi.me/MiniStar/Calculator)
+
+[English](./README.md) | [中文](./README.zh-CN.md)
+
+Science calculator,wechat miniapp
+
+![](https://git.yoqi.me/attachments/0a1c2082-cb3a-441c-862e-ada180dea76c)
+
+## Contributing
+
+There are same ways you can contribute.
+
+* Submit [bugs and feature requests](https://git.yoqi.me/MiniStar/Calculator/issues), and help us verify as they are checked in
+* Review [source code changes](https://git.yoqi.me/MiniStar/Calculator/pulls) 
+* Leave a message with email to this account: liuyuqi.gov@msn.cn
+
+
+## License
+
+Licensed under the [Apache 2.0](LICENSE) © [liuyuqi.gov@msn.cn](https://github.com/jianboy)

+ 24 - 0
README.zh-CN.md

@@ -0,0 +1,24 @@
+# Calculator
+
+[![Version](https://img.shields.io/badge/version-v1.1.0-brightgreen)](https://git.yoqi.me/MiniStar/Calculator)
+[![.NET](https://img.shields.io/badge/wechatsdk-v2.12.2-brightgreen?style=plastic)](https://git.yoqi.me/MiniStar/Calculator)
+
+[English](./README.md) | [中文](./README.zh-CN.md)
+
+科学计算器,微信小程序
+
+![](https://git.yoqi.me/attachments/0a1c2082-cb3a-441c-862e-ada180dea76c)
+
+## 反馈和贡献
+
+有如下方法:
+
+* 提交bugs和需求 [bugs and feature requests](https://git.yoqi.me/MiniStar/Calculator/issues)
+* 发起pull请求,提交你的代码  [source code changes](https://git.yoqi.me/MiniStar/Calculator/pulls) 
+* 或者通过邮件联系我们: liuyuqi.gov@msn.cn
+
+## License
+
+如果您在你的项目中使用我们的代码,请保留 License 声明,谢谢
+
+Licensed under the [Apache 2.0](LICENSE) © [liuyuqi.gov@msn.cn](https://github.com/jianboy)

+ 20 - 0
app.js

@@ -0,0 +1,20 @@
+//app.js
+App({
+  onLaunch: function() { 
+    // Do something initial when launch.
+  },
+  onShow: function() {
+      // Do something when show.
+  },
+  onHide: function() {
+      // Do something when hide.
+  },
+  getUserInfo:function(){
+
+  },
+  globalData:{
+    userInfo:null,
+    screenHeight:100,
+    screenWidth:100
+  }
+})

+ 14 - 0
app.json

@@ -0,0 +1,14 @@
+{
+  "pages": [
+    "pages/index/index",
+    "pages/super/index"
+  ],
+  "window": {
+    "backgroundTextStyle": "light",
+    "navigationBarBackgroundColor": "#fff",
+    "navigationBarTitleText": "微信计算器",
+    "navigationBarTextStyle": "black"
+  },
+  "debug": true,
+  "sitemapLocation": "sitemap.json"
+}

+ 9 - 0
app.wxss

@@ -0,0 +1,9 @@
+/**app.wxss**/
+.container {
+  height: 100vh;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: space-between;
+  box-sizing: border-box;
+} 

+ 286 - 0
pages/index/index.js

@@ -0,0 +1,286 @@
+//index.js
+var app = getApp()
+var util = require('../../utils/util.js'); 
+var calc = require('../../utils/calc.js'); 
+var core = require('../../utils/core.js'); 
+Page({
+  data: {
+    layout:[
+    [{
+	    opt:"bindViewTapOpt",
+    	type:"warn",
+	    id:"of",
+	    value:"ON/OFF",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"s",
+	    value:"高级",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"c",
+	    value:"C",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"ac",
+	    value:"AC",
+    }],
+    [{
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"7",
+    	value:"7",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"8",
+    	value:"8",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"9",
+    	value:"9",
+    },
+    {
+    	opt:"bindViewTapOpt",
+    	type:"primary",
+    	id:"÷",
+    	value:"÷",
+    }],
+    [{
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"4",
+	    value:"4",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"5",
+	    value:"5",
+    },
+    {
+	    opt:"bindViewTapInput",
+    	type:"default",
+    	id:"6",
+    	value:"6",
+    },
+    {
+    	opt:"bindViewTapOpt",
+    	type:"primary",
+    	id:"×",
+    	value:"×",
+    }],
+    [{
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"1",
+    	value:"1",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"2",
+    	value:"2",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"3",
+    	value:"3",
+    },
+    {
+    	opt:"bindViewTapOpt",
+    	type:"primary",
+    	id:"-",
+    	value:"-",
+    }],
+    [{
+	    opt:"bindViewTapInput",
+	    type:"default",
+	    id:"0",
+	    value:"0",
+    },
+    {
+	    opt:"bindViewTapInput",
+	    type:"default",
+	    id:".",
+	    value:".",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"=",
+	    value:"=",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"primary",
+	    id:"+",    
+	    value:"+",
+    }]],
+    lines: [
+      "",
+      "",
+      "",
+      "",
+      0
+    ],
+    power:1,
+    line:"------------------------------------------------",
+    infix:"0"
+  },
+  onLoad: function () {
+    //core.showToast();
+    //core.showModal();
+    //core.showActionSheet();
+    this.clear();
+    wx.setNavigationBarTitle({
+      title: '微信计算器'
+    })
+  },
+  onReady: function() {
+    wx.showNavigationBarLoading();
+    wx.hideNavigationBarLoading();
+    
+  },
+  onShow: function() {
+    // Do something when page ready.
+  },
+  onHide: function() {
+    // Do something when page hide.
+  },
+  onUnload: function() {
+    // Do something when page close.
+  },
+  onPullDownRefresh: function() {
+    // Do something when pull down.
+  },
+  onReachBottom: function() {
+    // Do something when page reach bottom.
+  },
+  clear:function(){
+    this.output([0]);
+  },
+  clearAll:function(){
+    this.output(["","","","",0],true);
+    this.setData({
+      infix: "",
+    });
+  },
+  calculator:function(){
+    var infix = this.data.infix; 
+    var res = calc.calculate(infix);
+    this.makeInfix("0",true);
+    return res;
+  },
+  bindViewTapInput:function (e){
+    var content = e.currentTarget.id;
+    this.getNumber(content);
+  },
+  bindViewTapOpt:function (e){
+    var content = e.currentTarget.id;
+    //console.log(content);
+    switch(content){
+      case 'c':
+          this.clear();
+          break;
+      case 's':
+          wx.navigateTo({
+             url: '/pages/super/index?id=1'
+          })
+          break;
+      case 'of':
+          this.setData({
+            power:0-this.data.power
+          });
+          this.clearAll();
+          break;
+      case 'ac':
+          this.clearAll();
+          break;
+      case '=':
+          this.makeInfix();
+          var res = this.calculator();
+          this.output([this.data.line,res],true);
+          break;
+      default:
+          this.makeInfix(content);
+          this.output([content],true);
+          break;
+    }
+  },
+  makeInfix:function(content,flash){
+    //生成中缀表达式
+    content = content ? content : ""; 
+    var oldInfix = this.data.infix.toString();
+    var lastNum = this.data.lines[(this.data.lines.length-1)].toString();
+    if(oldInfix == "0"){
+      oldInfix = "";
+    }
+    if(!flash){
+        content = oldInfix+lastNum+content;
+    }
+    console.log(content);
+    this.setData({
+      infix:content
+    }); 
+  },
+  getNumber:function(content){
+    var lines = this.data.lines;
+    var move = false;
+    var old =  lines[(lines.length-1)].toString(); 
+    var newNum;
+    if(content=="." && old.indexOf(".")!=-1){
+    //当原字符串有小数点时再输入小数点无反应
+        return false;
+    }
+    if(content=="0" && old=="0"){
+    //当原字符串等于0再输入0无反应
+        return false;
+    }
+    if(isNaN(old) && old != "0."){
+    //当原字符串是非数字即操作符(+-×÷)时新字符串另起一行为新数字
+    //需要排除 0.  这个不是字符,但是需要继续拼接
+      if(content=="."){
+        content = "0.";
+      }
+      newNum = content;
+      //另起一行的标志
+      move = true;
+    }else{
+      if(old == "0" && content != "."){
+        //当原字符串是0的时候又不是小数,需要把0去掉
+        old = "";
+      }
+      newNum = old+content;
+    }
+    this.output([newNum],move);
+  },
+  output:function(content,move){
+    var lines = this.data.lines;
+    if(move){
+      for(var index in content){
+        lines.shift();
+        lines.push(content[index]);
+      }
+    }else{
+      lines[(lines.length-1)] =  content[0];
+    }
+    
+    if(this.data.power <= 0){
+        lines = ["","","","",""];
+    }
+    this.setData({
+        lines:lines
+    });
+    //console.log(this.data);
+  }
+})

+ 5 - 0
pages/index/index.json

@@ -0,0 +1,5 @@
+{
+  "window":{
+    "navigationBarTitleText": "计算器"
+  }
+}

+ 21 - 0
pages/index/index.wxml

@@ -0,0 +1,21 @@
+<!--index.wxml-->
+<view class="container">
+
+    <!-- screen -->
+    <view class="screen">
+        <view plain="true" wx:for-items="{{lines}}" wx:for-index="idx" wx:for-item="line" wx:key="unique">
+            <button wx:if="{{idx == 4}}" class="current" plain="true">{{line}}</button>
+            <button wx:else plain="true">{{line}}</button>
+        </view>
+    </view>
+
+    <!-- keyboard -->
+    <view class="keyboard">
+        <view class="key-rows" wx:for-items="{{layout}}" wx:for-item="itemName" wx:key="unique">
+            <view class="key" wx:for-items="{{itemName}}" wx:for-index="id" wx:for-item="keyInfo" wx:key="unique">
+                <button bindtap="{{keyInfo.opt}}" id="{{keyInfo.id}}" type="{{keyInfo.type}}">{{keyInfo.value}}</button>
+            </view>
+        </view>
+    </view>
+
+</view>

+ 37 - 0
pages/index/index.wxss

@@ -0,0 +1,37 @@
+.keyboard{
+  width: 100vw;
+}
+.key-rows{ 
+  display:flex;
+  width: 100vw;
+}
+.key{
+  width: 25vw;
+}
+.key button{
+  margin: 1vh 1vw;
+  height:8.6vh;
+  line-height:8.6vh;
+}
+.screen{
+  width: 98vw;
+  height:44vh;
+  margin: 1vh 1vw;
+  padding: 1vh 1.4vw;
+  border:1px solid #353535;
+  box-sizing:border-box;
+  border-radius:4px;
+}
+.screen button{
+  text-align:right;
+  margin: 0;
+  line-height:8vh;
+  height:8vh;
+  border:none;
+  color: gainsboro;
+  font-size:7vw; 
+}
+.screen .current{
+  color: black;
+  font-size:12vw; 
+}

+ 335 - 0
pages/super/index.js

@@ -0,0 +1,335 @@
+//index.js
+var app = getApp()
+var util = require('../../utils/util.js'); 
+var calc = require('../../utils/calc.js'); 
+var core = require('../../utils/core.js'); 
+Page({
+  data: {
+    layout:[
+    [{
+	    opt:"bindViewTapOpt",
+    	type:"default",
+	    id:"!",
+	    value:"!",
+    },
+    {
+	    opt:"bindViewTapOpt",
+    	type:"default",
+	    id:"^",
+	    value:"^",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"default",
+	    id:"√",
+	    value:"√",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"default",
+	    id:"π",
+	    value:"π",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"c",
+	    value:"C",
+    }],
+    [{
+	    opt:"bindViewTapOpt",
+    	type:"default",
+	    id:"sin",
+	    value:"sin",
+    },
+    {
+	    opt:"bindViewTapOpt",
+    	type:"default",
+	    id:"(",
+	    value:"(",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"default",
+	    id:")",
+	    value:")",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"default",
+	    id:"e",
+	    value:"e",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"ac",
+	    value:"AC",
+    }],
+    [{
+    	opt:"bindViewTapOpt",
+    	type:"default",
+    	id:"cos",
+    	value:"cos",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"7",
+    	value:"7",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"8",
+    	value:"8",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"9",
+    	value:"9",
+    },
+    {
+    	opt:"bindViewTapOpt",
+    	type:"primary",
+    	id:"÷",
+    	value:"÷",
+    }],
+    [{
+    	opt:"bindViewTapOpt",
+    	type:"default",
+    	id:"tan",
+    	value:"tan",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"4",
+	    value:"4",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"5",
+	    value:"5",
+    },
+    {
+	    opt:"bindViewTapInput",
+    	type:"default",
+    	id:"6",
+    	value:"6",
+    },
+    {
+    	opt:"bindViewTapOpt",
+    	type:"primary",
+    	id:"×",
+    	value:"×",
+    }],
+    [{
+    	opt:"bindViewTapOpt",
+    	type:"default",
+    	id:"ln",
+    	value:"ln",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"1",
+    	value:"1",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"2",
+    	value:"2",
+    },
+    {
+    	opt:"bindViewTapInput",
+    	type:"default",
+    	id:"3",
+    	value:"3",
+    },
+    {
+    	opt:"bindViewTapOpt",
+    	type:"primary",
+    	id:"-",
+    	value:"-",
+    }],
+    [{
+    	opt:"bindViewTapOpt",
+    	type:"default",
+    	id:"lg",
+    	value:"lg",
+    },
+    {
+	    opt:"bindViewTapInput",
+	    type:"default",
+	    id:"0",
+	    value:"0",
+    },
+    {
+	    opt:"bindViewTapInput",
+	    type:"default",
+	    id:".",
+	    value:".",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"warn",
+	    id:"=",
+	    value:"=",
+    },
+    {
+	    opt:"bindViewTapOpt",
+	    type:"primary",
+	    id:"+",    
+	    value:"+",
+    }]],
+    lines: [
+      "",
+      "",
+      "",
+      "",
+      0
+    ],
+    power:1,
+    line:"------------------------------------------------",
+    infix:"0"
+  },
+  onLoad: function () {
+    wx.setNavigationBarTitle({
+      title: '科学计算器'
+    })
+    //core.showToast();
+    //core.showModal();
+    //core.showActionSheet();
+    this.clear();
+  },
+  onReady: function() {
+    wx.showNavigationBarLoading();
+    wx.hideNavigationBarLoading();
+    wx.setNavigationBarTitle({
+      title: '科学计算器'
+    })
+  },
+  onShow: function() {
+  },
+  clear:function(){
+    this.output([0]);
+  },
+  clearAll:function(){
+    this.output(["","","","",0],true);
+    this.setData({
+      infix: "",
+    });
+  },
+  calculator:function(){
+    var infix = this.data.infix; 
+    var res = calc.calculate(infix);
+    this.makeInfix("0",true);
+    return res;
+  },
+  bindViewTapInput:function (e){
+    var content = e.currentTarget.id;
+    this.getNumber(content);
+  },
+  bindViewTapOpt:function (e){
+    var content = e.currentTarget.id;
+    //console.log(content);
+    switch(content){
+      case 'c':
+          this.clear();
+          break;
+      case 't':
+          this.clearAll();
+          console.log(util.formatTime(new Date()));
+          this.output([util.formatTime(new Date())]);
+          break;
+      case 'of':
+          this.setData({
+            power:0-this.data.power
+          });
+          this.clearAll();
+          break;
+      case 'ac':
+          this.clearAll();
+          break;
+      case '=':
+          this.makeInfix();
+          var res = this.calculator();
+          this.output([this.data.line,res],true);
+          break;
+      default:
+          this.makeInfix(content);
+          this.output([content],true);
+          break;
+    }
+  },
+  makeInfix:function(content,flash){
+    //生成中缀表达式
+    content = content ? content : ""; 
+    var oldInfix = this.data.infix.toString();
+    var lastNum = this.data.lines[(this.data.lines.length-1)].toString();
+    if(oldInfix == "0"){
+      oldInfix = "";
+    }
+    if(!flash){
+        content = oldInfix+lastNum+content;
+    }
+    console.log(content);
+    this.setData({
+      infix:content
+    }); 
+  },
+  getNumber:function(content){
+    var lines = this.data.lines;
+    var move = false;
+    var old =  lines[(lines.length-1)].toString(); 
+    var newNum;
+    if(content=="." && old.indexOf(".")!=-1){
+    //当原字符串有小数点时再输入小数点无反应
+        return false;
+    }
+    if(content=="0" && old=="0"){
+    //当原字符串等于0再输入0无反应
+        return false;
+    }
+    if(isNaN(old) && old != "0."){
+    //当原字符串是非数字即操作符(+-×÷)时新字符串另起一行为新数字
+    //需要排除 0.  这个不是字符,但是需要继续拼接
+      if(content=="."){
+        content = "0.";
+      }
+      newNum = content;
+      //另起一行的标志
+      move = true;
+    }else{
+      if(old == "0" && content != "."){
+        //当原字符串是0的时候又不是小数,需要把0去掉
+        old = "";
+      }
+      newNum = old+content;
+    }
+    this.output([newNum],move);
+  },
+  output:function(content,move){
+    var lines = this.data.lines;
+    if(move){
+      for(var index in content){
+        lines.shift();
+        lines.push(content[index]);
+      }
+    }else{
+      lines[(lines.length-1)] =  content[0];
+    }
+    
+    if(this.data.power <= 0){
+        lines = ["","","","",""];
+    }
+    this.setData({
+        lines:lines
+    });
+    //console.log(this.data);
+  }
+})

+ 5 - 0
pages/super/index.json

@@ -0,0 +1,5 @@
+{
+  "window":{
+    "navigationBarTitleText": "科学计算器"
+  }
+}

+ 21 - 0
pages/super/index.wxml

@@ -0,0 +1,21 @@
+<!--index.wxml-->
+<view class="container">
+
+    <!-- screen -->
+    <view class="screen">
+        <view plain="true" wx:for-items="{{lines}}" wx:for-index="idx" wx:for-item="line" wx:key="unique">
+            <button wx:if="{{idx == 4}}" class="current" plain="true">{{line}}</button>
+            <button wx:else plain="true">{{line}}</button>
+        </view>
+    </view>
+
+    <!-- keyboard -->
+    <view class="keyboard">
+        <view class="key-rows" wx:for-items="{{layout}}" wx:for-item="itemName" wx:key="unique">
+            <view class="key" wx:for-items="{{itemName}}" wx:for-index="id" wx:for-item="keyInfo" wx:key="unique">
+                <button bindtap="{{keyInfo.opt}}" id="{{keyInfo.id}}" type="{{keyInfo.type}}">{{keyInfo.value}}</button>
+            </view>
+        </view>
+    </view>
+
+</view>

+ 37 - 0
pages/super/index.wxss

@@ -0,0 +1,37 @@
+.keyboard{
+  width: 100vw;
+}
+.key-rows{ 
+  display:flex;
+  width: 100vw;
+}
+.key{
+  width: 25vw;
+}
+.key button{
+  margin: 0.5vh 1vw;
+  height:8.6vh;
+  line-height:8.6vh;
+}
+.screen{
+  width: 98vw;
+  height:38vh;
+  margin: 1vh 1vw;
+  padding: 0vh 1.4vw;
+  border:1px solid #353535;
+  box-sizing:border-box;
+  border-radius:4px;
+}
+.screen button{
+  text-align:right;
+  margin: 0;
+  line-height:7vh;
+  height:7vh;
+  border:none;
+  color: gainsboro;
+  font-size:7vw; 
+}
+.screen .current{
+  color: black;
+  font-size:12vw; 
+}

+ 72 - 0
project.config.json

@@ -0,0 +1,72 @@
+{
+  "description": "Project configuration file",
+  "packOptions": {
+    "ignore": []
+  },
+  "setting": {
+    "urlCheck": true,
+    "es6": true,
+    "enhance": false,
+    "postcss": true,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "newFeature": false,
+    "coverView": true,
+    "nodeModules": false,
+    "autoAudits": false,
+    "showShadowRootInWxmlPanel": true,
+    "scopeDataCheck": false,
+    "uglifyFileName": false,
+    "checkInvalidKey": true,
+    "checkSiteMap": true,
+    "uploadWithSourceMap": true,
+    "compileHotReLoad": false,
+    "useMultiFrameRuntime": false,
+    "useApiHook": true,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    },
+    "enableEngineNative": false,
+    "bundle": false,
+    "useIsolateContext": true,
+    "useCompilerModule": true,
+    "userConfirmedUseCompilerModuleSwitch": false,
+    "userConfirmedBundleSwitch": false,
+    "packNpmManually": false,
+    "packNpmRelationList": [],
+    "minifyWXSS": true
+  },
+  "compileType": "miniprogram",
+  "libVersion": "2.12.2",
+  "appid": "wx8551d91392a2ea86",
+  "projectname": "miniprogram-1",
+  "debugOptions": {
+    "hidedInDevtools": []
+  },
+  "scripts": {},
+  "isGameTourist": false,
+  "simulatorType": "wechat",
+  "simulatorPluginLibVersion": {},
+  "condition": {
+    "search": {
+      "list": []
+    },
+    "conversation": {
+      "list": []
+    },
+    "game": {
+      "list": []
+    },
+    "plugin": {
+      "list": []
+    },
+    "gamePlugin": {
+      "list": []
+    },
+    "miniprogram": {
+      "list": []
+    }
+  }
+}

+ 7 - 0
sitemap.json

@@ -0,0 +1,7 @@
+{
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
+  "rules": [{
+  "action": "allow",
+  "page": "*"
+  }]
+}

+ 183 - 0
utils/calc.js

@@ -0,0 +1,183 @@
+var Stack = function(){}
+Stack.prototype={
+    Init:function(){
+        this.STACKMAX = 100;
+        this.stack = new Array(this.STACKMACK);
+        this.top = -1;
+        return this.stack;
+    },
+    isEmpty:function(){
+        if(this.top==-1){
+            return true;
+        }
+        else{
+            return false;
+        }
+    },
+    push:function(elem){
+        if(this.top==this.STACKMAX-1){
+            return "栈满";
+        }
+        else{
+            this.top++;
+            this.stack[this.top] = elem;
+        }
+    },
+    pop:function(){
+        if(this.top==-1){
+            return "空栈,无法删除栈顶元素!";
+        }
+        else{
+            var x = this.stack[this.top];
+            this.top--;
+            return x;
+        }
+    },
+    peek:function(){
+        if(this.top!=-1){
+            return this.stack[this.top];
+        }
+        else{
+            return "空栈,顶元素无返回值!";
+        }
+    },
+    Clear:function(){
+        this.top=-1;
+    },
+    Length:function(){
+        return this.top+1;
+    }
+}
+
+function toRPolish(s){
+	var list=new Array();
+	var op=new Stack();
+	op.Init();
+	//var num=str.match(/\d+(\.\d+)?/g);
+	var i=0;
+	while(i<s.length){
+		var c=s.charAt(i);
+		if(c>='0'&&c<='9'){
+			var s1=s.substr(i);
+			var m=s1.match(/\d+(\.\d+)?/g);
+			if (m.length>0){
+				s1=m[0];
+				list.push(s1);
+			}
+			i=i+s1.length;
+			continue;
+		}else if(c=='('){
+			op.push(c);
+		}else if(c==')'){
+			var p=op.pop();
+			while(p!='('){
+				list.push(p);
+				p=op.pop();
+			}
+		}else if(c=='+'||c=='-'){
+			while(!op.isEmpty()&&(op.peek()=='+'||op.peek()=='-'||op.peek()=='×'||op.peek()=='÷')){
+				list.push(op.pop());
+			}
+			op.push(c);
+		}else if(c=='×'||c=='÷'){
+			while(!op.isEmpty()&&(op.peek()=='×'||op.peek()=='÷')){
+				list.push(op.pop());
+			}
+			op.push(c);
+		}
+		i++;
+	}
+	while(!op.isEmpty()){
+		list.push(op.pop());
+	}
+	return list;
+}
+
+function g(a,b,c){
+	var v=0;
+	a=parseFloat(a);
+	b=parseFloat(b);
+	switch (c){
+        case '+':
+            v=floatAdd(a,b);
+            break;
+        case '-':
+            v=floatSub(a,b);;
+            break;
+        case '×':
+            v=floatMul(a,b);;
+            break;
+        case '÷':
+            v=floatDiv(a,b);;
+            break;
+    }
+    return v;
+}
+
+function getResult(list,result){
+	for (var i=0;i<list.length;i++){
+		if(!isNaN(list[i])){
+			result.push(list[i]);
+		}else{
+			var b=result.pop();
+			var a=result.pop();
+			var v=g(a,b,list[i]);
+
+			result.push(v);
+		}
+	}
+	return result.pop();
+}
+
+function calculate(input){
+    console.log(input);
+    var list=toRPolish(input);
+    console.log(list);
+    var result=new Stack();
+    result.Init();
+    return getResult(list, result);
+}
+ 
+
+//浮点数加法运算
+function floatAdd(arg1,arg2){
+    var r1,r2,m;
+    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
+    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
+    m=Math.pow(10,Math.max(r1,r2));
+    return (arg1*m+arg2*m)/m;
+}
+
+//浮点数减法运算
+function floatSub(arg1,arg2){
+    var r1,r2,m,n;
+    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
+    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
+    m=Math.pow(10,Math.max(r1,r2));
+    //动态控制精度长度
+    n=(r1=r2)?r1:r2;
+    return ((arg1*m-arg2*m)/m).toFixed(n);
+}
+
+//浮点数乘法运算
+function floatMul(arg1,arg2){
+    var m=0,s1=arg1.toString(),s2=arg2.toString();
+    try{m+=s1.split(".")[1].length}catch(e){}
+    try{m+=s2.split(".")[1].length}catch(e){}
+    return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
+}
+
+
+ //浮点数除法运算
+function floatDiv(arg1,arg2){
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length}catch(e){}
+    r1=Number(arg1.toString().replace(".",""));
+    r2=Number(arg2.toString().replace(".",""));
+    return (r1/r2)*Math.pow(10,t2-t1);
+}
+ 
+module.exports = {
+  calculate:calculate
+}

+ 81 - 0
utils/core.js

@@ -0,0 +1,81 @@
+
+function onAccelerometerChange() {
+    wx.onAccelerometerChange(function(res) {
+        console.log(res.x)
+        console.log(res.y)
+        console.log(res.z)
+        this.output(["","",'x:'+res.x,'y:'+res.y,'z:'+res.z],true);
+    })
+}
+
+function showToast() {
+    wx.showToast({
+      title: '加载中',//String 提示的内容
+      icon: 'loading',//图标,只支持"success"、"loading"
+      duration: 1000,//提示的延迟时间,单位毫秒,默认:1500, 最大为10000
+      success:function(e){
+        //接口调用成功的回调函数
+      },
+      fail:function(e){
+        //接口调用失败的回调函数
+      },
+      complete:function(e){
+        //接口调用结束的回调函数(调用成功、失败都会执行)
+      }
+    })
+}
+
+function showModal() {
+    wx.showModal({
+      title: '提示',//String 提示的标题
+      content: '这是一个模态弹窗',//String	提示的内容
+      showCancel:true,//是否显示取消按钮,默认为 true
+      cancelText:'取消按钮',//String	取消按钮的文字,默认为"取消"
+      cancelColor:'#E64340', //HexColor	取消按钮的文字颜色,默认为"#000000"
+      confirmText:'确定按钮',//String	确定按钮的文字,默认为"确定"
+      confirmColor:'#1AAD19',  //HexColor	确定按钮的文字颜色,默认为"#3CC51F"
+      success: function(res) {
+        //接口调用成功的回调函数,返回res.confirm==1时,表示用户点击确定按钮
+        if (res.confirm) {
+          console.log('用户点击确定')
+        }else{
+          console.log('用户点击取消')
+        }
+      },
+      fail:function(e){
+        //接口调用失败的回调函数
+      },
+      complete:function(e){
+        //接口调用结束的回调函数(调用成功、失败都会执行)
+      }
+    })
+}
+
+function showActionSheet() {
+    wx.showActionSheet({
+      itemList: ['一', '二', '三','四','五','六'],//String Array 按钮的文字数组,数组长度最大为6个
+      itemColor:'#1AAD19',//HexColor	按钮的文字颜色,默认为"#000000"
+      success: function(res) {
+        if (!res.cancel) {
+          console.log(res.tapIndex)
+        }
+      },
+      fail:function(e){
+        //接口调用失败的回调函数
+      },
+      complete:function(e){
+        //接口调用结束的回调函数(调用成功、失败都会执行)
+      }
+    })
+}
+
+function demo() {
+
+}
+ 
+module.exports = {
+  onAccelerometerChange:onAccelerometerChange,
+  showToast:showToast,
+  showModal:showModal,
+  showActionSheet:showActionSheet,
+}

+ 64 - 0
utils/util.js

@@ -0,0 +1,64 @@
+function formatTime(date) {
+  var year = date.getFullYear()
+  var month = date.getMonth() + 1
+  var day = date.getDate()
+
+  var hour = date.getHours()
+  var minute = date.getMinutes()
+  var second = date.getSeconds()
+
+
+  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
+}
+
+function formatNumber(n) {
+  n = n.toString()
+  return n[1] ? n : '0' + n
+}
+
+//浮点数加法运算
+function floatAdd(arg1,arg2){
+    var r1,r2,m;
+    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
+    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
+    m=Math.pow(10,Math.max(r1,r2));
+    return (arg1*m+arg2*m)/m;
+}
+
+//浮点数减法运算
+function floatSub(arg1,arg2){
+    var r1,r2,m,n;
+    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
+    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
+    m=Math.pow(10,Math.max(r1,r2));
+    //动态控制精度长度
+    n=(r1=r2)?r1:r2;
+    return ((arg1*m-arg2*m)/m).toFixed(n);
+}
+
+//浮点数乘法运算
+function floatMul(arg1,arg2){
+    var m=0,s1=arg1.toString(),s2=arg2.toString();
+    try{m+=s1.split(".")[1].length}catch(e){}
+    try{m+=s2.split(".")[1].length}catch(e){}
+    return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
+}
+
+
+ //浮点数除法运算
+function floatDiv(arg1,arg2){
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length}catch(e){}
+    r1=Number(arg1.toString().replace(".",""));
+    r2=Number(arg2.toString().replace(".",""));
+    return (r1/r2)*Math.pow(10,t2-t1);
+}
+ 
+module.exports = {
+  formatTime:formatTime,
+  floatMul:floatMul,
+  floatDiv:floatDiv,
+  floatSub:floatSub,
+  floatAdd:floatAdd
+}