CNode

微信小程序 cnode社区版

分享
VvincentSea发布于10 年前最后回复10 年前13 回复14306 浏览0 收藏

微信小程序 cnode社区版本

官方文档:https://mp.weixin.qq.com/debug/wxadoc/dev/

入门小例子: https://github.com/vincentSea/wxsapp

项目地址:https://github.com/vincentSea/wechat-cnode

参考资料:https://github.com/coolfishstudio/wechat-webapp-cnode

小程序预览

8.png

项目结构

开发环境

下载地址 :https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=1474887501214

开发过程

  1. 配置默认启动页面

在app.json文件修改注册页面的顺序,把“pages/topics/topics” 放在第一位,就会自动把topics.wxml 显示默认启动

  1. 配置tabBar

    tabBar 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。

  1. window 设置

    具体看文档https://mp.weixin.qq.com/debug/wxadoc/dev/framework/config.html?t=1475052056717

  2. 简单封装wx.request(OBJECT)

  1. 滚动底部加载下一页

使用了小程序自带的scroll-view组件

2.png

  <!--列表list组件 -->
  <template name="list">
    <scroll-view class="scroll-posts-list" style="height:100%" scroll-y="true" bindscrolltolower="lower">
      <view class="postslist">
        <block wx:for="{{postsList}}">
          <view class="posts-list">
            <navigator url="/pages/detail/detail?id={{item.id}}">
              <view class="posts-list-info" index="{{index}}">
                  <image class="userimg" src="{{item.author.avatar_url}}" />
                  <view class="item-box">
                    <view class="userinfo">
                      <text class="username">{{item.author.loginname}}</text>
                      <text class="time">{{item.last_reply_at}}</text>
                    </view>
                    <view class="posts-title">
                      <view class="posts-tag hot" wx:if="{{item.top === true}}">置顶</view>
                      <view class="posts-tag" wx:if="{{item.good === true}}">精华</view>
                      <text>{{item.title}}</text>
                    </view>
                  </view>
              </view>
              <view class="bar-info">
                <view class="bar-info-item">
                  <image class="bar-info-item-icon" src="/images/icon/reply.png"></image>
                  <view class="bar-info-item-number">{{item.reply_count}}</view>
                </view>
                <view class="bar-info-item">
                  <image class="bar-info-item-icon" src="/images/icon/visit.png"></image>
                  <view class="bar-info-item-number">{{item.visit_count}}</view>
                </view>

                <view class="bar-info-item2"  wx:if="{{item.tab === 'good'}}">
                  <image class="bar-info-item-icon" src="/images/icon/type.png"></image>
                  <view class="bar-info-item-number">精华</view>
                </view>
                <view class="bar-info-item2"  wx:if="{{item.tab === 'share'}}">
                  <image class="bar-info-item-icon" src="/images/icon/type.png"></image>
                  <view class="bar-info-item-number">分享</view>
                </view>
                <view class="bar-info-item2"  wx:if="{{item.tab === 'ask'}}">
                  <image class="bar-info-item-icon" src="/images/icon/type.png"></image>
                  <view class="bar-info-item-number">问答</view>
                </view>
                <view class="bar-info-item2"  wx:if="{{item.tab === 'job'}}">
                  <image class="bar-info-item-icon" src="/images/icon/type.png"></image>
                  <view class="bar-info-item-number">招聘</view>
                </view>
              </view>
          </navigator>
          </view>
        </block>
      </view>
    </scroll-view>

    <loading class="loading" hidden="{{hidden}}">
      <text class="loading-font">加载中...</text>
    </loading>
  </template>
  <!-- topics.wxml  -->
  <import src="../common/nav.wxml"/>
  <import src="../common/list.wxml"/>

  <view class="page topics">
    <template is="nav" data="{{ navList, activeIndex }}"/>
    <template is="list" data="{{ postsList, hidden }}"/>
  </view>

滚动区的最大的父级层要设置height: 100%; 不然无法检测滚动事件 也不知道是不是我布局的原因,我这里是一定要这样设置的

.topics{
  height: 100%;
  overflow: hidden;
}
// 滑动底部加载
lower: function() {
  console.log('滑动底部加载', new Date());
  var that = this;
  that.setData({
    page: that.data.page + 1
  });
  if (that.data.tab !== 'all') {
    this.getData({tab: that.data.tab, page: that.data.page});
  } else {
    this.getData({page: that.data.page});
  }
}

用法

  <scroll-view class="scroll-posts-list" style="height:100%" scroll-y="true" bindscrolltolower="lower">
  </scroll-view>

使用说明

  1. 将仓库克隆到本地:
$ git clone https://github.com/vincentSea/wechat-cnode.git
  1. 打开微信Web开放者工具(注意:必须是0.9.092300版本)

  2. 选择添加项目,填写或选择相应信息

  • AppID:点击右下角无AppID
  • 项目名称:随便填写,因为不涉及到部署,所以无所谓
  • 项目目录:选择刚刚克隆的文件夹
  • 点击添加项目

特别感谢

感谢 coolfish 的项目案例

coolfish的github: https://github.com/coolfishstudio

查看回复

回复 (13)

C
coolfishstudio#1·10 年前

👍

V
vincentSea#2·10 年前
引用 coolfishstudio👍

@coolfishstudio 嘻嘻

L
leijianning#3·10 年前

不错不错

Z
zh-h#4·10 年前

突然想到一个问题,如果不小心按了左上角的的返回按钮,再次进入是不是要重新去找原来的页面

S
superhuahua#5·10 年前

mark!

1
13241491189#6·10 年前

开发工具没有 ubuntu系统的?

T
tomoya92#7·10 年前

有二维码吗?在微信小程序里没搜到

T
tomoya92#8·10 年前
引用 DevinXian微信小程序的css兼容性如何

@DevinXian 你难道想用小程序的css开发其它网页?

D
DevinXian#9·10 年前

微信小程序的css兼容性如何

D
DevinXian#10·10 年前
引用 tomoya92@DevinXian 你难道想用小程序的css开发其它网页?

@liygheart 比如现在有现成的样式,能不能直接用过去,这个试试才知道...我还没动过小程序

Z
zh-h#12·10 年前
引用 vincentSea@zh h 不太明白

@vincentSea untitled1.png 这样不小心按到了的话

M
moxiaobei2#13·10 年前

content:"fffff" ,在view里面只能显示fffff,不能像模板一样{{{}}}就自动编译成对应的images标签而是字符串形式,这怎么办

参与回复
登录后即可参与回复。登录