mali-applet-ui 1.0.80 → 1.0.82

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,8 +1,8 @@
1
1
  <template>
2
- <view v-if="isFromReadonly" class="ml-input is-readonly" :class="[className || '', {'is-right': align === 'right'}]">
2
+ <view v-if="isFromReadonly" class="ml-input is-readonly" :class="[className || '', {'is-right': align === 'right'}]" @tap="tapEvent">
3
3
  <view class="ml-input-readonly-content">{{ inpVal }}</view>
4
4
  </view>
5
- <view v-else-if="!editable && (platformEnv.isWXMP || platformEnv.isQWMP)" class="ml-input not-edit" :class="[className || '', {'is-right': align === 'right', 'is-border': border}]">
5
+ <view v-else-if="!editable && (platformEnv.isWXMP || platformEnv.isQWMP)" class="ml-input not-edit" :class="[className || '', {'is-right': align === 'right', 'is-border': border}]" @tap="tapEvent">
6
6
  <view class="ml-input-simulate">
7
7
  <text v-if="inpVal">{{ inpVal }}</text>
8
8
  <text v-else class="ml-input-placeholder">{{ placeholder }}</text>
@@ -24,6 +24,7 @@
24
24
  :placeholder="placeholder"
25
25
  :maxlength="maxlength"
26
26
  :disabled="disabled"
27
+ @tap="tapEvent"
27
28
  @input="inputEvent"
28
29
  @focus="focusEvent"
29
30
  @blur="blurEvent"
@@ -116,6 +117,10 @@ export default {
116
117
  this.$emit('input', value)
117
118
  this.$emit('change', { value })
118
119
  },
120
+ tapEvent () {
121
+ this.$emit('tap', {})
122
+ this.$emit('click', {})
123
+ },
119
124
  focusEvent () {
120
125
  this.$emit('focus', { value: this.inpVal })
121
126
  },
