Skip to content

Commit

Permalink
发布
Browse files Browse the repository at this point in the history
  • Loading branch information
coolfishstudio committed Sep 27, 2016
1 parent 0685b97 commit 8e83c30
Show file tree
Hide file tree
Showing 29 changed files with 1,033 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# wechat-webapp-cnode
微信小应用学习 cnode版
[学习文档](./study.md)

![首页列表](http://7xqxfk.com1.z0.glb.clouddn.com//xiaoyingyong/cnode/1.png)
![内容详情](http://7xqxfk.com1.z0.glb.clouddn.com//xiaoyingyong/cnode/2.png)

30 changes: 30 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
})
}
},
globalData:{
userInfo:null
}
})
33 changes: 33 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"pages":[
"pages/topics/topics",
"pages/index/index",
"pages/logs/logs",
"pages/detail/detail"
],
"window":{
"backgroundTextStyle":"black",
"backgroundColor":"#fff",
"navigationBarBackgroundColor":"#000",
"navigationBarTitleText":"CNODE 应用号版",
"navigationBarTextStyle":"white",
"enablePullDownRefresh":"true"
},
"tabBar":{
"color":"#272636",
"selectedColor":"#80bd01",
"backgroundColor":"#fff",
"borderStyle":"white",
"list":[{
"pagePath":"pages/topics/topics",
"text":"首页",
"iconPath":"images/tabBar/my.png",
"selectedIconPath":"images/tabBar/my_hl.png"
},{
"pagePath":"pages/index/index",
"text":"我的",
"iconPath":"images/tabBar/list.png",
"selectedIconPath":"images/tabBar/list_hl.png"
}]
}
}
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;
}
Binary file added images/.DS_Store
Binary file not shown.
Binary file added images/icon/.DS_Store
Binary file not shown.
Binary file added images/icon/reply.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon/visit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tabBar/.DS_Store
Binary file not shown.
Binary file added images/tabBar/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tabBar/list_hl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tabBar/my.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tabBar/my_hl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions pages/detail/detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// posts.js
var Api = require('../../utils/api.js');
var util = require('../../utils/util.js');

Page({
data: {
title: '话题详情',
detail: {},
hidden: false
},
onLoad: function (options) {
this.fetchData(options.id);
},
fetchData: function (id) {
var self = this;
self.setData({
hidden: false
});
wx.request({
url: Api.getTopicByID(id, { mdrender: false }),
success: function (res) {
console.log(res);
res.data.data.create_at = util.getDateDiff(new Date(res.data.data.create_at));
res.data.data.replies = res.data.data.replies.map(function (item) {
item.create_at = util.getDateDiff(new Date(item.create_at));
return item;
})
self.setData({
detail: res.data.data
});
setTimeout(function () {
self.setData({
hidden: true
});
}, 300);
}
});
}
})
43 changes: 43 additions & 0 deletions pages/detail/detail.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--detail.wxml-->
<view class="detail-main">
<view class="detail-post">
<view class="detail-post-header">
<view class="detail-post-title">{{ detail.title }}</view>
</view>
<view class="detail-post-meta">
<view class="detail-post-avatar">
<image class="detail-post-avatar-img" mode="scaleToFill" src="{{ detail.author.avatar_url }}"></image>
</view>
<view class="detail-post-info">
<view class="detail-post-author-name">{{ detail.author.loginname }}</view>
<view class="detail-post-time">楼主 发表于{{ detail.create_at }}</view>
</view>
</view>
<view class="detail-post-content">
<text class="content-info">{{ detail.content }}</text>
</view>
<view class="detail-post-comment">
<view class="detail-post-comment-title">评论</view>
<view class="detail-post-comment-list">
<block wx:for="{{ detail.replies }}">
<view class="detail-post-comment-item" index="{{index}}" id="{{item.id}}">
<view class="detail-post-comment-avatar">
<image class="detail-post-comment-avatar-img" mode="scaleToFill" src="{{ item.author.avatar_url }}"></image>
</view>
<view class="detail-post-comment-info">
<view class="detail-post-comment-author-name">{{ item.author.loginname }}</view>
</view>
<view class="detail-comment-content">
<text class="detail-comment-text">{{ item.content }}</text>
<view class="detail-post-comment-time">{{index + 2}}楼 发表于{{ item.create_at }}</view>
</view>
</view>
</block>
</view>
</view>
</view>

<loading hidden="{{hidden}}">
加载中...
</loading>
</view>
86 changes: 86 additions & 0 deletions pages/detail/detail.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
.detail-post {
background-color: #eee;
}
.detail-post-header {
background-color: #fff;
line-height: 40px;
padding: 15px 17px;
position: relative;
overflow: hidden;
border-bottom: 1px #ccc solid;
}
.detail-post-title {
margin: 0;
padding: 0;
font-weight: 400;
font-size: 29px;
color: #80bd01;
}
.detail-post-meta {
position: relative;
padding: 13px 18px 0 18px;
background: #fff;
}
.detail-post-avatar, .detail-post-comment-avatar {
width: 46px;
height: 46px;
display: block;
float: left;
margin-top: 3px;
}
.detail-post-avatar-img, .detail-post-comment-avatar-img {
width: 100%;
height: 100%;
border-radius: 50%;
}
.detail-post-info, .detail-post-comment-info, .detail-comment-content {
margin: 0 0 0 50px;
padding: 0 0 0 5px;
position: relative;
line-height: 20px;
overflow: hidden;
}
.detail-post-author-name, .detail-post-comment-author-name {
color: #6c6c6c;
font-size: 20px;
line-height: 30px;
margin-top: 3px;
}
.detail-post-time, .detail-post-comment-time {
line-height: 20px;
font-size: 12px;
color: #a4a4a4;
}
.detail-post-content {
background-color: #fff;
padding: 13px 18px 25px 18px;
font-family: Helvetica Neue,Helvetica,Hiragino Sans GB,Microsoft YaHei,Arial,sans-serif;
margin-bottom: 13px;
}
.content-info {
color: #6c6c6c;
font-size: 18px;
line-height: 20px;
word-wrap: break-word;
padding: 0;
}
.detail-post-comment {
background-color: #fff;
}
.detail-post-comment-title {
font-size: 20px;
line-height: 50px;
padding: 0 18px;
color: #666;
position: relative;
border-bottom: 1px #ccc solid;
}
.detail-post-comment-item {
padding: 12px 18px;
background: #fff;
border-bottom: 1px #ccc solid;
}
.detail-comment-text {
margin: 10px 0;
font-size: 15px;
}
26 changes: 26 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
console.log('onLoad')
var that = this
//调用应用实例的方法获取全局数据
app.getUserInfo(function(userInfo){
//更新数据
that.setData({
userInfo:userInfo
})
})
}
})
10 changes: 10 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--index.wxml-->
<view class="container">
<view bindtap="bindViewTap" class="userinfo">
<image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</view>
<view class="usermotto">
<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: #aaa;
}

.usermotto {
margin-top: 200px;
}
14 changes: 14 additions & 0 deletions pages/logs/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//logs.js
var util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(function (log) {
return util.formatTime(new Date(log))
})
})
}
})
3 changes: 3 additions & 0 deletions 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 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 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;
}
Loading

0 comments on commit 8e83c30

Please sign in to comment.