Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1 #174 第1次实验代码“ #354

Merged
merged 2 commits into from
Nov 17, 2017
Merged
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 1514080901134/app.js
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
}
})
12 changes: 12 additions & 0 deletions 1514080901134/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"pages":[
"pages/index/index",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}
11 changes: 11 additions & 0 deletions 1514080901134/app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**app.wxss**/
@import'weui.wxss';
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
12 changes: 12 additions & 0 deletions 1514080901134/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Page({
open: function () {
wx.showActionSheet({
itemList: ['A', 'B', 'C'],
success: function (res) {
if (!res.cancel) {
console.log(res.tapIndex)
}
}
});
}
});
34 changes: 34 additions & 0 deletions 1514080901134/pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<view class="page">
<view class="page__hd">
<view class="page__title">HELLO</view>
<view class="page__desc">welcome to one sheep</view>
</view>
<view class="page__bd">
<view class="weui-btn-area">
<button type="default" bindtap="open">HELLO</button>
</view>
</view>
<view class="page__hd">
<view class="page__title">Button</view>
<view class="page__desc">按钮,WeUI采用小程序原生的按钮为主体,加入一些间距的样式。</view>
</view>
<view class="page__bd page__bd_spacing">
<button class="weui-btn" type="primary">我的文件 </button>


<button class="weui-btn" type="default">我的收藏 </button>


<button class="weui-btn" type="warn">设置 </button>


<view class="button-sp-area">
<button class="weui-btn" type="primary" plain="true">进入</button>




<button class="weui-btn mini-btn" type="warn" size="mini">退出</button>
</view>
</view>
</view>
11 changes: 11 additions & 0 deletions 1514080901134/pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
page{
background-color: #FFFFFF;
}
.button-sp-area{
margin: 0 auto;
padding-top: 15px;
width: 60%;
}
.mini-btn{
margin-right: 5px;
}
15 changes: 15 additions & 0 deletions 1514080901134/pages/logs/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//logs.js
const util = require('../../utils/util.js')

Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
}
})
3 changes: 3 additions & 0 deletions 1514080901134/pages/logs/logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "查看启动日志"
}
6 changes: 6 additions & 0 deletions 1514080901134/pages/logs/logs.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
8 changes: 8 additions & 0 deletions 1514080901134/pages/logs/logs.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
19 changes: 19 additions & 0 deletions 1514080901134/utils/util.js
Original file line number Diff line number Diff line change
@@ -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: formatTime
}