金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.1 KiB

  1. <template>
  2. <view id="article-list">
  3. <view class="content">
  4. <block v-for="(item, index) in list" :key="index" >
  5. <view class="item" v-for="(item, index) in items" :key="index" :data-id="item.id" @tap="jump">
  6. <image mode="widthFix" :src="item.img"></image>
  7. </view>
  8. </block>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  14. export default {
  15. data() {
  16. return {
  17. list: '',
  18. type: '',
  19. more: true,
  20. page: 1
  21. };
  22. },
  23. //下拉刷新
  24. onReachBottom() {
  25. if (this.more) {
  26. let page = this.page + 1;
  27. this.getArticleList(page, this.type);
  28. } else {
  29. wx.showToast({
  30. image: '../../../static/error.png',
  31. title: '再拉也没有啦'
  32. });
  33. }
  34. },
  35. onLoad(e) {
  36. if (e.type) {
  37. this.setData({
  38. type: e.type
  39. });
  40. this.getArticleList(1, e.type);
  41. }
  42. },
  43. components: {},
  44. props: {},
  45. methods: {
  46. jump(e) {
  47. let id = e.currentTarget.dataset.id;
  48. wx.navigateTo({
  49. url: '/pages/article/detail/detail?id=' + id
  50. });
  51. },
  52. //获取文章列表
  53. getArticleList(page, type) {
  54. wx.showLoading({
  55. title: "加载中",
  56. mask: true
  57. });
  58. this.$http.get({
  59. api: 'api/article/list',
  60. data: {
  61. page: page,
  62. type: type
  63. }
  64. }).then(res => {
  65. if (res.statusCode == 200) {
  66. res = res.data;
  67. if (res.status) {
  68. var pages = res.meta.pagination;
  69. var current_page = pages.current_page;
  70. var total_pages = pages.total_pages;
  71. this.setData({
  72. [`list[${page - 1}]`]: res.data,
  73. more: current_page < total_pages,
  74. page: current_page
  75. });
  76. wx.setNavigationBarTitle({
  77. title: res.meta.title
  78. });
  79. } else {
  80. wx.showModal({
  81. content: res.message || '请求失败',
  82. showCancel: false
  83. });
  84. }
  85. } else {
  86. wx.showModal({
  87. content: res.message || '请求失败',
  88. showCancel: false
  89. });
  90. }
  91. this.setData({
  92. show: false
  93. });
  94. wx.hideLoading();
  95. }).catch(rej => {
  96. wx.hideLoading();
  97. wx.showModal({
  98. content: res.message || '请求失败',
  99. showCancel: false
  100. });
  101. });
  102. },
  103. setData: function (obj) {
  104. let that = this;
  105. let keys = [];
  106. let val, data;
  107. Object.keys(obj).forEach(function (key) {
  108. keys = key.split('.');
  109. val = obj[key];
  110. data = that.$data;
  111. keys.forEach(function (key2, index) {
  112. if (index + 1 == keys.length) {
  113. that.$set(data, key2, val);
  114. } else {
  115. if (!data[key2]) {
  116. that.$set(data, key2, {});
  117. }
  118. }
  119. data = data[key2];
  120. });
  121. });
  122. }
  123. },
  124. computed: {},
  125. watch: {}
  126. };
  127. </script>
  128. <style rel="stylesheet/less" lang="less">
  129. @import "list";
  130. </style>