diff --git a/app.js b/app.js new file mode 100644 index 0000000..f9db25d --- /dev/null +++ b/app.js @@ -0,0 +1,39 @@ +// 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 + } + }) + // 获取用户信息 + wx.getSetting({ + success: res => { + if (res.authSetting['scope.userInfo']) { + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + wx.getUserInfo({ + success: res => { + // 可以将 res 发送给后台解码出 unionId + this.globalData.userInfo = res.userInfo + + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + if (this.userInfoReadyCallback) { + this.userInfoReadyCallback(res) + } + } + }) + } + } + }) + }, + globalData: { + userInfo: null + } +}) diff --git a/app.json b/app.json new file mode 100644 index 0000000..dda85fb --- /dev/null +++ b/app.json @@ -0,0 +1,16 @@ +{ + "pages":[ + "pages/index/index", + "pages/logs/logs", + "pages/jisuan/jisuan", + "pages/lishi/lishi" + ], + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#FFB6C1", + "navigationBarTitleText": "阿锹计算器", + "navigationBarTextStyle":"white" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..3388ec6 --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,59 @@ +// index.js +// 获取应用实例 +const app = getApp() + +Page({ + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo') + }, + // 事件处理函数 + bindViewTap() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + jiSuanQi:function(){ + wx.navigateTo({ + url: '../jisuan/jisuan' + }) +}, + onLoad() { + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true + }) + } else if (this.data.canIUse) { + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + }, + getUserInfo(e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..7e47dc9 --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,14 @@ + + + + + + + {{userInfo.nickName}} + + + + + {{motto}} + + diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..d1c03dd --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,21 @@ +/**index.wxss**/ +.userinfo { + display: flex; + flex-direction: column; + align-items: center; +} + +.userinfo-avatar { + width: 128rpx; + height: 128rpx; + margin: 20rpx; + border-radius: 50%; +} + +.userinfo-nickname { + color:rgb(253, 228, 247); +} + +.usermotto { + margin-top: 200px; +} \ No newline at end of file diff --git a/pages/jisuan/jisuan.js b/pages/jisuan/jisuan.js new file mode 100644 index 0000000..0bde3b0 --- /dev/null +++ b/pages/jisuan/jisuan.js @@ -0,0 +1,172 @@ +// pages/jisuan/jisuan.js +Page({ + data: { + id0:0, + id1:1, + id2:2, + id3:3, + id4:4, + id5:5, + id6:6, + id7:7, + id8:8, + id9:9, + ida:'+', + idb:'-', + idc:'*', + idd:'/', + gl:'gl', + ch:'ch', + zf:'zf', + xsd:'.', + ls:'ls', + dy:'=', + screenData:0, + isFuHao:false, + sz:[] + /** + * 页面的初始数据 + */ + + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + lishi:function() { + wx.navigateTo({ + url: '../lishi/lishi' + }) + }, + clickBtn:function(e) { + var code=e.currentTarget.id; + if(code==this.data.ch){ + data=this.data.screenData; + var lastWord=data[data.length-1]; + if(lastWord==this.data.ida||lastWord==this.data.idb||lastWord==this.data.idc||lastWord==this.data.idd){ + this.setData({isFuHao:false}) + } + str=data.substring(0,data.length-1); + this.setData({screenData:str}) + this.data.sz.pop; + }else if(code==this.data.gl){ + this.setData({screenData:0}) + this.setData({isFuHao:false}) + this.data.sz=[]; + }else if(code==this.data.zf){ + data =this.data.screenData; + var firstWord=data[0]; + if(isNaN(firstWord)){ + var str=data.substring(1,data.length) + }else{ + var str='-'+data; + } + this.setData({screenData:str}); + }else if(code==this.data.dy){ + var newSz=[]; + var num=''; + var sz=this.data.sz; + for(var i in sz){ + if(isNaN(sz[i])==false||sz[i]==this.data.xsd){ + num+=sz[i]; + }else{ + newSz.push(num); + newSz.push(sz[i]); + num=""; + } + } + newSz.push(num); + var result=Number(newSz[0]); + for(var i=1;i<=newSz.length;i++){ + if(newSz[i]==this.data.ida){ + result+=Number(newSz[i+1]); + }else if(newSz[i]==this.data.idb){ + result-=Number(newSz[i+1]); + }else if(newSz[i]==this.data.idc){ + result*=Number(newSz[i+1]); + }else if(newSz[i]==this.data.idd){ + result/=Number(newSz[i+1]); + } + } + + this.setData({screenData:result}); + console.log(newSz); + console.log(result); + }else{ + var code=e.currentTarget.id; + var data=this.data.screenData; + if(code == this.data.ida || code==this.data.idb || code==this.data.idc ||code==this.data.idd){ + if(this.data.isFuHao==true){ + return''; + } + } + var str=null; + if(data==0){ + str=code; + }else{ + str=data+code; + } + this.setData({'isFuHao':false}); + if(code== this.data.ida|| code==this.data.idb|| code==this.data.idc||code==this.data.idd){ + this.setData({'isFuHao':true}); + } + this.data.sz.push(code); + this.setData({screenData:str}) + } + + console.log(this.data.screenData); + console.log(this.data.sz); + }, + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) diff --git a/pages/jisuan/jisuan.json b/pages/jisuan/jisuan.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/jisuan/jisuan.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/jisuan/jisuan.wxml b/pages/jisuan/jisuan.wxml new file mode 100644 index 0000000..87c2080 --- /dev/null +++ b/pages/jisuan/jisuan.wxml @@ -0,0 +1,40 @@ + + + + + {{screenData}} + + + + + 归零 + 撤回 + +/- + + + + + 9 + 8 + 7 + - + + + 6 + 5 + 4 + * + + + 3 + 2 + 1 + / + + + 0 + . + 历史 + = + + + diff --git a/pages/jisuan/jisuan.wxss b/pages/jisuan/jisuan.wxss new file mode 100644 index 0000000..41da69c --- /dev/null +++ b/pages/jisuan/jisuan.wxss @@ -0,0 +1,55 @@ +/* pages/jisuan/jisuan.wxss */ +.aaa{ + height: 200rpx; + display: flex; + flex-direction: column; + align-items: center; +} +.bbb{ + width: 100%; + height: 200rpx; + background: lightpink; + margin-bottom: 30rpx; + margin-top: 5rpx; + border-radius: 35rpx; +} +.ccc{ + width: 100%; +} +.screen{ + text-align: right; + width: 100%; + line-height: 200rpx; + padding: 0px 10rpx; + box-sizing: border-box; + font-size: 99rpx; + +} +.ddd{ + display: flex; + flex-direction: row; + width: 100%; + height: 200rpx; + font-size: 66rpx; + font-family: STHupo; + font-color: pink;/*不知道怎么搞*/ +} +.eee{ + width: 25%; + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + margin-top: 5rpx; + margin-right: 5rpx; + border-radius: 52rpx; +} +.colora{ + background: cornflowerblue; +} +.colorb{ + background: lightskyblue; +} +.colorc{ + background: skyblue; +} \ No newline at end of file diff --git a/pages/lishi/lishi.js b/pages/lishi/lishi.js new file mode 100644 index 0000000..1d94f82 --- /dev/null +++ b/pages/lishi/lishi.js @@ -0,0 +1,66 @@ +// pages/lishi/lishi.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/lishi/lishi.json b/pages/lishi/lishi.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/lishi/lishi.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/lishi/lishi.wxml b/pages/lishi/lishi.wxml new file mode 100644 index 0000000..a2f852b --- /dev/null +++ b/pages/lishi/lishi.wxml @@ -0,0 +1,2 @@ + +

