11<template >
22 <div :class =" prefixCls" class =" wd-tags-panel" >
3- <FTag v-for =" tag in tags" :key =" tag" :closable =" !disabled" @close =" deleteTag(tag)" :size =" size" :type =" type" :effect =" effect" >
4- <FEllipsis :content =" tag" style =" max-width : 240px " >
5- </FEllipsis >
6- </FTag >
3+ <div v-for =" (tag,index) in tags" :key =" index" >
4+ <FTag v-if =" !showTagInputArray[index]" @dblclick =" startEdit(index)" :closable =" !disabled" @close =" deleteTag(index)" :size =" size" :type =" type" :effect =" effect" >
5+ <FEllipsis :content =" tag" style =" max-width : 240px " >
6+ </FEllipsis >
7+ </FTag >
8+ <FInput v-else :ref =" (el) => { if (el) editTagInputRefs[index] = el as any }" v-model =" editTempTagInput" class =" input-in-tag input-nef-tag" size =" small"
9+ :maxlength =" maxlength" :showWordLimit =" showWordLimit" @keydown.escape =" cancelEdit(index)" @keyup.enter =" commitEdit(index)" @blur =" commitEdit(index)" >
10+ </FInput >
11+ </div >
712 <FInput v-if =" showTagInput" ref =" tagInputRef" v-model =" tempTagInput" class =" input-nef-tag" size =" small"
813 :maxlength =" maxlength" :showWordLimit =" showWordLimit" @keyup.enter =" addNewTag" @blur =" addNewTag" >
914 </FInput >
@@ -62,6 +67,11 @@ const props = defineProps({
6267 type: Boolean ,
6368 default: false
6469 },
70+ // 是否可双击编辑标签
71+ editabled: {
72+ type: Boolean ,
73+ default: false
74+ },
6575 // 尺寸,可选值:small、middle、large
6676 size: {
6777 type: String ,
@@ -87,18 +97,42 @@ const props = defineProps({
8797// eslint-disable-next-line no-undef
8898const emit = defineEmits ([' update:tags' ]);
8999const { datasource } = useFormModel (props , emit , [' tags' ]);
100+ const showTagInputArray = ref (datasource .tags .map (() => false ));
101+ const editTagInputRefs = ref <InstanceType <typeof FInput >[]>([] as any []);
102+ const editTempTagInput = ref <string >(' ' );
103+
104+ // 开始编辑
105+ const startEdit = (index : number ) => {
106+ if (! props .editabled ) return ;
107+ editTempTagInput .value = datasource .tags [index ];
108+ showTagInputArray .value .splice (index , 1 , true );
109+ nextTick (() => {
110+ editTagInputRefs .value [index ].focus ();
111+ });
112+ };
113+
114+ // 提交编辑
115+ const commitEdit = (index : number ) => {
116+ const newText = editTempTagInput .value ;
117+ showTagInputArray .value .splice (index , 1 , false );
118+ datasource .tags .splice (index , 1 , newText );
119+ };
120+
121+ // 取消编辑
122+ const cancelEdit = (index : number ) => {
123+ showTagInputArray .value .splice (index , 1 , false );
124+ };
90125
91126const showTagInput = ref <boolean >(false );
92127
93128const tempTagInput = ref <string >(' ' );
94129const currentInstance = getCurrentInstance ();
95- const deleteTag = async (tag : string ) => {
96- const index = datasource .tags .indexOf (tag );
130+ const deleteTag = async (index : number ) => {
97131 datasource .tags .splice (index , 1 );
98132 console .log (datasource .tags );
99133 await currentInstance ?.proxy ?.$forceUpdate ();
100134};
101- const notNull = (value : string ) => {
135+ const notNull = (value : string ) => { /* */
102136 if (! value ) {
103137 return false ;
104138 }
0 commit comments