@weitutech/by-components 1.1.0 → 1.1.1

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,112 +0,0 @@
1
- <template>
2
- <div class="b-picker wrapper">
3
- <el-date-picker
4
- style="width: 70%"
5
- v-model="value[config.field]"
6
- :start-placeholder="config.startPlaceholder || '开始时间'"
7
- :end-placeholder="config.endPlaceholder || '结束时间'"
8
- :range-separator="config.rangeSeparator || '-'"
9
- :size="config.size || 'mini'"
10
- type="daterange"
11
- @input="handleChange"
12
- />
13
- <div class="btn">
14
- <span
15
- v-for="item in shortcuts"
16
- :key="item.key"
17
- class="item"
18
- :class="{ item_active: item.key === active }"
19
- @click="handleClick(item)"
20
- >
21
- {{ item.label }}
22
- </span>
23
- </div>
24
- </div>
25
- </template>
26
-
27
- <script>
28
- import moment from 'moment'
29
- export default {
30
- name: 'ByDatePickerRange',
31
- props: {
32
- //绑定的表单数据
33
- value: {
34
- type: Object,
35
- default: null
36
- },
37
- //当前配置
38
- config: {
39
- type: Object,
40
- default: null
41
- }
42
- },
43
- data() {
44
- return {
45
- shortcuts: [
46
- {
47
- label: '上月',
48
- start_time: moment()
49
- .subtract(1, 'months')
50
- .startOf('month')
51
- .format('YYYY-MM-DD'),
52
- end_time: moment()
53
- .subtract(1, 'months')
54
- .endOf('month')
55
- .format('YYYY-MM-DD'),
56
- key: 'last_month'
57
- },
58
- {
59
- label: '昨天',
60
- start_time: moment().subtract(1, 'days').format('YYYY-MM-DD'),
61
- end_time: moment().subtract(1, 'days').format('YYYY-MM-DD'),
62
- key: 'yesterday'
63
- },
64
- {
65
- label: '今天',
66
- start_time: moment().startOf('day').format('YYYY-MM-DD'),
67
- end_time: moment().startOf('day').format('YYYY-MM-DD'),
68
- key: 'today'
69
- },
70
- {
71
- label: '本周',
72
- start_time: moment().startOf('week').format('YYYY-MM-DD'),
73
- end_time: moment().endOf('week').format('YYYY-MM-DD'),
74
- key: 'week'
75
- },
76
- {
77
- label: '本月',
78
- start_time: moment().startOf('month').format('YYYY-MM-DD'),
79
- end_time: moment().endOf('month').format('YYYY-MM-DD'),
80
- key: 'month'
81
- }
82
- ],
83
- active: ''
84
- }
85
- },
86
- mounted() {
87
- this.active = this.config.active || 'today'
88
- const item = this.shortcuts.find(item => item.key === this.active) || {}
89
- if (item.start_time && item.end_time) {
90
- this.handleClick(item)
91
- }
92
- },
93
- methods: {
94
- handleChange(e) {
95
- if (!e) {
96
- this.$emit('input', [])
97
- } else {
98
- this.$emit(
99
- 'input',
100
- e.map(item => moment(item).format('YYYY-MM-DD'))
101
- )
102
- }
103
- this.active = ''
104
- },
105
- handleClick(item) {
106
- this.active = item.key
107
- this.value[this.config.field] = [item.start_time, item.end_time]
108
- this.$emit('input', [item.start_time, item.end_time])
109
- }
110
- }
111
- }
112
- </script>
@@ -1,79 +0,0 @@
1
- <template>
2
- <div class="w-full flex">
3
- <el-input
4
- class="w-1/2"
5
- :value="value[0]"
6
- :placeholder="earliestPlaceholder"
7
- @input="value => handleInput(value, 'min')"
8
- @blur="e => handleBlur(+e.target.value, 'min')"
9
- />
10
- <span>~</span>
11
- <el-input
12
- class="w-1/2"
13
- :value="value[1]"
14
- :placeholder="latestPlaceholder"
15
- @input="value => handleInput(value, 'max')"
16
- @blur="e => handleBlur(+e.target.value, 'max')"
17
- />
18
- </div>
19
- </template>
20
-
21
- <script>
22
- export default {
23
- props: {
24
- value: {
25
- type: Array,
26
- required: true,
27
- default: () => ['', 0]
28
- },
29
- earliestPlaceholder: {
30
- type: String,
31
- default: ''
32
- },
33
- latestPlaceholder: {
34
- type: String,
35
- default: ''
36
- }
37
- },
38
-
39
- methods: {
40
- /**
41
- * 输入框输入回调,将其转换为数字,并反馈到父组件
42
- * @param { string } val 输入框的value值
43
- * @param { string } type 输入框的类型 min | max
44
- */
45
- handleInput(val, type) {
46
- if (type === 'min') {
47
- const values = [val.replace(/\D+/, ''), this.value[1]]
48
-
49
- this.$emit('input', values)
50
- } else if (type === 'max') {
51
- const values = [this.value[0], val.replace(/\D+/, '')]
52
-
53
- this.$emit('input', values)
54
- }
55
- },
56
-
57
- /**
58
- * 输入框失去焦点回调,判断最小输入框是否大于最大输入框和最大输入框小于最小输入框,并反馈到父组件
59
- * @param { number } val 输入框的value值
60
- * @param { string } type 输入框的类型 min | max
61
- */
62
- handleBlur(val, type) {
63
- if (type === 'min') {
64
- if (val > this.value[1]) {
65
- const values = [this.value[1], this.value[1]]
66
-
67
- this.$emit('input', values)
68
- }
69
- } else if (type === 'max') {
70
- if (val < this.value[0]) {
71
- const values = [this.value[0], this.value[0]]
72
-
73
- this.$emit('input', values)
74
- }
75
- }
76
- }
77
- }
78
- }
79
- </script>
@@ -1,130 +0,0 @@
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="
32
- item[config.optionValue || 'value'] +
33
- '-' +
34
- item[config.optionLabel || 'label']
35
- "
36
- :label="item[config.optionLabel || 'label']"
37
- :value="item[config.optionValue || 'value']"
38
- />
39
- </template>
40
- </el-select>
41
- </template>
42
- <script>
43
- import { Select } from 'element-ui'
44
- export default {
45
- name: 'BYSelect',
46
- props: {
47
- ...Select.props,
48
- value: {
49
- type: [String, Number, Array]
50
- },
51
- // 下拉框数据
52
- placeholder: {
53
- type: String,
54
- default: '请选择'
55
- },
56
- // 下拉框数据
57
- options: {
58
- type: Array,
59
- default: () => {
60
- return []
61
- }
62
- },
63
- //当前配置
64
- config: {
65
- type: Object,
66
- default: null
67
- }
68
- },
69
- data() {
70
- return {
71
- searchVal: '',
72
- filterData: []
73
- }
74
- },
75
- watch: {
76
- options: {
77
- handler() {
78
- this.filterData = this.options
79
- },
80
- deep: true,
81
- immediate: true
82
- }
83
- },
84
- methods: {
85
- change(e) {
86
- this.$emit('change', arguments.length === 1 ? e : arguments)
87
- this.$emit('input', e)
88
- },
89
- input(e) {
90
- this.$emit('change', arguments.length === 1 ? e : arguments)
91
- this.$emit('input', e)
92
- },
93
- visibleChange(e) {
94
- this.$emit('visible-change', arguments.length === 1 ? e : arguments)
95
- },
96
- removeTag(e) {
97
- this.$emit('remove-tag', arguments.length === 1 ? e : arguments)
98
- },
99
- clear(e) {
100
- this.$emit('clear', arguments.length === 1 ? e : arguments)
101
- },
102
- blur(e) {
103
- this.$emit('blur', arguments.length === 1 ? e : arguments)
104
- },
105
- focus(e) {
106
- // 如果是多选模式 则做处理
107
- if (this.multiple) {
108
- this.searchNoReset()
109
- }
110
- this.$emit('blur', arguments.length === 1 ? e : arguments)
111
- },
112
- // 解决多选时选择后下拉数据会重置问题
113
- searchNoReset() {
114
- // 离开时重置数据
115
- this.$refs.selection.$refs.input.blur = () => {
116
- this.filterData = this.options
117
- }
118
-
119
- // 根据数据筛选数据
120
- this.$refs.selection.$refs.input.onkeyup = () => {
121
- this.filterData = this.options
122
- this.searchVal = this.$refs.selection.$refs.input.value
123
- this.filterData = this.options.filter(
124
- item => item[this.config.optionLabel].indexOf(this.searchVal) !== -1
125
- )
126
- }
127
- }
128
- }
129
- }
130
- </script>