Skip to content

Commit 57a0cad

Browse files
committed
feat(start): create start page
1 parent dace3d1 commit 57a0cad

17 files changed

+404
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Windows
2+
[Dd]esktop.ini
3+
Thumbs.db
4+
$RECYCLE.BIN/
5+
6+
# macOS
7+
.DS_Store
8+
.fseventsd
9+
.Spotlight-V100
10+
.TemporaryItems
11+
.Trashes
12+
13+
# Node.js
14+
node_modules/

app.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//app.js
2+
App({
3+
onLaunch: function () {
4+
// 展示本地存储能力
5+
var logs = wx.getStorageSync('logs') || []
6+
logs.unshift(Date.now())
7+
wx.setStorageSync('logs', logs)
8+
9+
// 登录
10+
wx.login({
11+
success: res => {
12+
// 发送 res.code 到后台换取 openId, sessionKey, unionId
13+
}
14+
})
15+
// 获取用户信息
16+
wx.getSetting({
17+
success: res => {
18+
if (res.authSetting['scope.userInfo']) {
19+
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
20+
wx.getUserInfo({
21+
success: res => {
22+
// 可以将 res 发送给后台解码出 unionId
23+
this.globalData.userInfo = res.userInfo
24+
25+
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
26+
// 所以此处加入 callback 以防止这种情况
27+
if (this.userInfoReadyCallback) {
28+
this.userInfoReadyCallback(res)
29+
}
30+
}
31+
})
32+
}
33+
}
34+
})
35+
},
36+
globalData: {
37+
userInfo: null
38+
}
39+
})

app.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"pages":[
3+
"pages/start/start",
4+
"pages/index/index"
5+
],
6+
"window":{
7+
"backgroundTextStyle":"light",
8+
"navigationBarBackgroundColor": "#fff",
9+
"navigationBarTitleText": "WeChat",
10+
"navigationBarTextStyle":"black"
11+
}
12+
}

app.wxss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**app.wxss**/
2+
.container {
3+
height: 100%;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: space-between;
8+
padding: 200rpx 0;
9+
box-sizing: border-box;
10+
}

package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "coderiver-mini-program",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/coderiver-org/coderiver-mini-program.git"
12+
},
13+
"keywords": [],
14+
"author": "",
15+
"license": "ISC",
16+
"bugs": {
17+
"url": "https://github.com/coderiver-org/coderiver-mini-program/issues"
18+
},
19+
"homepage": "https://github.com/coderiver-org/coderiver-mini-program#readme",
20+
"devDependencies": {
21+
"cz-conventional-changelog": "^2.1.0"
22+
},
23+
"config": {
24+
"commitizen": {
25+
"path": "./node_modules/cz-conventional-changelog"
26+
}
27+
}
28+
}

pages/index/index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//index.js
2+
//获取应用实例
3+
const app = getApp()
4+
5+
Page({
6+
data: {
7+
motto: 'Hello World',
8+
userInfo: {},
9+
hasUserInfo: false,
10+
canIUse: wx.canIUse('button.open-type.getUserInfo')
11+
},
12+
//事件处理函数
13+
bindViewTap: function() {
14+
wx.navigateTo({
15+
url: '../logs/logs'
16+
})
17+
},
18+
onLoad: function () {
19+
if (app.globalData.userInfo) {
20+
this.setData({
21+
userInfo: app.globalData.userInfo,
22+
hasUserInfo: true
23+
})
24+
} else if (this.data.canIUse){
25+
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
26+
// 所以此处加入 callback 以防止这种情况
27+
app.userInfoReadyCallback = res => {
28+
this.setData({
29+
userInfo: res.userInfo,
30+
hasUserInfo: true
31+
})
32+
}
33+
} else {
34+
// 在没有 open-type=getUserInfo 版本的兼容处理
35+
wx.getUserInfo({
36+
success: res => {
37+
app.globalData.userInfo = res.userInfo
38+
this.setData({
39+
userInfo: res.userInfo,
40+
hasUserInfo: true
41+
})
42+
}
43+
})
44+
}
45+
},
46+
getUserInfo: function(e) {
47+
console.log(e)
48+
app.globalData.userInfo = e.detail.userInfo
49+
this.setData({
50+
userInfo: e.detail.userInfo,
51+
hasUserInfo: true
52+
})
53+
}
54+
})

pages/index/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

pages/index/index.wxml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!--index.wxml-->
2+
<view class="container">
3+
<view class="userinfo">
4+
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
5+
<block wx:else>
6+
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
7+
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
8+
</block>
9+
</view>
10+
<view class="usermotto">
11+
<text class="user-motto">{{motto}}</text>
12+
</view>
13+
</view>

pages/index/index.wxss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**index.wxss**/
2+
.userinfo {
3+
display: flex;
4+
flex-direction: column;
5+
align-items: center;
6+
}
7+
8+
.userinfo-avatar {
9+
width: 128rpx;
10+
height: 128rpx;
11+
margin: 20rpx;
12+
border-radius: 50%;
13+
}
14+
15+
.userinfo-nickname {
16+
color: #aaa;
17+
}
18+
19+
.usermotto {
20+
margin-top: 200px;
21+
}

pages/start/start.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Page({
2+
3+
/**
4+
* 页面的初始数据
5+
*/
6+
data: {
7+
8+
},
9+
10+
/**
11+
* 生命周期函数--监听页面加载
12+
*/
13+
onLoad: function(options) {
14+
setTimeout(() => {
15+
wx.redirectTo({
16+
url: '../index/index'
17+
})
18+
}, 3000)
19+
},
20+
21+
/**
22+
* 生命周期函数--监听页面初次渲染完成
23+
*/
24+
onReady: function() {
25+
26+
},
27+
28+
/**
29+
* 生命周期函数--监听页面显示
30+
*/
31+
onShow: function() {
32+
33+
},
34+
35+
/**
36+
* 生命周期函数--监听页面隐藏
37+
*/
38+
onHide: function() {
39+
40+
},
41+
42+
/**
43+
* 生命周期函数--监听页面卸载
44+
*/
45+
onUnload: function() {
46+
47+
},
48+
49+
/**
50+
* 页面相关事件处理函数--监听用户下拉动作
51+
*/
52+
onPullDownRefresh: function() {
53+
54+
},
55+
56+
/**
57+
* 页面上拉触底事件的处理函数
58+
*/
59+
onReachBottom: function() {
60+
61+
},
62+
63+
/**
64+
* 用户点击右上角分享
65+
*/
66+
onShareAppMessage: function() {
67+
68+
}
69+
})

pages/start/start.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"navigationBarTitleText": "CodeRiver"
3+
}

pages/start/start.wxml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<view class='start-warp'>
2+
<view class='start-image'>
3+
<image mode='widthFix' style="width:160px;" src='../../static/images/logo@3x.png'></image>
4+
</view>
5+
<view class='start-text'>
6+
<text>CodrRiver©2018</text>
7+
</view>
8+
</view>

pages/start/start.wxss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.start-warp {
2+
box-sizing: border-box;
3+
padding: 25rpx;
4+
width: 100%;
5+
height: 100vh;
6+
display: flex;
7+
flex-direction: column;
8+
align-items: center;
9+
justify-content: flex-end;
10+
position: relative;
11+
}
12+
13+
.start-image {
14+
position: absolute;
15+
left: 50%;
16+
top: 50%;
17+
transform: translate(-50%,-50%);
18+
19+
}
20+
.start-text {
21+
color: #18262a;
22+
font-size: 20px;
23+
}

0 commit comments

Comments
 (0)