-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #553 from WilliamMJC/master
#6 提交实验6代码
- Loading branch information
Showing
12 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//app.js | ||
App({ | ||
onLaunch: function () { | ||
// 展示本地存储能力 | ||
var 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 | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"pages": [ | ||
"pages/index/index", | ||
"pages/about/about", | ||
"pages/logs/logs" | ||
], | ||
"window": { | ||
"backgroundTextStyle": "light", | ||
"navigationBarBackgroundColor": "#436EEE", | ||
"navigationBarTitleText": "懒人课表", | ||
"navigationBarTextStyle": "white" | ||
}, | ||
"tabBar": { | ||
"list": [ | ||
{ | ||
"pagePath": "pages/index/index", | ||
"text": "首页", | ||
"iconPath": "images/homenor.png", | ||
"selectedIconPath": "images/homepre.png" | ||
}, | ||
{ | ||
"pagePath": "pages/about/about", | ||
"text": "关于课表", | ||
"iconPath": "images/aboutnor.png", | ||
"selectedIconPath": "images/aboutpre.png" | ||
} | ||
] | ||
}, | ||
"sitemapLocation": "sitemap.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//index.js | ||
//获取应用实例 | ||
const app = getApp() | ||
|
||
Page({ | ||
data: { | ||
motto: '作为一个超级懒人', | ||
userInfo: {}, | ||
hasUserInfo: false, | ||
canIUse: wx.canIUse('button.open-type.getUserInfo') | ||
}, | ||
//事件处理函数 | ||
bindViewTap: function() { | ||
wx.navigateTo({ | ||
url: '../logs/logs' | ||
}) | ||
}, | ||
onLoad: function () { | ||
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: function(e) { | ||
console.log(e) | ||
app.globalData.userInfo = e.detail.userInfo | ||
this.setData({ | ||
userInfo: e.detail.userInfo, | ||
hasUserInfo: true | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"usingComponents": {} | ||
} |
17 changes: 17 additions & 0 deletions
17
students/1714080903221/smallprogram/pages/index/index.wxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!--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}}" background-size="cover"></image> | ||
<text class="userinfo-nickname">{{userInfo.nickName}}</text> | ||
</block> | ||
</view> | ||
<view class="usermotto"> | ||
<text class="user-motto">{{motto}}</text> | ||
</view> | ||
<view> | ||
<text>懒人课表就是拯救懒人的存在</text> | ||
<button>开启课表</button> | ||
</view> | ||
</view> |
22 changes: 22 additions & 0 deletions
22
students/1714080903221/smallprogram/pages/index/index.wxss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/**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: #aaa; | ||
} | ||
|
||
.usermotto { | ||
margin-top: 200px; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"description": "项目配置文件。", | ||
"setting": { | ||
"urlCheck": true, | ||
"es6": true, | ||
"postcss": true, | ||
"minified": true, | ||
"newFeature": true | ||
}, | ||
"compileType": "miniprogram", | ||
"libVersion": "1.9.94", | ||
"appid": "wx389c5cd59e56fa20", | ||
"projectname": "smallprogram", | ||
"isGameTourist": false, | ||
"simulatorType": "wechat", | ||
"simulatorPluginLibVersion": {}, | ||
"condition": { | ||
"search": { | ||
"current": -1, | ||
"list": [] | ||
}, | ||
"conversation": { | ||
"current": -1, | ||
"list": [] | ||
}, | ||
"plugin": { | ||
"current": -1, | ||
"list": [] | ||
}, | ||
"game": { | ||
"currentL": -1, | ||
"list": [] | ||
}, | ||
"miniprogram": { | ||
"current": -1, | ||
"list": [ | ||
{ | ||
"id": -1, | ||
"name": "about", | ||
"pathName": "pages/about/about", | ||
"query": "" | ||
}, | ||
{ | ||
"id": -1, | ||
"name": "logs", | ||
"pathName": "pages/logs/logs", | ||
"query": "" | ||
} | ||
] | ||
} | ||
} | ||
} |