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

86 lines
1.9 KiB

3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 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. // 去掉 方便在组件中再使用 方便 只读对应list
  42. methods: {
  43. /**
  44. * 获取列表数据
  45. * @param {Object} queryParams - 查询参数
  46. * @returns {Promise} 返回Promise对象
  47. */
  48. getData(queryParams){
  49. return new Promise((success, error) => {
  50. if(!this.mixinsListApi){
  51. return console.error('mixinsListApi 缺失');
  52. }
  53. uni.showLoading({
  54. title: '加载列表中...'
  55. })
  56. this.$api(this.mixinsListApi,
  57. query(this, queryParams), res => {
  58. uni.stopPullDownRefresh()
  59. uni.hideLoading()
  60. if(res.code == 200){
  61. success(res.result)
  62. // 更新列表数据
  63. this[this.mixinsListKey || 'list'] = res.result.records || res.result
  64. // 更新总数
  65. this.total = res.result.total || res.result.length
  66. // 调用数据加载完成的回调
  67. this.getDataThen && this.getDataThen(res.result.records, res.result.total, res.result)
  68. }
  69. })
  70. })
  71. },
  72. /**
  73. * 加载更多数据
  74. */
  75. loadMoreData(){
  76. if(this.queryParams.pageSize < this.total){
  77. this.queryParams.pageSize += 10
  78. this.getData()
  79. }
  80. },
  81. }
  82. }