Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -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
}
})
16 changes: 16 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -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"
}
10 changes: 10 additions & 0 deletions app.wxss
Original file line number Diff line number Diff line change
@@ -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;
}
59 changes: 59 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -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
})
}
})
3 changes: 3 additions & 0 deletions pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
14 changes: 14 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto">
<button bindtap="jiSuanQi">啊锹的计算器</button>
<text class="user-motto">{{motto}}</text>
</view>
</view>
21 changes: 21 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -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;
}
172 changes: 172 additions & 0 deletions pages/jisuan/jisuan.js
Original file line number Diff line number Diff line change
@@ -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 () {

}
})
3 changes: 3 additions & 0 deletions pages/jisuan/jisuan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
40 changes: 40 additions & 0 deletions pages/jisuan/jisuan.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--pages/jisuan/jisuan.wxml-->
<view class="aaa">
<view class="bbb">
<view class="screen">
{{screenData}}
</view>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结果在右侧可以加一个padding,会好看点

</view>
<view class="ccc">
<view class="ddd">
<view bindtap="clickBtn" id="{{gl}}" class="eee colorc">归零</view>
<view bindtap="clickBtn" id="{{ch}}" class="eee colorc">撤回</view>
<view bindtap="clickBtn" id="{{zf}}" class="eee colorb">+/-</view>
<view bindtap="clickBtn" id="{{ida}}" class="eee colorb">+</view>
</view>
<view class="ddd">
<view bindtap="clickBtn" id="{{id9}}" class="eee colora">9</view>
<view bindtap="clickBtn" id="{{id8}}" class="eee colora">8</view>
<view bindtap="clickBtn" id="{{id7}}" class="eee colora">7</view>
<view bindtap="clickBtn" id="{{idb}}" class="eee colorb">-</view>
</view>
<view class="ddd">
<view bindtap="clickBtn" id="{{id6}}" class="eee colora">6</view>
<view bindtap="clickBtn" id="{{id5}}" class="eee colora">5</view>
<view bindtap="clickBtn" id="{{id4}}" class="eee colora">4</view>
<view bindtap="clickBtn" id="{{idc}}" class="eee colorb">*</view>
</view>
<view class="ddd">
<view bindtap="clickBtn" id="{{id3}}" class="eee colora">3</view>
<view bindtap="clickBtn" id="{{id2}}" class="eee colora">2</view>
<view bindtap="clickBtn" id="{{id1}}" class="eee colora">1</view>
<view bindtap="clickBtn" id="{{idd}}" class="eee colorb">/</view>
</view>
<view class="ddd">
<view bindtap="clickBtn" id="{{id0}}" class="eee colora">0</view>
<view bindtap="clickBtn" id="{{xsd}}" class="eee colorb">.</view>
<view bindtap="clickBtn" id="{{ls}}" class="eee colorc" bindtap="lishi">历史</view>
<view bindtap="clickBtn" id="{{dy}}" class="eee colorb">=</view>
</view>
</view>
</view>
Loading