[关闭]
@xiaoxiaowang 2017-07-30T09:12:08.000000Z 字数 3121 阅读 1277

微信小程序娱乐---哇哦窝

IT 微信小程序 wxapp


自从去年微信小程序诞生到现在已经有段时间了,个人还是挺看好小程序的,去年的时候就打算玩一玩小程序,但是一直都抽不出时间。自从上次弄了台阿里云ECS之后,就又有了玩玩小程序的欲望,于是花了两个晚上的时间,算是开发完成了。界面很简单,如下
view.gif

这里讲下我遇到的一些问题

布局

本来我使用的是scroll-view 然后发现这种添加下拉刷新,上拉加载功能的时候效果不是很好,没有使用view体验的舒服,最终我使用的是view然后再onPullDownRefresh方法中处理加载的数据。

新闻详情页

小程序本身是不支持html布局的,于是我使用了开源代码wxParse转换的。于是我的后台代码将新闻详情页的主题内容html抽了出来,使用wxParse转换了一下,就如上图所示,样式自己调了下,还能接受,新闻api是用的阿里云的新闻接口。

外链

小程序是不允许请求其他域名下面的服务,本地调试除外,所以我新闻列表和新闻详情都是在同一域名下解析的。

颜色搭配

下面的图标是我自己简单制作的,颜色搭配也是自己搭配的,所以,尽管吐槽我的搭配吧。。。

初衷

我玩小程序的初衷是想弄些精简的内容,自己在上下班的时候浏览浏览,不需太多,但是最终微信没有给通过,说是涉及到了资讯,需要使用企业微信号。。。

废话不多说,代码在下面,感兴趣的玩一玩
目录

  1. .
  2. ├── app.js
  3. ├── app.json
  4. ├── app.wxss
  5. ├── images
  6. ├── page
  7. ├── README.md
  8. ├── utils
  9. └── wxParse

主要的布局

  1. <view class="grid">
  2. <view class="list" scroll-top="{{scrollTop}}" scroll-y style="height:{{scrollHeight}}px;" class="list" bindscrolltolower="bindDownLoad" bindscroll="scroll" bindscrolltoupper="refresh">
  3. <view class="card short-card" wx:for="{{list}}" wx:for-item="item">
  4. <view>
  5. <navigator url="../content/index?url={{item.url}}&title={{item.title}}" hover-class="changestyle"><text class="title">{{item.title}}</text></navigator>
  6. </view>
  7. <!--<image src="{{item.thumbnail_pic_s}}" style="width: {{imagewidth}}px; height: {{imageheight}}px;" class="new-img"></image>-->
  8. <view>
  9. <text class="tag">发布于 {{ item.date }}, 来自 {{item.author_name}}</text>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="body-view">
  14. <loading hidden="{{hidden}}" bindchange="loadingChange">
  15. 拼命加载中...
  16. </loading>
  17. </view>
  18. </view>

js

  1. //text.js
  2. // var imageUtil = require('../../utils/util.js');
  3. var url = 'http://wangxc.club:8080/api/news';
  4. var GetList = function (that) {
  5. that.setData({
  6. hidden: false
  7. });
  8. wx.request({
  9. url: url,
  10. success: function (res) {
  11. wx.stopPullDownRefresh() //停止下拉刷新
  12. // console.log(res.data.data)
  13. that.setData({
  14. hidden: true,
  15. list: res.data.data
  16. });
  17. wx.hideNavigationBarLoading();
  18. }
  19. })
  20. }
  21. Page({
  22. data: {
  23. hidden: true,
  24. list: [],
  25. scrollTop: 0,
  26. scrollHeight: 0
  27. },
  28. onLoad: function () {
  29. // 这里要非常注意,微信的scroll-view必须要设置高度才能监听滚动事件,所以,需要在页面的onLoad事件中给scroll-view的高度赋值
  30. var that = this;
  31. wx.getSystemInfo({
  32. success: function (res) {
  33. console.info(res.windowHeight);
  34. that.setData({
  35. scrollHeight: res.windowHeight
  36. });
  37. }
  38. });
  39. },
  40. // imageLoad: function (e) {
  41. // var imageSize = imageUtil.imageUtil(e)
  42. // this.setData({
  43. // imagewidth: imageSize.imageWidth,
  44. // imageheight: imageSize.imageHeight
  45. // })
  46. // },
  47. onShow: function () {
  48. // 在页面展示之后先获取一次数据
  49. var that = this;
  50. GetList(that);
  51. },
  52. onHide: function () {
  53. // 页面隐藏
  54. },
  55. bindDownLoad: function () {
  56. var that = this;
  57. GetList(that);
  58. },
  59. onUnload: function () {
  60. // 页面关闭
  61. },
  62. scroll: function (event) {
  63. // console.log(event.detail.scrollTop)
  64. this.setData({
  65. scrollTop: event.detail.scrollTop
  66. });
  67. },
  68. refresh: function (event) {
  69. wx.showNavigationBarLoading();
  70. this.setData({
  71. list: [],
  72. scrollTop: 0
  73. });
  74. GetList(this)
  75. },
  76. onPullDownRefresh: function () {
  77. // wx.showNavigationBarLoading() //在标题栏中显示加载
  78. //let newwords = [{ message: '从天而降', viewid: '-1', time: util.formatTime(new Date), greeting: 'hello' }].concat(this.data.words);
  79. GetList(this)
  80. // setTimeout(() => {
  81. // this.setData({
  82. // words: newwords
  83. // })
  84. // wx.hideNavigationBarLoading() //完成停止加载
  85. // wx.stopPullDownRefresh() //停止下拉刷新
  86. // }, 2000)
  87. },
  88. onReachBottom: function () {
  89. GetList(this)
  90. }
  91. })

目前代码就这些,功能的话等我有了新的想法和创意了,我会接着去开发~
小程序代码 https://github.com/vector4wang/vw
后台服务 https://github.com/vector4wang/spring-boot-quick/tree/master/quick-wx-api

欢迎浏览我的个人博客 http://vector4wang.tk/

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注