mali-applet-ui 1.1.76 → 1.1.78

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.
@@ -0,0 +1,249 @@
1
+ <template>
2
+ <view v-if="isFromReadonly" class="ml-cascader-picker is-readonly">
3
+ <view class="ml-cascader-picker-readonly-content">{{ selectLabel }}</view>
4
+ </view>
5
+ <view v-else class="ml-cascader-picker" :class="[className || '', {'is-border': border, 'is-clear': value.length}]">
6
+ <view class="ml-cascader-picker-warpper" @click="openPopup()">
7
+ <view class="ml-cascader-picker-text">
8
+ <view v-if="value.length" class="ml-cascader-picker-label">{{ selectLabel }}</view>
9
+ <view v-else class="ml-cascader-picker-placeholder">{{ placeholder }}</view>
10
+ </view>
11
+ <view v-if="clearable && value.length" class="ml-cascader-picker-clear-icon" @click.stop="clearEvent">
12
+ <ml-icon name="delete-filling"></ml-icon>
13
+ </view>
14
+ <view v-else class="ml-cascader-picker-icon">
15
+ <ml-icon name="arrow-right" />
16
+ </view>
17
+ </view>
18
+
19
+ <ml-drawer v-model="showPopup" title="请选择" height="500rpx" showConfirmButton showCancelButton @confirm="confirmEvent">
20
+ <picker-view v-if="showPicker" :value="selectIndexs" @change="changeEvent" style="height: 400rpx;text-align: center;">
21
+ <picker-view-column v-for="(num, index) in countLevel" :key="index">
22
+ <view class="ml-cascader-picker-picker-item" v-for="(item, cIndex) in pickerDataMaps[index]" :key="cIndex">{{ item[optLabelField] }}</view>
23
+ </picker-view-column>
24
+ </picker-view>
25
+ </ml-drawer>
26
+ </view>
27
+ </template>
28
+
29
+ <script>
30
+ import XEUtils from 'xe-utils'
31
+
32
+ export default {
33
+ name: 'MlCascaderPicker',
34
+ props: {
35
+ value: Array,
36
+ options: Array,
37
+ border: Boolean,
38
+ placeholder: String,
39
+ clearable: Boolean,
40
+ width: String,
41
+ isAll: Boolean,
42
+ optionProps: Object,
43
+ className: String
44
+ },
45
+ inject: {
46
+ form: {
47
+ from: 'mlForm',
48
+ default: null
49
+ }
50
+ },
51
+ data () {
52
+ return {
53
+ showPopup: false,
54
+ showPicker: false,
55
+ selectIndexs: [0],
56
+ // 最多支持6级
57
+ pickerDataMaps: {
58
+ 0: [],
59
+ 1: [],
60
+ 2: [],
61
+ 3: [],
62
+ 4: [],
63
+ 5: []
64
+ }
65
+ }
66
+ },
67
+ computed: {
68
+ isFromReadonly () {
69
+ return this.form ? this.form.readonly : false
70
+ },
71
+ optOptions () {
72
+ return Object.assign({}, this.optionProps)
73
+ },
74
+ optLabelField () {
75
+ return this.optOptions.label || 'label'
76
+ },
77
+ optValueField () {
78
+ return this.optOptions.value || 'value'
79
+ },
80
+ optChildrenField () {
81
+ return this.optOptions.children || 'children'
82
+ },
83
+ selectItems () {
84
+ return this.value.map((val, index) => {
85
+ const list = this.pickerDataMaps[index]
86
+ const item = list ? list.find(item => item[this.optValueField] === val) : null
87
+ return item
88
+ })
89
+ },
90
+ selectLabel () {
91
+ const labels = []
92
+ for (let i = 0; i < this.selectItems.length; i++) {
93
+ const item = this.selectItems[i]
94
+ if (!item) {
95
+ break
96
+ }
97
+ labels.push(item[this.optLabelField])
98
+ }
99
+ return labels.join(' / ')
100
+ },
101
+ treeOpts () {
102
+ return {
103
+ children: this.optChildrenField
104
+ }
105
+ },
106
+ countLevel () {
107
+ let maxLevel = 2
108
+ XEUtils.eachTree(this.options, (item, index, items, path, parent, nodes) => {
109
+ if (maxLevel < nodes.length) {
110
+ maxLevel = nodes.length
111
+ }
112
+ }, this.treeOpts)
113
+ return maxLevel
114
+ }
115
+ },
116
+ watch: {
117
+ options () {
118
+ this.updatePickerData()
119
+ }
120
+ },
121
+ created () {
122
+ this.updatePickerData()
123
+ },
124
+ methods: {
125
+ closePopup () {
126
+ this.showPopup = false
127
+ this.showPicker = false
128
+ },
129
+ openPopup () {
130
+ this.showPopup = true
131
+ setTimeout(() => {
132
+ this.showPicker = true
133
+ }, 50)
134
+ },
135
+ updatePickerData () {
136
+ const dataMaps = {
137
+ 0: this.isAll ? [{ [this.optLabelField]: '全部', [this.optValueField]: '' }].concat(this.options) : this.options,
138
+ 1: [],
139
+ 2: [],
140
+ 3: [],
141
+ 4: [],
142
+ 5: []
143
+ }
144
+ for (let i = 1; i < this.countLevel; i++) {
145
+ const prevOpts = dataMaps[i - 1]
146
+ let prevItem = null
147
+ if (prevOpts) {
148
+ prevItem = prevOpts[this.selectIndexs[i - 1]]
149
+ // if (!prevItem) {
150
+ // prevItem = prevOpts.find(item => item[this.optValueField] === prevValue)
151
+ // }
152
+ }
153
+ if (prevItem) {
154
+ const currList = prevItem[this.optChildrenField] || []
155
+ dataMaps[i] = currList
156
+ if (!this.selectIndexs[i]) {
157
+ this.selectIndexs[i] = currList.length ? 0 : null
158
+ }
159
+ }
160
+ }
161
+ this.pickerDataMaps = dataMaps
162
+ },
163
+ changeEvent (e) {
164
+ this.selectIndexs = e.detail.value
165
+ this.updatePickerData()
166
+ },
167
+ clearEvent () {
168
+ const value = []
169
+ this.selectIndexs = [0]
170
+ this.confirmEvent()
171
+ this.$emit('clear', { value })
172
+ this.$emit('change', { value, labels: [], selection: [] })
173
+ },
174
+ confirmEvent () {
175
+ const value = []
176
+ const selection = []
177
+ const labels = []
178
+ this.selectIndexs.slice(0, this.countLevel).forEach((valIndex, colIndex) => {
179
+ if (valIndex !== null) {
180
+ const item = this.pickerDataMaps[colIndex][valIndex]
181
+ selection.push(item || null)
182
+ value.push(item ? item[this.optValueField] : null)
183
+ labels.push(item ? item[this.optLabelField] : '')
184
+ }
185
+ })
186
+ this.$emit('input', value)
187
+ this.$emit('change', { value, labels, selection })
188
+ this.closePopup()
189
+ }
190
+ }
191
+ }
192
+ </script>
193
+
194
+ <style lang="scss">
195
+ .ml-cascader-picker-readonly-content {
196
+ padding: 20rpx;
197
+ }
198
+ .ml-cascader-picker {
199
+ width: 100%;
200
+ &.is-border {
201
+ border: 1px solid #e5e5e5;
202
+ background: #fff;
203
+ }
204
+ }
205
+ .ml-cascader-picker-warpper {
206
+ position: relative;
207
+ display: flex;
208
+ flex-direction: row;
209
+ align-items: center;
210
+ padding: 0 20rpx;
211
+ height: 70rpx;
212
+ border-radius: $ml-border-radius;
213
+ .ml-cascader-picker-text {
214
+ flex-grow: 1;
215
+ padding-right: 10rpx;
216
+ overflow: hidden;
217
+ .ml-cascader-picker-label,
218
+ .ml-cascader-picker-placeholder {
219
+ overflow: hidden;
220
+ text-overflow: ellipsis;
221
+ white-space: nowrap;
222
+ }
223
+ }
224
+ .ml-cascader-picker-clear-icon {
225
+ width: 60rpx;
226
+ display: flex;
227
+ flex-shrink: 0;
228
+ align-items: center;
229
+ justify-content: center;
230
+ background: #fff;
231
+ color: $ml-input-clear-icon-color;
232
+ border-radius: 0 10rpx 10rpx 0;
233
+ }
234
+ .ml-cascader-picker-icon {
235
+ width: 34rpx;
236
+ display: flex;
237
+ flex-shrink: 0;
238
+ align-items: center;
239
+ justify-content: center;
240
+ color: #6a6a6a;
241
+ }
242
+ }
243
+ .ml-cascader-picker-picker-item {
244
+ display: flex;
245
+ flex-direction: row;
246
+ align-items: center;
247
+ justify-content: center;
248
+ }
249
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "1.1.76",
3
+ "version": "1.1.78",
4
4
  "description": "码里UI-小程序组件库(vue2)",
