-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(data integration): extract edit topic list
- Loading branch information
1 parent
eae1d52
commit 0ad364a
Showing
5 changed files
with
110 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<template> | ||
<ul class="form-topic-list-vertical"> | ||
<li class="topic-item" v-for="(item, $index) in topics" :key="$index"> | ||
<el-form-item :prop="`${prop}.${$index}`" :rules="rules"> | ||
<el-input v-model="topics[$index]" /> | ||
<div class="btn-container vertical-align-center"> | ||
<el-button | ||
class="btn-del" | ||
:icon="Delete" | ||
:disabled="(!allowEmpty && topics.length <= 1) || !$hasPermission('delete')" | ||
@click="delTopic($index)" | ||
/> | ||
<el-button | ||
v-if="$index === topics.length - 1" | ||
class="btn-add" | ||
:icon="Plus" | ||
:disabled="!$hasPermission('post')" | ||
@click="addTopic" | ||
/> | ||
</div> | ||
</el-form-item> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { Delete, Plus } from '@element-plus/icons-vue' | ||
import type { FormItemRule } from 'element-plus' | ||
import { computed, defineProps, defineEmits } from 'vue' | ||
const props = defineProps<{ | ||
modelValue: string[] | ||
allowEmpty?: boolean | ||
rules?: Array<FormItemRule> | ||
prop?: string | ||
}>() | ||
const emit = defineEmits<{ | ||
(e: 'update:modelValue', value: string[]): void | ||
}>() | ||
const topics = computed({ | ||
get() { | ||
return props.modelValue | ||
}, | ||
set(value) { | ||
emit('update:modelValue', value) | ||
}, | ||
}) | ||
const addTopic = () => { | ||
topics.value.push('') | ||
} | ||
const delTopic = (index: number) => { | ||
topics.value.splice(index, 1) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters