feat(tag): add beforeDelete props (#52)

This commit is contained in:
Kagol 2023-03-13 15:40:44 +08:00 committed by GitHub
parent a872c07fa5
commit 23eae8510a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 2 deletions

View File

@ -0,0 +1,54 @@
<template>
<div>
<p>
<tiny-switch v-model="beforeDeleteValue"></tiny-switch>
before-change 返回 {{ beforeDeleteValue }} {{ beforeDeleteText }}
<br>
</p>
<tiny-tag v-for="tag in tags" :key="'tiny-tag1-' + tag.name" closable :type="tag.type" @close="close(tag)" :before-delete="beforeDelete">{{ tag.name }}</tiny-tag>
</div>
</template>
<script>
import { Tag, Switch } from '@opentiny/vue'
export default {
components: {
TinyTag: Tag,
TinySwitch: Switch
},
data() {
return {
tags: [
{ name: '标签一', type: '' },
{ name: '标签二', type: 'success' },
{ name: '标签三', type: 'info' },
{ name: '标签四', type: 'warning' },
{ name: '标签五', type: 'danger' }
],
beforeDeleteValue: false
}
},
computed: {
beforeDeleteText() {
return this.beforeDeleteValue ? '可执行 close 事件,点击删除图标可以删除标签' : '将拦截 close 事件的执行,点击删除图标将无法删除标签'
}
},
methods: {
close(tag) {
this.tags.splice(this.tags.indexOf(tag), 1)
},
beforeDelete(done) {
setTimeout(() => {
this.beforeDeleteValue && done()
})
}
}
}
</script>
<style scoped>
.tiny-tag + .tiny-tag {
margin-left: 10px;
}
</style>

View File

@ -0,0 +1,20 @@
<div class="demo-header">
<p class="overviewicon">
<span class="wapi-form-tag"/>
</p>
## Tag 标签
<nova-uxlink widget-name="Tag"></nova-uxlink>
Tag 标签组件,用于标记事物的属性和维度
</div>
### 删除前的回调
<p>before-delete 回调函数会暂停 close 事件的执行,回调函数内执行 done 参数方法的时候才是真正执行 close 事件的时候。</p>
<nova-demo-view link="tag/before-delete"></nova-demo-view>
<br>
<nova-attributes link="tag"></nova-attributes>

View File

@ -4238,6 +4238,10 @@
{
"path": "/tag/tag-events",
"name": "事件"
},
{
"path": "/tag/before-delete",
"name": "删除前的回调"
}
]
},

View File

@ -1305,6 +1305,11 @@ export default [
meta: { title: '其他组件-Tag 标签-事件', lang: 'zh-CN', sign: 'component' },
component: () => import(/* webpackChunkName: 'v3-tag' */ './docs/zh-CN/tag/tag-events.md')
},
{
path: 'tag/before-delete',
meta: { title: '其他组件-Tag 标签-删除前的回调', lang: 'zh-CN', sign: 'component' },
component: () => import(/* webpackChunkName: 'v3-tag' */ './docs/zh-CN/tag/before-delete.md')
},
{
path: 'textpopup',
meta: { title: '其他组件-TextPopup 输入框', lang: 'zh-CN', sign: 'component' },

View File

@ -28,7 +28,8 @@ export default {
type: String,
default: 'light',
validator: (value) => ~['dark', 'light', 'plain'].indexOf(value)
}
},
beforeDelete: Function
},
setup(props, context) {
return $setup({ props, context, template })

View File

@ -19,7 +19,7 @@ export default {
IconClose: iconClose()
},
emits: ['click', 'close'],
props: [...props, 'text', 'closable', 'type', 'hit', 'disabled', 'color', 'size', 'effect'],
props: [...props, 'text', 'closable', 'type', 'hit', 'disabled', 'color', 'size', 'effect', 'beforeDelete'],
setup(props, context) {
return setup({ props, context, renderless, api, h })
},