EditDataSource.vue
7.22 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<template>
<el-dialog
title="项目基础配置"
width="50%"
:close-on-click-modal="false"
center
:visible.sync="visib"
:before-close="closeDialog"
>
<el-form
ref="userForm"
:model="dialogForm"
:rules="rules"
size="small"
label-width="100px"
>
<el-row :gutter="10">
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
<el-form-item label="数据源类型" prop="sourceType">
<el-select
v-model.trim="dialogForm.sourceType"
placeholder="请选择"
clearable
@change="selectChange"
>
<el-option
v-for="item in dictionaryOptions"
:key="item.id"
:label="item.text"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
<el-form-item label="数据源编码" prop="sourceCode">
<el-input
:disabled="updataDisabled"
v-model.trim="dialogForm.sourceCode"
placeholder="唯一标识"
/>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
<el-form-item label="数据源名称" prop="sourceName">
<el-input v-model.trim="dialogForm.sourceName" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="24" :lg="24" :xl="24">
<el-form-item label="数据源描述">
<el-input
v-model.trim="dialogForm.sourceDesc"
type="textarea"
:autosize="{ minRows: 2, maxRows: 4 }"
/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col
v-for="(data, index) in dataLink"
:key="index"
:xs="24"
:sm="24"
:md="24"
:lg="24"
:xl="24"
>
<el-form-item :label="data.labelValue">
<el-input v-model.trim="data.value" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="closeDialog">取消</el-button>
<el-button type="warning" @click="test">测试</el-button>
<el-button type="primary" @click="UserConfirm('userForm')"
>确定</el-button
>
</div>
</el-dialog>
</template>
<script>
import {
testConnection,
reportDataSourceDetail,
reportDataSourceAdd,
reportDataSourceUpdate
} from "@/api/reportDataSource";
import { getDictList } from "@/api/dict-data"; // 获取数据字典
import Dictionary from "@/components/Dictionary/index";
import { validateEngOrNum } from "@/utils/validate";
export default {
name: "Support",
components: { Dictionary },
props: {
visib: {
required: true,
type: Boolean,
default: false
},
dataSource: {
required: false,
type: Object,
default: () => {
return "";
}
}
},
data() {
return {
dictionaryOptions: [], // 数据源类型
selectedList: [],
clickType: "",
formData: {},
list: null,
totalCount: 0,
totalPage: 0,
listLoading: true,
// 弹框默认隐藏
dialogFormVisible: false,
basicDialog: false,
params: {
sourceName: "",
sourceCode: "",
sourceType: "",
pageNumber: 1,
pageSize: 10,
order: "DESC",
sort: "update_time"
},
dialogForm: {
sourceName: "",
sourceCode: "",
sourceType: "",
sourceDesc: "",
sourceConfig: ""
},
dataLink: [],
rules: {
sourceType: [
{ required: true, message: "数据集名称必选", trigger: "change" }
],
sourceCode: [
{ required: true, message: "数据集编码(sName)必填", trigger: "blur" },
{ validator: validateEngOrNum, trigger: "blur" }
],
sourceName: [
{ required: true, message: "数据源名称必选", trigger: "blur" }
]
},
value: "",
updataDisabled: false,
testReplyCode: null
};
},
methods: {
async setDataSource() {
this.dialogForm = {
sourceName: "",
sourceCode: "",
sourceType: "",
sourceDesc: "",
sourceConfig: ""
};
//根据dataSourceId判断新增还是编辑
if (this.dataSource.id) {
const { code, data } = await reportDataSourceDetail(this.dataSource);
if (code != "200") return;
this.dialogForm = data;
const newSourceType = this.dialogForm;
let newDataLink = [];
this.dictionaryOptions.map(item => {
if (item.id == newSourceType.sourceType) {
newDataLink = JSON.parse(item.extend);
let sourceConfigJson = JSON.parse(newSourceType.sourceConfig);
for (let i = 0; i < newDataLink.length; i++) {
newDataLink[i].value = sourceConfigJson[newDataLink[i].label];
}
}
});
this.dataLink = newDataLink;
}
},
// 获取数据字典
async getSystem() {
const { code, data } = await getDictList("SOURCE_TYPE");
if (code != "200") return;
this.dictionaryOptions = data;
this.dialogForm.sourceType = this.dictionaryOptions[0].text;
this.dataLink = JSON.parse(this.dictionaryOptions[0].extend);
this.setDataSource();
},
// 关闭模态框
closeDialog() {
this.$emit("handleClose");
},
// 提交
async UserConfirm(formName) {
const newList = {};
this.dataLink.forEach(item => {
newList[item.label] = item.value;
});
this.dialogForm.sourceConfig = JSON.stringify(newList);
this.$refs[formName].validate(async (valid, obj) => {
if (valid) {
if (this.testReplyCode != "200") {
this.$message.error("测试结果为成功后方可保存!");
return;
}
if (this.dialogForm.id == undefined) {
const { code } = await reportDataSourceAdd(this.dialogForm);
if (code != "200") return;
this.$emit("refreshList");
} else {
const { code } = await reportDataSourceUpdate(this.dialogForm);
if (code != "200") return;
this.$emit("refreshList");
}
this.closeDialog();
} else {
return;
}
});
},
selectChange(val) {
this.dataLink = [];
const extendJSON = this.dictionaryOptions.find(function(obj) {
return obj.id == val;
});
this.dataLink = JSON.parse(extendJSON.extend);
},
// 测试
test() {
const newList = {};
this.dataLink.forEach(item => {
newList[item.label] = item.value;
});
this.dialogForm.sourceConfig = JSON.stringify(newList);
testConnection(this.dialogForm).then(data => {
if (data.code == "200") {
this.testReplyCode = data.code;
this.$message({
message: "测试成功!",
type: "success"
});
} else {
this.testReplyCode = null;
}
});
}
}
};
</script>