推拿小程序前端代码仓库
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.

79 lines
1.8 KiB

3 months ago
3 weeks ago
3 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. console.log("queryParams")
  49. console.log(queryParams)
  50. return new Promise((success, error) => {
  51. if(!this.mixinsListApi){
  52. return console.error('mixinsListApi 缺失');
  53. }
  54. this.$api(this.mixinsListApi,
  55. query(this, queryParams), res => {
  56. uni.stopPullDownRefresh()
  57. if(res.code == 200){
  58. success(res.result)
  59. // 更新列表数据
  60. this[this.mixinsListKey || 'list'] = res.result.records || res.result
  61. // 更新总数
  62. this.total = res.result.total || res.result.length
  63. // 调用数据加载完成的回调
  64. this.getDataThen && this.getDataThen(res.result.records, res.result.total, res.result)
  65. }
  66. })
  67. })
  68. },
  69. /**
  70. * 加载更多数据
  71. */
  72. loadMoreData(){
  73. if(this.queryParams.pageSize < this.total){
  74. this.queryParams.pageSize += 10
  75. this.getData()
  76. }
  77. },
  78. }
  79. }