mali-applet-ui 1.0.75 → 1.0.77

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