index.vue
4.6 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
<BasicModal
v-bind="$attrs"
width="55rem"
@register="register"
:title="getTitle"
@ok="handleSubmit"
>
<CollapseContainer title="键名筛选器" class="border mb-8">
<BasicTable :resizeHeightOffset="200" @register="registerTable" :dataSource="getTableApiData">
<template #toolbar>
<a-button type="primary" @click="handleAddKey"> 新增键名筛选器 </a-button>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '编辑',
icon: 'clarity:note-edit-line',
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
},
},
]"
/>
</template>
</BasicTable>
</CollapseContainer>
<CollapseContainer title="筛选器预览" class="border mb-8">
<BasicTable :resizeHeightOffset="200" :columns="columnsView" :dataSource="detailData" />
</CollapseContainer>
<BasicForm :showResetButton="false" :showSubmitButton="false" @register="registerForm" />
</BasicModal>
<KeyValueModal @register="registerModal" @success="handleSuccess" />
</template>
<script lang="ts">
import { defineComponent, ref, computed, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form';
import { formSchema, columns, DescDetailSchema, columnsView } from './config';
import { CollapseContainer } from '/@/components/Container/index';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import KeyValueModal from './cpns/index.vue';
export default defineComponent({
name: 'DetailTemplate',
components: {
KeyValueModal,
BasicModal,
BasicForm,
CollapseContainer,
BasicTable,
TableAction,
},
emits: ['success', 'register', 'getAllFieldsRule', 'getLastAllFieldsRule'],
setup(_, { emit }) {
const getTableApiData: any = ref([]);
const detailData: any = ref([]);
const receiveData: any = ref(null);
const lastValues: any = ref(null);
const isUpdate = ref(true);
const [registerForm, { getFieldsValue }] = useForm({
labelWidth: 120,
schemas: formSchema,
});
const [registerModal, { openModal }] = useModal();
const getTitle = computed(() => (!unref(isUpdate) ? '添加报警规则条件' : '编辑报警规则条件'));
const [register, { closeModal }] = useModalInner((data) => {
isUpdate.value = !!data?.isUpdate;
});
const [registerTable, { reload }] = useTable({
title: '键名筛选器',
columns,
bordered: true,
showIndexColumn: false,
actionColumn: {
width: 180,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
},
});
const handleSubmit = () => {
if (unref(isUpdate.value)) {
const values = getFieldsValue();
getTableApiData.value.push(values);
detailData.value.push(values);
}
lastValues.value = getFieldsValue();
emit('getAllFieldsRule', receiveData.value, lastValues.value);
closeModal();
};
const handleAddKey = () => {
openModal(true, {
isUpdate: false,
});
};
const handleEdit = (record: Recordable) => {
openModal(true, {
isUpdate: true,
record,
});
};
const handleDelete = (record: Recordable) => {
console.log(record);
getTableApiData.value.splice(0, 1);
detailData.value.splice(0, 1);
reload();
};
const handleSuccess = (v) => {
receiveData.value = v;
setTimeout(() => {
doFunc();
}, 10);
};
const doFunc = () => {
getTableApiData.value.push(receiveData.value);
detailData.value.push(receiveData.value);
};
return {
columnsView,
DescDetailSchema,
detailData,
getTableApiData,
handleSuccess,
handleEdit,
handleDelete,
registerModal,
registerTable,
handleAddKey,
registerForm,
handleSubmit,
register,
getTitle,
};
},
});
</script>