@bsgoal/common 2.0.0 → 2.5.0

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.
@@ -0,0 +1,142 @@
1
+ <!--
2
+ * @Author: canlong.shen
3
+ * @Date: 2023-05-24 14:09:57
4
+ * @LastEditors: canlong.shen
5
+ * @LastEditTime: 2023-05-24 16:54:26
6
+ * @FilePath: \common\src\components\bsgoal-base-time-range\index.vue
7
+ * @Description: 时间选择 公共组件
8
+ *
9
+ -->
10
+
11
+ <script setup>
12
+ /* setup模板
13
+ ---------------------------------------------------------------- */
14
+ import { ref, unref, watch, watchEffect } from 'vue'
15
+ import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
16
+ import { dayjs } from 'element-plus'
17
+ const props = defineProps({
18
+ /**
19
+ * value
20
+ */
21
+ modelValue: {
22
+ type: [Array],
23
+ default: () => [new Date(), new Date()]
24
+ },
25
+
26
+ /**
27
+ * 开始时间 绑定的值
28
+ */
29
+ startTime: {
30
+ type: [String],
31
+ default: ''
32
+ },
33
+ /**
34
+ * 结束时间 绑定的值
35
+ */
36
+ endTime: {
37
+ type: [String],
38
+ default: ''
39
+ },
40
+ /**
41
+ * 格式 HH:mm:ss
42
+ */
43
+ format: {
44
+ type: [String],
45
+ default: 'HH:mm'
46
+ }
47
+ })
48
+
49
+ const emits = defineEmits(['update:modelValue', 'update:startTime', 'update:endTime'])
50
+ // ---> S 值绑定 <---
51
+ const bindValue = ref([])
52
+
53
+ /**
54
+ * @Author: canlong.shen
55
+ * @description: 转换 字符串 time 为 Date
56
+ * @default:
57
+ * @return {*}
58
+ */
59
+ const stringToDate = (timeString = '') => {
60
+ return dayjs(`0000-00-00 ${timeString}`)
61
+ }
62
+
63
+ /**
64
+ * @Author: canlong.shen
65
+ * @description: 格式化 Date 为 time 字符串
66
+ * @default:
67
+ * @return {*}
68
+ */
69
+ const dateToString = (date = new Date()) => {
70
+ return dayjs(date).format(props.format)
71
+ }
72
+
73
+ watchEffect(() => {
74
+ const { startTime = '', endTime = '', modelValue = [] } = props
75
+ let startDate = new Date()
76
+ let endDate = new Date()
77
+ const startTimeValue = unref(startTime)
78
+ const endTimeValue = unref(endTime)
79
+ const modelValueList = unref(modelValue)
80
+ if (startTimeValue && endTimeValue) {
81
+ startDate = stringToDate(startTimeValue)
82
+ endDate = stringToDate(endTimeValue)
83
+ } else if (Array.isArray(modelValueList) && modelValueList.length === 2) {
84
+ const { 0: startValue = '', 1: endValue = '' } = modelValueList
85
+ startDate = stringToDate(startValue)
86
+ endDate = stringToDate(endValue)
87
+ }
88
+
89
+ bindValue.value = [startDate, endDate]
90
+ })
91
+
92
+ /**
93
+ * @Author: canlong.shen
94
+ * @description: 触发 值变化
95
+ * @default:
96
+ * @return {*}
97
+ */
98
+ const triggerChange = (range = []) => {
99
+ const { startTime = '', endTime = '' } = props
100
+
101
+ const { 0: startDate, 1: endDate } = range
102
+ const startDateFormat = dateToString(startDate)
103
+ const endDateFormat = dateToString(endDate)
104
+ if (unref(startTime) && unref(endTime)) {
105
+ emits('update:startTime', startDateFormat)
106
+ emits('update:endTime', endDateFormat)
107
+ } else {
108
+ emits('update:modelValue', [startDateFormat, endDateFormat])
109
+ }
110
+ }
111
+
112
+ // ---> E 值绑定 <---
113
+ </script>
114
+ <script>
115
+ export default {
116
+ name: 'BsgoalBaseTimeRange'
117
+ }
118
+ </script>
119
+ <template>
120
+ <div class="bsgoal-base-time-range">
121
+ <el-config-provider :locale="zhCn">
122
+ <el-time-picker
123
+ v-model="bindValue"
124
+ is-range
125
+ class="base_time_range"
126
+ :format="format"
127
+ range-separator="至"
128
+ start-placeholder="开始时间"
129
+ end-placeholder="结束时间"
130
+ @change="triggerChange"
131
+ />
132
+ </el-config-provider>
133
+ </div>
134
+ </template>
135
+ <style lang="scss" scoped>
136
+ /* 自定义样式
137
+ ---------------------------------------------------------------- */
138
+ </style>
139
+ <style lang="scss">
140
+ /* 覆盖样式
141
+ ---------------------------------------------------------------- */
142
+ </style>
package/src/entry.js CHANGED
@@ -9,6 +9,11 @@ import BsgoalBaseLink from '@/components/bsgoal-base-link/index.vue'
9
9
  import BsgoalBaseButton from '@/components/bsgoal-base-button/index.vue'
