Skip to content

Commit c1a4c04

Browse files
authored
Merge pull request #67 from WeBankFinTech/branch_bertcai
Branch bertcai
2 parents 1123d88 + 9895007 commit c1a4c04

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

docs/.vitepress/components/BTagsPanel/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ app.use(BTagsPanel);
2020

2121
--USEDISABLED
2222

23+
### 双击编辑标签
24+
允许通过双击标签编辑标签
25+
26+
--USEEDITABLED
27+
2328
### 长度限制
2429
支持限制单标签长度,样例设置标签最大长度为8,设置展示当前输入长度。
2530
--USElIMIT
@@ -50,6 +55,7 @@ app.use(BTagsPanel);
5055
| effect | 主题,可选值:dark、light、plain | string|light|
5156
| type | 类型,可选值:default、success、info、warning、danger | string|default|
5257
| disabled | 是否不可编辑 | boolean|false|
58+
| editabled | 是否支持双击标签编辑标签内容 | boolean|false|
5359
| maxlength | 单标签最大长度 | number|25|
5460
| showWordLimit | 是否显示输入内容长度统计 | boolean|false|
5561
| regex | 是否自定义输入标签校验 | string|''|
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<BTagsPanel v-model:tags="tags" :editabled="true"></BTagsPanel>
3+
<br>
4+
当前tag列表:{{ tags }}
5+
</template>
6+
<script setup lang="ts">
7+
import { ref } from 'vue';
8+
import { BTagsPanel } from '@fesjs/traction-widget';
9+
10+
const tags = ref<string[]>(['默认标签1', '默认标签2']);
11+
12+
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fesjs/traction-widget",
3-
"version": "1.12.5",
3+
"version": "1.12.6",
44
"description": "集合大型中台项目使用到的通用组件和工具函数",
55
"scripts": {
66
"docs:dev": "npm run build && node docs/.vitepress/scripts/generate-doc.js && vitepress dev docs",

packages/traction-widget/components/TagsPanel/TagsPanel.vue

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
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
8898
const emit = defineEmits(['update:tags']);
8999
const { 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
91126
const showTagInput = ref<boolean>(false);
92127
93128
const tempTagInput = ref<string>('');
94129
const 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
}

packages/traction-widget/components/TagsPanel/style/index.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
width: 100px;
1212
}
1313

14+
.input-in-tag {
15+
margin-right: 8px;
16+
margin-bottom: 8px;
17+
}
18+
1419
.button-nef-tag {
1520
margin-right: 16px;
1621
}

0 commit comments

Comments
 (0)