103103 <bk-form-item
104104 v-else
105105 :property =" `varList.${$index}.value`"
106- :rules =" rules.value "
107- ext-cls = " var-value-form-item "
106+ :rules =" getValueRules($index) "
107+ :icon-offset = " varList[$index].is_sensitive && !varList[$index].isNew ? 28 : 8 "
108108 >
109109 <div class =" input-wrapper" >
110110 <bk-input
113113 :password-icon =" []"
114114 type =" text"
115115 :ext-cls =" row.value === ENCRYPTED_PLACEHOLDER ? 'encrypted-input' : ''"
116- @input = " (value, event) => handleValueInput( row, event, value )"
116+ @focus = " handleValueFocus( row)"
117117 @keydown =" (value, event) => handleKeyDown(`descriptionInput${$index}`, event)"
118118 ></bk-input >
119119 <i
@@ -288,18 +288,6 @@ export default {
288288 // 批量编辑模式
289289 isBatchEditing: false ,
290290 rules: {
291- value: [
292- {
293- required: true ,
294- message: this .$t (' VALUE是必填项' ),
295- trigger: ' blur' ,
296- },
297- {
298- max: 2048 ,
299- message: this .$t (' 不能超过2048个字符' ),
300- trigger: ' blur' ,
301- },
302- ],
303291 description: [
304292 {
305293 max: 200 ,
@@ -378,6 +366,25 @@ export default {
378366 return baseRules;
379367 },
380368
369+ // 动态生成value的校验规则
370+ getValueRules (index ) {
371+ const currentRow = this .formData .varList [index];
372+ const isSensitiveAndNotNew = currentRow? .is_sensitive && ! currentRow? .isNew ;
373+ const baseRules = [
374+ {
375+ required: true ,
376+ message: this .$t (' VALUE是必填项' ),
377+ trigger: isSensitiveAndNotNew ? ' change' : ' blur' ,
378+ },
379+ {
380+ max: 2048 ,
381+ message: this .$t (' 不能超过2048个字符' ),
382+ trigger: ' blur' ,
383+ },
384+ ];
385+ return baseRules;
386+ },
387+
381388 // 校验KEY是否重复
382389 validateDuplicateKey (value , index ) {
383390 if (! value) return true ;
@@ -408,12 +415,9 @@ export default {
408415 this .formData .varList = [... this .filteredVarList ];
409416 },
410417
411- // 处理输入事件,特殊按钮清空输入框
412- handleValueInput (row , event ) {
413- if (! row .is_sensitive || row .isNew ) {
414- return ;
415- }
416- if (row .value .startsWith (this .ENCRYPTED_PLACEHOLDER .substring (0 , 5 ))) {
418+ // 聚焦后清空加密占位符
419+ handleValueFocus (row ) {
420+ if (row .is_sensitive && ! row .isNew && row .value === this .ENCRYPTED_PLACEHOLDER ) {
417421 row .value = ' ' ;
418422 }
419423 },
@@ -690,7 +694,7 @@ export default {
690694 }
691695 i .paasng - undo {
692696 position: absolute;
693- right: 10px ;
697+ right: 8px ;
694698 top: 50 % ;
695699 transform: translateY (- 50 % );
696700 font- size: 16px ;
@@ -702,9 +706,6 @@ export default {
702706 }
703707 }
704708 }
705- .var - value- form- item .is - error .input - wrapper i .paasng - undo {
706- right: 28px ;
707- }
708709 .key - wrapper {
709710 display: flex;
710711 align- items: center;
0 commit comments