Skip to content

Commit

Permalink
hzuapps#1 hzuapps#90 第1次实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
YJJJack committed Oct 26, 2017
1 parent 972dcbf commit 2e7b347
Show file tree
Hide file tree
Showing 79 changed files with 3,746 additions and 0 deletions.
39 changes: 39 additions & 0 deletions 1514080901132/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
}
})
31 changes: 31 additions & 0 deletions 1514080901132/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/comp/view",
"pages/comp/scroll",
"pages/comp/form",
"pages/demo/scrollView",
"pages/form/form"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#000000",
"navigationBarTitleText": "我是谁?我是杰哥",
"navigationBarTextStyle": "white"
},
"tabBar": {
"color": "#000000",
"selectedColor": "#009444",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/logs/logs",
"text": ""
}
]
}
}
13 changes: 13 additions & 0 deletions 1514080901132/app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**app.wxss**/
@import 'style/weui.wxss';

/* . 表示 类 class */
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
71 changes: 71 additions & 0 deletions 1514080901132/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//index.js
//获取应用实例
const app = getApp()

Page({
data: {
motto: 'Hello HZU',
userInfo: {},
hasUserInfo: false,
textColor: 'red',
textClass: 'description',
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
console.dir('bindViewTap')
wx.navigateTo({
url: '../logs/logs'
})
},
changeColor: function() {
//console.log('changeColor')
var me = this;
if (me.data.textClass == 'description') {
this.setData({
textClass: 'blue'
})
} else {
this.setData({
textClass: 'description'
})
}
//this.data.textColor = 'blue'
},
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
})
}
})
16 changes: 16 additions & 0 deletions 1514080901132/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--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 bindtap="changeColor" class="{{textClass}}">
<text>这是一个微信小程序演示版本。</text>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
31 changes: 31 additions & 0 deletions 1514080901132/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**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: blue;
}

.usermotto {
margin-top: 200px;
color: #009A89;
text-decoration: underline;
font-weight: bold;
}
.description {
color: red;
font-size: 18px;
}
.blue {
color: blue;
}
66 changes: 66 additions & 0 deletions 1514080901132/pages/comp/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// pages/comp/form.js
Page({

/**
* 页面的初始数据
*/
data: {

},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

},

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

}
})
1 change: 1 addition & 0 deletions 1514080901132/pages/comp/form.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 2 additions & 0 deletions 1514080901132/pages/comp/form.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!--pages/comp/form.wxml-->
<text>pages/comp/form.wxml</text>
1 change: 1 addition & 0 deletions 1514080901132/pages/comp/form.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* pages/comp/form.wxss */
89 changes: 89 additions & 0 deletions 1514080901132/pages/comp/scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// pages/comp/scroll.js
Page({

/**
* 页面的初始数据
*/
data: {

},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this
// 设置窗口大小
wx.getSystemInfo({
success: (res) => {
that.setData({
windowHeight: res.windowHeight - 5,
windowWidth: res.windowWidth
})
//console.dir(that.data.windowHeight)
}
})
},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

},

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

},

onUpper: function () { },
onLower: function () {
var that = this
that.setData({
isLower: true
});
// load more data
console.log("onLower")
},
onScroll: function () {
console.log("onScroll")
}
})
1 change: 1 addition & 0 deletions 1514080901132/pages/comp/scroll.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 2e7b347

Please sign in to comment.