EditDataSet.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="dialogFormVisibleTitle"
  5. :visible.sync="visib"
  6. :close-on-click-modal="false"
  7. :before-close="closeDialog"
  8. width="65%"
  9. >
  10. <el-form
  11. ref="form"
  12. :model="formData"
  13. :rules="formRules"
  14. size="small"
  15. label-width="130px"
  16. >
  17. <el-row :gutter="10">
  18. <el-col
  19. v-if="this.setType == 'sql'"
  20. :xs="24"
  21. :sm="20"
  22. :md="8"
  23. :lg="8"
  24. :xl="8"
  25. >
  26. <el-form-item label="数据源" prop="sourceCode">
  27. <el-select
  28. v-model.trim="formData.sourceCode"
  29. class="organisation"
  30. size="mini"
  31. @change="changeSource"
  32. >
  33. <el-option
  34. v-for="item in sourceList"
  35. :key="item.sourceName"
  36. :label="item.sourceName"
  37. :value="item.sourceCode"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :xs="24" :sm="20" :md="7" :lg="7" :xl="7">
  43. <el-form-item label="数据集编码" prop="setCode">
  44. <el-input
  45. :disabled="updataDisabled"
  46. v-model.trim="formData.setCode"
  47. placeholder="唯一标识"
  48. size="mini"
  49. />
  50. </el-form-item>
  51. </el-col>
  52. <el-col :xs="24" :sm="20" :md="7" :lg="7" :xl="7">
  53. <el-form-item label="数据集名称" prop="setName">
  54. <el-input v-model.trim="formData.setName" size="mini" />
  55. </el-form-item>
  56. </el-col>
  57. <el-col :xs="24" :sm="20" :md="22" :lg="22" :xl="22">
  58. <el-form-item label="数据集描述">
  59. <el-input v-model.trim="formData.setDesc" size="mini" />
  60. </el-form-item>
  61. </el-col>
  62. </el-row>
  63. <el-row v-if="this.setType == 'sql'" :gutter="10">
  64. <el-col
  65. :xs="24"
  66. :sm="20"
  67. :md="22"
  68. :lg="22"
  69. :xl="22"
  70. class="code-mirror-form"
  71. >
  72. <el-form-item label="查询SQL">
  73. <div class="codemirror">
  74. <monaco-editor
  75. v-model.trim="formData.dynSentence"
  76. language="sql"
  77. style="height: 500px"
  78. />
  79. </div>
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <el-row v-if="this.setType == 'http'">
  84. <el-form-item label="请求路径">
  85. <el-input
  86. placeholder="请输入请求路径..."
  87. v-model="httpForm.apiUrl"
  88. class="input-with-select"
  89. >
  90. <el-select
  91. v-model="httpForm.method"
  92. slot="prepend"
  93. placeholder="请选择"
  94. >
  95. <el-option label="GET" value="GET"></el-option>
  96. <el-option label="POST" value="POST"></el-option>
  97. <el-option label="PUT" value="PUT"></el-option>
  98. <el-option label="DELETE" value="DELETE"></el-option>
  99. </el-select>
  100. </el-input>
  101. </el-form-item>
  102. <el-form-item label="请求头">
  103. <el-input
  104. v-model.trim="httpForm.header"
  105. size="mini"
  106. placeholder="请输入请求头..."
  107. />
  108. </el-form-item>
  109. <el-form-item label="请求体">
  110. <el-input
  111. v-model.trim="httpForm.body"
  112. size="mini"
  113. placeholder="请输入请求体..."
  114. />
  115. </el-form-item>
  116. </el-row>
  117. <el-row :gutter="10">
  118. <el-col :xs="24" :sm="20" :md="22" :lg="22" :xl="22">
  119. <el-form label-width="100px" class="demo-ruleForm">
  120. <el-tabs
  121. v-model.trim="tabsActiveName"
  122. type="card"
  123. @tab-click="handleClickTabs"
  124. >
  125. <el-tab-pane label="查询参数" name="first">
  126. <el-button
  127. v-if="tableData.length == 0"
  128. type="text"
  129. size="small"
  130. @click="addRow()"
  131. >添加
  132. </el-button>
  133. <el-table :data="tableData" border style="width: 100%">
  134. <el-table-column
  135. align="center"
  136. label="序号"
  137. type="index"
  138. min-width="80"
  139. />
  140. <el-table-column label="参数名" align="center">
  141. <template slot-scope="scope">
  142. <el-input
  143. v-model.trim="tableData[scope.$index].paramName"
  144. :disabled="
  145. tableData[scope.$index].paramName == 'pageSize' ||
  146. tableData[scope.$index].paramName == 'pageNumber'
  147. "
  148. />
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="描述" align="center">
  152. <template slot-scope="scope">
  153. <el-input
  154. v-model.trim="tableData[scope.$index].paramDesc"
  155. />
  156. </template>
  157. </el-table-column>
  158. <el-table-column label="数据类型" align="center">
  159. <template slot-scope="scope">
  160. <el-input
  161. v-model.trim="tableData[scope.$index].paramType"
  162. />
  163. </template>
  164. </el-table-column>
  165. <el-table-column label="示例值" align="center">
  166. <template slot-scope="scope">
  167. <el-input
  168. v-model.trim="tableData[scope.$index].sampleItem"
  169. />
  170. </template>
  171. </el-table-column>
  172. <el-table-column label="校验" width="220" align="center">
  173. <template slot-scope="scope">
  174. <el-checkbox
  175. v-model="tableData[scope.$index].mandatory"
  176. @change="Mandatory(scope.$index)"
  177. >必选
  178. </el-checkbox>
  179. <el-button
  180. type="primary"
  181. icon="el-icon-plus"
  182. @click="permissionClick(scope.row, scope.$index)"
  183. >
  184. 高级规则
  185. </el-button>
  186. </template>
  187. </el-table-column>
  188. <el-table-column label="操作" width="200" align="center">
  189. <template slot-scope="scope">
  190. <el-button
  191. type="text"
  192. size="small"
  193. @click.native.prevent="
  194. cutOutRow(scope.$index, tableData)
  195. "
  196. >删除
  197. </el-button>
  198. <el-button
  199. type="text"
  200. size="small"
  201. @click="addRow(scope.row)"
  202. >追加
  203. </el-button>
  204. </template>
  205. </el-table-column>
  206. </el-table>
  207. </el-tab-pane>
  208. <el-tab-pane label="数据转换" name="second">
  209. <template>
  210. <div class="filterWrapper">
  211. <div class="filterTable">
  212. <div
  213. v-for="(item, index) in itemFilterList"
  214. :key="index"
  215. class="filterBox"
  216. >
  217. <div class="box">
  218. <Dictionary
  219. v-model="item.transformType"
  220. :updata-dict="item.transformType"
  221. :dict-key="'TRANSFORM_TYPE'"
  222. @change="changeForm"
  223. />
  224. <el-button
  225. type="text"
  226. class="reduceFilter"
  227. icon="el-icon-close"
  228. @click="reduceFilter(item)"
  229. />
  230. <el-button
  231. v-if="
  232. item.transformType == 'js' ||
  233. item.transformType == 'dict' ||
  234. item.transformType == 'javaBean'
  235. "
  236. type="text"
  237. class="editor"
  238. icon="el-icon-edit"
  239. @click="filterScriptBtn(item)"
  240. />
  241. </div>
  242. <el-button
  243. type="text"
  244. class="font-icon-right"
  245. icon="el-icon-right"
  246. />
  247. </div>
  248. <el-dialog
  249. :title="dialogTitle"
  250. :visible.sync="dialogSwitchVisible"
  251. :close-on-click-modal="false"
  252. width="60%"
  253. min-height="400px"
  254. append-to-body
  255. >
  256. <div
  257. v-if="
  258. isItemFilterType.transformType == 'js' ||
  259. isItemFilterType.transformType == 'javaBean'
  260. "
  261. >
  262. <div class="codemirror">
  263. <!-- //自定义高级规则? -->
  264. <monaco-editor
  265. v-if="jsScriptVisible"
  266. v-model.trim="transformScript"
  267. language="javascript"
  268. style="height: 500px"
  269. />
  270. </div>
  271. </div>
  272. <div v-else>
  273. <div
  274. v-for="(item, index) in tableData2"
  275. :key="index"
  276. >
  277. <label>字典项名称:</label>
  278. <el-input
  279. v-model.trim="item.name"
  280. size="small"
  281. style="width: 25%"
  282. />
  283. <el-button
  284. type="danger"
  285. size="small"
  286. plain
  287. icon="el-icon-delete"
  288. @click="delAllDict(index, tableData2)"
  289. />
  290. <el-table
  291. :data="item.children"
  292. border
  293. style="width: 80%"
  294. >
  295. <el-table-column label="key" width="180">
  296. <template slot-scope="scope">
  297. <el-input
  298. v-model.trim="
  299. item.children[scope.$index].name
  300. "
  301. />
  302. </template>
  303. </el-table-column>
  304. <el-table-column label="值">
  305. <template slot-scope="scope">
  306. <el-input
  307. v-model.trim="
  308. item.children[scope.$index].value
  309. "
  310. />
  311. </template>
  312. </el-table-column>
  313. <el-table-column
  314. label="操作"
  315. width="150px"
  316. align="center"
  317. >
  318. <template slot-scope="scope">
  319. <el-button
  320. type="success"
  321. circle
  322. plain
  323. icon="el-icon-plus"
  324. @click="
  325. addDict(scope.$index, item.children)
  326. "
  327. />
  328. <el-button
  329. type="danger"
  330. circle
  331. plain
  332. icon="el-icon-delete"
  333. @click="
  334. delDict(scope.$index, item.children)
  335. "
  336. />
  337. </template>
  338. </el-table-column>
  339. </el-table>
  340. </div>
  341. <el-button type="success" @click="addAllDict()"
  342. >新增
  343. </el-button>
  344. </div>
  345. <span slot="footer" class="dialog-footer">
  346. <el-button @click="dialogSwitchVisible = false"
  347. >取消</el-button
  348. >
  349. <el-button
  350. type="primary"
  351. @click="filterScriptConfirm"
  352. >保存</el-button
  353. >
  354. </span>
  355. </el-dialog>
  356. <!-- //添加数据转换 -->
  357. <div
  358. class="addFilter"
  359. disabled="true"
  360. @click="addFilter"
  361. >
  362. <i class="el-icon-plus" /><span>新增</span>
  363. </div>
  364. </div>
  365. </div>
  366. </template>
  367. </el-tab-pane>
  368. <el-tab-pane label="测试预览" name="third">
  369. <div style="max-height: 400px; overflow: auto">
  370. <vue-json-editor
  371. v-model="cols"
  372. :show-btns="false"
  373. :mode="'code'"
  374. lang="zh"
  375. @json-change="onJsonChange"
  376. @json-save="onJsonSave"
  377. />
  378. </div>
  379. </el-tab-pane>
  380. </el-tabs>
  381. </el-form>
  382. </el-col>
  383. </el-row>
  384. </el-form>
  385. <div slot="footer" class="dialog-footer">
  386. <el-button @click="closeDialog">取消</el-button>
  387. <el-button type="primary" @click="submit('form')">保存</el-button>
  388. </div>
  389. </el-dialog>
  390. <el-dialog
  391. :title="title"
  392. :visible.sync="dialogPermissionVisible"
  393. :close-on-click-modal="false"
  394. width="60%"
  395. >
  396. <div class="codemirror">
  397. <!-- //自定义高级规则? -->
  398. <monaco-editor
  399. v-model.trim="validationRules"
  400. language="javascript"
  401. style="height: 500px"
  402. />
  403. </div>
  404. <span slot="footer" class="dialog-footer">
  405. <el-button type="warning" @click="testResultset">测试</el-button>
  406. <el-button type="primary" @click="dialogValidationRules"
  407. >保存</el-button
  408. >
  409. <el-button @click="dialogPermissionVisible = false">关闭</el-button>
  410. </span>
  411. </el-dialog>
  412. </div>
  413. </template>
  414. <script>
  415. import {
  416. queryAllDataSourceSet,
  417. verificationSet,
  418. testTransformSet,
  419. dataSetPreview,
  420. addDataSet,
  421. editDataSet
  422. } from "@/api/report";
  423. import Dictionary from "@/components/Dictionary/index";
  424. import { codemirror } from "vue-codemirror"; // 引入codeMirror全局实例
  425. import "codemirror/mode/sql/sql.js";
  426. import "codemirror/mode/javascript/javascript.js";
  427. import "codemirror/lib/codemirror.css"; // 核心样式
  428. import "codemirror/theme/cobalt.css"; // 引入主题后还需要在 options 中指定主题才会生效
  429. import vueJsonEditor from "vue-json-editor";
  430. import MonacoEditor from "./MonacoEditor.vue";
  431. import { validateEngOrNum } from "@/utils/validate";
  432. export default {
  433. name: "Support",
  434. components: { Dictionary, codemirror, vueJsonEditor, MonacoEditor },
  435. props: {
  436. visib: {
  437. required: true,
  438. type: Boolean,
  439. default: false
  440. },
  441. dataSet: {
  442. required: false,
  443. type: Object,
  444. default: () => {
  445. return "";
  446. }
  447. }
  448. },
  449. data() {
  450. return {
  451. data: [],
  452. listLoading: true,
  453. permission: {
  454. add: ["admin", "alipayConfig:add"],
  455. edit: ["admin", "alipayConfig:edit"],
  456. del: ["admin", "datasource:del"]
  457. },
  458. // 内部真实的内容
  459. code: "",
  460. // 默认配置
  461. optionsSql: {
  462. mode: "text/x-sql",
  463. tabSize: 2, // 缩进格式
  464. // theme: 'cobalt', // monokai主题,对应主题库 JS 需要提前引入
  465. lineNumbers: true, // 显示行号
  466. line: true,
  467. styleActiveLine: true, // 高亮选中行
  468. hintOptions: {
  469. completeSingle: true // 当匹配只有一项的时候是否自动补全
  470. }
  471. },
  472. optionsJavascript: {
  473. mode: "text/javascript",
  474. tabSize: 2, // 缩进格式
  475. // theme: 'cobalt', // monokai主题,对应主题库 JS 需要提前引入
  476. lineNumbers: true, // 显示行号
  477. line: true,
  478. styleActiveLine: true, // 高亮选中行
  479. hintOptions: {
  480. completeSingle: true // 当匹配只有一项的时候是否自动补全
  481. }
  482. },
  483. selectedList: [],
  484. clickType: "",
  485. formData: {},
  486. // 弹框默认隐藏
  487. dialogFormVisible: false,
  488. dialogFormVisibleTitle: "",
  489. dialogPermissionVisible: false,
  490. dialogSwitchVisible: false,
  491. jsScriptVisible: false,
  492. permissionTextarea: "",
  493. isItemFilterType: "", // 选中的转换类型id
  494. itemFilterList: [
  495. {
  496. transformType: "js",
  497. transformScript: ``
  498. }
  499. ],
  500. transformScript: `function dataTransform(data){\n\t//自定义脚本内容\n\treturn data;\n}`,
  501. itemFilterScriptId: "",
  502. title: "自定义高级规则",
  503. totalCount: 0,
  504. totalPage: 0,
  505. params: {
  506. pageNumber: 1,
  507. pageSize: 10,
  508. helpTitle: "",
  509. enabled: null,
  510. helpCategory: "",
  511. order: "DESC",
  512. sort: "update_time"
  513. },
  514. formRules: {
  515. setName: [
  516. { required: true, message: "数据集名称必填", trigger: "blur" }
  517. ],
  518. setCode: [
  519. { required: true, message: "数据集编码必填", trigger: "blur" },
  520. { validator: validateEngOrNum, trigger: "blur" }
  521. ],
  522. sourceCode: [
  523. { required: true, message: "数据源必选", trigger: "change" }
  524. ]
  525. },
  526. sourceList: [],
  527. validationRules: "",
  528. tabsActiveName: "first",
  529. cols: [],
  530. tableData: [
  531. {
  532. paramName: "",
  533. paramDesc: "",
  534. paramType: "",
  535. sampleItem: "",
  536. mandatory: true,
  537. requiredFlag: 1,
  538. validationRules: `function verification(data){\n\t//自定义脚本内容\n\t//可返回true/false单纯校验键入的data正确性\n\t//可返回文本,实时替换,比如当前时间等\n\t//return "2099-01-01 00:00:00";\n\treturn true;\n}`
  539. }
  540. ],
  541. isRowData: {},
  542. tableData2: [],
  543. dialogTitle: "js脚本填写",
  544. isShowPagination: false,
  545. updataDisabled: false,
  546. dialogCaseResult: false,
  547. caseResultTitle: "",
  548. caseResultContent: null,
  549. testMassageCode: null,
  550. query: {
  551. setName: "",
  552. setCode: ""
  553. },
  554. setType: "", //数据集类型,主要用于区分http addSql addHttp edit
  555. httpForm: {
  556. //http数据源相关数据
  557. apiUrl: "",
  558. method: "GET",
  559. header: '{"Content-Type":"application/json;charset=UTF-8"}',
  560. body: ""
  561. },
  562. //待删除
  563. dictionaryOptions: [], // 数据源类型
  564. list: null,
  565. basicDialog: false,
  566. dialogForm: {
  567. sourceName: "",
  568. sourceCode: "",
  569. sourceType: "",
  570. sourceDesc: "",
  571. sourceConfig: ""
  572. },
  573. dataLink: [],
  574. rules: {
  575. sourceType: [
  576. { required: true, message: "数据集名称必选", trigger: "change" }
  577. ],
  578. sourceCode: [
  579. { required: true, message: "数据集编码必填", trigger: "blur" }
  580. ],
  581. sourceName: [
  582. { required: true, message: "数据源名称必选", trigger: "blur" }
  583. ]
  584. },
  585. value: "",
  586. testReplyCode: null
  587. };
  588. },
  589. methods: {
  590. // 编辑数据集,获取单条数据详情
  591. async addOrEditDataSet(row, type) {
  592. this.setType = type;
  593. if (type == "http" && row.dynSentence) {
  594. this.httpForm = JSON.parse(row.dynSentence);
  595. }
  596. //获取数据源下拉
  597. const { code, data } = await queryAllDataSourceSet();
  598. if (code != "200") return;
  599. this.sourceList = data;
  600. this.dialogFormVisible = true;
  601. this.tabsActiveName = "first";
  602. this.testMassageCode = null;
  603. if (row.id) {
  604. this.updataDisabled = true;
  605. this.dialogFormVisibleTitle = "编辑数据集";
  606. dataSetPreview(row).then(data => {
  607. this.formData = data.data;
  608. if (
  609. data.data.dataSetParamDtoList != null ||
  610. data.data.dataSetParamDtoList.length > 0
  611. ) {
  612. this.tableData = data.data.dataSetParamDtoList;
  613. let count = 0;
  614. this.tableData.find((value, i) => {
  615. if (
  616. value.paramName === "pageNumber" ||
  617. value.paramName === "pageSize"
  618. ) {
  619. count++;
  620. }
  621. if (value.requiredFlag == 1) {
  622. this.tableData[i].mandatory = true;
  623. } else {
  624. this.tableData[i].mandatory = false;
  625. }
  626. });
  627. if (count === 2) {
  628. this.isShowPagination = true;
  629. } else {
  630. this.isShowPagination = false;
  631. }
  632. } else {
  633. this.tableData = [];
  634. this.isShowPagination = false;
  635. }
  636. if (data.data.dataSetTransformDtoList !== null) {
  637. this.itemFilterList = data.data.dataSetTransformDtoList;
  638. } else {
  639. this.itemFilterList = [];
  640. }
  641. this.itemFilterList.forEach((item, i) => {
  642. if (item.transformType == "dict") {
  643. const extendObj = JSON.parse(item.transformScript);
  644. const extendArry = [];
  645. for (const i in extendObj) {
  646. const children = [];
  647. for (const y in extendObj[i]) {
  648. children.push({ name: y, value: extendObj[i][y] });
  649. }
  650. extendArry.push({ name: i, children: children });
  651. }
  652. this.tableData2 = extendArry;
  653. }
  654. });
  655. });
  656. } else {
  657. this.dialogFormVisibleTitle = "新增数据集";
  658. this.updataDisabled = false;
  659. this.formData = {
  660. setName: "",
  661. setCode: "",
  662. setDesc: "",
  663. sourceCode: "",
  664. dynSentence: ""
  665. };
  666. this.tableData = [];
  667. this.itemFilterList = [];
  668. this.isShowPagination = false;
  669. }
  670. },
  671. changeForm(val) {
  672. if (!val) {
  673. this.dialogSwitchVisible = false;
  674. this.jsScriptVisible = false
  675. }
  676. },
  677. // 关闭模态框
  678. closeDialog() {
  679. this.$emit("handleClose");
  680. },
  681. onJsonChange(value) {},
  682. onJsonSave(value) {},
  683. handleClose(done) {
  684. this.dialogFormVisible = false;
  685. },
  686. isShowCaseResult(item) {
  687. this.dialogCaseResult = true;
  688. this.caseResultTitle = item.setName;
  689. this.caseResultContent = JSON.parse(item.caseResult);
  690. },
  691. // 测试预览
  692. async handleClickTabs(tab, event) {
  693. if (this.setType == "http") {
  694. //针对http数据源
  695. console.log("http数据集" + this.httpForm);
  696. this.formData.dynSentence = JSON.stringify(this.httpForm);
  697. }
  698. if (tab.paneName == "third") {
  699. const params = {
  700. sourceCode: this.formData.sourceCode,
  701. dynSentence: this.formData.dynSentence,
  702. dataSetParamDtoList: this.tableData,
  703. dataSetTransformDtoList: this.itemFilterList,
  704. setType: this.setType
  705. };
  706. const { code, data } = await testTransformSet(params);
  707. if (code != "200") return;
  708. this.cols = data.data;
  709. this.testMassageCode = code;
  710. }
  711. },
  712. // 必选
  713. Mandatory(val) {
  714. if (!this.tableData[val].mandatory) {
  715. this.tableData[val].requiredFlag = 0;
  716. } else {
  717. this.tableData[val].requiredFlag = 1;
  718. }
  719. },
  720. // 分页参数增加列
  721. changePagination() {
  722. if (this.isShowPagination) {
  723. this.tableData.push(
  724. {
  725. paramName: "pageNumber",
  726. paramDesc: "当前页",
  727. paramType: "int",
  728. sampleItem: "1",
  729. mandatory: true,
  730. requiredFlag: 1,
  731. validationRules: `function verification(data){\n\t//自定义脚本内容\n\treturn true;\n}`
  732. },
  733. {
  734. paramName: "pageSize",
  735. paramDesc: "条数",
  736. paramType: "int",
  737. sampleItem: "10",
  738. mandatory: true,
  739. requiredFlag: 1,
  740. validationRules: `function verification(data){\n\t//自定义脚本内容\n\treturn true;\n}`
  741. }
  742. );
  743. } else {
  744. this.tableData.forEach((item, i) => {
  745. if (item.paramName == "pageSize" || item.paramName == "pageNumber") {
  746. this.tableData.splice(i, 2);
  747. }
  748. });
  749. }
  750. },
  751. // js 脚本编辑
  752. async filterScriptBtn(item) {
  753. console.log(item);
  754. this.isItemFilterType = item;
  755. this.dialogSwitchVisible = true;
  756. this.jsScriptVisible = true
  757. if (item.transformType == "js") {
  758. this.itemFilterScriptId = item.itemFilterSort;
  759. const fnCont = `function dataTransform(data){\n\t//自定义脚本内容\n\treturn data;\n}`;
  760. this.transformScript = item.transformScript
  761. ? item.transformScript
  762. : fnCont;
  763. } else if (item.transformType == "dict") {
  764. } else if (item.transformType == "javaBean") {
  765. this.itemFilterScriptId = item.itemFilterSort;
  766. const fnCont = `package com;
  767. import com.alibaba.fastjson.JSONObject;
  768. import com.anjiplus.template.gaea.business.modules.datasettransform.service.IGroovyHandler;
  769. import java.util.List;
  770. /**
  771. * 建议在idea写好复制整个类到此处,位置report-core/src/test/java/com/DemoGroovyHandler.java
  772. */
  773. public class DemoGroovyHandler implements IGroovyHandler {
  774. @Override
  775. public List<JSONObject> transform(List<JSONObject> data) {
  776. return data;
  777. }
  778. }`;
  779. this.transformScript = item.transformScript
  780. ? item.transformScript
  781. : fnCont;
  782. }
  783. },
  784. // js 脚本编辑确定
  785. filterScriptConfirm() {
  786. const arr = this.toObject(this.tableData2);
  787. this.itemFilterList.forEach((el, index) => {
  788. if (el.transformType == "dict") {
  789. el.transformScript = JSON.stringify(arr);
  790. } else {
  791. el.transformScript = this.transformScript;
  792. }
  793. });
  794. this.dialogSwitchVisible = false;
  795. },
  796. addFilter() {
  797. let obj = {};
  798. this.tableData2 = [];
  799. if (this.itemFilterList.length == 0) {
  800. obj = {
  801. transformType: "",
  802. transformScript: "",
  803. itemFilterSort: 1
  804. };
  805. } else {
  806. obj = {
  807. transformType: "",
  808. transformScript: "",
  809. itemFilterSort: this.itemFilterList.length + 1
  810. };
  811. }
  812. this.itemFilterList.push(obj);
  813. },
  814. // 删除filter
  815. reduceFilter(item) {
  816. if (this.itemFilterList.length > 0) {
  817. let index = this.itemFilterList.indexOf(item);
  818. if (index > -1) {
  819. this.itemFilterList.splice(index, 1);
  820. }
  821. }
  822. },
  823. // --查询参数-----------------///////////////////////////////////////////////////////////////////////
  824. permissionClick(row, index) {
  825. this.title = "自定义高级规则";
  826. if (this.isRowData.sampleItem != "") {
  827. this.isRowData = row;
  828. const fnCont = `function verification(data){\n\t//自定义脚本内容\n\t//可返回true/false单纯校验键入的data正确性\n\t//可返回文本,实时替换,比如当前时间等\n\t//return "2099-01-01 00:00:00";\n\treturn true;\n}`;
  829. this.validationRules = row.validationRules
  830. ? row.validationRules
  831. : fnCont;
  832. }
  833. this.dialogPermissionVisible = true;
  834. },
  835. dialogValidationRules() {
  836. this.isRowData.validationRules = this.validationRules;
  837. this.dialogPermissionVisible = false;
  838. },
  839. // 字典项 增删改
  840. addAllDict() {
  841. this.tableData2.push({
  842. name: "",
  843. children: [{ name: "", value: "" }]
  844. });
  845. },
  846. addDict(index, item) {
  847. item.push({ name: "", value: "" });
  848. },
  849. delAllDict(index, rows) {
  850. rows.splice(index, 1);
  851. },
  852. delDict(index, rows) {
  853. if (index == 0) {
  854. this.$message.error("至少保留一条");
  855. return;
  856. }
  857. rows.splice(index, 1);
  858. },
  859. // -------------------------------------------------------------------------------
  860. // 数据源下拉切换
  861. changeSource() {},
  862. // 自定义高级规则
  863. async testResultset() {
  864. this.isRowData.validationRules = this.validationRules;
  865. console.log(this.isRowData, "12345678");
  866. const { code, message, data } = await verificationSet(this.isRowData);
  867. if (code == "200") {
  868. if (data) {
  869. this.$message.success("返回结果:" + data);
  870. } else {
  871. this.$message.warning("当前示例值校验不通过");
  872. }
  873. } else {
  874. this.$message.error(message);
  875. }
  876. },
  877. // 删除
  878. cutOutRow(index, rows) {
  879. rows.splice(index, 1);
  880. },
  881. // 追加
  882. addRow(index, row) {
  883. this.tableData.push({
  884. paramName: "",
  885. paramDesc: "",
  886. paramType: "",
  887. sampleItem: "",
  888. mandatory: true,
  889. requiredFlag: 1,
  890. validationRules: `function verification(data){\n\t//自定义脚本内容\n\t//可返回true/false单纯校验键入的data正确性\n\t//可返回文本,实时替换,比如当前时间等\n\t//return "2099-01-01 00:00:00";\n\treturn true;\n}`
  891. });
  892. },
  893. async submit(formName) {
  894. if (this.setType == "http") {
  895. //针对http数据源
  896. console.log("http数据集" + this.httpForm);
  897. this.formData.dynSentence = JSON.stringify(this.httpForm);
  898. }
  899. this.formData.setType = this.setType;
  900. this.$refs[formName].validate(async (valid, obj) => {
  901. if (valid) {
  902. if (this.testMassageCode == 200) {
  903. this.formData.dataSetParamDtoList = this.tableData;
  904. this.formData.dataSetTransformDtoList = this.itemFilterList;
  905. this.formData.caseResult = JSON.stringify(this.cols);
  906. if (this.dialogFormVisibleTitle === "新增数据集") {
  907. const { code } = await addDataSet(this.formData);
  908. if (code != "200") return;
  909. this.$emit("refreshList");
  910. this.closeDialog();
  911. } else {
  912. const { code } = await editDataSet(this.formData);
  913. if (code != "200") return;
  914. this.$emit("refreshList");
  915. this.closeDialog();
  916. }
  917. } else {
  918. this.$message.error("请先测试预览,操作成功后便可保存!");
  919. return;
  920. }
  921. } else {
  922. return;
  923. }
  924. });
  925. },
  926. toObject(val) {
  927. const objfirst = {};
  928. const objSecond = {};
  929. val.forEach(el => {
  930. el.name ? (objfirst[el.name] = el.children) : "";
  931. });
  932. for (const key in objfirst) {
  933. const newObj = {};
  934. objfirst[key].map(ev => {
  935. Object.assign(newObj, { [ev.name]: ev.value });
  936. });
  937. objSecond[key] = newObj;
  938. }
  939. return objSecond;
  940. }
  941. }
  942. };
  943. </script>
  944. <style lang="scss" scoped>
  945. .code-mirror-form {
  946. /deep/ .el-form-item__content {
  947. height: 200px;
  948. overflow: hidden;
  949. }
  950. }
  951. .my-editor {
  952. height: 400px;
  953. div.jsoneditor {
  954. height: 400px !important;
  955. }
  956. }
  957. .title {
  958. width: 100%;
  959. display: inline-block;
  960. text-align: left;
  961. }
  962. .addSwitch {
  963. ul {
  964. list-style: none;
  965. margin: 0px;
  966. li {
  967. width: 200px;
  968. height: 60px;
  969. padding: 10px;
  970. border: 1px solid #aaa;
  971. float: left;
  972. margin-right: 10px;
  973. text-align: center;
  974. line-height: 40px;
  975. cursor: pointer;
  976. &.add,
  977. &:hover {
  978. border: 1px solid #3385ff;
  979. color: #3385ff;
  980. }
  981. }
  982. }
  983. }
  984. .filterWrapper {
  985. position: relative;
  986. }
  987. .filterTable {
  988. display: flex;
  989. flex-direction: row;
  990. flex-wrap: wrap;
  991. border: 1px solid #dcdfe6;
  992. border-radius: 4px;
  993. padding: 5px 15px 25px 15px;
  994. }
  995. .filterWrapper .addFilter {
  996. cursor: pointer;
  997. width: 150px;
  998. height: 50px;
  999. border-radius: 3px;
  1000. border: 1px solid #67c23a;
  1001. margin-top: 20px;
  1002. background: #e4f7da;
  1003. padding-left: 24px;
  1004. }
  1005. .filterWrapper .addFilter i {
  1006. font-size: 20px;
  1007. color: #67c23a;
  1008. margin-top: 16px;
  1009. margin-left: 16px;
  1010. }
  1011. .filterWrapper .addFilter span {
  1012. color: #67c23a;
  1013. margin-left: 5px;
  1014. font-size: 18px;
  1015. }
  1016. .filterBox {
  1017. width: 182px;
  1018. position: relative;
  1019. margin-top: 20px;
  1020. display: flex;
  1021. flex-direction: row;
  1022. }
  1023. .filterBox .box {
  1024. width: 150px;
  1025. height: 50px;
  1026. text-align: center;
  1027. position: relative;
  1028. background: #e0e8ff;
  1029. border-radius: 3px;
  1030. border: 1px solid #b8caff;
  1031. float: left;
  1032. padding: 5px 20px;
  1033. }
  1034. .filterBox .box .reduceFilter {
  1035. width: 10px;
  1036. height: 10px;
  1037. position: absolute;
  1038. right: 4px;
  1039. top: 4px;
  1040. cursor: pointer;
  1041. }
  1042. .filterBox .box .editor {
  1043. width: 12px;
  1044. height: 13px;
  1045. position: absolute;
  1046. left: -5px;
  1047. top: 5px;
  1048. cursor: pointer;
  1049. }
  1050. .filterBox .rightIcon {
  1051. width: 45px;
  1052. height: 19px;
  1053. position: absolute;
  1054. right: 10px;
  1055. top: 15px;
  1056. }
  1057. .filterTextarea /deep/ .el-textarea__inner {
  1058. min-height: 300px !important;
  1059. }
  1060. .filterBox .code-selected {
  1061. width: 70%;
  1062. margin-top: 4px;
  1063. }
  1064. .filterBox /deep/ .el-input--suffix .el-input__inner {
  1065. background: #f4f7ff;
  1066. border-radius: 3px;
  1067. border: 1px solid #b8caff;
  1068. color: #89a3ee;
  1069. }
  1070. .font-icon-right {
  1071. line-height: 35px;
  1072. font-size: 30px;
  1073. }
  1074. .popover-box {
  1075. width: 100%;
  1076. height: 220px;
  1077. overflow-y: auto;
  1078. padding: 10px;
  1079. }
  1080. </style>