10
10
  import BsgoalBaseLayout from '@/components/bsgoal-base-layout/index.vue'
11
11
  import BsgoalBaseAlert from '@/components/bsgoal-base-alert/index.vue'
12
+ import BsgoalBaseSelect from '@/components/bsgoal-base-select/index.vue'
13
+ import BsgoalBaseTime from '@/components/bsgoal-base-time/index.vue'
14
+ import BsgoalBaseTimeRange from '@/components/bsgoal-base-time-range/index.vue'
15
+ import BsgoalBaseSwitch from '@/components/bsgoal-base-switch/index.vue'
16
+ import BsgoalBaseItem from '@/components/bsgoal-base-item/index.vue'
12
17
  import componentTypeEnums from '@/enums/componentTypeEnums.js'
13
18
  import { useFetch } from '@/combines/useFetchs.js'
14
19
 
@@ -31,7 +36,12 @@ export default {
31
36
  BsgoalBaseLink,
32
37
  BsgoalBaseButton,
33
38
  BsgoalBaseLayout,
34
- BsgoalBaseAlert
39
+ BsgoalBaseAlert,
40
+ BsgoalBaseSelect,
41
+ BsgoalBaseTime,
42
+ BsgoalBaseTimeRange,
43
+ BsgoalBaseSwitch,
44
+ BsgoalBaseItem,
35
45
  }
36
46
 
37
47
  for (const [name, component] of Object.entries(componentsMap)) {
@@ -2,7 +2,7 @@
2
2
  * @Author: canlong.shen
3
3
  * @Date: 2023-04-10 10:41:52
4
4
  * @LastEditors: canlong.shen
5
- * @LastEditTime: 2023-05-24 09:56:01
5
+ * @LastEditTime: 2023-05-24 17:43:27
6
6
  * @FilePath: \common\src\router\index.js
7
7
  * @Description: 路由配置
8
8
  *
@@ -98,6 +98,31 @@ const router = createRouter({
98
98
  name: 'alert提示',
99
99
  component: import('@/components/bsgoal-base-alert/demo.vue')
100
100
  },
101
+ {
102
+ path: 'bsgoal-base-select-demo',
103
+ name: '下拉选择器',
104
+ component: import('@/components/bsgoal-base-select/demo.vue')
105
+ },
106
+ {
107
+ path: 'bsgoal-base-time-range-demo',
108
+ name: '时间范围选择器',
109
+ component: import('@/components/bsgoal-base-time-range/demo.vue')
110
+ },
111
+ {
112
+ path: 'bsgoal-base-time-demo',
113
+ name: '时间选择器',
114
+ component: import('@/components/bsgoal-base-time/demo.vue')
115
+ },
116
+ {
117
+ path: 'bsgoal-base-switch-demo',
118
+ name: '开关',
119
+ component: import('@/components/bsgoal-base-switch/demo.vue')
120
+ },
121
+ {
122
+ path: 'bsgoal-base-item-demo',
123
+ name: '表单项',
124
+ component: import('@/components/bsgoal-base-item/demo.vue')
125
+ },
101
126
  ]
102
127
  }
103
128
  ]