VisualOptionsModal.vue
2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script lang="ts" setup>
import { ref, unref } from 'vue';
import {
WidgetComponentType,
schemasMap,
VisualOptionParams,
visualOptionField,
Gradient,
} from '../config/visualOptions';
import { useForm, BasicForm } from '/@/components/Form';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { ComponentInfo } from '/@/api/dataBoard/model';
import { computed } from '@vue/reactivity';
const emit = defineEmits(['close', 'register']);
const props = defineProps<{
value?: string;
}>();
const recordId = ref('');
const getSchemas = computed(() => {
return schemasMap.get((props.value as WidgetComponentType) || 'text-component-1');
});
const [registerForm, method] = useForm({
showActionButtonGroup: false,
labelWidth: 120,
baseColProps: {
span: 12,
},
});
const [register, { closeModal }] = useModalInner(
(data: { recordId: string; componentInfo: ComponentInfo }) => {
recordId.value = data.recordId;
const gradientInfo = data.componentInfo?.gradientInfo || [];
let gradientRecord = {};
if (gradientInfo && gradientInfo.length) {
const first = gradientInfo.find((item) => item.key === Gradient.FIRST);
const second = gradientInfo.find((item) => item.key === Gradient.SECOND);
const third = gradientInfo.find((item) => item.key === Gradient.THIRD);
gradientRecord = {
[visualOptionField.FIRST_PHASE_COLOR]: first?.color,
[visualOptionField.FIRST_PHASE_VALUE]: first?.value,
[visualOptionField.SECOND_PHASE_COLOR]: second?.color,
[visualOptionField.SECOND_PHASE_VALUE]: second?.value,
[visualOptionField.THIRD_PHASE_COLOR]: third?.color,
[visualOptionField.THIRD_PHASE_VALUE]: third?.value,
};
}
method.setFieldsValue({ ...(data.componentInfo || {}), ...gradientRecord });
}
);
const handleGetValue = () => {
const value = method.getFieldsValue();
emit('close', unref(recordId), transformValue(value));
};
const transformValue = (value: Partial<VisualOptionParams>) => {
return {
fontColor: value.fontColor || null,
icon: value.icon || null,
iconColor: value.iconColor || null,
unit: value.unit || null,
gradientInfo: [
{ key: Gradient.FIRST, value: value.firstPhaseValue, color: value.firstPhaseColor },
{ key: Gradient.SECOND, value: value.secondPhaseValue, color: value.secondPhaseColor },
{ key: Gradient.THIRD, value: value.thirdPhaseValue, color: value.thirdPhaseColor },
],
};
};
const handleClose = () => {
handleGetValue();
closeModal();
};
</script>
<template>
<BasicModal
v-bind="$attrs"
destroy-on-close
@register="register"
@ok="handleClose"
title="选项"
width="40%"
>
<BasicForm class="form" @register="registerForm" :schemas="getSchemas" />
</BasicModal>
</template>
<style scoped>
.form:deep(.ant-input-number) {
width: 100%;
}
</style>