lw-cdp-ui 1.5.2 → 1.5.4

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,191 +1,191 @@
1
- /**
2
- * 完整解析Cron表达式为中文描述
3
- * @param {string} cronExpression - 标准Cron表达式
4
- * @returns {string} 中文描述
5
- */
6
- function parseCronExpression(cronExpression) {
7
- // 标准化表达式,处理可能的多空格
8
- const normalized = cronExpression.trim().replace(/\s+/g, ' ')
9
- const parts = normalized.split(' ')
10
-
11
- if (parts.length < 5 || parts.length > 7) {
12
- return '无效的Cron表达式'
13
- }
14
-
15
- // 补全年份部分(可选)
16
- const [second, minute, hour, dayOfMonth, month, dayOfWeek, year] = parts.length === 5 ? ['0', ...parts, '*'] : parts
17
-
18
- // 解析各个字段
19
- const timeDesc = parseTime(second, minute, hour)
20
- const dateDesc = parseDate(dayOfMonth, month, dayOfWeek)
21
- const yearDesc = parseYear(year)
22
-
23
- // 组合结果
24
- let result = ''
25
- if (dateDesc) result += dateDesc
26
- if (timeDesc) result += timeDesc
27
- if (yearDesc) result += yearDesc
28
-
29
- // 特殊处理常见表达式
30
- const commonPatterns = {
31
- '0 0 0 * * *': '每天午夜12点整执行',
32
- '0 0 12 * * *': '每天中午12点整执行',
33
- '0 0 8-18 * * 1-5': '工作日每天上午8点到下午6点每小时执行',
34
- '0 0 9 * * 1': '每周一上午9点整执行',
35
- '0 0 12 1 * *': '每月1日中午12点整执行',
36
- '0 0 0 1 1 *': '每年1月1日午夜12点整执行'
37
- }
38
-
39
- return commonPatterns[normalized] || result || '无法解析的Cron表达式'
40
-
41
- // 解析时间部分
42
- function parseTime(sec, min, hr) {
43
- const secondDesc = parseField(sec, {
44
- '*': '每秒',
45
- 0: '',
46
- default: (val) => `每${val}秒`
47
- })
48
-
49
- const minuteDesc = parseField(min, {
50
- '*': '每分钟',
51
- 0: '整',
52
- default: (val) => `每${val}分`
53
- })
54
-
55
- const hourDesc = parseField(hr, {
56
- '*': '每小时',
57
- default: (val) => {
58
- const num = parseInt(val, 10)
59
- const period = num < 12 ? '上午' : '下午'
60
- const displayHour = num % 12 === 0 ? 12 : num % 12
61
- return `${period}${displayHour}点`
62
- }
63
- })
64
-
65
- // 处理范围
66
- if (hr.includes('-')) {
67
- const [start, end] = hr.split('-').map(Number)
68
- return `从${start}点到${end}点每小时执行`
69
- }
70
-
71
- // 组合时间描述
72
- if (secondDesc && minuteDesc && hourDesc) {
73
- return `${hourDesc}${minuteDesc}${secondDesc}执行`
74
- }
75
-
76
- return `${hourDesc}${minuteDesc}${secondDesc}`.trim() + '执行'
77
- }
78
-
79
- // 解析日期部分
80
- function parseDate(dom, mon, dow) {
81
- const dayOfMonthDesc = parseField(dom, {
82
- '*': '',
83
- '?': '',
84
- L: '最后一天',
85
- default: (val) => {
86
- if (val.includes(',')) {
87
- return `每月${val.split(',').join('日、')}日`
88
- }
89
- if (val.includes('-')) {
90
- const [start, end] = val.split('-')
91
- return `每月${start}日到${end}日`
92
- }
93
- if (val.includes('/')) {
94
- const [start, step] = val.split('/')
95
- return `从${start || '1'}日开始每${step}天`
96
- }
97
- return `每月${val}日`
98
- }
99
- })
100
-
101
- const monthDesc = parseField(mon, {
102
- '*': '',
103
- default: (val) => {
104
- const months = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
105
- if (val.includes(',')) {
106
- return `${val
107
- .split(',')
108
- .map((m) => `${months[parseInt(m, 10) - 1]}月`)
109
- .join('、')}`
110
- }
111
- if (val.includes('-')) {
112
- const [start, end] = val.split('-').map((m) => months[parseInt(m, 10) - 1])
113
- return `${start}月到${end}月`
114
- }
115
- return `${months[parseInt(val, 10) - 1]}月`
116
- }
117
- })
118
-
119
- const dayOfWeekDesc = parseField(dow, {
120
- '*': '',
121
- '?': '',
122
- '1-5': '工作日',
123
- '6,7': '周末',
124
- L: '最后一周',
125
- default: (val) => {
126
- const days = ['日', '一', '二', '三', '四', '五', '六']
127
- if (val.includes(',')) {
128
- return `每周${val
129
- .split(',')
130
- .map((d) => `周${days[parseInt(d, 10)]}`)
131
- .join('、')}`
132
- }
133
- if (val.includes('-')) {
134
- const [start, end] = val.split('-').map((d) => days[parseInt(d, 10)])
135
- return `每周${start}到周${end}`
136
- }
137
- if (val.includes('#')) {
138
- const [day, week] = val.split('#')
139
- return `每月第${week}个周${days[parseInt(day, 10)]}`
140
- }
141
- return `每周${days[parseInt(val, 10)]}`
142
- }
143
- })
144
-
145
- // 组合日期描述
146
- let result = ''
147
- if (monthDesc) result += monthDesc
148
- if (dayOfMonthDesc) result += dayOfMonthDesc
149
- if (dayOfWeekDesc) result += dayOfWeekDesc
150
-
151
- // 默认描述
152
- if (!monthDesc && !dayOfMonthDesc && !dayOfWeekDesc) {
153
- return '每天'
154
- }
155
-
156
- return result
157
- }
158
-
159
- // 解析年份部分
160
- function parseYear(yr) {
161
- return parseField(yr, {
162
- '*': '',
163
- default: (val) => {
164
- if (!val) return ''
165
- if (val?.includes('/')) {
166
- const [start, step] = val.split('/')
167
- return `从${start}年开始每${step}年`
168
- }
169
- return `${val}年`
170
- }
171
- })
172
- }
173
-
174
- // 通用字段解析
175
- function parseField(value, options) {
176
- if (value in options) {
177
- return options[value]
178
- }
179
-
180
- if (options.default) {
181
- if (typeof options.default === 'function') {
182
- return options.default(value)
183
- }
184
- return options.default
185
- }
186
-
187
- return ''
188
- }
189
- }
190
-
191
- export default parseCronExpression
1
+ /**
2
+ * 完整解析Cron表达式为中文描述
3
+ * @param {string} cronExpression - 标准Cron表达式
4
+ * @returns {string} 中文描述
5
+ */
6
+ function parseCronExpression(cronExpression) {
7
+ // 标准化表达式,处理可能的多空格
8
+ const normalized = cronExpression.trim().replace(/\s+/g, ' ')
9
+ const parts = normalized.split(' ')
10
+
11
+ if (parts.length < 5 || parts.length > 7) {
12
+ return '无效的Cron表达式'
13
+ }
14
+
15
+ // 补全年份部分(可选)
16
+ const [second, minute, hour, dayOfMonth, month, dayOfWeek, year] = parts.length === 5 ? ['0', ...parts, '*'] : parts
17
+
18
+ // 解析各个字段
19
+ const timeDesc = parseTime(second, minute, hour)
20
+ const dateDesc = parseDate(dayOfMonth, month, dayOfWeek)
21
+ const yearDesc = parseYear(year)
22
+
23
+ // 组合结果
24
+ let result = ''
25
+ if (dateDesc) result += dateDesc
26
+ if (timeDesc) result += timeDesc
27
+ if (yearDesc) result += yearDesc
28
+
29
+ // 特殊处理常见表达式
30
+ const commonPatterns = {
31
+ '0 0 0 * * *': '每天午夜12点整执行',
32
+ '0 0 12 * * *': '每天中午12点整执行',
33
+ '0 0 8-18 * * 1-5': '工作日每天上午8点到下午6点每小时执行',
34
+ '0 0 9 * * 1': '每周一上午9点整执行',
35
+ '0 0 12 1 * *': '每月1日中午12点整执行',
36
+ '0 0 0 1 1 *': '每年1月1日午夜12点整执行'
37
+ }
38
+
39
+ return commonPatterns[normalized] || result || '无法解析的Cron表达式'
40
+
41
+ // 解析时间部分
42
+ function parseTime(sec, min, hr) {
43
+ const secondDesc = parseField(sec, {
44
+ '*': '每秒',
45
+ 0: '',
46
+ default: (val) => `每${val}秒`
47
+ })
48
+
49
+ const minuteDesc = parseField(min, {
50
+ '*': '每分钟',
51
+ 0: '整',
52
+ default: (val) => `每${val}分`
53
+ })
54
+
55
+ const hourDesc = parseField(hr, {
56
+ '*': '每小时',
57
+ default: (val) => {
58
+ const num = parseInt(val, 10)
59
+ const period = num < 12 ? '上午' : '下午'
60
+ const displayHour = num % 12 === 0 ? 12 : num % 12
61
+ return `${period}${displayHour}点`
62
+ }
63
+ })
64
+
65
+ // 处理范围
66
+ if (hr.includes('-')) {
67
+ const [start, end] = hr.split('-').map(Number)
68
+ return `从${start}点到${end}点每小时执行`
69
+ }
70
+
71
+ // 组合时间描述
72
+ if (secondDesc && minuteDesc && hourDesc) {
73
+ return `${hourDesc}${minuteDesc}${secondDesc}执行`
74
+ }
75
+
76
+ return `${hourDesc}${minuteDesc}${secondDesc}`.trim() + '执行'
77
+ }
78
+
79
+ // 解析日期部分
80
+ function parseDate(dom, mon, dow) {
81
+ const dayOfMonthDesc = parseField(dom, {
82
+ '*': '',
83
+ '?': '',
84
+ L: '最后一天',
85
+ default: (val) => {
86
+ if (val.includes(',')) {
87
+ return `每月${val.split(',').join('日、')}日`
88
+ }
89
+ if (val.includes('-')) {
90
+ const [start, end] = val.split('-')
91
+ return `每月${start}日到${end}日`
92
+ }
93
+ if (val.includes('/')) {
94
+ const [start, step] = val.split('/')
95
+ return `从${start || '1'}日开始每${step}天`
96
+ }
97
+ return `每月${val}日`
98
+ }
99
+ })
100
+
101
+ const monthDesc = parseField(mon, {
102
+ '*': '',
103
+ default: (val) => {
104
+ const months = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']
105
+ if (val.includes(',')) {
106
+ return `${val
107
+ .split(',')
108
+ .map((m) => `${months[parseInt(m, 10) - 1]}月`)
109
+ .join('、')}`
110
+ }
111
+ if (val.includes('-')) {
112
+ const [start, end] = val.split('-').map((m) => months[parseInt(m, 10) - 1])
113
+ return `${start}月到${end}月`
114
+ }
115
+ return `${months[parseInt(val, 10) - 1]}月`
116
+ }
117
+ })
118
+
119
+ const dayOfWeekDesc = parseField(dow, {
120
+ '*': '',
121
+ '?': '',
122
+ '1-5': '工作日',
123
+ '6,7': '周末',
124
+ L: '最后一周',
125
+ default: (val) => {
126
+ const days = ['日', '一', '二', '三', '四', '五', '六']
127
+ if (val.includes(',')) {
128
+ return `每周${val
129
+ .split(',')
130
+ .map((d) => `周${days[parseInt(d, 10)]}`)
131
+ .join('、')}`
132
+ }
133
+ if (val.includes('-')) {
134
+ const [start, end] = val.split('-').map((d) => days[parseInt(d, 10)])
135
+ return `每周${start}到周${end}`
136
+ }
137
+ if (val.includes('#')) {
138
+ const [day, week] = val.split('#')
139
+ return `每月第${week}个周${days[parseInt(day, 10)]}`
140
+ }
141
+ return `每周${days[parseInt(val, 10)]}`
142
+ }
143
+ })
144
+
145
+ // 组合日期描述
146
+ let result = ''
147
+ if (monthDesc) result += monthDesc
148
+ if (dayOfMonthDesc) result += dayOfMonthDesc
149
+ if (dayOfWeekDesc) result += dayOfWeekDesc
150
+
151
+ // 默认描述
152
+ if (!monthDesc && !dayOfMonthDesc && !dayOfWeekDesc) {
153
+ return '每天'
154
+ }
155
+
156
+ return result
157
+ }
158
+
159
+ // 解析年份部分
160
+ function parseYear(yr) {
161
+ return parseField(yr, {
162
+ '*': '',
163
+ default: (val) => {
164
+ if (!val) return ''
165
+ if (val?.includes('/')) {
166
+ const [start, step] = val.split('/')
167
+ return `从${start}年开始每${step}年`
168
+ }
169
+ return `${val}年`
170
+ }
171
+ })
172
+ }
173
+
174
+ // 通用字段解析
175
+ function parseField(value, options) {
176
+ if (value in options) {
177
+ return options[value]
178
+ }
179
+
180
+ if (options.default) {
181
+ if (typeof options.default === 'function') {
182
+ return options.default(value)
183
+ }
184
+ return options.default
185
+ }
186
+
187
+ return ''
188
+ }
189
+ }
190
+
191
+ export default parseCronExpression
@@ -192,8 +192,9 @@ export default {
192
192
  // 遍历路径并逐层查找
193
193
  for (let i = 0; i < keys.length; i++) {
194
194
  // 如果当前层级不存在,则创建该层级对象
195
- if (current[keys[i]] === undefined) {
196
- current[keys[i]] = i === keys.length - 1 ? defaultValue : {} // 如果是最后一个层级,设为默认值,否则创建空对象
195
+ if (current === null || current === undefined || current[keys[i]] === undefined) {
196
+ current = current || {}
197
+ current[keys[i]] = i === keys.length - 1 ? defaultValue : {}
197
198
  }
198
199
  // 否则,继续向下查找
199
200
  current = current[keys[i]]
@@ -37,9 +37,7 @@
37
37
 
38
38
  <!-- input -->
39
39
  <template v-if="item.component == 'input'">
40
- <template v-if="item?.options?.prepend">{{ item?.options.prepend }}</template>
41
- <textToPassword v-model="objItem.value" :password="item?.options?.password" />
42
- <template v-if="item?.options?.append">{{ item?.options.append }}</template>
40
+ <textToPassword v-model="objItem.value" :password="item?.options?.password" :append="item?.options?.append" />
43
41
  </template>
44
42
  <!-- upload -->
45
43
  <template v-else-if="item.component == 'upload'">
@@ -219,9 +217,10 @@ export default {
219
217
  let current = obj
220
218
  // 遍历路径并逐层查找
221
219
  for (let i = 0; i < keys.length; i++) {
222
- // 如果当前层级不存在,则创建该层级对象
223
- if (current[keys[i]] === undefined) {
224
- current[keys[i]] = i === keys.length - 1 ? defaultValue : {} // 如果是最后一个层级,设为默认值,否则创建空对象
220
+ // 如果当前层级不存在或为 null,则创建该层级对象
221
+ if (current === null || current === undefined || current[keys[i]] === undefined) {
222
+ current = current || {}
223
+ current[keys[i]] = i === keys.length - 1 ? defaultValue : {}
225
224
  }
226
225
  // 否则,继续向下查找
227
226
  current = current[keys[i]]
@@ -6,6 +6,7 @@
6
6
  </el-tooltip>
7
7
  <!-- 切换加密/解密按钮 -->
8
8
  <el-icon v-if="password" class="primary" @click="toggleEncryption"><el-icon-view /></el-icon>
9
+ <span v-if="append" class="text">{{ append }}</span>
9
10
  </span>
10
11
  </template>
11
12
 
@@ -14,6 +15,7 @@ export default {
14
15
  props: {
15
16
  modelValue: { type: [String, Array, Boolean], default: '' }, // 传入的字符串或数组
16
17
  width: { type: String, default: '' },
18
+ append: { type: String, default: '' },
17
19
  password: { type: Boolean, default: false } // 是否需要加密显示
18
20
  },
19
21
  data() {