mali-applet-ui 0.0.56 → 0.0.59

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.
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <button class="ml-button" :class="[className || '', `type-${type}`, status ? `status-${status}` : '', round ? 'is-round' : '']" @tap="tapEvent" @click="clickEvent">
2
+ <button class="ml-button" :class="[className || '', `type-${type}`, status ? `status-${status}` : '', round ? 'is-round' : '']" :style="styles" @tap="tapEvent" @click="clickEvent">
3
3
  <slot>{{ content }}</slot>
4
4
  </button>
5
5
  </template>
@@ -18,10 +18,16 @@ export default {
18
18
  type: String,
19
19
  default: 'button'
20
20
  },
21
+ width: String,
21
22
  redirect: Boolean,
22
23
  url: String,
23
24
  className: String
24
25
  },
26
+ computed: {
27
+ styles () {
28
+ return this.width ? `width:${this.width};` : ''
29
+ }
30
+ },
25
31
  methods: {
26
32
  tapEvent () {
27
33
  if (this.url) {
@@ -4,21 +4,129 @@
4
4
  <scroll-view scroll-y>
5
5
  <slot></slot>
6
6
  </scroll-view>
7
- <uni-load-more v-if="loadMore" v-show="!loading" :status="loadStatus"></uni-load-more>
7
+ <uni-load-more v-if="showPage" :status="loadStatus"></uni-load-more>
8
8
  </view>
9
9
  </view>
10
10
  </template>
11
11
 
12
12
  <script>
13
+ import globalStore from '../../config/store'
14
+ import XEUtils from 'xe-utils'
15
+
13
16
  export default {
14
17
  name: 'MlListGroup',
15
18
  options: {
16
19
  virtualHost: true
17
20
  },
18
21
  props: {
22
+ value: Array,
23
+ showPage: Boolean,
24
+ autoload: {
25
+ type: Boolean,
26
+ default: true
27
+ },
28
+ pageProps: Object,
29
+ requestMethod: Function,
19
30
  title: String,
20
- loadMore: Boolean,
21
31
  className: String
32
+ },
33
+ data () {
34
+ return {
35
+ loading: false,
36
+ pageVO: {
37
+ pageSize: globalStore.list.pageSize,
38
+ currPage: 1,
39
+ total: 0
40
+ }
41
+ }
42
+ },
43
+ computed: {
44
+ loadStatus () {
45
+ if (this.loading) {
46
+ return 'loading'
47
+ }
48
+ return this.pageVO.pageSize * this.pageVO.currPage < Number(this.pageVO.total) ? 'more' : 'noMore'
49
+ },
50
+ pagePropOpts () {
51
+ return { ...globalStore.list.pageProp, ...this.pageProps }
52
+ }
53
+ },
54
+ created () {
55
+ if (this.autoload && this.requestMethod) {
56
+ this.reload()
57
+ }
58
+ },
59
+ methods: {
60
+ getParams () {
61
+ return this.showPage ? {
62
+ pageObj: this.pageVO,
63
+ data: {
64
+ [this.pagePropOpts.currentPage || 'page']: this.pageVO.currPage,
65
+ [this.pagePropOpts.pageSize || 'limit']: this.pageVO.pageSize
66
+ }
67
+ } : {
68
+ data: {}
69
+ }
70
+ },
71
+ getList () {
72
+ this.loading = true
73
+ if (this.requestMethod) {
74
+ return Promise.resolve(
75
+ this.requestMethod(this.getParams())
76
+ ).then(res => {
77
+ let data = []
78
+ if (XEUtils.isFunction(globalStore.list.resProps.result)) {
79
+ data = globalStore.list.resProps.result({ response: res }) || []
80
+ } else {
81
+ data = Array.isArray(res) ? res : XEUtils.get(res, globalStore.list.resProps.result || 'datas')
82
+ }
83
+ if (this.showPage) {
84
+ if (XEUtils.isFunction(globalStore.list.resProps.total)) {
85
+ this.pageVO.total = XEUtils.toNumber(globalStore.list.resProps.total({ response: res }))
86
+ } else {
87
+ this.pageVO.total = XEUtils.toNumber(XEUtils.get(res, globalStore.list.resProps.total || 'total'))
88
+ }
89
+ }
90
+ this.loading = false
91
+ return data
92
+ }).catch(() => {
93
+ this.loading = false
94
+ return []
95
+ })
96
+ }
97
+ return Promise.resolve([])
98
+ },
99
+ reload () {
100
+ this.pageVO.currPage = 1
101
+ return this.load()
102
+ },
103
+ async load() {
104
+ uni.showLoading({
105
+ title: '加载中'
106
+ })
107
+ try {
108
+ const data = await this.getList()
109
+ uni.stopPullDownRefresh()
110
+ uni.hideLoading()
111
+ this.$emit('input', data)
112
+ } catch (e) {
113
+ uni.stopPullDownRefresh()
114
+ uni.hideLoading()
115
+ console.error(e)
116
+ }
117
+ },
118
+ async loadMore() {
119
+ if (this.showPage && !this.loading && this.loadStatus === 'more') {
120
+ try {
121
+ this.pageVO.currPage++
122
+ const data = await this.getList()
123
+ const moreList = (this.value || []).concat(data)
124
+ this.$emit('input', moreList)
125
+ } catch (e) {
126
+ console.error(e)
127
+ }
128
+ }
129
+ }
22
130
  }
23
131
  }
24
132
  </script>
package/config/store.js CHANGED
@@ -28,9 +28,17 @@ const globalStore = {
28
28
  optionMethod: null
29
29
  }
30
30
  },
31
- // 图表
32
- echarts: {
33
- color: ['#582D27', '#391085', '#13c2c2', '#04395E', '#5E503F', '#7C98B3', '#69C6DB', '#A98467', '#b37feb']
31
+ // 列表组件
32
+ list: {
33
+ pageSize: 30,
34
+ pageProp: {
35
+ pageSize: 'limit',
36
+ currentPage: 'page'
37
+ },
38
+ resProps: {
39
+ result: 'datas',
40
+ total: 'total'
41
+ }
34
42
  }
35
43
  }
36
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "0.0.56",
3
+ "version": "0.0.59",
4
4
  "description": "码里云小程序组件库",
5
5
  "files": [
6
6
  "components",