diff --git a/newcal/.eslintrc.js b/newcal/.eslintrc.js new file mode 100644 index 0000000000000000000000000000000000000000..115cc02b049fd21c82bc61a7200f51fcec66e528 --- /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 0000000000000000000000000000000000000000..1ed57c47fc86716c337dee0e196bdbbac27abfe5 --- /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 0000000000000000000000000000000000000000..9ccac71eebd24599867170a37c25fc39a2efaea2 --- /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 0000000000000000000000000000000000000000..0b7f3d167e32d4138a29603c3db041877cf58dc3 --- /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 0000000000000000000000000000000000000000..41b35dc355c2c594fe86ed97ce811b6a50899796 --- /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 0000000000000000000000000000000000000000..1d830e54c1a3e791d3f11bae72f86887a9476d3c --- /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 0000000000000000000000000000000000000000..0bc1771e0cc0d108cafecb8af2fc8ae31af71eee --- /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 0000000000000000000000000000000000000000..8835af0699ccec004cbe685ef938cd2d63ea7037 --- /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 0000000000000000000000000000000000000000..f00d29406f00e4bd1bdf10294f79c196b73759e3 --- /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 0000000000000000000000000000000000000000..eb642035f7e0b270a8d1ea8cf26e5f252cb2c4ac --- /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 0000000000000000000000000000000000000000..85f6aac5ab16db728fa27cdf75c4ab2126b1105b --- /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 0000000000000000000000000000000000000000..3ee76c183c748834923c80f78292e46d739d556e --- /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 0000000000000000000000000000000000000000..0b6b6456f7ac8b92181e8aff296890fd7d3d86a3 --- /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 0000000000000000000000000000000000000000..94d4b88a27dcea1fbaa6da8fc19c6a8821983924 --- /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 0000000000000000000000000000000000000000..dc4acf5717b094bea28ae8542e9ff60006e4c05c --- /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 0000000000000000000000000000000000000000..ca02add20b581be471b8d17f887b8e8337070546 --- /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 0000000000000000000000000000000000000000..764bc2ce26ab9b55a21cbb069dcf084a8418dffd --- /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 +}