@@ -141,7 +146,7 @@ export default {
141
146
  display: flex;
142
147
  flex-direction: row;
143
148
  .ml-input-placeholder {
144
- color: $ml-input-color-placeholder;;
149
+ color: $ml-input-color-placeholder;
145
150
  }
146
151
  .ml-input-simulate {
147
152
  padding: 0 10rpx;
@@ -36,6 +36,7 @@ export default {
36
36
  vertical: Boolean,
37
37
  showPage: Boolean,
38
38
  autoload: Boolean,
39
+ border: Boolean,
39
40
  prefixIcon: String,
40
41
  height: String,
41
42
  pageProps: Object,
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="ml-list-item" :class="[className || '', itemType ? `type-${itemType}` : '', {'is-padding': padding, 'is-vertical': itemVertical, 'is-disabled': disabled}]" :style="styles" @click="clickEvent" @tap="tapEvent">
2
+ <view class="ml-list-item" :class="[className || '', itemType ? `type-${itemType}` : '', {'is-border': itemBorder, 'is-padding': padding, 'is-vertical': itemVertical, 'is-disabled': disabled}]" :style="styles" @click="clickEvent" @tap="tapEvent">
3
3
  <view v-if="itemType === 'checkbox'" class="ml-list-checkbox-icon">
4
4
  <ml-checkbox :value="hasCheckedChecked" :disabled="disabled"></ml-checkbox>
5
5
  </view>
@@ -53,6 +53,10 @@ export default {
53
53
  className: String
54
54
  },
55
55
  inject: {
56
+ listSelectGroup: {
57
+ from: 'mlListSelectGroup',
58
+ default: null
59
+ },
56
60
  listGroup: {
57
61
  from: 'mlListGroup',
58
62
  default: null
@@ -79,11 +83,20 @@ export default {
79
83
  return this.selection.includes(this.value)
80
84
  },
81
85
  hasRadioChecked () {
86
+ if (this.listSelectGroup) {
87
+ return this.listSelectGroup ? this.listSelectGroup.selectValue : null
88
+ }
82
89
  return this.listGroup ? this.listGroup.selectValue : null
83
90
  },
84
91
  selection () {
92
+ if (this.listSelectGroup) {
93
+ return this.listSelectGroup ? this.listSelectGroup.selection : null
94
+ }
85
95
  return this.listGroup ? this.listGroup.selection : []
86
96
  },
97
+ itemBorder () {
98
+ return this.listGroup ? this.listGroup.border : null
99
+ },
87
100
  itemVertical () {
88
101
  if (this.vertical) {
89
102
  return true
@@ -91,6 +104,9 @@ export default {
91
104
  return this.listGroup ? this.listGroup.vertical : false
92
105
  },
93
106
  itemType () {
107
+ if (this.listSelectGroup) {
108
+ return this.listSelectGroup ? this.listSelectGroup.type : null
109
+ }
94
110
  return this.listGroup ? this.listGroup.type : ''
95
111
  }
96
112
  },
@@ -133,7 +149,9 @@ export default {
133
149
  if (this.disabled) {
134
150
  return
135
151
  }
136
- if (this.listGroup) {
152
+ if (this.listSelectGroup) {
153
+ this.listSelectGroup.triggerItemEvent({ value: this.value })
154
+ } else if (this.listGroup) {
137
155
  this.listGroup.triggerItemEvent({ value: this.value })
138
156
  }
139
157
  if (this.url) {
@@ -162,6 +180,12 @@ export default {
162
180
  border-radius: $ml-border-radius;
163
181
  background: #ffffff;
164
182
  font-size: $ml-describe-font-size;
183
+ &.is-border {
184
+ border-bottom: 1px solid #e5e5e5;
185
+ &:first-child {
186
+ border-top: 1px solid #e5e5e5;
187
+ }
188
+ }
165
189
  &.is-disabled {
166
190
  opacity: 0.5;
167
191
  // #ifdef H5
@@ -27,10 +27,12 @@ export default {
27
27
  },
28
28
  isAllChecked: Boolean,
29
29
  isAllIndeterminate: Boolean,
30
+ optionProps: Object,
30
31
  type: String,
31
32
  vertical: Boolean,
32
33
  prefixIcon: String,
33
34
  height: String,
35
+ options: Array,
34
36
  className: String
35
37
  },
36
38
  data () {
@@ -48,6 +50,15 @@ export default {
48
50
  computed: {
49
51
  contentStyle () {
50
52
  return this.height ? `height: ${this.height};` : ''
53
+ },
54
+ optOptions () {
55
+ return Object.assign({}, this.optionProps)
56
+ },
57
+ optLabelField () {
58
+ return this.optOptions.label || 'label'
59
+ },
60
+ optValueField () {
61
+ return this.optOptions.value || 'value'
51
62
  }
52
63
  },
53
64
  watch: {
@@ -0,0 +1,193 @@
1
+ <template>
2
+ <view class="ml-list-select-group" :class="[className || '', type ? `type-${type}` : '']">
3
+ <slot>
4
+ <ml-list-group :border="border">
5
+ <ml-list-item v-for="(item, index) in options" :key="index" :value="item[optValueField]" :padding="false" suffixIcon="none">{{ item[optLabelField] }}</ml-list-item>
6
+ </ml-list-group>
7
+ </slot>
8
+ </view>
9
+ </template>
10
+
11
+ <script>
12
+ import XEUtils from 'xe-utils'
13
+
14
+ export default {
15
+ name: 'MlListSelectGroup',
16
+ props: {
17
+ value: Array,
18
+ checkedKeys: {
19
+ type: Array,
20
+ default: null
21
+ },
22
+ checkedKey: {
23
+ type: [Number, String],
24
+ default: null
25
+ },
26
+ optionProps: Object,
27
+ isAllChecked: Boolean,
28
+ isAllIndeterminate: Boolean,
29
+ type: String,
30
+ border: Boolean,
31
+ options: {
32
+ type: Array,
33
+ default: () => []
34
+ },
35
+ className: String
36
+ },
37
+ provide () {
38
+ return {
39
+ mlListSelectGroup: this
40
+ }
41
+ },
42
+ data () {
43
+ return {
44
+ selectValue: null,
45
+ selection: []
46
+ }
47
+ },
48
+ computed: {
49
+ optOptions () {
50
+ return Object.assign({}, this.optionProps)
51
+ },
52
+ optLabelField () {
53
+ return this.optOptions.label || 'label'
54
+ },
55
+ optValueField () {
56
+ return this.optOptions.value || 'value'
57
+ }
58
+ },
59
+ watch: {
60
+ checkedKeys (value) {
61
+ if (!this.updateModel) {
62
+ this.selection = []
63
+ this.handleCheckboxRow(value, true)
64
+ }
65
+ this.updateModel = false
66
+ },
67
+ checkedKey (value) {
68
+ if (!this.updateModel) {
69
+ this.selectValue = null
70
+ this.handleRadioRow(value)
71
+ }
72
+ this.updateModel = false
73
+ },
74
+ options () {
75
+ if (this.type === 'checkbox') {
76
+ this.handleCheckboxRow(this.checkedKeys, true)
77
+ } else if (this.type === 'radio') {
78
+ this.handleRadioRow(this.checkedKey)
79
+ }
80
+ }
81
+ },
82
+ created () {
83
+ if (this.type === 'checkbox') {
84
+ if (this.checkedKeys) {
85
+ this.selection = this.checkedKeys
86
+ }
87
+ } else if (this.type === 'radio') {
88
+ if (this.checkedKey) {
89
+ this.selectValue = this.checkedKey
90
+ }
91
+ }
92
+ },
93
+ mounted () {
94
+ if (this.type === 'checkbox') {
95
+ setTimeout(() => this.updateStatus(), 10)
96
+ }
97
+ },
98
+ methods: {
99
+ updateStatus () {
100
+ const disableItems = this.options.filter(item => item.disabled)
101
+ const allSelectSize = this.selection.length + disableItems.length
102
+ const isAllChecked = allSelectSize > 0 && allSelectSize >= this.options.length
103
+ const isAllIndeterminate = this.selection.length > 0 && this.selection.length < this.options.length
104
+ this.$emit('update:isAllChecked', isAllChecked)
105
+ this.$emit('update:isAllIndeterminate', isAllIndeterminate)
106
+ },
107
+ updateChecked () {
108
+ let rest = null
109
+ this.updateModel = true
110
+ if (this.type === 'checkbox') {
111
+ rest = this.selection
112
+ this.$emit('update:checkedKeys', rest)
113
+ } else if (this.type === 'radio') {
114
+ rest = this.selectValue
115
+ this.$emit('update:checkedKey', rest)
116
+ }
117
+ this.$emit('change', { value: rest })
118
+ this.updateStatus()
119
+ },
120
+ toggleCheckboxRow (label) {
121
+ const index = this.selection.indexOf(label)
122
+ if (index > -1) {
123
+ this.selection.splice(index, 1)
124
+ } else {
125
+ this.selection.push(label)
126
+ }
127
+ this.updateChecked()
128
+ },
129
+ handleCheckboxRow (label, checked) {
130
+ let labels = label
131
+ if (!XEUtils.isArray(label)) {
132
+ labels = [label]
133
+ }
134
+ labels.forEach(val => {
135
+ const item = this.options.find(item => item[this.optValueField] === val)
136
+ if (item && !item.disabled) {
137
+ if (checked) {
138
+ if (!this.selection.includes(val)) {
139
+ this.selection.push(val)
140
+ }
141
+ } else {
142
+ const index = this.selection.indexOf(val)
143
+ if (index > -1) {
144
+ this.selection.splice(index, 1)
145
+ }
146
+ }
147
+ }
148
+ })
149
+ this.updateStatus()
150
+ },
151
+ setCheckboxRow (val, checked) {
152
+ this.handleCheckboxRow(val, checked)
153
+ this.updateChecked()
154
+ },
155
+ clearCheckboxRow () {
156
+ this.selection = []
157
+ this.updateChecked()
158
+ },
159
+ handleRadioRow (val) {
160
+ this.selectValue = val
161
+ this.updateStatus()
162
+ },
163
+ setRadioRow (val) {
164
+ this.handleRadioRow(val)
165
+ this.updateChecked()
166
+ },
167
+ clearRadioRow () {
168
+ this.selectValue = null
169
+ this.updateChecked()
170
+ },
171
+ triggerItemEvent (params) {
172
+ const { value: label } = params
173
+ if (this.type === 'checkbox') {
174
+ this.toggleCheckboxRow(label)
175
+ this.$emit('checkbox-change', {})
176
+ } else if (this.type === 'radio') {
177
+ this.setRadioRow(label)
178
+ this.$emit('radio-change', {})
179
+ }
180
+ }
181
+ }
182
+ }
183
+ </script>
184
+
185
+ <style lang="scss">
186
+ .ml-list-select-group {
187
+ margin-bottom: $ml-page-interval-margin;
188
+ color: $uni-text-color;
189
+ font-size: $ml-base-font-size;
190
+ display: flex;
191
+ flex-direction: column;
192
+ }
193
+ </style>
@@ -0,0 +1,128 @@
1
+ <template>
2
+ <view class="ml-list-select-page" :class="[className || '', {'is-border': border}]" @tap="tapEvent">
3
+ <view class="ml-list-select-page-warpper">
4
+ <view v-if="hasEmpty" class="ml-list-select-page-placeholder">{{ placeholder }}</view>
5
+ <view v-else>
6
+ <slot>
7
+ <view>{{ selectLabel }}</view>
8
+ </slot>
9
+ </view>
10
+ </view>
11
+ <view v-if="clearable && value.length" class="ml-list-select-page-clear-icon" @click.stop="clearEvent">
12
+ <ml-icon name="delete-filling"></ml-icon>
13
+ </view>
14
+ <view v-else class="ml-list-select-page-icon">
15
+ <ml-icon name="arrow-right" />
16
+ </view>
17
+ </view>
18
+ </template>
19
+
20
+ <script>
21
+ import XEUtils from 'xe-utils'
22
+
23
+ export default {
24
+ name: 'MlListSelectPage',
25
+ props: {
26
+ value: [Array, Number, String],
27
+ optionProps: Object,
28
+ compTitle: {
29
+ type: String,
30
+ default: '请选择'
31
+ },
32
+ compRender: {
33
+ type: Object,
34
+ default: () => ({})
35
+ },
36
+ type: String,
37
+ placeholder: {
38
+ type: String,
39
+ default: '请选择'
40
+ },
41
+ border: Boolean,
42
+ clearable: Boolean,
43
+ className: String
44
+ },
45
+ data () {
46
+ return {
47
+ dataList: []
48
+ }
49
+ },
50
+ computed: {
51
+ optOptions () {
52
+ return Object.assign({}, this.optionProps)
53
+ },
54
+ optLabelField () {
55
+ return this.optOptions.label || 'label'
56
+ },
57
+ optValueField () {
58
+ return this.optOptions.value || 'value'
59
+ },
60
+ hasEmpty () {
61
+ if (this.type === 'checkbox') {
62
+ return !this.value || !this.value.length
63
+ }
64
+ return XEUtils.eqNull(this.value) || this.value === ''
65
+ },
66
+ selectLabel () {
67
+ if (this.type === 'checkbox') {
68
+ return this.dataList.filter(item => this.value.includes(item[this.optValueField])).map(item => item[this.optLabelField]).join(', ')
69
+ }
70
+ if (this.type === 'radio') {
71
+ return this.dataList.filter(item => this.value === item[this.optValueField]).map(item => item[this.optLabelField]).join(', ')
72
+ }
73
+ return ''
74
+ }
75
+ },
76
+ methods: {
77
+ tapEvent () {
78
+ // 打开选择列表页面
79
+ this.$store.dispatch('openSelectPage', {
80
+ compName: this.compRender.name, // 指定加载组件名称
81
+ compTitle: this.compTitle, // 页面标题
82
+ compType: this.type, // 单选框和复选框
83
+ compProps: this.compRender.props, // 组件参数
84
+ optionProps: this.optionProps,
85
+ value: this.value, // 选择值
86
+ events: {
87
+ // 加载完成事件
88
+ load: (params) => {
89
+ this.dataList = params.options || []
90
+ },
91
+ // 点击确认事件
92
+ confirm: (params) => {
93
+ this.$emit('input', params.value)
94
+ }
95
+ }
96
+ })
97
+ this.$emit('tap', {})
98
+ this.$emit('click', {})
99
+ },
100
+ clearEvent () {
101
+
102
+ }
103
+ }
104
+ }
105
+ </script>
106
+
107
+ <style lang="scss">
108
+ .ml-list-select-page {
109
+ display: flex;
110
+ flex-direction: row;
111
+ padding: 0 10rpx;
112
+ height: 70rpx;
113
+ line-height: 70rpx;
114
+ .ml-list-select-page-warpper {
115
+ flex-grow: 1;
116
+ overflow: hidden;
117
+ text-overflow: ellipsis;
118
+ white-space: nowrap;
119
+ }
120
+ .ml-list-select-page-clear-icon,
121
+ .ml-list-select-page-icon {
122
+ flex-shrink: 0;
123
+ }
124
+ .ml-list-select-page-placeholder {
125
+ color: $ml-input-color-placeholder;
126
+ }
127
+ }
128
+ </style>
@@ -89,7 +89,11 @@ export default {
89
89
  created () {
90
90
  this.$nextTick(() => {
91
91
  if (this.autoload && this.requestMethod) {
92
- this.reload()
92
+ this.reload().then(() => {
93
+ this.$emit('init')
94
+ })
95
+ } else {
96
+ this.$emit('init')
93
97
  }
94
98
  })
95
99
  },
@@ -152,6 +156,7 @@ export default {
152
156
  }
153
157
  uni.stopPullDownRefresh()
154
158
  this.$emit('input', data)
159
+ this.$emit('query', { value: data })
155
160
  } catch (e) {
156
161
  if (this.$loading) {
157
162
  this.$loading.hide()
@@ -160,6 +165,9 @@ export default {
160
165
  console.error(e)
161
166
  }
162
167
  this.updateEmptyStatus()
168
+ return new Promise(resolve => {
169
+ setTimeout(resolve, 100)
170
+ })
163
171
  },
164
172
  async loadMore () {
165
173
  if (this.showPage && !this.loading && this.loadStatus === 'more') {
@@ -168,6 +176,7 @@ export default {
168
176
  const data = await this.getList()
169
177
  const moreList = (this.value || []).concat(data)
170
178
  this.$emit('input', moreList)
179
+ this.$emit('more', { value: moreList })
171
180
  } catch (e) {
172
181
  console.error(e)
173
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "1.0.80",
3
+ "version": "1.0.82",
4
4
  "description": "码里云小程序组件库",
5
5
  "files": [
6
6
  "lib",
package/store/base.js ADDED
@@ -0,0 +1,53 @@
1
+ const base = {
2
+ state: {
3
+ },
4
+ getters: {
5
+ },
6
+ mutations: {
7
+ },
8
+ actions: {
9
+ initSelectPage ({ commit }) {
10
+ commit('setEventData', null)
11
+ },
12
+ clearSelectPage ({ commit }) {
13
+ commit('setEventData', null)
14
+ },
15
+ openSelectPage (params, options) {
16
+ const opts = { ...options }
17
+ const compParams = {
18
+ value: opts.value, // 默认选中
19
+ compName: opts.compName, // 指定加载组件名称
20
+ compType: opts.compType, // 单选框和复选框
21
+ compProps: opts.compProps,
22
+ optionProps: opts.optionProps
23
+ }
24
+ if (!opts.compName) {
25
+ console.error('openSelectPage:compName 不能为空')
26
+ return
27
+ }
28
+ const evnts = opts.events || {}
29
+ uni.navigateTo({
30
+ url: `/pagesA/base/select/SelectPage?compName=${opts.compName}`,
31
+ success ({ eventChannel }) {
32
+ if (opts && opts.compTitle) {
33
+ uni.setNavigationBarTitle({
34
+ title: opts.compTitle
35
+ })
36
+ }
37
+ eventChannel.emit('init', compParams)
38
+ },
39
+ events: {
40
+ ...evnts,
41
+ confirm (params) {
42
+ if (evnts.confirm) {
43
+ evnts.confirm(params)
44
+ }
45
+ uni.navigateBack()
46
+ }
47
+ }
48
+ })
49
+ }
50
+ }
51
+ }
52
+
53
+ export default base
package/store/events.js CHANGED
@@ -13,9 +13,6 @@ const events = {
13
13
  setEvent (state, evnt) {
14
14
  state[`global${evnt.type.slice(0, 1).toUpperCase()}${evnt.type.slice(1)}`] = evnt
15
15
  },
16
- initEventData (state) {
17
- state.eventData = null
18
- },
19
16
  setEventData (state, data) {
20
17
  state.eventData = data
21
18
  }