parent
96572867f7
commit
b9d99e3f2c
|
|
@ -25,6 +25,7 @@ Vue.component(Picker.name, Picker)
|
||||||
|data|data source|Array<{value, lable, ...}>[]|`[]`|-|
|
|data|data source|Array<{value, lable, ...}>[]|`[]`|-|
|
||||||
|cols|number of columns|Number|`1`|-|
|
|cols|number of columns|Number|`1`|-|
|
||||||
|default-index|indexes of initially selected items in each column|Array|`[]`|-|
|
|default-index|indexes of initially selected items in each column|Array|`[]`|-|
|
||||||
|
|default-value|values of initially selected items in each column|Array|`[]`|Available key `text/lable/value`|
|
||||||
|invalid-index|indexes of disabled items in each column|Array|`[]`|array of multiple disabled items, such as `[[1,2], 2]`|
|
|invalid-index|indexes of disabled items in each column|Array|`[]`|array of multiple disabled items, such as `[[1,2], 2]`|
|
||||||
|is-view|inline display in page, otherwise it shows as `Popup`|Boolean|`false`|-|
|
|is-view|inline display in page, otherwise it shows as `Popup`|Boolean|`false`|-|
|
||||||
|is-cascade|data in each column is cascaded or not|Boolean|`false`|see #Appendix for the format of cascaded data|
|
|is-cascade|data in each column is cascaded or not|Boolean|`false`|see #Appendix for the format of cascaded data|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ Vue.component(Picker.name, Picker)
|
||||||
|data|数据源|Array<{value, lable, ...}>[]|`[]`|-|
|
|data|数据源|Array<{value, lable, ...}>[]|`[]`|-|
|
||||||
|cols|数据列数|Number|`1`|-|
|
|cols|数据列数|Number|`1`|-|
|
||||||
|default-index|选择器各列初始选中项索引|Array|`[]`|-|
|
|default-index|选择器各列初始选中项索引|Array|`[]`|-|
|
||||||
|
|default-value|选择器各列初始选中项值|Array|`[]`|可用字段`text/lable/value`|
|
||||||
|invalid-index|选择器各列不可用选项索引|Array|`[]`|某列多个不可用项使用数组,单个使用数字, 如`[[1,2], 2]`|
|
|invalid-index|选择器各列不可用选项索引|Array|`[]`|某列多个不可用项使用数组,单个使用数字, 如`[[1,2], 2]`|
|
||||||
|is-view|是否内嵌在页面内展示,否则以弹层形式|Boolean|`false`|-|
|
|is-view|是否内嵌在页面内展示,否则以弹层形式|Boolean|`false`|-|
|
||||||
|is-cascade|各列数据是否级联|Boolean|`false`|级联数据格式见附录|
|
|is-cascade|各列数据是否级联|Boolean|`false`|级联数据格式见附录|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,22 @@ const defaultOptions = {
|
||||||
maxLevel: 0,
|
maxLevel: 0,
|
||||||
values: [],
|
values: [],
|
||||||
defaultIndex: [],
|
defaultIndex: [],
|
||||||
|
defaultValue: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultIndex(data, defaultIndex, defaultValue) {
|
||||||
|
let activeIndex = 0
|
||||||
|
if (defaultIndex !== undefined) {
|
||||||
|
return defaultIndex
|
||||||
|
} else if (defaultValue !== undefined) {
|
||||||
|
data.some((item, index) => {
|
||||||
|
if (item.text === defaultValue || item.label === defaultValue || item.value === defaultValue) {
|
||||||
|
activeIndex = index
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return activeIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,9 +42,9 @@ export default function(picker, options = {}, fn) {
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
for (let i = options.currentLevel + 1; i < options.maxLevel; i++) {
|
for (let i = options.currentLevel + 1; i < options.maxLevel; i++) {
|
||||||
const activeIndex = options.defaultIndex[i] || 0
|
const columnValues = (!i ? values[i] : values.children) || []
|
||||||
const columnValues = values.children || []
|
|
||||||
picker.setColumnValues(i, columnValues)
|
picker.setColumnValues(i, columnValues)
|
||||||
|
const activeIndex = getDefaultIndex(columnValues, options.defaultIndex[i], options.defaultValue[i])
|
||||||
values = columnValues[activeIndex] || []
|
values = columnValues[activeIndex] || []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,14 +88,15 @@ export default {
|
||||||
defaultIndex: {
|
defaultIndex: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default() {
|
default() {
|
||||||
if (this.cols < 1) {
|
// if (this.cols < 1) {
|
||||||
return []
|
// return []
|
||||||
}
|
// }
|
||||||
const arr = new Array(this.cols)
|
// const arr = new Array(this.cols)
|
||||||
for (let i = 0, len = arr.length; i < len; i++) {
|
// for (let i = 0, len = arr.length; i < len; i++) {
|
||||||
arr[i] = 0
|
// arr[i] = 0
|
||||||
}
|
// }
|
||||||
return arr
|
// return arr
|
||||||
|
return []
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
invalidIndex: {
|
invalidIndex: {
|
||||||
|
|
@ -221,13 +222,15 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultIndex = this.$_getDefaultIndex()
|
const defaultIndex = this.$_getDefaultIndex()
|
||||||
const defaultIndexOfFirstColumn = defaultIndex[0] || 0
|
const defaultValue = this.$_getDefaultValue()
|
||||||
|
// const defaultIndexOfFirstColumn = defaultIndex[0] || 0
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
cascadePicker(this.column, {
|
cascadePicker(this.column, {
|
||||||
currentLevel: 0,
|
currentLevel: -1,
|
||||||
maxLevel: this.cols,
|
maxLevel: this.cols,
|
||||||
values: this.data[0] ? this.data[0][defaultIndexOfFirstColumn] || [] : [],
|
values: this.data || [],
|
||||||
defaultIndex,
|
defaultIndex,
|
||||||
|
defaultValue,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue