lw-cdp-ui 1.2.22 → 1.2.24

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.
@@ -376,6 +376,16 @@ export default {
376
376
  }
377
377
  }
378
378
 
379
+ .title-name {
380
+ font-size: 18px;
381
+ font-weight: bold;
382
+ margin-bottom: 10px;
383
+ margin-top: 25px;
384
+ border-top: 10px solid #f5f7fa;
385
+ padding-top: 20px;
386
+ }
387
+
388
+
379
389
  .form-mini {
380
390
  display: flex;
381
391
  width: 100%;
@@ -390,14 +400,6 @@ export default {
390
400
  width: 100px;
391
401
  }
392
402
 
393
- .title-name {
394
- font-size: 18px;
395
- font-weight: bold;
396
- margin-bottom: 10px;
397
- margin-top: 25px;
398
- border-top: 10px solid #f5f7fa;
399
- padding-top: 20px;
400
- }
401
403
 
402
404
  :deep(.form-item-name-null) {
403
405
  > .el-form-item__label {
@@ -0,0 +1,388 @@
1
+ <template>
2
+ <!-- 间隔标题 -->
3
+ <div v-if="item.component == 'divider'"
4
+ class="title-name title-name-divider"
5
+ :id="'divider-' + index"
6
+ :data-index="index">
7
+ {{ item.label }}
8
+ <el-tooltip v-if="item.tips">
9
+ <template #content>
10
+ <span style="max-width: 300px; display: inline-block;">
11
+ {{ item.tips }}
12
+ </span>
13
+ </template>
14
+ <el-icon><el-icon-question-filled /></el-icon>
15
+ </el-tooltip>
16
+ </div>
17
+
18
+ <!-- 表单内容 -->
19
+ <el-form-item v-else
20
+ :class="{ 'form-item-name-null': !item?.label }"
21
+ :prop="getPropName(item)"
22
+ :rules="rulesHandle(item)">
23
+ <template #label>
24
+ {{ item.label }}
25
+ <el-tooltip v-if="item.tips"
26
+ :raw-content="item?.rawContent"
27
+ :content="item.tips">
28
+ <el-icon><el-icon-question-filled /></el-icon>
29
+ </el-tooltip>
30
+ </template>
31
+
32
+ <!-- input -->
33
+ <template v-if="item.component == 'input'">
34
+ <template
35
+ v-if="item?.options?.prepend">{{ item?.options.prepend }}</template>
36
+ <textToPassword v-model="objItem.value"
37
+ :password="item?.options?.password" />
38
+ <template
39
+ v-if="item?.options?.append">{{ item?.options.append }}</template>
40
+
41
+ </template>
42
+ <!-- upload -->
43
+ <template v-else-if="item.component == 'upload'">
44
+ <template v-for="(_item, _index) in objItem?.options.items"
45
+ :key="_index">
46
+ <lw-upload v-model="_item.value"
47
+ :height="item.height"
48
+ :width="item.width"
49
+ :maxSize="_item.maxSize"
50
+ :accept="_item.accept"
51
+ :title="_item.label"
52
+ :parseData="item.parseData"
53
+ :disabled="true"
54
+ :multiple="_item?.multiple"
55
+ :limit="_item?.limit"
56
+ :returnFile="_item?.returnFile"
57
+ :tip="_item?.tip"
58
+ :apiObj="item.apiObj"></lw-upload>
59
+
60
+ </template>
61
+ </template>
62
+ <!-- checkbox -->
63
+ <template v-else-if="item.component == 'checkbox'">
64
+ <template v-for="(_item, _index) in objItem?.options.items"
65
+ :key="_index">{{ getKeyToLabel(_item.value, objItem?.options.items) }}</template>
66
+ </template>
67
+ <!-- checkboxGroup 、select、radio -->
68
+ <template
69
+ v-else-if="item.component == 'checkboxGroup' || item.component == 'select' || item.component == 'radio'">
70
+ {{ getKeyToLabel(objItem.value, item?.options.items) }}
71
+ </template>
72
+
73
+ <!-- switch -->
74
+ <template v-else-if="item.component == 'switch'">
75
+ {{ objItem.value ? item?.options?.true || '是' : item?.options?.false || '否' }}
76
+ </template>
77
+ <!-- treeSelect -->
78
+ <template v-else-if="item.component == 'treeSelect'">
79
+ <el-tree-select v-model="objItem.value"
80
+ :props="item?.options?.props"
81
+ disabled
82
+ :node-Key="item?.options?.nodeKey"
83
+ :multiple="item?.options?.multiple"
84
+ :check-Strictly="item?.options?.checkStrictly"
85
+ :data="item?.options?.items"></el-tree-select>
86
+
87
+ </template>
88
+ <!-- cascader -->
89
+ <template v-else-if="item.component == 'cascader'">
90
+ <el-cascader v-model="objItem.value"
91
+ style="width: 100%;"
92
+ :props="item?.options?.props"
93
+ :separator="item?.options?.separator"
94
+ disabled
95
+ :options="item?.options.items"
96
+ clearable></el-cascader>
97
+ </template>
98
+ <!-- date -->
99
+ <template v-else-if="item.component == 'date'">
100
+ {{ dayjs(objItem.value).format(item?.options.valueFormat || 'YYYY-MM-DD HH:mm:ss') }}
101
+ </template>
102
+ <!-- number -->
103
+ <template v-else-if="item.component == 'number'">
104
+ <el-input-number v-model="objItem.value"
105
+ :disabled="item?.options?.disabled"
106
+ :min="item?.options?.min"
107
+ :max="item?.options?.max"
108
+ :step="item?.options?.step || 1"
109
+ :precision="item?.options?.precision"
110
+ :placeholder="item?.options?.placeholder || ''"
111
+ :controls-position="item?.options?.controlsPosition || 'right'">
112
+ <template v-if="item?.options?.suffix"
113
+ #suffix>
114
+ <span>{{ item?.options.suffix }}</span>
115
+ </template>
116
+ </el-input-number>
117
+ </template>
118
+ <!-- color -->
119
+ <template v-else-if="item.component == 'color'">
120
+ <el-color-picker v-model="objItem.value"
121
+ disabled />
122
+ </template>
123
+ <!-- rate -->
124
+ <template v-else-if="item.component == 'rate'">
125
+ <el-rate style="margin-top: 6px;"
126
+ v-model="objItem.value"
127
+ disabled></el-rate>
128
+ </template>
129
+ <!-- slider -->
130
+ <template v-else-if="item.component == 'slider'">
131
+ <el-slider v-model="objItem.value"
132
+ :marks="item?.options.marks"
133
+ disabled></el-slider>
134
+ </template>
135
+
136
+ <!-- tags -->
137
+ <template v-else-if="item.component == 'tags'">
138
+ <div class="tags-list">
139
+ <el-tag v-for="tag in objItem.value"
140
+ :key="tag">
141
+ {{ tag }}
142
+ </el-tag>
143
+ </div>
144
+ </template>
145
+
146
+ <!-- 没有组件是component值 就是插槽名称 -->
147
+ <template v-else>
148
+ <slot :name="item.component"
149
+ :itemCur="item"
150
+ :formCur="form">
151
+ <el-tag type="danger">[{{ item.component }}]
152
+ 没有这个默认组件也未自定义插槽内容</el-tag>
153
+ </slot>
154
+ </template>
155
+ <div v-if="item.message"
156
+ class="el-form-item-msg">{{ item.message }}</div>
157
+ </el-form-item>
158
+ </template>
159
+
160
+ <script>
161
+ import lwUpload from '../lwUpload'
162
+ import dayjs from 'dayjs'
163
+ import textToPassword from './textToPassword'
164
+ export default {
165
+ name: 'ViewItem',
166
+ data() {
167
+ return {
168
+ tagVisible: {},
169
+ dataForm: {},
170
+ objItem: {},
171
+ tagValue: ''
172
+ }
173
+ },
174
+ components: {
175
+ lwUpload,
176
+ textToPassword
177
+ },
178
+ props: {
179
+ item: {
180
+ type: Object,
181
+ default: () => { }
182
+ },
183
+ index: {
184
+ type: Number,
185
+ default: 0
186
+ },
187
+ form: {
188
+ type: Object,
189
+ default: () => { }
190
+ }
191
+ },
192
+ watch: {
193
+ item: {
194
+ handler(val) {
195
+ this.objItem = val
196
+ },
197
+ immediate: true,
198
+ deep: true
199
+ },
200
+ form: {
201
+ handler(val) {
202
+ if (this.item.component === 'checkbox' || this.item.component === 'upload') {
203
+ this.objItem.options?.items?.forEach((option) => {
204
+ option.value = this.flattenObject(this.form, option.name, option.value)
205
+ });
206
+ } else {
207
+ this.objItem.value = this.flattenObject(this.form, this.item.name, this.objItem.value)
208
+ }
209
+
210
+ },
211
+ immediate: true,
212
+ deep: true
213
+ },
214
+ objItem: {
215
+ handler(val) {
216
+ if (val.component === 'checkbox' || val.component === 'upload') {
217
+ val.options?.items?.forEach((option) => {
218
+ this.unflattenObject(this.form, option.name, option.value)
219
+ });
220
+ } else {
221
+ this.unflattenObject(this.form, val.name, val.value)
222
+ }
223
+ },
224
+ deep: true
225
+ },
226
+ },
227
+ methods: {
228
+ flattenObject(obj, key, defaultValue = '') {
229
+ if (!key || !obj) { return false }
230
+ const keys = key.split('.'); // 将路径拆分成数组
231
+
232
+ let current = obj;
233
+ // 遍历路径并逐层查找
234
+ for (let i = 0; i < keys.length; i++) {
235
+ // 如果当前层级不存在,则创建该层级对象
236
+ if (current[keys[i]] === undefined) {
237
+ current[keys[i]] = (i === keys.length - 1) ? defaultValue : {}; // 如果是最后一个层级,设为默认值,否则创建空对象
238
+ }
239
+ // 否则,继续向下查找
240
+ current = current[keys[i]];
241
+ }
242
+ return current;
243
+ },
244
+ unflattenObject(obj, path, value) {
245
+ if (!path || !obj) { return false }
246
+ const keys = path.split('.'); // 按点分隔路径
247
+
248
+ keys.forEach((key, index) => {
249
+ if (index === keys.length - 1) {
250
+ // 最后一级,直接赋值
251
+ obj[key] = value;
252
+ } else {
253
+ // 如果不存在该层级,创建空对象
254
+ if (!obj[key] || typeof obj[key] !== 'object') {
255
+ obj[key] = {};
256
+ }
257
+ obj = obj[key]; // 进入下一层
258
+ }
259
+ });
260
+
261
+ },
262
+ // prop NAME
263
+ getPropName(item) {
264
+ if (item.component == 'checkbox' || item.component == 'upload') {
265
+ return item?.options.items[0].name
266
+ } else {
267
+ return item.name
268
+ }
269
+ },
270
+ // 处理动态必填
271
+ rulesHandle(item) {
272
+ if (item.requiredHandle) {
273
+ try {
274
+ const requiredHandleFunc = new Function("form", `return ${item.requiredHandle.replace(/\$/g, "form")}`);
275
+ const exp = requiredHandleFunc(this.form);
276
+
277
+ const requiredRule = item.rules.find(t => 'required' in t);
278
+ if (requiredRule) {
279
+ requiredRule.required = exp;
280
+ }
281
+ } catch (error) {
282
+ console.error("Error requiredHandle function:", error);
283
+ }
284
+ }
285
+ return item.rules;
286
+ },
287
+ // key to label
288
+ getKeyToLabel(val, items = []) {
289
+ let item = items.find(item => { return item.value == val })
290
+ return item?.label || '--'
291
+ },
292
+ dayjs: dayjs
293
+ }
294
+ }
295
+ </script>
296
+
297
+
298
+ <style lang="scss" scoped>
299
+ :deep(.el-col) {
300
+ &:first-child {
301
+ .title-name {
302
+ border: 0;
303
+ padding-top: 25px;
304
+ margin-top: 0;
305
+ }
306
+ }
307
+ }
308
+
309
+ .title-name {
310
+ font-size: 18px;
311
+ font-weight: bold;
312
+ margin-bottom: 10px;
313
+ margin-top: 25px;
314
+ border-top: 10px solid #f5f7fa;
315
+ padding-top: 20px;
316
+ }
317
+
318
+ .form-mini {
319
+ display: flex;
320
+ width: 100%;
321
+ box-sizing: border-box;
322
+ }
323
+ .form-affix {
324
+ min-width: 130px;
325
+ padding-left: 20px;
326
+ }
327
+
328
+ .w-20 {
329
+ width: 100px;
330
+ }
331
+
332
+ :deep(.form-item-name-null) {
333
+ > .el-form-item__label {
334
+ display: none !important;
335
+ }
336
+ }
337
+ .affix-body {
338
+ background-color: var(--el-fill-color-light);
339
+ border: 1px solid var(--el-border-color-light);
340
+ margin: 0;
341
+ position: relative;
342
+ &::after {
343
+ content: "";
344
+ position: absolute;
345
+ left: -2px;
346
+ right: 0;
347
+ height: 16px;
348
+ background-color: #ffffff;
349
+ top: -17px;
350
+ }
351
+ .anchor-link {
352
+ padding: 0 20px;
353
+ height: var(--el-tabs-header-height);
354
+ box-sizing: border-box;
355
+ list-style: none;
356
+ font-size: var(--el-font-size-base);
357
+ font-weight: bold;
358
+ color: var(--el-text-color-secondary);
359
+ position: relative;
360
+ height: 40px;
361
+ display: inline-block;
362
+ line-height: 40px;
363
+ cursor: pointer;
364
+ border-left: 1px solid transparent;
365
+ border-right: 1px solid transparent;
366
+ }
367
+ .active {
368
+ color: var(--el-color-primary);
369
+ background-color: var(--el-bg-color-overlay);
370
+ border-bottom: 1px solid var(--el-bg-color-overlay);
371
+ border-right-color: var(--el-border-color);
372
+ border-left: 1px solid var(--el-border-color-light);
373
+ border-right: 1px solid var(--el-border-color-light);
374
+ &:first-child {
375
+ border-left: 1px solid var(--el-fill-color-light);
376
+ }
377
+ }
378
+ }
379
+
380
+ :deep(.el-tag) {
381
+ & + .button-new-tag {
382
+ margin-left: 10px;
383
+ }
384
+ & + .w-20 {
385
+ margin-left: 10px;
386
+ }
387
+ }
388
+ </style>
@@ -31,7 +31,23 @@
31
31
  <template v-for="(item, index) in config.formItems">
32
32
  <el-col :span="item.span || 24"
33
33
  v-if="!hideHandle(item)">
34
- <FormItem :item="item"
34
+ <ViewItem v-if="isView"
35
+ :item="item"
36
+ :form="form"
37
+ :index="index">
38
+ <!-- 没有组件是component值 就是插槽名称 -->
39
+ <template v-if="!['input', 'upload', 'checkbox', 'checkboxGroup', 'switch', 'select', 'treeSelect', 'cascader', 'date', 'number', 'radio', 'color', 'rate', 'slider','tags'].includes(item.component)"
40
+ v-slot:[item.component]>
41
+ <slot :name="item.component"
42
+ :itemCur="item"
43
+ :formCur="form">
44
+ <el-tag type="danger">[{{ item.component }}]
45
+ 没有这个默认组件也未自定义插槽内容</el-tag>
46
+ </slot>
47
+ </template>
48
+ </ViewItem>
49
+ <FormItem v-else
50
+ :item="item"
35
51
  :form="form"
36
52
  :index="index">
37
53
  <!-- 没有组件是component值 就是插槽名称 -->
@@ -47,7 +63,7 @@
47
63
  </FormItem>
48
64
  </el-col>
49
65
  </template>
50
- <el-col :span="24">
66
+ <el-col v-if="!isView" :span="24">
51
67
  <el-form-item>
52
68
  <slot>
53
69
  <el-button type="primary"
@@ -61,9 +77,11 @@
61
77
 
62
78
  <script>
63
79
  import FormItem from './FormItem'
80
+ import ViewItem from './ViewItem'
64
81
  export default {
65
82
  components: {
66
- FormItem
83
+ FormItem,
84
+ ViewItem
67
85
  },
68
86
  props: {
69
87
  modelValue: { type: Object, default: () => { } },
@@ -0,0 +1,61 @@
1
+ <template>
2
+ <span class="item-text"
3
+ :style="{width: textWidth}">
4
+ <!-- 根据加密状态显示加密或解密后的文本 -->
5
+ <span>{{ isEncrypted ? encryptedText : modelValue }}</span>
6
+ <!-- 切换加密/解密按钮 -->
7
+ <el-icon v-if="password"
8
+ class="primary"
9
+ @click="toggleEncryption"><el-icon-view /></el-icon>
10
+ </span>
11
+ </template>
12
+
13
+ <script>
14
+ export default {
15
+ props: {
16
+ modelValue: { type: String, default: '' }, // 传入的字符串
17
+ width: { type: String, default: '' },
18
+ password: { type: Boolean, default: false }, // 是否需要加密显示
19
+ },
20
+ data() {
21
+ return {
22
+ isEncrypted: this.password, // 根据传入的 password 值初始化加密状态
23
+ };
24
+ },
25
+ computed: {
26
+ encryptedText() {
27
+ // 将输入字符串加密成 *,长度与原字符串相同
28
+ return "*".repeat(this.modelValue.length);
29
+ },
30
+ textWidth() {
31
+ return this?.width ? `calc(100% - ${this.width} - 10px)` : "";
32
+ }
33
+ },
34
+ methods: {
35
+ toggleEncryption() {
36
+ // 切换加密和解密状态
37
+ this.isEncrypted = !this.isEncrypted;
38
+ // 如果是解密状态,可以更新父组件的值
39
+ if (!this.isEncrypted) {
40
+ this.$emit('update:modelValue', this.modelValue);
41
+ }
42
+ },
43
+ },
44
+ };
45
+ </script>
46
+ <style lang="scss" scoped>
47
+ .item-text {
48
+ display: inline-flex;
49
+ gap: 10px;
50
+ align-items: center;
51
+ span {
52
+ word-wrap: break-word;
53
+ word-break: break-all;
54
+ white-space: normal;
55
+ }
56
+ .primary{
57
+ cursor: pointer;
58
+ color: var(--el-color-primary);
59
+ }
60
+ }
61
+ </style>
@@ -324,13 +324,16 @@ export default {
324
324
  username: this.ruleForm.user,
325
325
  password: this.ruleForm.password,
326
326
  };
327
-
327
+ console.log(data)
328
328
  if (this.isEncryption) {
329
329
  const publicKey = await this.$api.auth.key()
330
- data = {
331
- username: this.encrypt(publicKey, this.ruleForm.user),
332
- password: this.encrypt(publicKey, this.ruleForm.password),
333
- };
330
+ console.log(publicKey)
331
+ if (publicKey) {
332
+ data = {
333
+ username: this.encrypt(publicKey, this.ruleForm.user),
334
+ password: this.encrypt(publicKey, this.ruleForm.password),
335
+ };
336
+ }
334
337
  }
335
338
 
336
339
  //获取token