换ubuntu
This commit is contained in:
2
utils/dist/picker/index.d.ts
vendored
2
utils/dist/picker/index.d.ts
vendored
@@ -1 +1 @@
|
||||
export {};
|
||||
export {};
|
||||
|
||||
270
utils/dist/picker/index.js
vendored
270
utils/dist/picker/index.js
vendored
@@ -1,135 +1,135 @@
|
||||
import { VantComponent } from '../common/component';
|
||||
import { pickerProps } from './shared';
|
||||
VantComponent({
|
||||
classes: ['active-class', 'toolbar-class', 'column-class'],
|
||||
props: Object.assign(Object.assign({}, pickerProps), { valueKey: {
|
||||
type: String,
|
||||
value: 'text'
|
||||
}, toolbarPosition: {
|
||||
type: String,
|
||||
value: 'top'
|
||||
}, defaultIndex: {
|
||||
type: Number,
|
||||
value: 0
|
||||
}, columns: {
|
||||
type: Array,
|
||||
value: [],
|
||||
observer(columns = []) {
|
||||
this.simple = columns.length && !columns[0].values;
|
||||
this.children = this.selectAllComponents('.van-picker__column');
|
||||
if (Array.isArray(this.children) && this.children.length) {
|
||||
this.setColumns().catch(() => { });
|
||||
}
|
||||
}
|
||||
} }),
|
||||
beforeCreate() {
|
||||
this.children = [];
|
||||
},
|
||||
methods: {
|
||||
noop() { },
|
||||
setColumns() {
|
||||
const { data } = this;
|
||||
const columns = this.simple ? [{ values: data.columns }] : data.columns;
|
||||
const stack = columns.map((column, index) => this.setColumnValues(index, column.values));
|
||||
return Promise.all(stack);
|
||||
},
|
||||
emit(event) {
|
||||
const { type } = event.currentTarget.dataset;
|
||||
if (this.simple) {
|
||||
this.$emit(type, {
|
||||
value: this.getColumnValue(0),
|
||||
index: this.getColumnIndex(0)
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.$emit(type, {
|
||||
value: this.getValues(),
|
||||
index: this.getIndexes()
|
||||
});
|
||||
}
|
||||
},
|
||||
onChange(event) {
|
||||
if (this.simple) {
|
||||
this.$emit('change', {
|
||||
picker: this,
|
||||
value: this.getColumnValue(0),
|
||||
index: this.getColumnIndex(0)
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.$emit('change', {
|
||||
picker: this,
|
||||
value: this.getValues(),
|
||||
index: event.currentTarget.dataset.index
|
||||
});
|
||||
}
|
||||
},
|
||||
// get column instance by index
|
||||
getColumn(index) {
|
||||
return this.children[index];
|
||||
},
|
||||
// get column value by index
|
||||
getColumnValue(index) {
|
||||
const column = this.getColumn(index);
|
||||
return column && column.getValue();
|
||||
},
|
||||
// set column value by index
|
||||
setColumnValue(index, value) {
|
||||
const column = this.getColumn(index);
|
||||
if (column == null) {
|
||||
return Promise.reject(new Error('setColumnValue: 对应列不存在'));
|
||||
}
|
||||
return column.setValue(value);
|
||||
},
|
||||
// get column option index by column index
|
||||
getColumnIndex(columnIndex) {
|
||||
return (this.getColumn(columnIndex) || {}).data.currentIndex;
|
||||
},
|
||||
// set column option index by column index
|
||||
setColumnIndex(columnIndex, optionIndex) {
|
||||
const column = this.getColumn(columnIndex);
|
||||
if (column == null) {
|
||||
return Promise.reject(new Error('setColumnIndex: 对应列不存在'));
|
||||
}
|
||||
return column.setIndex(optionIndex);
|
||||
},
|
||||
// get options of column by index
|
||||
getColumnValues(index) {
|
||||
return (this.children[index] || {}).data.options;
|
||||
},
|
||||
// set options of column by index
|
||||
setColumnValues(index, options, needReset = true) {
|
||||
const column = this.children[index];
|
||||
if (column == null) {
|
||||
return Promise.reject(new Error('setColumnValues: 对应列不存在'));
|
||||
}
|
||||
const isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
|
||||
if (isSame) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return column.set({ options }).then(() => {
|
||||
if (needReset) {
|
||||
column.setIndex(0);
|
||||
}
|
||||
});
|
||||
},
|
||||
// get values of all columns
|
||||
getValues() {
|
||||
return this.children.map((child) => child.getValue());
|
||||
},
|
||||
// set values of all columns
|
||||
setValues(values) {
|
||||
const stack = values.map((value, index) => this.setColumnValue(index, value));
|
||||
return Promise.all(stack);
|
||||
},
|
||||
// get indexes of all columns
|
||||
getIndexes() {
|
||||
return this.children.map((child) => child.data.currentIndex);
|
||||
},
|
||||
// set indexes of all columns
|
||||
setIndexes(indexes) {
|
||||
const stack = indexes.map((optionIndex, columnIndex) => this.setColumnIndex(columnIndex, optionIndex));
|
||||
return Promise.all(stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
import { VantComponent } from '../common/component';
|
||||
import { pickerProps } from './shared';
|
||||
VantComponent({
|
||||
classes: ['active-class', 'toolbar-class', 'column-class'],
|
||||
props: Object.assign(Object.assign({}, pickerProps), { valueKey: {
|
||||
type: String,
|
||||
value: 'text'
|
||||
}, toolbarPosition: {
|
||||
type: String,
|
||||
value: 'top'
|
||||
}, defaultIndex: {
|
||||
type: Number,
|
||||
value: 0
|
||||
}, columns: {
|
||||
type: Array,
|
||||
value: [],
|
||||
observer(columns = []) {
|
||||
this.simple = columns.length && !columns[0].values;
|
||||
this.children = this.selectAllComponents('.van-picker__column');
|
||||
if (Array.isArray(this.children) && this.children.length) {
|
||||
this.setColumns().catch(() => { });
|
||||
}
|
||||
}
|
||||
} }),
|
||||
beforeCreate() {
|
||||
this.children = [];
|
||||
},
|
||||
methods: {
|
||||
noop() { },
|
||||
setColumns() {
|
||||
const { data } = this;
|
||||
const columns = this.simple ? [{ values: data.columns }] : data.columns;
|
||||
const stack = columns.map((column, index) => this.setColumnValues(index, column.values));
|
||||
return Promise.all(stack);
|
||||
},
|
||||
emit(event) {
|
||||
const { type } = event.currentTarget.dataset;
|
||||
if (this.simple) {
|
||||
this.$emit(type, {
|
||||
value: this.getColumnValue(0),
|
||||
index: this.getColumnIndex(0)
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.$emit(type, {
|
||||
value: this.getValues(),
|
||||
index: this.getIndexes()
|
||||
});
|
||||
}
|
||||
},
|
||||
onChange(event) {
|
||||
if (this.simple) {
|
||||
this.$emit('change', {
|
||||
picker: this,
|
||||
value: this.getColumnValue(0),
|
||||
index: this.getColumnIndex(0)
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.$emit('change', {
|
||||
picker: this,
|
||||
value: this.getValues(),
|
||||
index: event.currentTarget.dataset.index
|
||||
});
|
||||
}
|
||||
},
|
||||
// get column instance by index
|
||||
getColumn(index) {
|
||||
return this.children[index];
|
||||
},
|
||||
// get column value by index
|
||||
getColumnValue(index) {
|
||||
const column = this.getColumn(index);
|
||||
return column && column.getValue();
|
||||
},
|
||||
// set column value by index
|
||||
setColumnValue(index, value) {
|
||||
const column = this.getColumn(index);
|
||||
if (column == null) {
|
||||
return Promise.reject(new Error('setColumnValue: 对应列不存在'));
|
||||
}
|
||||
return column.setValue(value);
|
||||
},
|
||||
// get column option index by column index
|
||||
getColumnIndex(columnIndex) {
|
||||
return (this.getColumn(columnIndex) || {}).data.currentIndex;
|
||||
},
|
||||
// set column option index by column index
|
||||
setColumnIndex(columnIndex, optionIndex) {
|
||||
const column = this.getColumn(columnIndex);
|
||||
if (column == null) {
|
||||
return Promise.reject(new Error('setColumnIndex: 对应列不存在'));
|
||||
}
|
||||
return column.setIndex(optionIndex);
|
||||
},
|
||||
// get options of column by index
|
||||
getColumnValues(index) {
|
||||
return (this.children[index] || {}).data.options;
|
||||
},
|
||||
// set options of column by index
|
||||
setColumnValues(index, options, needReset = true) {
|
||||
const column = this.children[index];
|
||||
if (column == null) {
|
||||
return Promise.reject(new Error('setColumnValues: 对应列不存在'));
|
||||
}
|
||||
const isSame = JSON.stringify(column.data.options) === JSON.stringify(options);
|
||||
if (isSame) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return column.set({ options }).then(() => {
|
||||
if (needReset) {
|
||||
column.setIndex(0);
|
||||
}
|
||||
});
|
||||
},
|
||||
// get values of all columns
|
||||
getValues() {
|
||||
return this.children.map((child) => child.getValue());
|
||||
},
|
||||
// set values of all columns
|
||||
setValues(values) {
|
||||
const stack = values.map((value, index) => this.setColumnValue(index, value));
|
||||
return Promise.all(stack);
|
||||
},
|
||||
// get indexes of all columns
|
||||
getIndexes() {
|
||||
return this.children.map((child) => child.data.currentIndex);
|
||||
},
|
||||
// set indexes of all columns
|
||||
setIndexes(indexes) {
|
||||
const stack = indexes.map((optionIndex, columnIndex) => this.setColumnIndex(columnIndex, optionIndex));
|
||||
return Promise.all(stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
14
utils/dist/picker/index.json
vendored
14
utils/dist/picker/index.json
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"picker-column": "../picker-column/index",
|
||||
"loading": "../loading/index"
|
||||
}
|
||||
}
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"picker-column": "../picker-column/index",
|
||||
"loading": "../loading/index"
|
||||
}
|
||||
}
|
||||
|
||||
130
utils/dist/picker/index.wxml
vendored
130
utils/dist/picker/index.wxml
vendored
@@ -1,65 +1,65 @@
|
||||
<template name="toolbar">
|
||||
<view
|
||||
wx:if="{{ showToolbar }}"
|
||||
class="van-picker__toolbar van-hairline--top-bottom toolbar-class"
|
||||
>
|
||||
<view
|
||||
class="van-picker__cancel"
|
||||
hover-class="van-picker__cancel--hover"
|
||||
hover-stay-time="70"
|
||||
data-type="cancel"
|
||||
bindtap="emit"
|
||||
>
|
||||
{{ cancelButtonText }}
|
||||
</view>
|
||||
<view wx:if="{{ title }}" class="van-picker__title van-ellipsis">{{ title }}</view>
|
||||
<view
|
||||
class="van-picker__confirm"
|
||||
hover-class="van-picker__confirm--hover"
|
||||
hover-stay-time="70"
|
||||
data-type="confirm"
|
||||
bindtap="emit"
|
||||
>
|
||||
{{ confirmButtonText }}
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<view class="van-picker custom-class">
|
||||
<template is="toolbar" wx:if="{{ toolbarPosition === 'top' }}" data="{{ showToolbar, cancelButtonText, title, confirmButtonText }}"></template>
|
||||
<view wx:if="{{ loading }}" class="van-picker__loading">
|
||||
<loading color="#1989fa"/>
|
||||
</view>
|
||||
<view
|
||||
class="van-picker__columns"
|
||||
style="height: {{ itemHeight * visibleItemCount }}px"
|
||||
catch:touchmove="noop"
|
||||
>
|
||||
<picker-column
|
||||
class="van-picker__column"
|
||||
wx:for="{{ isSimple(columns) ? [columns] : columns }}"
|
||||
wx:key="index"
|
||||
data-index="{{ index }}"
|
||||
custom-class="column-class"
|
||||
value-key="{{ valueKey }}"
|
||||
initial-options="{{ isSimple(columns) ? item : item.values }}"
|
||||
default-index="{{ item.defaultIndex || defaultIndex }}"
|
||||
item-height="{{ itemHeight }}"
|
||||
visible-item-count="{{ visibleItemCount }}"
|
||||
active-class="active-class"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
<view
|
||||
class="van-picker__frame van-hairline--top-bottom"
|
||||
style="height: {{ itemHeight }}px"
|
||||
/>
|
||||
</view>
|
||||
<template is="toolbar" wx:if="{{ toolbarPosition === 'bottom' }}" data="{{ showToolbar, cancelButtonText, title, confirmButtonText }}"></template>
|
||||
</view>
|
||||
|
||||
<wxs module="isSimple">
|
||||
function isSimple(columns) {
|
||||
return columns.length && !columns[0].values;
|
||||
}
|
||||
module.exports = isSimple;
|
||||
</wxs>
|
||||
<template name="toolbar">
|
||||
<view
|
||||
wx:if="{{ showToolbar }}"
|
||||
class="van-picker__toolbar van-hairline--top-bottom toolbar-class"
|
||||
>
|
||||
<view
|
||||
class="van-picker__cancel"
|
||||
hover-class="van-picker__cancel--hover"
|
||||
hover-stay-time="70"
|
||||
data-type="cancel"
|
||||
bindtap="emit"
|
||||
>
|
||||
{{ cancelButtonText }}
|
||||
</view>
|
||||
<view wx:if="{{ title }}" class="van-picker__title van-ellipsis">{{ title }}</view>
|
||||
<view
|
||||
class="van-picker__confirm"
|
||||
hover-class="van-picker__confirm--hover"
|
||||
hover-stay-time="70"
|
||||
data-type="confirm"
|
||||
bindtap="emit"
|
||||
>
|
||||
{{ confirmButtonText }}
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<view class="van-picker custom-class">
|
||||
<template is="toolbar" wx:if="{{ toolbarPosition === 'top' }}" data="{{ showToolbar, cancelButtonText, title, confirmButtonText }}"></template>
|
||||
<view wx:if="{{ loading }}" class="van-picker__loading">
|
||||
<loading color="#1989fa"/>
|
||||
</view>
|
||||
<view
|
||||
class="van-picker__columns"
|
||||
style="height: {{ itemHeight * visibleItemCount }}px"
|
||||
catch:touchmove="noop"
|
||||
>
|
||||
<picker-column
|
||||
class="van-picker__column"
|
||||
wx:for="{{ isSimple(columns) ? [columns] : columns }}"
|
||||
wx:key="index"
|
||||
data-index="{{ index }}"
|
||||
custom-class="column-class"
|
||||
value-key="{{ valueKey }}"
|
||||
initial-options="{{ isSimple(columns) ? item : item.values }}"
|
||||
default-index="{{ item.defaultIndex || defaultIndex }}"
|
||||
item-height="{{ itemHeight }}"
|
||||
visible-item-count="{{ visibleItemCount }}"
|
||||
active-class="active-class"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
<view
|
||||
class="van-picker__frame van-hairline--top-bottom"
|
||||
style="height: {{ itemHeight }}px"
|
||||
/>
|
||||
</view>
|
||||
<template is="toolbar" wx:if="{{ toolbarPosition === 'bottom' }}" data="{{ showToolbar, cancelButtonText, title, confirmButtonText }}"></template>
|
||||
</view>
|
||||
|
||||
<wxs module="isSimple">
|
||||
function isSimple(columns) {
|
||||
return columns.length && !columns[0].values;
|
||||
}
|
||||
module.exports = isSimple;
|
||||
</wxs>
|
||||
|
||||
42
utils/dist/picker/shared.d.ts
vendored
42
utils/dist/picker/shared.d.ts
vendored
@@ -1,21 +1,21 @@
|
||||
export declare const pickerProps: {
|
||||
title: StringConstructor;
|
||||
loading: BooleanConstructor;
|
||||
showToolbar: BooleanConstructor;
|
||||
cancelButtonText: {
|
||||
type: StringConstructor;
|
||||
value: string;
|
||||
};
|
||||
confirmButtonText: {
|
||||
type: StringConstructor;
|
||||
value: string;
|
||||
};
|
||||
visibleItemCount: {
|
||||
type: NumberConstructor;
|
||||
value: number;
|
||||
};
|
||||
itemHeight: {
|
||||
type: NumberConstructor;
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
export declare const pickerProps: {
|
||||
title: StringConstructor;
|
||||
loading: BooleanConstructor;
|
||||
showToolbar: BooleanConstructor;
|
||||
cancelButtonText: {
|
||||
type: StringConstructor;
|
||||
value: string;
|
||||
};
|
||||
confirmButtonText: {
|
||||
type: StringConstructor;
|
||||
value: string;
|
||||
};
|
||||
visibleItemCount: {
|
||||
type: NumberConstructor;
|
||||
value: number;
|
||||
};
|
||||
itemHeight: {
|
||||
type: NumberConstructor;
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
|
||||
42
utils/dist/picker/shared.js
vendored
42
utils/dist/picker/shared.js
vendored
@@ -1,21 +1,21 @@
|
||||
export const pickerProps = {
|
||||
title: String,
|
||||
loading: Boolean,
|
||||
showToolbar: Boolean,
|
||||
cancelButtonText: {
|
||||
type: String,
|
||||
value: '取消'
|
||||
},
|
||||
confirmButtonText: {
|
||||
type: String,
|
||||
value: '确认'
|
||||
},
|
||||
visibleItemCount: {
|
||||
type: Number,
|
||||
value: 5
|
||||
},
|
||||
itemHeight: {
|
||||
type: Number,
|
||||
value: 44
|
||||
}
|
||||
};
|
||||
export const pickerProps = {
|
||||
title: String,
|
||||
loading: Boolean,
|
||||
showToolbar: Boolean,
|
||||
cancelButtonText: {
|
||||
type: String,
|
||||
value: '取消'
|
||||
},
|
||||
confirmButtonText: {
|
||||
type: String,
|
||||
value: '确认'
|
||||
},
|
||||
visibleItemCount: {
|
||||
type: Number,
|
||||
value: 5
|
||||
},
|
||||
itemHeight: {
|
||||
type: Number,
|
||||
value: 44
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user