@weitutech/by-components 1.0.27 → 1.0.30

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.
@@ -1,127 +1,127 @@
1
- <template>
2
- <el-select
3
- v-bind="$props"
4
- :value="value"
5
- ref="selection"
6
- :placeholder="config.placeholder || '请选择'"
7
- @change="change"
8
- @visible-change="visibleChange"
9
- @remove-tag="removeTag"
10
- @clear="clear"
11
- @blur="blur"
12
- @focus="focus"
13
- >
14
- <template v-if="config.mode === 'group'">
15
- <el-option-group
16
- v-for="group in item.options"
17
- :key="group[config.optionValue || 'value']"
18
- :label="group[config.optionLabel || 'label']"
19
- >
20
- <el-option
21
- v-for="gItem in group.options"
22
- :key="gItem[config.optionValue || 'value']"
23
- :label="gItem[config.optionLabel || 'label']"
24
- :value="gItem[config.optionValue || 'value']"
25
- />
26
- </el-option-group>
27
- </template>
28
- <template v-else>
29
- <el-option
30
- v-for="(item) in filterData"
31
- :key="item[config.optionValue || 'value'] +'-' +item[config.optionLabel || 'label']"
32
- :label="item[config.optionLabel || 'label']"
33
- :value="item[config.optionValue || 'value']"
34
- />
35
- </template>
36
- </el-select>
37
- </template>
38
- <script>
39
- import { Select } from 'element-ui'
40
- export default {
41
- name: 'BYSelect',
42
- props: {
43
- ...Select.props,
44
- value: {
45
- type: [String, Number, Array],
46
- },
47
- // 下拉框数据
48
- placeholder: {
49
- type: String,
50
- default: '请选择'
51
- },
52
- // 下拉框数据
53
- options: {
54
- type: Array,
55
- default: () => {
56
- return []
57
- }
58
- },
59
- //当前配置
60
- config: {
61
- type: Object,
62
- default: null
63
- }
64
- },
65
- data() {
66
- return {
67
- searchVal: '',
68
- filterData: []
69
- }
70
- },
71
- watch: {
72
- options: {
73
- handler() {
74
- this.filterData = this.options
75
- },
76
- deep: true,
77
- immediate: true
78
- }
79
- },
80
- methods: {
81
- change(e) {
82
- this.$emit('change', arguments.length === 1 ? e : arguments)
83
- this.$emit("input", e)
84
- },
85
- input(e) {
86
- this.$emit('change', arguments.length === 1 ? e : arguments)
87
- this.$emit("input", e)
88
- },
89
- visibleChange(e) {
90
- this.$emit('visible-change', arguments.length === 1 ? e : arguments)
91
- },
92
- removeTag(e) {
93
- this.$emit('remove-tag', arguments.length === 1 ? e : arguments)
94
- },
95
- clear(e) {
96
- this.$emit('clear', arguments.length === 1 ? e : arguments)
97
- },
98
- blur(e) {
99
- this.$emit('blur', arguments.length === 1 ? e : arguments)
100
- },
101
- focus(e) {
102
- // 如果是多选模式 则做处理
103
- if (this.multiple) {
104
- this.searchNoReset()
105
- }
106
- this.$emit('blur', arguments.length === 1 ? e : arguments)
107
- },
108
- // 解决多选时选择后下拉数据会重置问题
109
- searchNoReset() {
110
- // 离开时重置数据
111
- this.$refs.selection.$refs.input.blur = () => {
112
- this.filterData = this.options
113
- }
114
-
115
- // 根据数据筛选数据
116
- this.$refs.selection.$refs.input.onkeyup = () => {
117
- this.filterData = this.options
118
- this.searchVal = this.$refs.selection.$refs.input.value
119
- this.filterData = this.options.filter(
120
- (item) => item[this.config.optionLabel].indexOf(this.searchVal) !== -1
121
- )
122
- }
123
- }
124
- }
125
- }
126
- </script>
127
-
1
+ <template>
2
+ <el-select
3
+ v-bind="$props"
4
+ :value="value"
5
+ ref="selection"
6
+ :placeholder="config.placeholder || '请选择'"
7
+ @change="change"
8
+ @visible-change="visibleChange"
9
+ @remove-tag="removeTag"
10
+ @clear="clear"
11
+ @blur="blur"
12
+ @focus="focus"
13
+ >
14
+ <template v-if="config.mode === 'group'">
15
+ <el-option-group
16
+ v-for="group in item.options"
17
+ :key="group[config.optionValue || 'value']"
18
+ :label="group[config.optionLabel || 'label']"
19
+ >
20
+ <el-option
21
+ v-for="gItem in group.options"
22
+ :key="gItem[config.optionValue || 'value']"
23
+ :label="gItem[config.optionLabel || 'label']"
24
+ :value="gItem[config.optionValue || 'value']"
25
+ />
26
+ </el-option-group>
27
+ </template>
28
+ <template v-else>
29
+ <el-option
30
+ v-for="(item) in filterData"
31
+ :key="item[config.optionValue || 'value'] +'-' +item[config.optionLabel || 'label']"
32
+ :label="item[config.optionLabel || 'label']"
33
+ :value="item[config.optionValue || 'value']"
34
+ />
35
+ </template>
36
+ </el-select>
37
+ </template>
38
+ <script>
39
+ import { Select } from 'element-ui'
40
+ export default {
41
+ name: 'BYSelect',
42
+ props: {
43
+ ...Select.props,
44
+ value: {
45
+ type: [String, Number, Array],
46
+ },
47
+ // 下拉框数据
48
+ placeholder: {
49
+ type: String,
50
+ default: '请选择'
51
+ },
52
+ // 下拉框数据
53
+ options: {
54
+ type: Array,
55
+ default: () => {
56
+ return []
57
+ }
58
+ },
59
+ //当前配置
60
+ config: {
61
+ type: Object,
62
+ default: null
63
+ }
64
+ },
65
+ data() {
66
+ return {
67
+ searchVal: '',
68
+ filterData: []
69
+ }
70
+ },
71
+ watch: {
72
+ options: {
73
+ handler() {
74
+ this.filterData = this.options
75
+ },
76
+ deep: true,
77
+ immediate: true
78
+ }
79
+ },
80
+ methods: {
81
+ change(e) {
82
+ this.$emit('change', arguments.length === 1 ? e : arguments)
83
+ this.$emit("input", e)
84
+ },
85
+ input(e) {
86
+ this.$emit('change', arguments.length === 1 ? e : arguments)
87
+ this.$emit("input", e)
88
+ },
89
+ visibleChange(e) {
90
+ this.$emit('visible-change', arguments.length === 1 ? e : arguments)
91
+ },
92
+ removeTag(e) {
93
+ this.$emit('remove-tag', arguments.length === 1 ? e : arguments)
94
+ },
95
+ clear(e) {
96
+ this.$emit('clear', arguments.length === 1 ? e : arguments)
97
+ },
98
+ blur(e) {
99
+ this.$emit('blur', arguments.length === 1 ? e : arguments)
100
+ },
101
+ focus(e) {
102
+ // 如果是多选模式 则做处理
103
+ if (this.multiple) {
104
+ this.searchNoReset()
105
+ }
106
+ this.$emit('blur', arguments.length === 1 ? e : arguments)
107
+ },
108
+ // 解决多选时选择后下拉数据会重置问题
109
+ searchNoReset() {
110
+ // 离开时重置数据
111
+ this.$refs.selection.$refs.input.blur = () => {
112
+ this.filterData = this.options
113
+ }
114
+
115
+ // 根据数据筛选数据
116
+ this.$refs.selection.$refs.input.onkeyup = () => {
117
+ this.filterData = this.options
118
+ this.searchVal = this.$refs.selection.$refs.input.value
119
+ this.filterData = this.options.filter(
120
+ (item) => item[this.config.optionLabel].indexOf(this.searchVal) !== -1
121
+ )
122
+ }
123
+ }
124
+ }
125
+ }
126
+ </script>
127
+