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

84 lines
1.9 KiB

3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 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
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. 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. uni.showLoading({
  53. title: '加载中...'
  54. })
  55. this.$api(this.mixinsListApi,
  56. query(this, queryParams), res => {
  57. uni.stopPullDownRefresh()
  58. uni.hideLoading()
  59. if(res.code == 200){
  60. success(res.result)
  61. // 更新列表数据
  62. this[this.mixinsListKey || 'list'] = res.result.records || res.result
  63. // 输出获得的分类列表
  64. console.log('这是你获得的分类商品',this.list);
  65. // 更新总数
  66. this.total = res.result.total || res.result.length
  67. // 调用数据加载完成的回调
  68. this.getDataThen && this.getDataThen(res.result.records, res.result.total, res.result)
  69. }
  70. })
  71. })
  72. },
  73. /**
  74. * 加载更多数据
  75. */
  76. loadMoreData(){
  77. if(this.queryParams.pageSize < this.total){
  78. this.queryParams.pageSize += 10
  79. this.getData()
  80. }
  81. },
  82. }
  83. }