敢为人鲜小程序前端代码仓库
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.

77 lines
1.8 KiB

10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
10 months ago
11 months ago
  1. /**
  2. * 处理查询参数
  3. * @param {Object} self - 组件实例
  4. * @param {Object} queryParams - 额外的查询参数
  5. * @returns {Object} 合并后的查询参数
  6. */
  7. function query(self, queryParams){
  8. // 深度合并对象
  9. return self.$utils.deepMergeObject(
  10. self.$utils.deepMergeObject(self.queryParams,
  11. (self.beforeGetData && self.beforeGetData()) || {}),
  12. queryParams)
  13. }
  14. /**
  15. * 列表数据加载混入
  16. * 提供列表数据的加载分页下拉刷新上拉加载更多等功能
  17. */
  18. export default {
  19. data() {
  20. return {
  21. queryParams: {
  22. pageNo: 1,
  23. pageSize: 10,
  24. },
  25. total : 0,
  26. list : [],
  27. }
  28. },
  29. // 下拉刷新
  30. onPullDownRefresh() {
  31. this.getData()
  32. },
  33. // 上拉加载更多
  34. onReachBottom() {
  35. this.loadMoreData()
  36. },
  37. // 页面显示时加载数据
  38. onShow() {
  39. this.getData()
  40. },
  41. methods: {
  42. /**
  43. * 获取列表数据
  44. * @param {Object} queryParams - 查询参数
  45. * @returns {Promise} 返回Promise对象
  46. */
  47. getData(queryParams){
  48. return new Promise((success, error) => {
  49. if(!this.mixinsListApi){
  50. return console.error('mixinsListApi 缺失');
  51. }
  52. this.$api(this.mixinsListApi,
  53. query(this, queryParams), res => {
  54. uni.stopPullDownRefresh()
  55. if(res.code == 200){
  56. success(res.result)
  57. // 更新列表数据
  58. this[this.mixinsListKey || 'list'] = res.result.records || res.result
  59. // 更新总数
  60. this.total = res.result.total || res.result.length
  61. // 调用数据加载完成的回调
  62. this.getDataThen && this.getDataThen(res.result.records, res.result.total, res.result)
  63. }
  64. })
  65. })
  66. },
  67. /**
  68. * 加载更多数据
  69. */
  70. loadMoreData(){
  71. if(this.queryParams.pageSize < this.total){
  72. this.queryParams.pageSize += 10
  73. this.getData()
  74. }
  75. },
  76. }
  77. }