mali-applet-ui 0.0.99 → 0.1.0

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.
@@ -5,7 +5,7 @@
5
5
  </view>
6
6
  <view class="ml-checkbox-content">
7
7
  <slot>
8
- <text>{{ content }}</text>
8
+ <view>{{ content }}</view>
9
9
  </slot>
10
10
  </view>
11
11
  </view>
@@ -53,13 +53,13 @@ export default {
53
53
 
54
54
  <style lang="scss">
55
55
  .ml-checkbox {
56
- display: inline-block;
56
+ display: inline-flex;
57
57
  margin-right: 20rpx;
58
+ align-items: center;
58
59
  &.is-checked {
59
60
  color: $uni-color-primary;
60
61
  }
61
62
  .ml-checkbox-icon {
62
- display: inline-block;
63
63
  width: 40rpx;
64
64
  margin-right: 10rpx;
65
65
  text-align: center;
@@ -67,10 +67,9 @@ export default {
67
67
  }
68
68
  .ml-checkbox-icon,
69
69
  .ml-checkbox-content {
70
- vertical-align: middle;
71
- }
72
- .ml-checkbox-content {
73
- display: inline-block;
70
+ display: inline-flex;
71
+ align-items: center;
72
+ flex-direction: row;
74
73
  }
75
74
  }
76
75
  </style>
@@ -1,6 +1,6 @@
1
1
  <template>
2
- <view class="ml-radio-group" :class="[className || '', {'is-disabled': disabled, 'is-vertical': vertical}]">
3
- <view class="ml-radio-group-item" v-for="(item, index) in options" :key="index">
2
+ <view class="ml-checkbox-group" :class="[className || '', {'is-disabled': disabled, 'is-vertical': vertical}]">
3
+ <view class="ml-checkbox-group-item" v-for="(item, index) in options" :key="index">
4
4
  <ml-checkbox :value="value.includes(item.value) ? item.value : null" :label="item.value" :content="item.label" :disabled="disabled || item.disabled" @change="changeEvent"></ml-checkbox>
5
5
  </view>
6
6
  </view>
@@ -33,12 +33,12 @@ export default {
33
33
  </script>
34
34
 
35
35
  <style lang="scss">
36
- .ml-radio-group {
36
+ .ml-checkbox-group {
37
37
  display: inline-flex;
38
38
  &.is-vertical {
39
39
  width: 100%;
40
40
  flex-direction: column;
41
- & > .ml-radio-group-item {
41
+ & > .ml-checkbox-group-item {
42
42
  margin: 4rpx 0;
43
43
  }
44
44
  }
@@ -26,7 +26,6 @@ export default {
26
26
  name: 'MlForm',
27
27
  props: {
28
28
  value: Object,
29
- data: Object,
30
29
  items: Array,
31
30
  rules: Object,
32
31
  align: String,
@@ -49,14 +48,58 @@ export default {
49
48
  },
50
49
  methods: {
51
50
  validate () {
52
- return new Promise(resolve => {
53
- resolve()
54
- })
51
+ let errMaps = null
52
+ for (let i = 0; i < this.itemList.length; i++) {
53
+ const item = this.itemList[i]
54
+ const errRule = this.validRule(item)
55
+ if (errRule) {
56
+ if (!errMaps) {
57
+ errMaps = {}
58
+ }
59
+ errMaps[item.field] = errRule
60
+ item.errRule = { field: item.field, message: errRule.message }
61
+ } else {
62
+ item.errRule = null
63
+ }
64
+ }
65
+ return errMaps ? Promise.resolve(errMaps) : Promise.resolve()
55
66
  },
56
- validateField (fields) {
57
- return new Promise(resolve => {
58
- resolve()
59
- })
67
+ validateField (field) {
68
+ let errMaps = null
69
+ if (field) {
70
+ const item = this.itemList.find(item => item.field === field)
71
+ if (item) {
72
+ const errRule = this.validRule(item)
73
+ if (errRule) {
74
+ errMaps = { [field]: errRule }
75
+ item.errRule = { field, message: errRule.message }
76
+ } else {
77
+ item.errRule = null
78
+ }
79
+ }
80
+ }
81
+ return errMaps ? Promise.resolve(errMaps) : Promise.resolve()
82
+ },
83
+ validRule (item) {
84
+ const rules = item && this.rules ? this.rules[item.field] : null
85
+ const itemValue = item && this.value ? this.value[item.field] : null
86
+ let errRule = null
87
+ if (rules) {
88
+ for (let i = 0; i < rules.length; i++) {
89
+ const rule = rules[i]
90
+ if (rule.required) {
91
+ if (!itemValue) {
92
+ errRule = rule
93
+ break
94
+ }
95
+ if (rule.type === 'array' && !itemValue.length) {
96
+ errRule = rule
97
+ break
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return errRule
60
103
  },
61
104
  updateModel ({ field, value }) {
62
105
  this.$emit('input', { ...this.value, [field]: value })
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="ml-form-item" :class="[className, '', itemTitleAlign ? `title-align-${itemTitleAlign}` : '', itemAlign ? `align-${itemAlign}` : '', {'is-border': isFormBorder, 'is-vertical': itemVertical, 'is-required': isRequired}]">
2
+ <view class="ml-form-item" :class="[className || '', itemTitleAlign ? `title-align-${itemTitleAlign}` : '', itemAlign ? `align-${itemAlign}` : '', {'is-border': isFormBorder, 'is-vertical': itemVertical, 'is-required': isRequired, 'is-error': itemErrRule}]">
3
3
  <view class="ml-form-item-header" :style="titleStyle">
4
4
  <view v-if="isRequired" class="ml-form-item-header-asterisk">*</view>
5
5
  <view class="ml-form-item-header-title">
@@ -19,6 +19,7 @@
19
19
  <text v-else class="ml-form-item-default-content">{{ itemValue }}</text>
20
20
  </slot>
21
21
  </view>
22
+ <view class="ml-form-item-content-error">{{ itemErrRule.message }}</view>
22
23
  </view>
23
24
  </view>
24
25
  </template>
@@ -47,18 +48,31 @@ export default {
47
48
  default: null
48
49
  }
49
50
  },
51
+ provide() {
52
+ return {
53
+ mlFormItem: this
54
+ }
55
+ },
50
56
  data () {
51
57
  return {
52
58
  mId: XEUtils.uniqueId('mlFItem')
53
59
  }
54
60
  },
61
+ watch: {
62
+ itemValue () {
63
+ if (this.form) {
64
+ this.form.validateField(this.field)
65
+ }
66
+ }
67
+ },
55
68
  mounted () {
56
69
  this.$nextTick(() => {
57
70
  if (this.form) {
58
71
  this.form.itemList.push({
59
72
  mId: this.mId,
60
73
  title: this.title,
61
- field: this.field
74
+ field: this.field,
75
+ errRule: null
62
76
  })
63
77
  }
64
78
  })
@@ -84,6 +98,13 @@ export default {
84
98
  }
85
99
  return false
86
100
  },
101
+ itemErrRule () {
102
+ if (this.form) {
103
+ const item = this.form.itemList.find(item => item.mId === this.mId)
104
+ return item ? item.errRule : null
105
+ }
106
+ return null
107
+ },
87
108
  itemValue () {
88
109
  const value = this.formData[this.field]
89
110
  return XEUtils.eqNull(value) ? '' : value
@@ -147,6 +168,12 @@ export default {
147
168
  border: 0;
148
169
  }
149
170
  }
171
+ &.is-error {
172
+ .ml-form-item-content-error {
173
+ opacity: 1;
174
+ transform: scaleY(1);
175
+ }
176
+ }
150
177
  .ml-form-item-header {
151
178
  min-height: 70rpx;
152
179
  color: rgba(0, 0, 0, 0.65);
@@ -204,8 +231,10 @@ export default {
204
231
  }
205
232
  }
206
233
  .ml-form-item-content {
234
+ position: relative;
207
235
  display: flex;
208
236
  align-items: center;
237
+ flex-direction: column;
209
238
  flex-grow: 1;
210
239
  }
211
240
  .ml-form-item-content-warpper {
@@ -213,4 +242,17 @@ export default {
213
242
  width: 100%;
214
243
  padding: 10rpx 0;
215
244
  }
245
+ .ml-form-item-content-error {
246
+ position: absolute;
247
+ left: 0;
248
+ bottom: -20rpx;
249
+ width: 100%;
250
+ color: $uni-color-error;
251
+ font-size: 24rpx;
252
+ text-align: left;
253
+ opacity: 0;
254
+ transform-origin: center top;
255
+ transform: scaleY(0);
256
+ transition: all 0.3s;
257
+ }
216
258
  </style>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="ml-list-group" :class="className">
2
+ <view class="ml-list-group" :class="[className || '']">
3
3
  <view class="ml-list-group-content" :style="contentStyle">
4
4
  <scroll-view scroll-y>
5
5
  <slot></slot>
@@ -74,12 +74,9 @@ export default {
74
74
  display: flex;
75
75
  flex-direction: row;
76
76
  padding: 20rpx;
77
- margin: 20rpx 0;
77
+ margin-bottom: 20rpx;
78
78
  border-radius: 10rpx;
79
79
  background: #ffffff;
80
- &:first-child {
81
- margin-top: 0;
82
- }
83
80
  &:last-child {
84
81
  margin-bottom: 0;
85
82
  }
@@ -81,10 +81,11 @@ export default {
81
81
  .ml-list-menu-item {
82
82
  display: flex;
83
83
  flex-direction: row;
84
+ align-items: center;
84
85
  border-bottom: 1px solid #e5e5e5;
85
- line-height: 90rpx;
86
+ min-height: 90rpx;
86
87
  font-size: 30rpx;
87
- padding: 0 20rpx;
88
+ padding: 10rpx 20rpx;
88
89
  background: #ffffff;
89
90
  &:first-child {
90
91
  border-top: 1px solid #e5e5e5;
@@ -1,17 +1,19 @@
1
1
  <template>
2
- <view class="ml-popup" :class="[className || '', {'is-visible': visible, 'is-animate': isAnimate}]">
3
- <view v-if="visible" class="ml-popup-warpper">
2
+ <view class="ml-popup" :class="[className || '', {'is-visible': visible, 'is-animate': isAnimate}]" @tap="tapMaskEvent">
3
+ <view v-if="visible" class="ml-popup-warpper" @tap.stop>
4
4
  <view v-if="showHeader" class="ml-popup-header">
5
5
  <slot name="header">
6
6
  <view v-if="title" class="ml-popup-header-title">{{ title }}</view>
7
7
  </slot>
8
8
  </view>
9
9
  <view class="ml-popup-body" :style="bodyStyles">
10
- <slot></slot>
10
+ <scroll-view scroll-y>
11
+ <slot></slot>
12
+ </scroll-view>
11
13
  </view>
12
14
  <view v-if="showConfirmButton || showCancelButton" class="ml-popup-footer">
13
- <ml-button width="40%" round @click="cancelEvent">{{ cancelButtonText }}</ml-button>
14
- <ml-button status="primary" width="40%" round @click="confirmEvent">{{ confirmButtonText }}</ml-button>
15
+ <ml-button v-if="showCancelButton" width="40%" round @click="cancelEvent">{{ cancelButtonText }}</ml-button>
16
+ <ml-button v-if="showConfirmButton" status="primary" width="40%" round @click="confirmEvent">{{ confirmButtonText }}</ml-button>
15
17
  </view>
16
18
  </view>
17
19
  </view>
@@ -28,6 +30,7 @@ export default {
28
30
  type: Boolean,
29
31
  default: true
30
32
  },
33
+ maskClosable: Boolean,
31
34
  showConfirmButton: Boolean,
32
35
  confirmButtonText: {
33
36
  type: String,
@@ -48,7 +51,8 @@ export default {
48
51
  data () {
49
52
  return {
50
53
  visible: false,
51
- isAnimate: false
54
+ isAnimate: false,
55
+ animateTime: null
52
56
  }
53
57
  },
54
58
  computed: {
@@ -76,26 +80,41 @@ export default {
76
80
  },
77
81
  methods: {
78
82
  close () {
83
+ clearTimeout(this.animateTime)
84
+ this.isAnimate = true
79
85
  this.isAnimate = false
80
- setTimeout(() => {
86
+ this.animateTime = setTimeout(() => {
81
87
  this.visible = false
88
+ this.$emit('input', false)
89
+ this.$emit('show', {})
82
90
  }, 300)
83
91
  },
84
92
  open () {
93
+ clearTimeout(this.animateTime)
94
+ this.isAnimate = false
85
95
  this.visible = true
86
- this.$nextTick(() => {
96
+ this.animateTime = setTimeout(() => {
87
97
  this.isAnimate = true
88
- })
98
+ this.$emit('hide', {})
99
+ }, 20)
100
+ this.$emit('input', true)
101
+ },
102
+ tapMaskEvent () {
103
+ if (this.maskClosable) {
104
+ this.close()
105
+ }
89
106
  },
90
107
  cancelEvent () {
91
108
  if (this.cancelClosable) {
92
109
  this.close()
93
110
  }
111
+ this.$emit('cancel', {})
94
112
  },
95
113
  confirmEvent () {
96
114
  if (this.confirmClosable) {
97
115
  this.close()
98
116
  }
117
+ this.$emit('confirm', {})
99
118
  }
100
119
  }
101
120
  }
@@ -125,22 +144,28 @@ export default {
125
144
  bottom: 0;
126
145
  left: 0;
127
146
  width: 100%;
147
+ padding-bottom: 20rpx;
128
148
  transform: translateY(100%);
129
- transition: transform 300ms ease 0ms, transform 300ms ease 0ms;
149
+ transition: transform 0.3s ease, transform 0.3s ease;
130
150
  background: #fff;
131
151
  }
132
152
  .ml-popup-header-title {
133
153
  text-align: center;
134
154
  height: 70rpx;
135
155
  line-height: 70rpx;
156
+ font-size: $uni-font-size-base;
157
+ overflow: hidden;
158
+ text-overflow: ellipsis;
159
+ white-space: nowrap;
136
160
  }
137
161
  .ml-popup-body {
138
162
  padding: 20rpx;
139
163
  overflow: auto;
140
- height: 600rpx;
164
+ height: 500rpx;
141
165
  }
142
166
  .ml-popup-footer {
143
167
  display: flex;
144
168
  flex-direction: row;
169
+ padding: 20rpx;
145
170
  }
146
171
  </style>
@@ -5,7 +5,7 @@
5
5
  </view>
6
6
  <view class="ml-radio-content">
7
7
  <slot>
8
- <text>{{ content }}</text>
8
+ <view>{{ content }}</view>
9
9
  </slot>
10
10
  </view>
11
11
  </view>
@@ -44,22 +44,21 @@ export default {
44
44
 
45
45
  <style lang="scss">
46
46
  .ml-radio {
47
- display: inline-block;
47
+ display: inline-flex;
48
48
  margin-right: 20rpx;
49
+ align-items: center;
49
50
  &.is-checked {
50
51
  color: $uni-color-primary;
51
52
  }
52
53
  .ml-radio-icon {
53
- display: inline-block;
54
54
  margin-right: 10rpx;
55
55
  font-size: 1.4em;
56
56
  }
57
57
  .ml-radio-icon,
58
58
  .ml-radio-content {
59
- vertical-align: middle;
60
- }
61
- .ml-radio-content {
62
- display: inline-block;
59
+ display: inline-flex;
60
+ align-items: center;
61
+ flex-direction: row;
63
62
  }
64
63
  }
65
64
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "0.0.99",
3
+ "version": "0.1.0",
4
4
  "description": "码里云小程序组件库",
5
5
  "files": [
6
6
  "components",