@weitutech/by-components 1.0.31 → 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,135 +0,0 @@
1
- <template>
2
- <div class="b-picker wrapper">
3
- <el-date-picker
4
- style="width: 70%"
5
- :value="value"
6
- v-bind="dateOptions"
7
- @input="handleChange"
8
- />
9
- <div class="btn">
10
- <span
11
- v-for="item in shortcuts"
12
- :key="item.key"
13
- class="item"
14
- :class="{ item_active: item.key === active }"
15
- @click="handleClick(item)"
16
- >
17
- {{ item.label }}
18
- </span>
19
- </div>
20
- </div>
21
- </template>
22
-
23
- <script>
24
- import moment from "moment"
25
- export default {
26
- props: {
27
- value: {
28
- type: [Array, String],
29
- required: true,
30
- default: () => []
31
- },
32
- otherOption: {
33
- type: Object,
34
- default: () => ({
35
- startPlaceholder: "开始时间",
36
- endPlaceholder: "结束时间",
37
- type: "daterange",
38
- rangeSeparator: "-",
39
- size: "mini",
40
- active: ""
41
- })
42
- },
43
- startTimeField: {
44
- type: String,
45
- default: ""
46
- },
47
- endTimeField: {
48
- type: String,
49
- default: ""
50
- }
51
- },
52
-
53
- data() {
54
- return {
55
- shortcuts: [
56
- { label: "上月", start_time: moment().subtract(1, "months").startOf("month").format("YYYY-MM-DD"), end_time: moment().subtract(1, "months").endOf("month").format("YYYY-MM-DD"), key: "last_month" },
57
- { label: "昨天", start_time: moment().subtract(1, "days").format("YYYY-MM-DD"), end_time: moment().subtract(1, "days").format("YYYY-MM-DD"), key: "yesterday" },
58
- { label: "今天", start_time: moment().startOf("day").format("YYYY-MM-DD"), end_time: moment().startOf("day").format("YYYY-MM-DD"), key: "today" },
59
- { label: "本周", start_time: moment().startOf("week").format("YYYY-MM-DD"), end_time: moment().endOf("week").format("YYYY-MM-DD"), key: "week" },
60
- { label: "本月", start_time: moment().startOf("month").format("YYYY-MM-DD"), end_time: moment().endOf("month").format("YYYY-MM-DD"), key: "month" }
61
- ],
62
- active: ""
63
- }
64
- },
65
-
66
- computed: {
67
- dateOptions() {
68
- return {
69
- startPlaceholder: "开始时间",
70
- endPlaceholder: "结束时间",
71
- type: "daterange",
72
- rangeSeparator: "至",
73
- size: "mini",
74
- active: "",
75
- ...this.otherOption
76
- }
77
- }
78
- },
79
-
80
- watch: {
81
- value: {
82
- handler(newValue, oldValue) {
83
- if (newValue && newValue.length) {
84
- this.active = ""
85
- this.shortcuts.forEach(item => {
86
- if (item.start_time === newValue[0] && item.end_time === newValue[1]) {
87
- this.active = item.key
88
- }
89
- })
90
- } else {
91
- this.active = this.dateOptions.active
92
- const item = this.shortcuts.find(item => item.key === this.dateOptions.active) || {}
93
- if (item.start_time && item.end_time) {
94
- this.handleClick(item)
95
- }
96
- }
97
- },
98
- immediate: true
99
- }
100
- },
101
-
102
- methods: {
103
- handleChange(e) {
104
- if (!e) {
105
- this.$emit("input", [])
106
- if (this.startTimeField && this.endTimeField) {
107
- this.$emit("range-change", { startTime: "", endTime: "" })
108
- }
109
- } else {
110
- const formattedDates = e.map(item => moment(item).format("YYYY-MM-DD"))
111
- this.$emit("input", formattedDates)
112
-
113
- if (this.startTimeField && this.endTimeField) {
114
- this.$emit("range-change", {
115
- startTime: formattedDates[0],
116
- endTime: formattedDates[1]
117
- })
118
- }
119
- }
120
- this.active = ""
121
- },
122
- handleClick(item) {
123
- this.active = item.key
124
- this.$emit("input", [item.start_time, item.end_time])
125
-
126
- if (this.startTimeField && this.endTimeField) {
127
- this.$emit("range-change", {
128
- startTime: item.start_time,
129
- endTime: item.end_time
130
- })
131
- }
132
- }
133
- }
134
- }
135
- </script>
@@ -1,78 +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
- { label: "上月", start_time: moment().subtract(1, "months").startOf("month").format("YYYY-MM-DD"), end_time: moment().subtract(1, "months").endOf("month").format("YYYY-MM-DD"), key: "last_month" },
47
- { label: "昨天", start_time: moment().subtract(1, "days").format("YYYY-MM-DD"), end_time: moment().subtract(1, "days").format("YYYY-MM-DD"), key: "yesterday" },
48
- { label: "今天", start_time: moment().startOf("day").format("YYYY-MM-DD"), end_time: moment().startOf("day").format("YYYY-MM-DD"), key: "today" },
49
- { label: "本周", start_time: moment().startOf("week").format("YYYY-MM-DD"), end_time: moment().endOf("week").format("YYYY-MM-DD"), key: "week" },
50
- { label: "本月", start_time: moment().startOf("month").format("YYYY-MM-DD"), end_time: moment().endOf("month").format("YYYY-MM-DD"), key: "month" }
51
- ],
52
- active: ""
53
- }
54
- },
55
- mounted() {
56
- this.active = this.config.active || 'today'
57
- const item = this.shortcuts.find(item => item.key === this.active) || {}
58
- if (item.start_time && item.end_time) {
59
- this.handleClick(item)
60
- }
61
- },
62
- methods: {
63
- handleChange(e) {
64
- if (!e) {
65
- this.$emit("input", [])
66
- } else {
67
- this.$emit("input", e.map(item => moment(item).format("YYYY-MM-DD")))
68
- }
69
- this.active = ""
70
- },
71
- handleClick(item) {
72
- this.active = item.key
73
- this.value[this.config.field] = [item.start_time, item.end_time]
74
- this.$emit("input", [item.start_time, item.end_time])
75
- }
76
- }
77
- }
78
- </script>
@@ -1,67 +0,0 @@
1
- <template>
2
- <div class="w-full flex">
3
- <el-input class="w-1/2" :value="value[0]" :placeholder="earliestPlaceholder" @input="(value) => handleInput(value, 'min')" @blur="(e) => handleBlur(+e.target.value, 'min')" />
4
- <span>~</span>
5
- <el-input class="w-1/2" :value="value[1]" :placeholder="latestPlaceholder" @input="(value) => handleInput(value, 'max')" @blur="(e) => handleBlur(+e.target.value, 'max')" />
6
- </div>
7
- </template>
8
-
9
- <script>
10
- export default {
11
- props: {
12
- value: {
13
- type: Array,
14
- required: true,
15
- default: () => ["", 0]
16
- },
17
- earliestPlaceholder: {
18
- type: String,
19
- default: ""
20
- },
21
- latestPlaceholder: {
22
- type: String,
23
- default: ""
24
- }
25
- },
26
-
27
- methods: {
28
- /**
29
- * 输入框输入回调,将其转换为数字,并反馈到父组件
30
- * @param { string } val 输入框的value值
31
- * @param { string } type 输入框的类型 min | max
32
- */
33
- handleInput(val, type) {
34
- if (type === "min") {
35
- const values = [val.replace(/\D+/, ""), this.value[1]]
36
-
37
- this.$emit("input", values)
38
- } else if (type === "max") {
39
- const values = [this.value[0], val.replace(/\D+/, "")]
40
-
41
- this.$emit("input", values)
42
- }
43
- },
44
-
45
- /**
46
- * 输入框失去焦点回调,判断最小输入框是否大于最大输入框和最大输入框小于最小输入框,并反馈到父组件
47
- * @param { number } val 输入框的value值
48
- * @param { string } type 输入框的类型 min | max
49
- */
50
- handleBlur(val, type) {
51
- if (type === "min") {
52
- if (val > this.value[1]) {
53
- const values = [this.value[1], this.value[1]]
54
-
55
- this.$emit("input", values)
56
- }
57
- } else if (type === "max") {
58
- if (val < this.value[0]) {
59
- const values = [this.value[0], this.value[0]]
60
-
61
- this.$emit("input", values)
62
- }
63
- }
64
- }
65
- }
66
- }
67
- </script>
@@ -1,127 +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="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
-