5
5
  "files": [
6
6
  "lib",
package/webview/index.js CHANGED
@@ -9,11 +9,17 @@ export function defineH5Transfer (vueOpts = {}) {
9
9
  if (options) {
10
10
  const { _url, _fnName, _syncStorage } = options
11
11
  let data = {}
12
+ let url = _url ? decodeURIComponent(_url) : ''
12
13
  if (options && _syncStorage) {
13
14
  data = XEUtils.toStringJSON(decodeURIComponent(_syncStorage))
14
15
  }
15
- if (globalStore.webview && globalStore.webview.setStorage) {
16
- globalStore.webview.setStorage({ data })
16
+ if (globalStore.webview) {
17
+ if (globalStore.webview.setStorage) {
18
+ globalStore.webview.setStorage({ data })
19
+ }
20
+ if (globalStore.webview.redirectPath) {
21
+ url = globalStore.webview.redirectPath({ url }) || url
22
+ }
17
23
  }
18
24
  if (vueOpts.onStorage) {
19
25
  vueOpts.onStorage.call(this, { data })
@@ -23,9 +29,9 @@ export function defineH5Transfer (vueOpts = {}) {
23
29
  }
24
30
  MaliLoading.show()
25
31
  setTimeout(() => {
26
- if (_url && ['navigateTo', 'redirectTo'].includes(_fnName)) {
32
+ if (url && ['navigateTo', 'redirectTo'].includes(_fnName)) {
27
33
  uni.redirectTo({
28
- url: decodeURIComponent(_url),
34
+ url: url,
29
35
  complete () {
30
36
  MaliLoading.hide()
31
37
  }