mali-applet-ui 0.1.49 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -38,7 +38,7 @@ export default {
|
|
|
38
38
|
return {
|
|
39
39
|
loading: false,
|
|
40
40
|
pageVO: {
|
|
41
|
-
pageSize: globalStore.
|
|
41
|
+
pageSize: globalStore.loadMore.pageSize,
|
|
42
42
|
currPage: 1,
|
|
43
43
|
total: 0
|
|
44
44
|
}
|
|
@@ -55,7 +55,7 @@ export default {
|
|
|
55
55
|
return this.pageVO.pageSize * this.pageVO.currPage < Number(this.pageVO.total) ? 'more' : 'noMore'
|
|
56
56
|
},
|
|
57
57
|
pagePropOpts () {
|
|
58
|
-
return { ...globalStore.
|
|
58
|
+
return { ...globalStore.loadMore.pageProp, ...this.pageProps }
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
created () {
|
|
@@ -84,16 +84,16 @@ export default {
|
|
|
84
84
|
this.requestMethod.call(this.currVM, this.getParams())
|
|
85
85
|
).then(res => {
|
|
86
86
|
let data = []
|
|
87
|
-
if (XEUtils.isFunction(globalStore.
|
|
88
|
-
data = globalStore.
|
|
87
|
+
if (XEUtils.isFunction(globalStore.loadMore.resProps.result)) {
|
|
88
|
+
data = globalStore.loadMore.resProps.result({ response: res }) || []
|
|
89
89
|
} else {
|
|
90
|
-
data = Array.isArray(res) ? res : XEUtils.get(res, globalStore.
|
|
90
|
+
data = Array.isArray(res) ? res : XEUtils.get(res, globalStore.loadMore.resProps.result || 'datas')
|
|
91
91
|
}
|
|
92
92
|
if (this.showPage) {
|
|
93
|
-
if (XEUtils.isFunction(globalStore.
|
|
94
|
-
this.pageVO.total = XEUtils.toNumber(globalStore.
|
|
93
|
+
if (XEUtils.isFunction(globalStore.loadMore.resProps.total)) {
|
|
94
|
+
this.pageVO.total = XEUtils.toNumber(globalStore.loadMore.resProps.total({ response: res }))
|
|
95
95
|
} else {
|
|
96
|
-
this.pageVO.total = XEUtils.toNumber(XEUtils.get(res, globalStore.
|
|
96
|
+
this.pageVO.total = XEUtils.toNumber(XEUtils.get(res, globalStore.loadMore.resProps.total || 'total'))
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
this.loading = false
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ml-load-more" :class="[className]">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
<view v-if="showPage" class="ml-load-more-warpper">
|
|
5
|
+
<view v-if="loadStatus === 'more'" class="ml-load-more-more">上拉显示更多</view>
|
|
6
|
+
<view v-if="loadStatus === 'noMore'" class="ml-load-more-no-more">没有更多数据了</view>
|
|
7
|
+
</view>
|
|
8
|
+
</view>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
import globalStore from '../../config/store'
|
|
13
|
+
import XEUtils from 'xe-utils'
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
props: {
|
|
17
|
+
value: Array,
|
|
18
|
+
autoload: Boolean,
|
|
19
|
+
showPage: Boolean,
|
|
20
|
+
pageProps: Object,
|
|
21
|
+
requestMethod: Function,
|
|
22
|
+
className: String
|
|
23
|
+
},
|
|
24
|
+
inject: {
|
|
25
|
+
currVM: {
|
|
26
|
+
from: '$pageVM',
|
|
27
|
+
default: null
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
data () {
|
|
31
|
+
return {
|
|
32
|
+
loading: false,
|
|
33
|
+
pageVO: {
|
|
34
|
+
pageSize: globalStore.loadMore.pageSize,
|
|
35
|
+
currPage: 1,
|
|
36
|
+
total: 0
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
computed: {
|
|
41
|
+
loadStatus () {
|
|
42
|
+
if (this.loading) {
|
|
43
|
+
return 'loading'
|
|
44
|
+
}
|
|
45
|
+
return this.pageVO.pageSize * this.pageVO.currPage < Number(this.pageVO.total) ? 'more' : 'noMore'
|
|
46
|
+
},
|
|
47
|
+
pagePropOpts () {
|
|
48
|
+
return { ...globalStore.loadMore.pageProp, ...this.pageProps }
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
created () {
|
|
52
|
+
this.$nextTick(() => {
|
|
53
|
+
if (this.autoload && this.requestMethod) {
|
|
54
|
+
this.reload()
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
methods: {
|
|
59
|
+
getParams () {
|
|
60
|
+
return this.showPage ? {
|
|
61
|
+
pageObj: this.pageVO,
|
|
62
|
+
data: {
|
|
63
|
+
[this.pagePropOpts.currentPage || 'page']: this.pageVO.currPage,
|
|
64
|
+
[this.pagePropOpts.pageSize || 'limit']: this.pageVO.pageSize
|
|
65
|
+
}
|
|
66
|
+
} : {
|
|
67
|
+
data: {}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
getList () {
|
|
71
|
+
this.loading = true
|
|
72
|
+
if (this.requestMethod) {
|
|
73
|
+
return Promise.resolve(
|
|
74
|
+
this.requestMethod.call(this.currVM, this.getParams())
|
|
75
|
+
).then(res => {
|
|
76
|
+
let data = []
|
|
77
|
+
if (XEUtils.isFunction(globalStore.loadMore.resProps.result)) {
|
|
78
|
+
data = globalStore.loadMore.resProps.result({ response: res }) || []
|
|
79
|
+
} else {
|
|
80
|
+
data = Array.isArray(res) ? res : XEUtils.get(res, globalStore.loadMore.resProps.result || 'datas')
|
|
81
|
+
}
|
|
82
|
+
if (this.showPage) {
|
|
83
|
+
if (XEUtils.isFunction(globalStore.loadMore.resProps.total)) {
|
|
84
|
+
this.pageVO.total = XEUtils.toNumber(globalStore.loadMore.resProps.total({ response: res }))
|
|
85
|
+
} else {
|
|
86
|
+
this.pageVO.total = XEUtils.toNumber(XEUtils.get(res, globalStore.loadMore.resProps.total || 'total'))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this.loading = false
|
|
90
|
+
return data
|
|
91
|
+
}).catch(() => {
|
|
92
|
+
this.loading = false
|
|
93
|
+
return []
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
return Promise.resolve([])
|
|
97
|
+
},
|
|
98
|
+
reload () {
|
|
99
|
+
this.pageVO.currPage = 1
|
|
100
|
+
return this.load()
|
|
101
|
+
},
|
|
102
|
+
async load() {
|
|
103
|
+
if (this.$loading) {
|
|
104
|
+
this.$loading.show()
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const data = await this.getList()
|
|
108
|
+
if (this.$loading) {
|
|
109
|
+
this.$loading.hide()
|
|
110
|
+
}
|
|
111
|
+
uni.stopPullDownRefresh()
|
|
112
|
+
this.$emit('input', data)
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (this.$loading) {
|
|
115
|
+
this.$loading.hide()
|
|
116
|
+
}
|
|
117
|
+
uni.stopPullDownRefresh()
|
|
118
|
+
console.error(e)
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
async loadMore() {
|
|
122
|
+
if (this.showPage && !this.loading && this.loadStatus === 'more') {
|
|
123
|
+
try {
|
|
124
|
+
this.pageVO.currPage++
|
|
125
|
+
const data = await this.getList()
|
|
126
|
+
const moreList = (this.value || []).concat(data)
|
|
127
|
+
this.$emit('input', moreList)
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.error(e)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
</script>
|
|
136
|
+
|
|
137
|
+
<style lang="scss">
|
|
138
|
+
.ml-load-more-warpper {
|
|
139
|
+
text-align: center;
|
|
140
|
+
.ml-load-more-more,
|
|
141
|
+
.ml-load-more-no-more {
|
|
142
|
+
padding: 20rpx;
|
|
143
|
+
color: rgb(119, 119, 119);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
</style>
|
package/config/store.js
CHANGED