mali-applet-ui 1.0.75 → 1.0.76

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.
@@ -29,6 +29,7 @@ import globalStore from '../../../config/store'
29
29
  import XEUtils from 'xe-utils'
30
30
 
31
31
  export default {
32
+ name: 'MlLoadMore',
32
33
  props: {
33
34
  value: Array,
34
35
  autoload: Boolean,
@@ -0,0 +1,195 @@
1
+ <template>
2
+ <view class="ml-pager" :class="[className || '', {'not-data': showNotData}]">
3
+ <view class="ml-pager-content">
4
+ <slot></slot>
5
+ </view>
6
+ <view v-if="showNotData && !loading" class="ml-pager-empty">
7
+ <slot name="empty">
8
+ <ml-not-data :emptyUrl="emptyUrl" :emptyText="emptyText" :emptyHint="emptyHint"></ml-not-data>
9
+ <view class="ml-pager-empty-content">
10
+ <slot name="emptycontent"></slot>
11
+ </view>
12
+ </slot>
13
+ </view>
14
+ <ml-fixed-footer>
15
+ <ml-button>上一页</ml-button>
16
+ <ml-button>{{ pageVO.currPage }}/{{ pageCount }}</ml-button>
17
+ <ml-button>下一页</ml-button>
18
+ </ml-fixed-footer>
19
+ </view>
20
+ </template>
21
+
22
+ <script>
23
+ import globalStore from '../../../config/store'
24
+ import XEUtils from 'xe-utils'
25
+
26
+ export default {
27
+ name: 'MlPager',
28
+ props: {
29
+ value: Array,
30
+ autoload: Boolean,
31
+ pageProps: Object,
32
+ requestMethod: Function,
33
+ filterForm: Object,
34
+ emptyConfig: Object,
35
+ className: String
36
+ },
37
+ inject: {
38
+ currVM: {
39
+ from: '$pageVM',
40
+ default: null
41
+ }
42
+ },
43
+ data () {
44
+ return {
45
+ loading: false,
46
+ pageVO: {
47
+ pageSize: globalStore.loadMore.pageSize,
48
+ currPage: 1,
49
+ total: 0
50
+ },
51
+ emptyUrl: '',
52
+ emptyText: '',
53
+ emptyHint: ''
54
+ }
55
+ },
56
+ computed: {
57
+ pageCount () {
58
+ return Math.floor(this.pageVO.pageSize / this.pageVO.total) + 1
59
+ },
60
+ loadStatus () {
61
+ if (this.loading) {
62
+ return 'loading'
63
+ }
64
+ return this.pageVO.pageSize * this.pageVO.currPage < Number(this.pageVO.total) ? 'more' : 'noMore'
65
+ },
66
+ showNotData () {
67
+ return !this.value || !this.value.length
68
+ },
69
+ pagePropOpts () {
70
+ return { ...globalStore.loadMore.pageProp, ...this.pageProps }
71
+ },
72
+ hasFilters () {
73
+ const fields = this.emptyOpts.fields || []
74
+ for (const key in this.filterForm) {
75
+ const itemValue = this.filterForm[key]
76
+ if (fields.includes(key) && (XEUtils.isArray(itemValue) ? itemValue.length : itemValue)) {
77
+ return true
78
+ }
79
+ }
80
+ return false
81
+ },
82
+ emptyOpts () {
83
+ return Object.assign({}, this.emptyConfig)
84
+ }
85
+ },
86
+ created () {
87
+ this.$nextTick(() => {
88
+ if (this.autoload && this.requestMethod) {
89
+ this.reload()
90
+ }
91
+ })
92
+ },
93
+ methods: {
94
+ getParams () {
95
+ return {
96
+ pageObj: this.pageVO,
97
+ data: {
98
+ [this.pagePropOpts.currentPage || 'page']: this.pageVO.currPage,
99
+ [this.pagePropOpts.pageSize || 'limit']: this.pageVO.pageSize
100
+ }
101
+ }
102
+ },
103
+ getList () {
104
+ if (this.requestMethod) {
105
+ this.loading = true
106
+ return Promise.resolve(
107
+ this.requestMethod.call(this.currVM, this.getParams())
108
+ ).then(res => {
109
+ let data = []
110
+ if (XEUtils.isFunction(globalStore.loadMore.resProps.result)) {
111
+ data = globalStore.loadMore.resProps.result({ response: res }) || []
112
+ } else {
113
+ data = Array.isArray(res) ? res : XEUtils.get(res, globalStore.loadMore.resProps.result || 'datas')
114
+ }
115
+ if (XEUtils.isFunction(globalStore.loadMore.resProps.total)) {
116
+ this.pageVO.total = XEUtils.toNumber(globalStore.loadMore.resProps.total({ response: res }))
117
+ } else {
118
+ this.pageVO.total = XEUtils.toNumber(XEUtils.get(res, globalStore.loadMore.resProps.total || 'total'))
119
+ }
120
+ this.loading = false
121
+ return data
122
+ }).catch((e) => {
123
+ console.error(e)
124
+ console.error('请检查是否在容器组件 <PageLayout ...> 或 <ViewContainer ...> 下使用')
125
+ this.loading = false
126
+ return []
127
+ })
128
+ }
129
+ return Promise.resolve([])
130
+ },
131
+ reload () {
132
+ this.pageVO.currPage = 1
133
+ return this.load()
134
+ },
135
+ async load () {
136
+ if (this.$loading) {
137
+ this.$loading.show()
138
+ }
139
+ try {
140
+ const data = await this.getList()
141
+ if (this.$loading) {
142
+ this.$loading.hide()
143
+ }
144
+ uni.stopPullDownRefresh()
145
+ this.$emit('input', data)
146
+ } catch (e) {
147
+ if (this.$loading) {
148
+ this.$loading.hide()
149
+ }
150
+ uni.stopPullDownRefresh()
151
+ console.error(e)
152
+ }
153
+ this.updateEmptyStatus()
154
+ },
155
+ async loadMore () {
156
+ if (this.showPage && !this.loading && this.loadStatus === 'more') {
157
+ try {
158
+ this.pageVO.currPage++
159
+ const data = await this.getList()
160
+ const moreList = (this.value || []).concat(data)
161
+ this.$emit('input', moreList)
162
+ } catch (e) {
163
+ console.error(e)
164
+ }
165
+ }
166
+ },
167
+ updateEmptyStatus () {
168
+ this.$nextTick(() => {
169
+ if (this.hasFilters) {
170
+ this.emptyUrl = this.emptyOpts.resultUrl || globalStore.loadMore.notData.resultUrl || ''
171
+ this.emptyText = XEUtils.template(this.emptyOpts.resultText || globalStore.loadMore.notData.resultText, this.filterForm) || ''
172
+ this.emptyHint = XEUtils.template(this.emptyOpts.resultHint || globalStore.loadMore.notData.resultHint, this.filterForm) || ''
173
+ } else {
174
+ this.emptyUrl = this.emptyOpts.emptyUrl || globalStore.loadMore.notData.emptyUrl || ''
175
+ this.emptyText = this.emptyOpts.emptyText || globalStore.loadMore.notData.emptyText || ''
176
+ this.emptyHint = this.emptyOpts.emptyHint || globalStore.loadMore.notData.emptyHint || ''
177
+ }
178
+ })
179
+ }
180
+ }
181
+ }
182
+ </script>
183
+
184
+ <style lang="scss">
185
+ .ml-pager {
186
+ &.not-data {
187
+ .ml-pager-content {
188
+ display: none;
189
+ }
190
+ }
191
+ .ml-pager-empty-content {
192
+ text-align: center;
193
+ }
194
+ }
195
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "1.0.75",
3
+ "version": "1.0.76",
4
4
  "description": "码里云小程序组件库",
5
5
  "files": [
6
6
  "lib",