|
@@ -0,0 +1,85 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div class="status-color-rules-editor">
|
|
|
|
|
+ <div v-for="(rule, index) in modelValue" :key="index" class="status-color-rule">
|
|
|
|
|
+ <el-input
|
|
|
|
|
+ :model-value="rule.value"
|
|
|
|
|
+ placeholder="匹配值"
|
|
|
|
|
+ @update:model-value="updateRule(index, 'value', $event)" />
|
|
|
|
|
+ <el-input
|
|
|
|
|
+ :model-value="rule.label"
|
|
|
|
|
+ placeholder="显示文字(可选)"
|
|
|
|
|
+ @update:model-value="updateRule(index, 'label', $event)" />
|
|
|
|
|
+ <div class="status-color-rule__actions">
|
|
|
|
|
+ <el-color-picker
|
|
|
|
|
+ :model-value="rule.color"
|
|
|
|
|
+ @update:model-value="updateRule(index, 'color', $event || '#909399')" />
|
|
|
|
|
+ <el-button type="danger" text @click="removeRule(index)">删除</el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <el-button class="w-1/1" plain type="primary" @click="addRule">新增状态</el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script setup lang="ts">
|
|
|
|
|
+import type { IStatusColorRule } from '@/components/mt-edit/store/types'
|
|
|
|
|
+import { ElButton, ElColorPicker, ElInput } from 'element-plus'
|
|
|
|
|
+
|
|
|
|
|
+const props = withDefaults(
|
|
|
|
|
+ defineProps<{
|
|
|
|
|
+ modelValue?: IStatusColorRule[]
|
|
|
|
|
+ }>(),
|
|
|
|
|
+ {
|
|
|
|
|
+ modelValue: () => []
|
|
|
|
|
+ }
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+const emit = defineEmits<{
|
|
|
|
|
+ 'update:modelValue': [value: IStatusColorRule[]]
|
|
|
|
|
+}>()
|
|
|
|
|
+
|
|
|
|
|
+const updateRule = (index: number, key: keyof IStatusColorRule, value: string) => {
|
|
|
|
|
+ const nextRules = props.modelValue.map((rule, ruleIndex) =>
|
|
|
|
|
+ ruleIndex === index ? { ...rule, [key]: value } : rule
|
|
|
|
|
+ )
|
|
|
|
|
+ emit('update:modelValue', nextRules)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const addRule = () => {
|
|
|
|
|
+ emit('update:modelValue', [
|
|
|
|
|
+ ...props.modelValue,
|
|
|
|
|
+ {
|
|
|
|
|
+ value: '',
|
|
|
|
|
+ label: '',
|
|
|
|
|
+ color: '#409eff'
|
|
|
|
|
+ }
|
|
|
|
|
+ ])
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const removeRule = (index: number) => {
|
|
|
|
|
+ emit(
|
|
|
|
|
+ 'update:modelValue',
|
|
|
|
|
+ props.modelValue.filter((_, ruleIndex) => ruleIndex !== index)
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+.status-color-rules-editor {
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.status-color-rule {
|
|
|
|
|
+ display: grid;
|
|
|
|
|
+ padding: 8px;
|
|
|
|
|
+ margin-bottom: 8px;
|
|
|
|
|
+ background: var(--el-fill-color-light);
|
|
|
|
|
+ border-radius: 4px;
|
|
|
|
|
+ gap: 6px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.status-color-rule__actions {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ justify-content: space-between;
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|