ScriptEditForm.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. <template>
  2. <div
  3. v-loading="saveLoading"
  4. class="inner-container"
  5. :element-loading-text="saveText"
  6. >
  7. <el-scrollbar class="data-set-scrollbar">
  8. <div class="header">
  9. <el-page-header class="bs-el-page-header">
  10. <template slot="content">
  11. <div class="page-header">
  12. <div class="page-header-left">
  13. {{ !isEdit ? '脚本数据集详情' : dataForm.id ? '编辑脚本数据集' : '新增脚本数据集' }}
  14. </div>
  15. <div class="page-header-right">
  16. <el-button
  17. class="bs-el-button-default"
  18. @click="openNewWindow('https://www.yuque.com/chuinixiongkou/bigscreen/groovy_dataset')"
  19. >
  20. 帮助
  21. </el-button>
  22. <el-button
  23. v-if="isEdit"
  24. type="primary"
  25. @click="save('form')"
  26. >
  27. 保存
  28. </el-button>
  29. <el-button
  30. class="bs-el-button-default"
  31. @click="goBack"
  32. >
  33. 返回
  34. </el-button>
  35. </div>
  36. </div>
  37. </template>
  38. </el-page-header>
  39. </div>
  40. <el-row style="margin: 16px 16px 0;">
  41. <el-col :span="isEdit ? 16 : 24">
  42. <el-form
  43. ref="form"
  44. :model="dataForm"
  45. :rules="rules"
  46. label-width="120px"
  47. style="padding: 16px 16px 0;"
  48. class="bs-el-form"
  49. >
  50. <el-row :gutter="20">
  51. <el-col :span="12">
  52. <el-form-item
  53. label="数据集名称"
  54. prop="name"
  55. >
  56. <el-input
  57. v-model="dataForm.name"
  58. class="bs-el-input"
  59. clearable
  60. :disabled="!isEdit"
  61. />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="12">
  65. <el-form-item
  66. label="分组"
  67. prop="typeId"
  68. >
  69. <el-select
  70. ref="selectParentName"
  71. v-model="dataForm.typeId"
  72. class="bs-el-select"
  73. popper-class="bs-el-select"
  74. placeholder="请选择分组"
  75. clearable
  76. :disabled="!isEdit"
  77. filterable
  78. :filter-method="selectorFilter"
  79. @clear="clearType"
  80. @visible-change="setCurrentNode"
  81. >
  82. <el-option
  83. style="height: auto;padding: 0;"
  84. :label="typeName"
  85. :value="dataForm.typeId"
  86. >
  87. <div class="tree-box">
  88. <el-tree
  89. ref="categorySelectTree"
  90. :data="categoryData"
  91. node-key="id"
  92. :indent="0"
  93. :props="{ label: 'name', children: 'children' }"
  94. :default-expand-all="true"
  95. :highlight-current="true"
  96. :expand-on-click-node="false"
  97. class="bs-el-tree"
  98. :filter-node-method="treeFilter"
  99. @node-click="selectParentCategory"
  100. >
  101. <span
  102. slot-scope="{ data }"
  103. class="custom-tree-node"
  104. >
  105. <span>
  106. <i
  107. :class="data.children && data.children.length ? 'el-icon el-icon-folder' : 'el-icon el-icon-document'"
  108. />
  109. {{ data.name }}
  110. </span>
  111. </span>
  112. </el-tree>
  113. </div>
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. <el-row :gutter="20">
  120. <el-col :span="12">
  121. <el-form-item
  122. label="备注"
  123. prop="remark"
  124. >
  125. <el-input
  126. v-model="dataForm.remark"
  127. class="bs-el-input"
  128. :disabled="!isEdit"
  129. />
  130. </el-form-item>
  131. </el-col>
  132. <el-col :span="12">
  133. <el-form-item
  134. label="数据缓存"
  135. prop="cache"
  136. >
  137. <el-radio-group
  138. v-model="dataForm.cache"
  139. class="bs-el-radio-group"
  140. >
  141. <el-radio :label="1">
  142. 开启
  143. </el-radio>
  144. <el-radio :label="0">
  145. 关闭
  146. </el-radio>
  147. </el-radio-group>
  148. <el-tooltip
  149. class="item"
  150. effect="light"
  151. content="开启缓存:会在首次调用该数据集时,将结果缓存,在接下来的十分钟内,若再次被调用则直接返回缓存中的数据,注意:在当前数据集编辑页面缓存不生效"
  152. placement="top"
  153. >
  154. <i
  155. class="el-icon-warning-outline"
  156. style="color: #E3C98C;margin-left: 16px;font-size:14px"
  157. />
  158. </el-tooltip>
  159. </el-form-item>
  160. </el-col>
  161. </el-row>
  162. <el-row>
  163. <el-col :span="12">
  164. <el-form-item
  165. label="标签"
  166. prop="labelIds"
  167. >
  168. <LabelSelect
  169. :dataset-id="datasetId"
  170. :id-list="dataForm.labelIds"
  171. @commit="(ids) =>{dataForm.labelIds = ids}"
  172. />
  173. </el-form-item>
  174. </el-col>
  175. </el-row>
  176. </el-form>
  177. <div
  178. v-if="isEdit"
  179. class="sql-config"
  180. >
  181. <div>
  182. <el-button-group>
  183. <el-button
  184. plain
  185. type="primary"
  186. class="bs-el-button-default"
  187. @click="example('es')"
  188. >
  189. ES案例
  190. </el-button>
  191. </el-button-group>
  192. <div class="code-out">
  193. <codemirror
  194. ref="targetInSql"
  195. v-model="dataForm.script"
  196. :options="cOptions"
  197. style="margin-top: 2px"
  198. />
  199. </div>
  200. </div>
  201. <div style="text-align: center; padding: 16px 0;">
  202. <el-button
  203. type="primary"
  204. @click="toExecute"
  205. >
  206. 解析并运行
  207. </el-button>
  208. </div>
  209. </div>
  210. </el-col>
  211. <el-col
  212. v-if="isEdit"
  213. :span="8"
  214. >
  215. <div class="right-setting">
  216. <div class="paramConfig">
  217. <div class="title-style bs-title-style">
  218. 脚本参数
  219. <el-button
  220. type="text"
  221. style="float: right;border: none;margin-top: -4px;"
  222. @click="openParamsConfig"
  223. >
  224. 配置
  225. </el-button>
  226. </div>
  227. <div class="field-wrap bs-field-wrap bs-scrollbar">
  228. <div
  229. v-for="param in dataForm.paramsList"
  230. :key="param.name"
  231. class="field-item"
  232. @click="openParamsConfig"
  233. >
  234. <span>{{ param.name }}</span>&nbsp;<span
  235. v-show="param.remark"
  236. style="color: #909399;"
  237. >({{ param.remark
  238. }})</span>
  239. <el-button
  240. class="edit_field"
  241. type="text"
  242. style="float: right;border: none;margin-top: 2px;"
  243. @click="openParamsConfig"
  244. >
  245. 配置
  246. </el-button>
  247. </div>
  248. </div>
  249. </div>
  250. <div class="structure">
  251. <div class="title-style bs-title-style">
  252. 输出字段
  253. <el-button
  254. type="text"
  255. style="float: right;border: none;margin-top: -4px;"
  256. @click="fieldsetVisible = true"
  257. >
  258. 配置
  259. </el-button>
  260. </div>
  261. <div class="field-wrap bs-field-wrap bs-scrollbar">
  262. <div
  263. v-for="field in structurePreviewList"
  264. :key="field.fieldName"
  265. class="field-item"
  266. @click="fieldsetVisible = true"
  267. >
  268. <span>{{ field.fieldName }}</span>&nbsp;<span
  269. v-show="field.fieldDesc"
  270. style="color: #909399;"
  271. >({{
  272. field.fieldDesc }})</span>
  273. <el-button
  274. class="edit_field"
  275. type="text"
  276. style="float: right;border: none;margin-top: 2px;"
  277. @click="fieldsetVisible = true"
  278. >
  279. 配置
  280. </el-button>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. </el-col>
  286. </el-row>
  287. <div
  288. v-if="isEdit"
  289. class="dataPreView"
  290. style="margin-top: 12px;"
  291. >
  292. <div class="result-view">
  293. 数据预览
  294. </div>
  295. <div
  296. v-loading="tableLoading"
  297. class="bs-table-box is-Edit bs-scrollbar"
  298. >
  299. <el-table
  300. align="center"
  301. :data="dataPreviewList"
  302. max-height="400"
  303. class="bs-el-table bs-scrollbar"
  304. >
  305. <el-table-column
  306. v-for="(value, key) in dataPreviewList[0] ? dataPreviewList[0] : noDataTableDisplayFields"
  307. :key="key"
  308. :label="key"
  309. align="center"
  310. show-overflow-tooltip
  311. :render-header="renderHeader"
  312. >
  313. <template slot-scope="scope">
  314. <span>{{ scope.row[key] }}</span>
  315. </template>
  316. </el-table-column>
  317. </el-table>
  318. </div>
  319. </div>
  320. <!-- 字段填充方式 -->
  321. <el-dialog
  322. title="提示"
  323. :visible.sync="fieldDescVisible"
  324. width="420px"
  325. append-to-body
  326. :close-on-click-modal="false"
  327. custom-class="fieldDescCheck"
  328. class="bs-dialog-wrap bs-el-dialog"
  329. >
  330. <p style="color:var(--bs-el-text);line-height: 24px;padding-left: 10px;display: flex;">
  331. <i
  332. class="el-icon-warning"
  333. style="color: #E6A23C;font-size: 24px;margin-right: 5px;"
  334. />存在字段描述信息为空,请确认
  335. </p>
  336. <span
  337. slot="footer"
  338. class="dialog-footer"
  339. >
  340. <el-button
  341. class="bs-el-button-default"
  342. @click="fieldDescFill"
  343. >使用字段名填充</el-button>
  344. <el-button
  345. class="bs-el-button-default"
  346. @click="fieldDescEdit"
  347. >进入编辑</el-button>
  348. <el-button
  349. type="primary"
  350. @click="toSave"
  351. >继续保存</el-button>
  352. </span>
  353. </el-dialog>
  354. <!-- 字段填充 -->
  355. <el-dialog
  356. title="输出字段配置"
  357. :visible.sync="fieldsetVisible"
  358. width="1000px"
  359. append-to-body
  360. :close-on-click-modal="false"
  361. :before-close="cancelField"
  362. class="bs-dialog-wrap bs-el-dialog"
  363. >
  364. <div class="bs-table-box">
  365. <el-table
  366. :data="structurePreviewListCopy"
  367. :border="true"
  368. align="center"
  369. class="bs-el-table"
  370. >
  371. <el-empty slot="empty" />
  372. <el-table-column
  373. align="left"
  374. show-overflow-tooltip
  375. prop="fieldName"
  376. label="字段值"
  377. />
  378. <el-table-column
  379. align="center"
  380. prop="fieldDesc"
  381. label="字段描述"
  382. >
  383. <template slot-scope="scope">
  384. <el-input
  385. v-if="isEdit"
  386. v-model="scope.row.fieldDesc"
  387. size="small"
  388. class="labeldsc bs-el-input"
  389. />
  390. <span v-else>{{ scope.row.fieldDesc }}</span>
  391. </template>
  392. </el-table-column>
  393. <!-- 添加一个插槽,供其他人可扩展表格列,并把表格列的数据返回出去 -->
  394. <slot name="output-field-table-column" />
  395. </el-table>
  396. </div>
  397. <span
  398. slot="footer"
  399. class="dialog-footer"
  400. >
  401. <el-button
  402. class="bs-el-button-default"
  403. @click="cancelField"
  404. >
  405. 取消
  406. </el-button>
  407. <el-button
  408. type="primary"
  409. @click="setField"
  410. >
  411. 确定
  412. </el-button>
  413. </span>
  414. </el-dialog>
  415. <!-- 参数配置 -->
  416. <el-dialog
  417. title="脚本参数配置"
  418. :visible.sync="paramsVisible"
  419. width="1000px"
  420. append-to-body
  421. :close-on-click-modal="false"
  422. :before-close="cancelParam"
  423. class="bs-dialog-wrap bs-el-dialog"
  424. >
  425. <div class="bs-table-box">
  426. <el-table
  427. ref="singleTable"
  428. :data="paramsListCopy"
  429. :border="true"
  430. align="center"
  431. class="bs-el-table"
  432. >
  433. <el-empty slot="empty" />
  434. <el-table-column
  435. prop="name"
  436. label="参数名称"
  437. align="center"
  438. >
  439. <template slot-scope="scope">
  440. <el-input
  441. v-model="scope.row.name"
  442. class="bs-el-input"
  443. :disabled="!isSet"
  444. placeholder="请输入名称"
  445. clearable
  446. @change="checkParamsName(scope.row)"
  447. />
  448. </template>
  449. </el-table-column>
  450. <el-table-column
  451. prop="type"
  452. label="参数类型"
  453. align="center"
  454. width="200"
  455. filterable
  456. >
  457. <template slot-scope="scope">
  458. <el-select
  459. v-model="scope.row.type"
  460. popper-class="bs-el-select"
  461. class="bs-el-select"
  462. placeholder="请选择"
  463. :disabled="!isSet"
  464. >
  465. <el-option
  466. v-for="item in typeSelect"
  467. :key="item.value"
  468. :label="item.value"
  469. :value="item.value"
  470. />
  471. </el-select>
  472. </template>
  473. </el-table-column>
  474. <el-table-column
  475. prop="require"
  476. label="是否必填"
  477. align="center"
  478. width="200"
  479. filterable
  480. >
  481. <template slot-scope="scope">
  482. <el-radio-group
  483. v-model="scope.row.require"
  484. :disabled="!isSet"
  485. class="bs-el-radio-group"
  486. >
  487. <el-radio :label="1">
  488. </el-radio>
  489. <el-radio :label="0">
  490. </el-radio>
  491. </el-radio-group>
  492. </template>
  493. </el-table-column>
  494. <el-table-column
  495. prop="value"
  496. label="参数值"
  497. align="center"
  498. >
  499. <template slot-scope="scope">
  500. <el-date-picker
  501. v-if="scope.row.type === 'Date'"
  502. v-model="scope.row.value"
  503. type="datetime"
  504. value-format="yyyy-MM-dd HH:mm:ss"
  505. placeholder="选择日期时间"
  506. />
  507. <el-input
  508. v-else
  509. v-model="scope.row.value"
  510. class="bs-el-input"
  511. clearable
  512. placeholder="请输入值"
  513. />
  514. </template>
  515. </el-table-column>
  516. <el-table-column
  517. prop="remark"
  518. label="备注"
  519. align="center"
  520. >
  521. <template slot-scope="scope">
  522. <el-input
  523. v-model="scope.row.remark"
  524. :disabled="!isSet"
  525. clearable
  526. class="bs-el-input"
  527. placeholder="请输入备注"
  528. rows="2"
  529. maxlength="200"
  530. />
  531. </template>
  532. </el-table-column>
  533. <el-table-column
  534. v-if="isSet"
  535. label="操作"
  536. width="105"
  537. align="center"
  538. >
  539. <template slot="header">
  540. <el-button
  541. icon="el-icon-plus"
  542. type="text"
  543. class="no-border"
  544. @click="addParam"
  545. >
  546. 添加
  547. </el-button>
  548. </template>
  549. <template slot-scope="scope">
  550. <el-button
  551. type="text"
  552. style="color: #e47470;"
  553. class="no-border"
  554. @click="delRow(scope.$index)"
  555. >
  556. 删除
  557. </el-button>
  558. </template>
  559. </el-table-column>
  560. </el-table>
  561. </div>
  562. <span
  563. slot="footer"
  564. class="dialog-footer"
  565. >
  566. <el-button
  567. class="bs-el-button-default"
  568. @click="cancelParam"
  569. >取消</el-button>
  570. <el-button
  571. type="primary"
  572. @click="setParam"
  573. >确定</el-button>
  574. </span>
  575. </el-dialog>
  576. <el-dialog
  577. title="脚本案例"
  578. :visible.sync="exampleVisible"
  579. width="1000px"
  580. height="1000px"
  581. append-to-body
  582. :close-on-click-modal="false"
  583. class="bs-dialog-wrap bs-el-dialog"
  584. >
  585. <div class="code-inner">
  586. <codemirror
  587. ref="example"
  588. v-model="currentExample"
  589. :options="cOptions"
  590. style="margin-top: 2px"
  591. />
  592. </div>
  593. <span
  594. slot="footer"
  595. class="dialog-footer"
  596. >
  597. <el-button
  598. class="bs-el-button-default"
  599. @click="exampleVisible = false"
  600. >关闭</el-button>
  601. <el-button
  602. type="primary"
  603. @click="useExample"
  604. >使用该案例</el-button>
  605. </span>
  606. </el-dialog>
  607. </el-scrollbar>
  608. </div>
  609. </template>
  610. <script>
  611. import LabelSelect from 'data-room-ui/DataSetLabelManagement/src/LabelSelect.vue'
  612. import {
  613. nameCheckRepeat,
  614. getCategoryTree,
  615. getDataset,
  616. datasetExecuteTest,
  617. datasetAdd, datasetUpdate
  618. } from 'data-room-ui/js/utils/datasetConfigService'
  619. import { codemirror } from 'vue-codemirror'
  620. import 'codemirror/mode/groovy/groovy'
  621. import 'codemirror/lib/codemirror.css'
  622. import 'codemirror/theme/nord.css'
  623. // import _ from 'lodash'
  624. import cloneDeep from 'lodash/cloneDeep'
  625. import { datasetMixins } from 'data-room-ui/js/mixins/datasetMixin'
  626. export default {
  627. name: 'ScriptEditForm',
  628. components: {
  629. codemirror,
  630. LabelSelect
  631. },
  632. mixins: [datasetMixins],
  633. data () {
  634. const validateName = (rule, value, callback) => {
  635. nameCheckRepeat({
  636. id: this.datasetId,
  637. name: value,
  638. moduleCode: this.appCode
  639. }).then((r) => {
  640. if (r) {
  641. callback(new Error('数据集名称已存在'))
  642. } else {
  643. callback()
  644. }
  645. })
  646. }
  647. return {
  648. dataForm: {
  649. id: '',
  650. name: '',
  651. typeId: '',
  652. datasetType: 'script',
  653. remark: '',
  654. cache: 0,
  655. labelIds: [],
  656. // 以下为config配置
  657. script: '',
  658. paramsList: [],
  659. fieldDesc: {},
  660. fieldList: []
  661. },
  662. rules: {
  663. name: [
  664. { required: true, message: '请输入数据集名称', trigger: 'blur' },
  665. { validator: validateName, trigger: 'blur' }
  666. ],
  667. typeId: [
  668. { required: true, message: '请选择分组', trigger: 'blur' }
  669. ]
  670. },
  671. cOptions: {
  672. mode: 'text/x-groovy',
  673. lineNumbers: true,
  674. lineWrapping: true,
  675. theme: 'nord',
  676. extraKey: { Ctrl: 'autocomplete' },
  677. hintOptions: {
  678. completeSingle: true
  679. }
  680. },
  681. paramsVisible: false,
  682. paramsListCopy: [],
  683. isSet: false, // 参数是否配置状态
  684. passTest: false,
  685. fieldDesc: null, // 字段描述
  686. exampleVisible: false,
  687. currentExample: '',
  688. exampleList: {
  689. es: `import com.gccloud.dataset.utils.ElasticsearchDsService;
  690. def dsl = '''
  691. {
  692. "query":{
  693. "match_all":{}
  694. }
  695. }
  696. '''
  697. def host = "127.0.0.1"
  698. int port = 9200
  699. def username = "elastic"
  700. def password = "pwd"
  701. def path = "/_search"
  702. /**
  703. * query方法的参数说明:
  704. * host es的ip
  705. * port es的端口
  706. * username es的用户名,如果没有可以不填
  707. * password es的密码,如果没有可以不填
  708. * path es的查询路径
  709. * dsl 查询的dsl,示例见上面
  710. * return 查询结果,List<Map>格式
  711. */
  712. return ElasticsearchDsService.query(host, port, username, password, path, dsl);
  713. `
  714. }
  715. }
  716. },
  717. computed: {
  718. noDataTableDisplayFields () {
  719. // 表格列对象
  720. const tableColumnObject = {}
  721. this.structurePreviewList.forEach(item => {
  722. tableColumnObject[item.fieldName] = ''
  723. })
  724. return tableColumnObject
  725. }
  726. },
  727. watch: {
  728. 'dataForm.script' () {
  729. this.passTest = false
  730. }
  731. },
  732. mounted () {
  733. this.init()
  734. },
  735. methods: {
  736. /**
  737. * 初始化
  738. * 1. 获取数据集分类
  739. * 2. 获取数据集详情
  740. * 3. 执行脚本数据集
  741. */
  742. async init () {
  743. this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
  744. if (this.typeId) {
  745. this.dataForm.typeId = this.typeId
  746. this.$nextTick(() => {
  747. try {
  748. this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
  749. } catch (error) {
  750. console.error(error)
  751. }
  752. })
  753. }
  754. if (!this.datasetId) {
  755. return
  756. }
  757. getDataset(this.datasetId).then(res => {
  758. this.dataForm.id = res.id
  759. this.dataForm.name = res.name
  760. this.dataForm.typeId = res.typeId
  761. this.dataForm.remark = res.remark
  762. this.dataForm.cache = res.cache
  763. this.dataForm.datasetType = res.datasetType
  764. this.dataForm.moduleCode = res.moduleCode
  765. this.dataForm.editable = res.editable
  766. this.dataForm.sourceId = res.sourceId
  767. // config 配置
  768. this.dataForm.script = res.config.script
  769. this.dataForm.paramsList = res.config.paramsList ? res.config.paramsList : []
  770. this.dataForm.fieldDesc = res.config.fieldDesc
  771. this.dataForm.fieldList = res.config.fieldList
  772. this.paramsListCopy = cloneDeep(this.dataForm.paramsList)
  773. this.scriptExecute(true)
  774. })
  775. },
  776. /**
  777. * 保存数据集
  778. * @param formName
  779. * @param noCheckToSave 是否不检查直接保存
  780. */
  781. save (formName, noCheckToSave = false) {
  782. if (this.passTest === false) {
  783. this.$message.error('请确保脚本不为空且执行通过')
  784. return
  785. }
  786. if (!this.structurePreviewList.length) {
  787. this.$message.warning('该执行脚本未生成输出字段,请重新检查')
  788. return
  789. }
  790. if (!noCheckToSave) {
  791. const temp = this.structurePreviewList.some(item => {
  792. return item.fieldDesc === '' || !item.hasOwnProperty('fieldDesc')
  793. }) // true-存在为空
  794. if (temp) {
  795. this.fieldDescVisible = true
  796. return
  797. }
  798. }
  799. this.$refs[formName].validate((valid) => {
  800. if (!valid) {
  801. return false
  802. }
  803. if (this.dataForm.paramsList.length > 0) {
  804. const names = this.dataForm.paramsList.map(value => value.name)
  805. const namesSet = new Set(names)
  806. if (namesSet.size !== names.length) {
  807. this.$message.error('参数名称不能重复,请重新输入')
  808. return
  809. }
  810. }
  811. this.dataForm.fieldList = this.structurePreviewList.length ? this.structurePreviewList : []
  812. // 组装输出字段描述
  813. const columnMap = {}
  814. if (this.structurePreviewList.length > 0) {
  815. this.structurePreviewList.forEach(r => {
  816. columnMap[r.fieldName] = r.fieldDesc
  817. })
  818. this.dataForm.fieldDesc = columnMap
  819. }
  820. this.saveLoading = true
  821. this.saveText = '正在保存...'
  822. const datasetSave = this.dataForm.id === '' ? datasetAdd : datasetUpdate
  823. const datasetParams = {
  824. id: this.dataForm.id,
  825. name: this.dataForm.name,
  826. typeId: this.dataForm.typeId,
  827. datasetType: 'script',
  828. remark: this.dataForm.remark,
  829. cache: this.dataForm.cache,
  830. sourceId: this.dataForm.sourceId,
  831. moduleCode: this.appCode,
  832. editable: this.appCode ? 1 : 0,
  833. labelIds: this.dataForm.labelIds,
  834. config: {
  835. className: 'com.gccloud.dataset.entity.config.GroovyDataSetConfig',
  836. script: this.dataForm.script,
  837. paramsList: this.dataForm.paramsList,
  838. fieldList: this.dataForm.fieldList,
  839. fieldDesc: this.dataForm.fieldDesc
  840. }
  841. }
  842. datasetSave(datasetParams).then(() => {
  843. this.$message.success('保存成功')
  844. this.$parent.init(false)
  845. this.$parent.setType = null
  846. this.saveLoading = false
  847. this.saveText = ''
  848. this.goBack()
  849. }).catch(() => {
  850. this.saveLoading = false
  851. this.saveText = ''
  852. })
  853. })
  854. },
  855. // 脚本执行
  856. scriptExecute (isInit = false) {
  857. // 组装数据集执行参数
  858. const executeParams = {
  859. script: this.dataForm.script,
  860. params: this.dataForm.paramsList,
  861. dataSetType: 'script'
  862. }
  863. this.saveLoading = true
  864. datasetExecuteTest(executeParams).then(res => {
  865. if (!isInit) {
  866. this.$message.success('脚本执行通过')
  867. }
  868. this.dataPreviewList = res.data ? res.data : []
  869. this.structurePreviewList = []
  870. if (res.data.length) {
  871. this.structurePreviewList = Object.keys(res.data[0]).map(item => {
  872. return {
  873. fieldName: item,
  874. fieldDesc: ''
  875. }
  876. })
  877. }
  878. if (this.structurePreviewList.length && this.dataForm.fieldDesc) {
  879. this.buildFieldDesc()
  880. }
  881. this.structurePreviewListCopy = cloneDeep(this.structurePreviewList)
  882. this.saveLoading = false
  883. this.passTest = true
  884. }).catch((e) => {
  885. this.passTest = false
  886. this.saveLoading = false
  887. })
  888. },
  889. // 执行事件
  890. toExecute () {
  891. if (this.dataForm.paramsList.length) {
  892. this.isSet = false
  893. this.paramsVisible = true
  894. } else {
  895. // 无参数,直接执行脚本
  896. this.scriptExecute()
  897. }
  898. },
  899. /**
  900. * 字段描述构建及同步
  901. */
  902. buildFieldDesc () {
  903. const fieldDesc = {}
  904. this.structurePreviewList.forEach(field => {
  905. if (this.dataForm.fieldDesc.hasOwnProperty(field.fieldName)) {
  906. field.fieldDesc = this.dataForm.fieldDesc[field.fieldName]
  907. }
  908. fieldDesc[field.fieldName] = field.fieldDesc
  909. })
  910. this.dataForm.fieldDesc = fieldDesc
  911. },
  912. /**
  913. * 打开参数配置弹窗
  914. */
  915. openParamsConfig () {
  916. this.isSet = true
  917. this.paramsVisible = true
  918. },
  919. /**
  920. * 取消编辑参数
  921. */
  922. cancelParam () {
  923. this.paramsListCopy = cloneDeep(this.dataForm.paramsList)
  924. this.paramsVisible = false
  925. },
  926. /**
  927. * 保存参数设置
  928. */
  929. setParam () {
  930. if (!this.isSet) {
  931. this.scriptExecute()
  932. this.paramsListCopy = cloneDeep(this.dataForm.paramsList)
  933. } else {
  934. this.dataForm.paramsList = cloneDeep(this.paramsListCopy)
  935. }
  936. this.paramsVisible = false
  937. },
  938. /**
  939. * 校验名称【参数名称不能与字段名重复】
  940. * @param value
  941. */
  942. checkParamsName (value) {
  943. const checkList = this.structurePreviewList.filter(item => item.fieldName === value.name)
  944. if (checkList.length) {
  945. this.$message.warning('参数名称不可以与字段名相同!')
  946. value.name = ''
  947. }
  948. },
  949. /**
  950. * 删除参数配置
  951. * @param index
  952. */
  953. delRow (index) {
  954. this.paramsListCopy.splice(index, 1)
  955. },
  956. /**
  957. * 新增参数配置
  958. */
  959. addParam () {
  960. this.paramsListCopy.push({
  961. name: '',
  962. type: '',
  963. value: '',
  964. status: 1,
  965. require: 0,
  966. remark: ''
  967. })
  968. },
  969. selectorFilter (value) {
  970. this.$refs.categorySelectTree.filter(value)
  971. },
  972. treeFilter (value, data) {
  973. if (!value) return true
  974. return data.name.indexOf(value) !== -1
  975. },
  976. /**
  977. * 获取脚本案例
  978. */
  979. example (type) {
  980. this.exampleVisible = true
  981. this.currentExample = this.exampleList[type]
  982. },
  983. useExample () {
  984. this.dataForm.script = this.currentExample
  985. this.exampleVisible = false
  986. }
  987. }
  988. }
  989. </script>
  990. <style lang="scss" scoped>
  991. @import '../../assets/style/bsTheme.scss';
  992. .data-set-scrollbar {
  993. height: 100%;
  994. overflow-y: auto;
  995. overflow-x: none;
  996. .el-scrollbar__view {
  997. height: 100%;
  998. }
  999. }
  1000. ::v-deep .el-input__inner {
  1001. width: 100% !important;
  1002. }
  1003. .page-header {
  1004. display: flex;
  1005. position: relative;
  1006. .page-header-right {
  1007. position: absolute;
  1008. right: 16px;
  1009. }
  1010. }
  1011. .sql-config {
  1012. padding: 0 16px;
  1013. }
  1014. .operation {
  1015. ::v-deep .el-select {
  1016. width: 200px !important;
  1017. margin-right: 16px;
  1018. }
  1019. display: flex;
  1020. }
  1021. // .codeStyle {
  1022. // border: 1px solid #EBEEF5;
  1023. // }
  1024. .code-out {
  1025. ::v-deep .CodeMirror {
  1026. height: 180px ;
  1027. font-family: Helvetica, Tahoma;
  1028. // .CodeMirror-scroll {
  1029. // background: #fff;
  1030. // .CodeMirror-gutters {
  1031. // background: #f6f7fb;
  1032. // }
  1033. // }
  1034. }
  1035. }
  1036. .code-inner {
  1037. ::v-deep .CodeMirror {
  1038. height: 400px ;
  1039. font-family: Helvetica, Tahoma;
  1040. }
  1041. }
  1042. .no-border {
  1043. border: 0;
  1044. }
  1045. ::v-deep .fieldDescCheck {
  1046. .el-dialog__body {
  1047. height: fit-content !important;
  1048. min-height: unset !important;
  1049. }
  1050. }
  1051. .title-style {
  1052. padding: 8px 12px;
  1053. background-color: #f6f7fb;
  1054. border-left: 5px solid var(--bs-el-color-primary);
  1055. margin: 16px 16px 0 0;
  1056. }
  1057. .field-wrap {
  1058. // max-height: 110px;
  1059. overflow: auto;
  1060. margin-right: 16px;
  1061. cursor: pointer;
  1062. .field-item {
  1063. line-height: 32px;
  1064. padding: 0 12px 0 16px;
  1065. .edit_field {
  1066. display: none;
  1067. }
  1068. &:hover {
  1069. background-color: #f2f7fe;
  1070. .edit_field {
  1071. display: block;
  1072. }
  1073. }
  1074. }
  1075. }
  1076. .right-setting {
  1077. height: 358px;
  1078. overflow: hidden;
  1079. display: flex;
  1080. flex-direction: column;
  1081. .paramConfig {
  1082. max-height: 179px;
  1083. .field-wrap {
  1084. max-height: 127px;
  1085. }
  1086. }
  1087. .structure {
  1088. flex: 1;
  1089. overflow: hidden;
  1090. .field-wrap {
  1091. height: calc(100% - 40px);
  1092. }
  1093. }
  1094. }
  1095. .result-view {
  1096. font-size: 14px;
  1097. font-weight: 600;
  1098. color: var(--bs-el-text);
  1099. position: relative;
  1100. padding: 16px 0;
  1101. padding-left: 12px;
  1102. border-bottom: 1px solid var(--bs-background-1);
  1103. &::before {
  1104. content: "";
  1105. height: 14px;
  1106. position: absolute;
  1107. left: 0;
  1108. top: 50%;
  1109. transform: translateY(-50%);
  1110. border-left: 4px solid var(--bs-el-color-primary);
  1111. }
  1112. }
  1113. ::v-deep .bs-table-box.is-Edit .el-table {
  1114. max-height: unset !important;
  1115. .el-table__body-wrapper {
  1116. max-height: unset !important;
  1117. }
  1118. }
  1119. .bs-table-box {
  1120. height: 100% !important;
  1121. margin-bottom: 0 !important;
  1122. }
  1123. .bs-el-select{
  1124. width: 100% !important;
  1125. }
  1126. ::v-deep .el-input__inner{
  1127. width: 100% !important;
  1128. }
  1129. </style>
  1130. <style>
  1131. .CodeMirror-vscrollbar {
  1132. right: 0;
  1133. top: 0;
  1134. overflow-x: hidden;
  1135. overflow-y: scroll;
  1136. margin-right: 4px;
  1137. }
  1138. /* Webkit浏览器滚动条样式 */
  1139. .CodeMirror-vscrollbar::-webkit-scrollbar {
  1140. width: 6px;
  1141. /* 滚动条宽度 */
  1142. }
  1143. .CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
  1144. background-color: #444851;
  1145. /* 滚动条滑块颜色 */
  1146. border-radius: 4px;
  1147. /* 滚动条滑块圆角 */
  1148. }
  1149. .CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover {
  1150. background-color: #444851;
  1151. /* 滚动条滑块悬停时颜色 */
  1152. }
  1153. /* Firefox和新版Chrome浏览器滚动条样式 */
  1154. .CodeMirror-vscrollbar {
  1155. scrollbar-width: thin;
  1156. /* 滚动条宽度 */
  1157. scrollbar-color: #444851 #444851;
  1158. /* 滚动条颜色 */
  1159. }
  1160. .CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
  1161. background-color: #444851;
  1162. /* 滚动条滑块颜色 */
  1163. }
  1164. .CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover {
  1165. background-color: #444851;
  1166. /* 滚动条滑块悬停时颜色 */
  1167. }
  1168. </style>