|
8 | 8 | </template> |
9 | 9 | <template v-else> |
10 | 10 | <checkbox-group v-if="multiple" class="checklist-group" :class="{'is-list':mode==='list' || wrap}" @change="chagne"> |
11 | | - <!-- :class="item.labelClass" --> |
12 | 11 | <label class="checklist-box" :class="['is--'+mode,item.selected?'is-checked':'',(disabled || !!item.disabled)?'is-disable':'',index!==0&&mode==='list'?'is-list-border':'']" |
13 | 12 | :style="item.styleBackgroud" v-for="(item,index) in dataList" :key="index"> |
14 | | - <checkbox class="hidden" hidden :disabled="disabled || !!item.disabled" :value="item.value+''" :checked="item.selected" /> |
15 | | - <!-- :style="item.styleIcon" --> |
16 | | - |
| 13 | + <checkbox class="hidden" hidden :disabled="disabled || !!item.disabled" :value="item[map.value]+''" :checked="item.selected" /> |
17 | 14 | <view v-if="(mode !=='tag' && mode !== 'list') || ( mode === 'list' && icon === 'left')" class="checkbox__inner" :style="item.styleIcon"> |
18 | | - <!-- :class="item.checkboxClass" --> |
19 | 15 | <view class="checkbox__inner-icon"></view> |
20 | 16 | </view> |
21 | 17 | <view class="checklist-content" :class="{'list-content':mode === 'list' && icon ==='left'}"> |
22 | | - <!-- :class="item.textClass" --> |
23 | | - <text class="checklist-text" :style="item.styleIconText">{{item.text}}</text> |
24 | | - <!-- :class="item.listClass" --> |
| 18 | + <text class="checklist-text" :style="item.styleIconText">{{item[map.text]}}</text> |
25 | 19 | <view v-if="mode === 'list' && icon === 'right'" class="checkobx__list" :style="item.styleBackgroud"></view> |
26 | 20 | </view> |
27 | 21 | </label> |
|
30 | 24 | <!-- --> |
31 | 25 | <label class="checklist-box" :class="['is--'+mode,item.selected?'is-checked':'',(disabled || !!item.disabled)?'is-disable':'',index!==0&&mode==='list'?'is-list-border':'']" |
32 | 26 | :style="item.styleBackgroud" v-for="(item,index) in dataList" :key="index"> |
33 | | - <radio class="hidden" hidden :disabled="disabled || item.disabled" :value="item.value+''" :checked="item.selected" /> |
34 | | - <!-- :class="item.checkboxBgClass" --> |
| 27 | + <radio class="hidden" hidden :disabled="disabled || item.disabled" :value="item[map.value]+''" :checked="item.selected" /> |
35 | 28 | <view v-if="(mode !=='tag' && mode !== 'list') || ( mode === 'list' && icon === 'left')" class="radio__inner" |
36 | 29 | :style="item.styleBackgroud"> |
37 | | - <!-- :class="item.checkboxClass" --> |
38 | 30 | <view class="radio__inner-icon" :style="item.styleIcon"></view> |
39 | 31 | </view> |
40 | 32 | <view class="checklist-content" :class="{'list-content':mode === 'list' && icon ==='left'}"> |
41 | | - <!-- :class="item.textClass" --> |
42 | | - <text class="checklist-text" :style="item.styleIconText">{{item.text}}</text> |
43 | | - <!-- :class="item.listClass" --> |
| 33 | + <text class="checklist-text" :style="item.styleIconText">{{item[map.text]}}</text> |
44 | 34 | <view v-if="mode === 'list' && icon === 'right'" :style="item.styleRightIcon" class="checkobx__list"></view> |
45 | 35 | </view> |
46 | 36 | </label> |
|
51 | 41 |
|
52 | 42 | <script> |
53 | 43 | /** |
54 | | - * DataCheckbox 数据选择器 |
| 44 | + * DataChecklist 数据选择器 |
55 | 45 | * @description 通过数据渲染 checkbox 和 radio |
56 | | - * @tutorial https://ext.dcloud.net.cn/plugin?id=3456 |
| 46 | + * @tutorial https://ext.dcloud.net.cn/plugin?id=xxx |
57 | 47 | * @property {String} mode = [default| list | button | tag] 显示模式 |
58 | 48 | * @value default 默认横排模式 |
59 | 49 | * @value list 列表模式 |
|
74 | 64 | * @event {Function} change 选中发生变化触发 |
75 | 65 | */ |
76 | 66 |
|
| 67 | + // import clientdb from './clientdb.js' |
77 | 68 | export default { |
78 | | - name: 'uniDataCheckbox', |
| 69 | + name: 'uniDataChecklist', |
| 70 | + // mixins: [clientdb], |
79 | 71 | mixins: [uniCloud.mixinDatacom || {}], |
80 | 72 | props: { |
81 | 73 | mode: { |
|
129 | 121 | disabled:{ |
130 | 122 | type: Boolean, |
131 | 123 | default: false |
| 124 | + }, |
| 125 | + map:{ |
| 126 | + type: Object, |
| 127 | + default(){ |
| 128 | + return { |
| 129 | + text:'text', |
| 130 | + value:'value' |
| 131 | + } |
| 132 | + } |
132 | 133 | } |
133 | 134 | }, |
134 | 135 | watch: { |
|
167 | 168 | created() { |
168 | 169 | this.form = this.getForm('uniForms') |
169 | 170 | this.formItem = this.getForm('uniFormsItem') |
170 | | - this.formItem && this.formItem.setValue(this.value) |
| 171 | + // this.formItem && this.formItem.setValue(this.value) |
171 | 172 |
|
172 | 173 | if (this.formItem) { |
173 | 174 | if (this.formItem.name) { |
|
224 | 225 |
|
225 | 226 | if (this.multiple) { |
226 | 227 | this.range.forEach(item => { |
227 | | - if (values.includes(item.value + '')) { |
228 | | - detail.value.push(item.value) |
| 228 | + |
| 229 | + if (values.includes(item[this.map.value] + '')) { |
| 230 | + detail.value.push(item[this.map.value]) |
229 | 231 | detail.data.push(item) |
230 | 232 | } |
231 | 233 | }) |
232 | 234 | } else { |
233 | | - const range = this.range.find(item => (item.value + '') === values) |
| 235 | + const range = this.range.find(item => (item[this.map.value] + '') === values) |
234 | 236 | if (range) { |
235 | 237 | detail = { |
236 | | - value: range.value, |
| 238 | + value: range[this.map.value], |
237 | 239 | data: range |
238 | 240 | } |
239 | 241 | } |
|
270 | 272 | item.disabled = item.disable || item.disabled || false |
271 | 273 | if (this.multiple) { |
272 | 274 | if (value.length > 0) { |
273 | | - let have = value.find(val => val === item.value) |
| 275 | + let have = value.find(val => val === item[this.map.value]) |
274 | 276 | item.selected = have !== undefined |
275 | 277 | } else { |
276 | 278 | item.selected = false |
277 | 279 | } |
278 | 280 | } else { |
279 | | - item.selected = value === item.value |
| 281 | + item.selected = value === item[this.map.value] |
280 | 282 | } |
281 | 283 |
|
282 | 284 | list.push(item) |
|
294 | 296 | list.forEach((item, index) => { |
295 | 297 | if (this.multiple) { |
296 | 298 | if (selectList.length <= min) { |
297 | | - let have = selectList.find(val => val.value === item.value) |
| 299 | + let have = selectList.find(val => val[this.map.value] === item[this.map.value]) |
298 | 300 | if (have !== undefined) { |
299 | 301 | item.disabled = true |
300 | 302 | } |
301 | 303 | } |
302 | 304 |
|
303 | 305 | if (selectList.length >= max && max !== '') { |
304 | | - let have = selectList.find(val => val.value === item.value) |
| 306 | + let have = selectList.find(val => val[this.map.value] === item[this.map.value]) |
305 | 307 | if (have === undefined) { |
306 | 308 | item.disabled = true |
307 | 309 | } |
|
335 | 337 | let selectedArr = [] |
336 | 338 | range.forEach((item) => { |
337 | 339 | if (item.selected) { |
338 | | - selectedArr.push(item.value) |
| 340 | + selectedArr.push(item[this.map.value]) |
339 | 341 | } |
340 | 342 | }) |
341 | 343 | return this.value.length > 0 ? this.value : selectedArr |
|
0 commit comments