冷笑话:我也不知道怎么显示历史哈哈哈

\ No newline at end of file diff --git a/pages/lishi/lishi.wxss b/pages/lishi/lishi.wxss new file mode 100644 index 0000000..e95ff13 --- /dev/null +++ b/pages/lishi/lishi.wxss @@ -0,0 +1,4 @@ +/* pages/lishi/lishi.wxss */ +.color{ + background: thistle; +} \ No newline at end of file diff --git a/pages/logs/logs.js b/pages/logs/logs.js new file mode 100644 index 0000000..3c7cb60 --- /dev/null +++ b/pages/logs/logs.js @@ -0,0 +1,15 @@ +// logs.js +const util = require('../../utils/util.js') + +Page({ + data: { + logs: [] + }, + onLoad() { + this.setData({ + logs: (wx.getStorageSync('logs') || []).map(log => { + return util.formatTime(new Date(log)) + }) + }) + } +}) diff --git a/pages/logs/logs.json b/pages/logs/logs.json new file mode 100644 index 0000000..3ee76c1 --- /dev/null +++ b/pages/logs/logs.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "查看启动日志", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/logs/logs.wxml b/pages/logs/logs.wxml new file mode 100644 index 0000000..b5a85ac --- /dev/null +++ b/pages/logs/logs.wxml @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log}} + + diff --git a/pages/logs/logs.wxss b/pages/logs/logs.wxss new file mode 100644 index 0000000..94d4b88 --- /dev/null +++ b/pages/logs/logs.wxss @@ -0,0 +1,8 @@ +.log-list { + display: flex; + flex-direction: column; + padding: 40rpx; +} +.log-item { + margin: 10rpx; +} diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..5d1d053 --- /dev/null +++ b/project.config.json @@ -0,0 +1,72 @@ +{ + "description": "项目配置文件", + "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.14.4", + "appid": "wx907288a4e8fd0ac7", + "projectname": "%E5%95%8A%E9%94%B9%E7%9A%84%E8%AE%A1%E7%AE%97%E5%99%A8", + "debugOptions": { + "hidedInDevtools": [] + }, + "scripts": {}, + "isGameTourist": false, + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "game": { + "list": [] + }, + "plugin": { + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [] + } + } +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/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/utils/util.js b/utils/util.js new file mode 100644 index 0000000..764bc2c --- /dev/null +++ b/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 +}