diff --git "a/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/.keep" "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.js" "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.js" new file mode 100644 index 0000000000000000000000000000000000000000..1c63524bf7bad8d315c0022cbe62ab57d71db77c --- /dev/null +++ "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.js" @@ -0,0 +1,278 @@ +var oprt = new Array(); +var rslt = "" + +Page({ + data:{ + result: "", + operotor: "", + }, + butn(e){ + var str = "" + str = e.target.dataset.val + if(str.length != 1){ + oprt.push(str) + } + else{ + if(oprt.length!=0){ + var tem = oprt[oprt.length-1][oprt[oprt.length-1].length-1] + if(tem <= "9" && tem >= "0"){ + if(str <= "9" && str >= "0" || str == "."){ + oprt[oprt.length-1] += str + } + else{ + oprt.push(str) + } + } + else if(tem == "."){ + if(str <= "9" && str >= "0"){ + oprt[oprt.length-1] += str + } + else{ + oprt.push(str) + } + } + else if(tem == "-" && oprt.length == 1){ + if(str <= "9" && str >= "0" || str == "." || str == "π" || str == "e"){ + oprt[oprt.length-1] += str + } + else{ + oprt.push(str) + } + } + else{ + if(str == ".") str = "0" + str + oprt.push(str) + } + } + else{ + if(str == ".") str = "0" + str + oprt.push(str) + } + } + this.calculate() + str = oprt.join("") + this.setData({ + operotor: str, + result: rslt + }) + }, + acbut(){ + oprt.splice(0,oprt.length) + rslt = "" + this.setData({ + operotor: "", + result: "" + }) + }, + eqbut(){ + oprt.splice(0,oprt.length) + oprt.push(rslt) + var str = oprt.join("") + rslt = "" + this.setData({ + operotor: str, + result: rslt + }) + }, + delbut(){ + oprt.pop() + this.calculate() + var str = oprt.join("") + this.setData({ + operotor: str, + result: rslt + }) + }, + + calculate(){ +//-------------------------------转化逆波兰---------------------------------------------- + var lastop = new Array + var trans = new Array + for(var i = 0; i < oprt.length; i++){ + var temp = oprt[i] + if(temp[0] >= "0" && temp[0] <= "9"){ + temp = Number(temp) + trans.push(temp) + } + else if(temp[0] == "π"){ + temp = Math.PI + trans.push(temp) + } + else if(temp[0] == "e"){ + temp = Math.E + trans.push(temp) + } + else if(temp[0] == "-" && i == 0){ + temp = Number(temp) + trans.push(temp) + } + else{ + if(temp == "+" || temp == "-"){ + while(lastop.length != 0){ + trans.push(lastop[lastop.length-1]) + lastop.pop() + } + lastop.push(temp) + } + else if(temp == "×" || temp == "÷"){ + lastop.push(temp) + } + else{ + while(lastop.length != 0 && lastop[lastop.length-1] != "+" && lastop[lastop.length-1] != "-"){ + trans.push(lastop[lastop.length-1]) + lastop.pop() + } + lastop.push(temp) + } + } + } + while(lastop.length != 0){ + trans.push(lastop[lastop.length-1]) + lastop.pop() + } +//--------------------------------后缀表达式计算----------------------------------------------------------------------------- + var ifcanop = 1 + var i = 0 + for(; i < trans.length; i++){ + if(typeof(trans[i]) == "number"){ + lastop.push(trans[i]) + } + else{ + switch(trans[i]){ + case "+": + if(lastop.length < 2){ + ifcanop = 0 + break + } + var s = lastop[lastop.length-2] + lastop[lastop.length-1] + lastop.pop() + lastop.pop() + lastop.push(s) + break + case "-": + if(lastop.length < 2){ + ifcanop = 0 + break + } + var s = lastop[lastop.length-2] - lastop[lastop.length-1] + lastop.pop() + lastop.pop() + lastop.push(s) + break + case "×": + if(lastop.length < 2){ + ifcanop = 0 + break + } + var s = lastop[lastop.length-2] * lastop[lastop.length-1] + lastop.pop() + lastop.pop() + lastop.push(s) + break + case "÷": + if(lastop.length < 2){ + ifcanop = 0 + break + } + var s = lastop[lastop.length-2] / lastop[lastop.length-1] + lastop.pop() + lastop.pop() + lastop.push(s) + break + case "sin": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.sin(lastop[lastop.length-1]) + lastop.pop() + lastop.push(s) + break + case "cos": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.cos(lastop[lastop.length-1]) + lastop.pop() + lastop.push(s) + break + case "tan": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.tan(lastop[lastop.length-1]) + lastop.pop() + lastop.push(s) + break + case "lg": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.log10(lastop[lastop.length-1]) + lastop.pop() + lastop.push(s) + break + case "ln": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.log(lastop[lastop.length-1]) + lastop.pop() + lastop.push(s) + break + case "√": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.sqrt(lastop[lastop.length-1]) + lastop.pop() + lastop.push(s) + break + case "%": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = lastop[lastop.length-1]/100 + lastop.pop() + lastop.push(s) + break + case "^": + if(lastop.length < 2){ + ifcanop = 0 + break + } + var s = Math.pow(lastop[lastop.length-2],lastop[lastop.length-1]) + lastop.pop() + lastop.pop() + lastop.push(s) + break + case "^2": + if(lastop.length < 1){ + ifcanop = 0 + break + } + var s = Math.pow(lastop[lastop.length-1],2) + lastop.pop() + lastop.push(s) + break + } + } + if(!ifcanop) break + } + if(lastop.length == 1 && ifcanop == 1){ + rslt = lastop[0].toFixed(8) + } + else if(ifcanop == 0 || i != trans.length-1){ + rslt = "wrong" + } + else{ + rslt = "wrong" + } + } +}) diff --git "a/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.wxml" "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.wxml" new file mode 100644 index 0000000000000000000000000000000000000000..8f5ef2f8d991fee59eb5bfa1d9a569267b1186a8 --- /dev/null +++ "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.wxml" @@ -0,0 +1,56 @@ + + + {{operotor}} + {{result}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.wxss" "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.wxss" new file mode 100644 index 0000000000000000000000000000000000000000..e836726538041c714265fae6a909433e2222a57f --- /dev/null +++ "b/\350\222\213\345\255\220\350\261\252-2020302778-\347\254\254\344\272\214\346\254\241mini \344\275\234\344\270\232/index.wxss" @@ -0,0 +1,112 @@ +page{ + display: flex; + flex-direction: column; + height: 100%; +} + +.showboard{ + height: 30%; + width: 100%; + background-color: rgb(241, 241, 241); +} + +.showoperotor{ + height: 50%; + width: 100%; + text-align:right; + font-size: 100rpx; + padding-top: 10%; + overflow: scroll; +} + +.showresult{ + height: 30%; + width: 100%; + font-size: 60rpx; + text-align: right; + color: rgb(124, 124, 124); + overflow: scroll; +} + +.keyboard{ + height: 70%; + width: 100%; + display: flex; + flex-direction: column; +} + +.line1{ + height: 16.66%; + width: 100%; + display:flex; +} + +.line2{ + height: 33.33%; + width: 100%; + display: flex; +} + +.but_1{ + margin: 1%; + background-color: rgb(241, 241, 241); + border-radius: 20%; + display: flex; + justify-content: center; + align-items: center; + font-size: 60rpx; +} + +.but_2{ + margin: 1%; + background-color: rgb(217, 238, 255); + border-radius: 20%; + display: flex; + justify-content: center; + align-items: center; + font-size: 60rpx; + color: rgb(63, 150, 221); +} + +.but_3{ + height: 45%; + margin: 5%; + background-color: rgb(241, 241, 241); + border-radius: 20%; + display: flex; + justify-content: center; + align-items: center; + font-size: 60rpx; +} + +.but_4{ + height: 92%; + margin-top: 5%; + background-color: rgb(76, 163, 117); + border-radius: 10%; + display: flex; + justify-content: center; + align-items: center; + font-size: 60rpx; + color: rgb(255, 255, 255); +} + +.row2{ + width: 20%; + height: 100%; +} + +.but_1hov{ + background-color: rgb(158, 158, 158); + color: rgb(37, 37, 37); +} + +.but_2hov{ + color: rgb(38, 72, 100); + background-color: rgb(155, 169, 180); +} + +.but_4hov{ + color: rgb(196, 196, 196); + background-color: rgb(53, 107, 78); +} \ No newline at end of file