...
|
...
|
@@ -5,9 +5,9 @@ |
5
|
5
|
<Authority>
|
6
|
6
|
<a-button type="primary" @click="handleAdd"> 新增规则链 </a-button>
|
7
|
7
|
</Authority>
|
8
|
|
- <!-- <Authority>
|
9
|
|
- <a-button type="primary" @click="handleImport"> 导入规则链 </a-button>
|
10
|
|
- </Authority> -->
|
|
8
|
+ <Upload :show-upload-list="false" :customRequest="handleImport">
|
|
9
|
+ <Button type="primary" :loading="importLoading"> 导入规则链 </Button>
|
|
10
|
+ </Upload>
|
11
|
11
|
<!-- <Authority>
|
12
|
12
|
<Popconfirm
|
13
|
13
|
title="您确定要批量删除数据"
|
...
|
...
|
@@ -90,14 +90,18 @@ |
90
|
90
|
getRuleChinsList,
|
91
|
91
|
exportRuleChine,
|
92
|
92
|
settingRootChine,
|
|
93
|
+ importRuleChine,
|
|
94
|
+ createRuleChine,
|
93
|
95
|
} from '/@/api/ruleengine/ruleengineApi';
|
94
|
96
|
import { useModal } from '/@/components/Modal';
|
95
|
97
|
import { Authority } from '/@/components/Authority';
|
96
|
|
- import { Tag } from 'ant-design-vue';
|
|
98
|
+ import { Tag, Button, Upload } from 'ant-design-vue';
|
97
|
99
|
import { RuleChainModal } from './component/index';
|
98
|
100
|
import { useMessage } from '/@/hooks/web/useMessage';
|
99
|
101
|
import { usePermission } from '/@/hooks/web/usePermission';
|
100
|
102
|
import { useRouter } from 'vue-router';
|
|
103
|
+ import { ref } from 'vue';
|
|
104
|
+ import { isObject, isString } from '/@/utils/is';
|
101
|
105
|
// import { ChainDetailDrawer } from './chainDetail/index';
|
102
|
106
|
// import { useDrawer } from '/@/components/Drawer';
|
103
|
107
|
|
...
|
...
|
@@ -112,7 +116,7 @@ |
112
|
116
|
bordered: true,
|
113
|
117
|
showIndexColumn: false,
|
114
|
118
|
formConfig: {
|
115
|
|
- labelWidth: 120,
|
|
119
|
+ labelWidth: 70,
|
116
|
120
|
schemas: searchFormSchema,
|
117
|
121
|
},
|
118
|
122
|
fetchSetting: {
|
...
|
...
|
@@ -133,7 +137,7 @@ |
133
|
137
|
},
|
134
|
138
|
},
|
135
|
139
|
actionColumn: {
|
136
|
|
- width: 200,
|
|
140
|
+ width: 220,
|
137
|
141
|
title: '操作',
|
138
|
142
|
dataIndex: 'action',
|
139
|
143
|
slots: { customRender: 'action' },
|
...
|
...
|
@@ -183,7 +187,64 @@ |
183
|
187
|
// console.log(record, '详情');
|
184
|
188
|
// };
|
185
|
189
|
|
186
|
|
- // const handleImport = () => {};
|
|
190
|
+ const paseJSON = (string: string) => {
|
|
191
|
+ let data = null;
|
|
192
|
+ let flag = false;
|
|
193
|
+ try {
|
|
194
|
+ if (!isString(string)) return { flag: false, data };
|
|
195
|
+ data = JSON.parse(string);
|
|
196
|
+ flag = true;
|
|
197
|
+ if (!isObject(data)) flag = false;
|
|
198
|
+ } catch (error) {}
|
|
199
|
+ return { flag, data };
|
|
200
|
+ };
|
|
201
|
+
|
|
202
|
+ const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length;
|
|
203
|
+
|
|
204
|
+ const importLoading = ref<boolean>(false);
|
|
205
|
+ const handleImport = (data: { file: File }) => {
|
|
206
|
+ const fileReader = new FileReader();
|
|
207
|
+
|
|
208
|
+ fileReader.onload = async () => {
|
|
209
|
+ const { flag, data } = paseJSON(fileReader.result as string);
|
|
210
|
+ if (!flag) {
|
|
211
|
+ createMessage.warning('JSON解析失败,请导入正确的JSON~');
|
|
212
|
+ return;
|
|
213
|
+ }
|
|
214
|
+ try {
|
|
215
|
+ importLoading.value = true;
|
|
216
|
+
|
|
217
|
+ Object.keys(data || {}).forEach((key) => {
|
|
218
|
+ const value = (data || {})[key];
|
|
219
|
+ if (value && isEmptyObject(value)) {
|
|
220
|
+ (data || {})[key] = [];
|
|
221
|
+ }
|
|
222
|
+ });
|
|
223
|
+ const { ruleChain, metadata } = data as any;
|
|
224
|
+
|
|
225
|
+ const value = await createRuleChine(ruleChain);
|
|
226
|
+ const { id } = value;
|
|
227
|
+
|
|
228
|
+ const values = {
|
|
229
|
+ ruleChainId: id,
|
|
230
|
+ ...metadata,
|
|
231
|
+ };
|
|
232
|
+ const rules = await importRuleChine(values);
|
|
233
|
+
|
|
234
|
+ rules
|
|
235
|
+ ? createMessage.success('导入成功~')
|
|
236
|
+ : createMessage.error('JSON解析失败,请导入正确的JSON~');
|
|
237
|
+
|
|
238
|
+ rules && reload();
|
|
239
|
+ } catch (error) {
|
|
240
|
+ throw error;
|
|
241
|
+ } finally {
|
|
242
|
+ importLoading.value = false;
|
|
243
|
+ }
|
|
244
|
+ };
|
|
245
|
+
|
|
246
|
+ fileReader.readAsText(data.file, 'utf-8');
|
|
247
|
+ };
|
187
|
248
|
|
188
|
249
|
const handleExport = async (record: Recordable) => {
|
189
|
250
|
if (!record) return;
|
...
|
...
|
|