From ee53cb0bccde6b243ce47af2a7c643d2923421a5 Mon Sep 17 00:00:00 2001 From: cc Date: Sat, 6 Nov 2021 08:17:09 +0800 Subject: [PATCH] practice2:chenchi-2021303090 --- newcal/.eslintrc.js | 31 ++++ newcal/app.js | 19 +++ newcal/app.json | 15 ++ newcal/app.wxss | 3 + newcal/pages/cal/cal.js | 292 ++++++++++++++++++++++++++++++++++ newcal/pages/cal/cal.json | 3 + newcal/pages/cal/cal.wxml | 54 +++++++ newcal/pages/cal/cal.wxss | 46 ++++++ newcal/pages/index/index.js | 48 ++++++ newcal/pages/index/index.json | 3 + newcal/pages/index/index.wxml | 23 +++ newcal/pages/index/index.wxss | 19 +++ newcal/pages/logs/logs.js | 18 +++ newcal/pages/logs/logs.json | 4 + newcal/pages/logs/logs.wxml | 6 + newcal/pages/logs/logs.wxss | 8 + newcal/project.config.json | 74 +++++++++ newcal/sitemap.json | 7 + newcal/utils/util.js | 19 +++ 19 files changed, 692 insertions(+) create mode 100644 newcal/.eslintrc.js create mode 100644 newcal/app.js create mode 100644 newcal/app.json create mode 100644 newcal/app.wxss create mode 100644 newcal/pages/cal/cal.js create mode 100644 newcal/pages/cal/cal.json create mode 100644 newcal/pages/cal/cal.wxml create mode 100644 newcal/pages/cal/cal.wxss create mode 100644 newcal/pages/index/index.js create mode 100644 newcal/pages/index/index.json create mode 100644 newcal/pages/index/index.wxml create mode 100644 newcal/pages/index/index.wxss create mode 100644 newcal/pages/logs/logs.js create mode 100644 newcal/pages/logs/logs.json create mode 100644 newcal/pages/logs/logs.wxml create mode 100644 newcal/pages/logs/logs.wxss create mode 100644 newcal/project.config.json create mode 100644 newcal/sitemap.json create mode 100644 newcal/utils/util.js diff --git a/newcal/.eslintrc.js b/newcal/.eslintrc.js new file mode 100644 index 0000000..115cc02 --- /dev/null +++ b/newcal/.eslintrc.js @@ -0,0 +1,31 @@ +/* + * Eslint config file + * Documentation: https://eslint.org/docs/user-guide/configuring/ + * Install the Eslint extension before using this feature. + */ +module.exports = { + env: { + es6: true, + browser: true, + node: true, + }, + ecmaFeatures: { + modules: true, + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + }, + globals: { + wx: true, + App: true, + Page: true, + getCurrentPages: true, + getApp: true, + Component: true, + requirePlugin: true, + requireMiniProgram: true, + }, + // extends: 'eslint:recommended', + rules: {}, +} diff --git a/newcal/app.js b/newcal/app.js new file mode 100644 index 0000000..1ed57c4 --- /dev/null +++ b/newcal/app.js @@ -0,0 +1,19 @@ +// app.js +App({ + onLaunch() { + // 展示本地存储能力 + const logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + } + }) + }, + globalData: { + userInfo: null + } +}) diff --git a/newcal/app.json b/newcal/app.json new file mode 100644 index 0000000..9ccac71 --- /dev/null +++ b/newcal/app.json @@ -0,0 +1,15 @@ +{ + "pages":[ + "pages/cal/cal", + "pages/index/index", + "pages/logs/logs" + ], + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "这是计算器", + "navigationBarTextStyle":"black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} diff --git a/newcal/app.wxss b/newcal/app.wxss new file mode 100644 index 0000000..0b7f3d1 --- /dev/null +++ b/newcal/app.wxss @@ -0,0 +1,3 @@ +page{ + height:100% +} \ No newline at end of file diff --git a/newcal/pages/cal/cal.js b/newcal/pages/cal/cal.js new file mode 100644 index 0000000..41b35dc --- /dev/null +++ b/newcal/pages/cal/cal.js @@ -0,0 +1,292 @@ +// pages/cal/cal.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + view:[], + tempformula:"", + answer:0, + showanswer:false, + Val:"", + elements:[], + scrollTop:100000 + }, + halfcal(thelist,index){ + var oplist=["="]; + var numlist=[]; + var pattIsNum=/[0-9]|\./; + for(var i=index;i<=thelist.length;){ + if(thelist[i]=="("||thelist[i]=="sin("||thelist[i]=="cos("||thelist[i]=="tan("||thelist[i]=="lg("||thelist[i]=="ln("||thelist[i]=="√("){ + var half=this.halfcal(thelist,i+1); + numlist.push(half[0]); + i=half[1]+1; + } + else if(i==thelist.length||thelist[i]==")"||this.righttable(thelist[i])<=this.lefttable(oplist[oplist.length-1])){ + while(((i==thelist.length||thelist[i]==")")&&this.righttable(")")<=this.lefttable(oplist[oplist.length-1]))||((i!=thelist.length&&thelist[i]!=")")&&this.righttable(thelist[i])<=this.lefttable(oplist[oplist.length-1]))){ + var op=oplist.pop(); + if(op=="+"){ + var num1=numlist.pop(); + var num2=numlist.pop(); + numlist.push(num1+num2); + } + else if(op=="-"){ + var num1=numlist.pop(); + var num2=numlist.pop(); + numlist.push(num2-num1); + } + else if(op=="×"){ + var num1=numlist.pop(); + var num2=numlist.pop(); + numlist.push(num2*num1); + } + else if(op=="÷"){ + var num1=numlist.pop(); + var num2=numlist.pop(); + numlist.push(num2/num1); + } + else if(op=="^"){ + console.log(1); + var num1=numlist.pop(); + var num2=numlist.pop(); + console.log(Math.pow(num1,num2)); + numlist.push(Math.pow(num1,num2)); + } + } + if(i!=thelist.length&&thelist[i]!=")"){ + console.log(thelist[i]); + oplist.push(thelist[i++]); + } + else {break;} + }else if(pattIsNum.test(thelist[i][0])){ + numlist.push(parseFloat(thelist[i++])); + }else if(this.righttable(thelist[i])>this.lefttable(oplist[oplist.length-1])){ + oplist.push(thelist[i++]); + } + else{ + } + + } + if(oplist.length==1&&numlist.length==1){ + var halfanswer=numlist[0]; + console.log(index,thelist[index-1]); + if(index!=0){ + if(thelist[index-1]=="sin("){ + halfanswer=Math.sin(halfanswer * Math.PI / 180); + }else if(thelist[index-1]=="cos("){ + halfanswer=Math.cos(halfanswer * Math.PI / 180); + }else if(thelist[index-1]=="tan("){ + halfanswer=Math.tan(halfanswer * Math.PI / 180); + }else if(thelist[index-1]=="lg("){ + halfanswer=Math.LOG10E*Math.log(halfanswer); + }else if(thelist[index-1]=="ln("){ + halfanswer=Math.log(halfanswer); + }else if(thelist[index-1]=="√("){ + halfanswer=Math.sqrt(halfanswer); + } + return [halfanswer,i] + } + else return [halfanswer,i]; + } + else {console.log("出错了");console.log(aaa)} + }, + + + cal(){ + var txt=this.data.Val; + var thelist=[]; + var i=0; + var pattIsNum=/[0-9]|\./; + while(i + + + + {{item[0]}} + {{item[1]}} + + + {{Val}} + ={{answer}} + + + + sin + cos + tan + lg + ln + ( + + + √x + C + 7 + 4 + 1 + ) + + + x^y + ÷ + 8 + 5 + 2 + 0 + + + + × + 9 + 6 + 3 + . + + + + del + - + + + = + + + + diff --git a/newcal/pages/cal/cal.wxss b/newcal/pages/cal/cal.wxss new file mode 100644 index 0000000..1d830e5 --- /dev/null +++ b/newcal/pages/cal/cal.wxss @@ -0,0 +1,46 @@ +.button{ + flex:1 +} +.buttons{ + flex:2; + width:100%; + display: flex; + background-color: burlywood; + flex-direction: row; +} +.buttonline{ + flex:1; + display: flex; + flex-direction: column; +} +.button{ + display:flex; + flex-direction: column; + border-radius: 20rpx; + background-color: rgb(192, 192, 192); + margin:10rpx; + text-align: center; + justify-content: center; + line-height: 100%; +} +/* .bracket{ + flex:1; + display: flex; + flex-direction: row; + border-radius: 20rpx; +} */ +.screen{ + display: flex; + flex-direction: column; + height:33%; + background-color: rgb(204, 204, 204); +} +.formula{ + text-align:right; +} +.container{ + height:100%; + display:flex; + flex-direction: column; + align-items: center; +} \ No newline at end of file diff --git a/newcal/pages/index/index.js b/newcal/pages/index/index.js new file mode 100644 index 0000000..0bc1771 --- /dev/null +++ b/newcal/pages/index/index.js @@ -0,0 +1,48 @@ +// index.js +// 获取应用实例 +const app = getApp() + +Page({ + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo'), + canIUseGetUserProfile: false, + canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false + }, + // 事件处理函数 + bindViewTap() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onLoad() { + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + }, + getUserProfile(e) { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + console.log(res) + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + }, + getUserInfo(e) { + // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 + console.log(e) + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/newcal/pages/index/index.json b/newcal/pages/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/newcal/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/newcal/pages/index/index.wxml b/newcal/pages/index/index.wxml new file mode 100644 index 0000000..f00d294 --- /dev/null +++ b/newcal/pages/index/index.wxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + 请使用1.4.4及以上版本基础库 + + + + {{userInfo.nickName}} + + + + {{motto}} + + diff --git a/newcal/pages/index/index.wxss b/newcal/pages/index/index.wxss new file mode 100644 index 0000000..eb64203 --- /dev/null +++ b/newcal/pages/index/index.wxss @@ -0,0 +1,19 @@ +/**index.wxss**/ +.userinfo { + display: flex; + flex-direction: column; + align-items: center; + color: #aaa; +} + +.userinfo-avatar { + overflow: hidden; + width: 128rpx; + height: 128rpx; + margin: 20rpx; + border-radius: 50%; +} + +.usermotto { + margin-top: 200px; +} \ No newline at end of file diff --git a/newcal/pages/logs/logs.js b/newcal/pages/logs/logs.js new file mode 100644 index 0000000..85f6aac --- /dev/null +++ b/newcal/pages/logs/logs.js @@ -0,0 +1,18 @@ +// logs.js +const util = require('../../utils/util.js') + +Page({ + data: { + logs: [] + }, + onLoad() { + this.setData({ + logs: (wx.getStorageSync('logs') || []).map(log => { + return { + date: util.formatTime(new Date(log)), + timeStamp: log + } + }) + }) + } +}) diff --git a/newcal/pages/logs/logs.json b/newcal/pages/logs/logs.json new file mode 100644 index 0000000..3ee76c1 --- /dev/null +++ b/newcal/pages/logs/logs.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "查看启动日志", + "usingComponents": {} +} \ No newline at end of file diff --git a/newcal/pages/logs/logs.wxml b/newcal/pages/logs/logs.wxml new file mode 100644 index 0000000..0b6b645 --- /dev/null +++ b/newcal/pages/logs/logs.wxml @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log.date}} + + diff --git a/newcal/pages/logs/logs.wxss b/newcal/pages/logs/logs.wxss new file mode 100644 index 0000000..94d4b88 --- /dev/null +++ b/newcal/pages/logs/logs.wxss @@ -0,0 +1,8 @@ +.log-list { + display: flex; + flex-direction: column; + padding: 40rpx; +} +.log-item { + margin: 10rpx; +} diff --git a/newcal/project.config.json b/newcal/project.config.json new file mode 100644 index 0000000..dc4acf5 --- /dev/null +++ b/newcal/project.config.json @@ -0,0 +1,74 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [ + { + "type": "file", + "value": ".eslintrc.js" + } + ] + }, + "setting": { + "bundle": false, + "userConfirmedBundleSwitch": false, + "urlCheck": true, + "scopeDataCheck": false, + "coverView": true, + "es6": true, + "postcss": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "preloadBackgroundData": false, + "minified": true, + "autoAudits": false, + "newFeature": false, + "uglifyFileName": false, + "uploadWithSourceMap": true, + "useIsolateContext": true, + "nodeModules": false, + "enhance": true, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "showShadowRootInWxmlPanel": true, + "packNpmManually": false, + "enableEngineNative": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "showES6CompileOption": false, + "minifyWXML": true + }, + "compileType": "miniprogram", + "libVersion": "2.19.4", + "appid": "wxf4c7d38caceb0e2f", + "projectname": "%E6%96%B0%E8%AE%A1%E7%AE%97%E5%99%A8", + "debugOptions": { + "hidedInDevtools": [] + }, + "scripts": {}, + "staticServerOptions": { + "baseURL": "", + "servePath": "" + }, + "isGameTourist": false, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "game": { + "list": [] + }, + "plugin": { + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [] + } + } +} \ No newline at end of file diff --git a/newcal/sitemap.json b/newcal/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/newcal/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/newcal/utils/util.js b/newcal/utils/util.js new file mode 100644 index 0000000..764bc2c --- /dev/null +++ b/newcal/utils/util.js @@ -0,0 +1,19 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : `0${n}` +} + +module.exports = { + formatTime +} -- Gitee