EditDataSet.vue 35 KB

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