OriginalEditForm.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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/ry3ggnrts7q3ro1g')"
  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. filterable
  77. :disabled="!isEdit"
  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>
  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="sourceId"
  124. >
  125. <el-select
  126. v-model="dataForm.sourceId"
  127. class="bs-el-select"
  128. popper-class="bs-el-select"
  129. clearable
  130. filterable
  131. :disabled="!isEdit"
  132. @change="setSource"
  133. >
  134. <el-option
  135. v-for="source in sourceList"
  136. :key="source.id"
  137. :label="source.sourceName"
  138. :value="source.id"
  139. />
  140. </el-select>
  141. </el-form-item>
  142. </el-col>
  143. <el-col :span="12">
  144. <el-form-item
  145. label="关联原始表"
  146. prop="tableName"
  147. >
  148. <el-select
  149. v-model="dataForm.tableName"
  150. v-loading="selectorLoading"
  151. element-loading-spinner="el-icon-loading"
  152. class="bs-el-select"
  153. popper-class="bs-el-select"
  154. clearable
  155. filterable
  156. :disabled="!isEdit"
  157. @change="setTable"
  158. >
  159. <el-option-group label="表">
  160. <el-option
  161. v-for="table in tableList"
  162. :key="table.name"
  163. :label="table.name"
  164. :value="table.name"
  165. :disabled="table.status == 1"
  166. />
  167. </el-option-group>
  168. <el-option-group label="视图">
  169. <el-option
  170. v-for="table in viewList"
  171. :key="table.name"
  172. :label="table.name"
  173. :value="table.name"
  174. :disabled="table.status == 1"
  175. />
  176. </el-option-group>
  177. </el-select>
  178. </el-form-item>
  179. </el-col>
  180. </el-row>
  181. <el-row :gutter="20">
  182. <el-col :span="12">
  183. <el-form-item
  184. label="输出字段"
  185. prop="fieldInfo"
  186. >
  187. <el-select
  188. v-model="dataForm.fieldInfo"
  189. class="bs-el-select"
  190. popper-class="bs-el-select"
  191. placeholder="请选择字段(为空时默认选择全部字段)"
  192. clearable
  193. filterable
  194. multiple
  195. collapse-tags
  196. :disabled="!isEdit"
  197. @change="setFields"
  198. >
  199. <el-option
  200. v-if="fieldList.length"
  201. label="全选"
  202. value="全选"
  203. >
  204. <el-checkbox
  205. v-model="isSelectAll"
  206. @click.prevent.native
  207. >
  208. 全选
  209. </el-checkbox>
  210. </el-option>
  211. <el-option
  212. v-for="field in fieldList"
  213. :key="field.columnName"
  214. :label="field.columnName"
  215. :value="field.columnName"
  216. >
  217. <el-checkbox
  218. v-model="field.isCheck"
  219. @click.prevent.native
  220. >
  221. {{ field.columnName }}
  222. </el-checkbox>
  223. </el-option>
  224. </el-select>
  225. </el-form-item>
  226. </el-col>
  227. <el-col :span="12">
  228. <el-form-item
  229. label="是否去重"
  230. prop="repeatStatus"
  231. >
  232. <el-radio-group
  233. v-model="dataForm.repeatStatus"
  234. class="bs-el-radio-group"
  235. :disabled="!isEdit"
  236. >
  237. <el-radio :label="1">
  238. </el-radio>
  239. <el-radio :label="0">
  240. </el-radio>
  241. </el-radio-group>
  242. </el-form-item>
  243. </el-col>
  244. </el-row>
  245. <el-row :gutter="20">
  246. <el-col :span="12">
  247. <el-form-item
  248. label="描述"
  249. prop="remark"
  250. >
  251. <el-input
  252. v-model="dataForm.remark"
  253. class="bs-el-input"
  254. :disabled="!isEdit"
  255. />
  256. </el-form-item>
  257. </el-col>
  258. <el-col :span="12">
  259. <el-form-item
  260. label="标签"
  261. prop="labelIds"
  262. >
  263. <LabelSelect
  264. :dataset-id="datasetId"
  265. :id-list="dataForm.labelIds"
  266. @commit="(ids) =>{dataForm.labelIds = ids}"
  267. />
  268. </el-form-item>
  269. </el-col>
  270. </el-row>
  271. </el-form>
  272. </el-col>
  273. <el-col
  274. v-if="isEdit"
  275. :span="8"
  276. >
  277. <div class="structure">
  278. <div class="title-style bs-title-style">
  279. 输出字段
  280. <el-button
  281. type="text"
  282. style="float: right;border: none;margin-top: -4px;"
  283. @click="fieldsetVisible = true"
  284. >
  285. 配置
  286. </el-button>
  287. </div>
  288. <div class="field-wrap bs-field-wrap bs-scrollbar">
  289. <div
  290. v-for="field in structurePreviewList"
  291. :key="field.fieldName"
  292. class="field-item"
  293. @click="fieldsetVisible = true"
  294. >
  295. <span>{{ field.fieldName }}</span>&nbsp;<span
  296. v-show="field.fieldDesc"
  297. style="color: #909399;"
  298. >({{
  299. field.fieldDesc }})</span>
  300. <el-button
  301. class="edit_field"
  302. type="text"
  303. style="float: right;border: none;margin-top: 2px;"
  304. @click="fieldsetVisible = true"
  305. >
  306. 配置
  307. </el-button>
  308. </div>
  309. </div>
  310. </div>
  311. </el-col>
  312. </el-row>
  313. <div
  314. v-if="isEdit"
  315. class="dataPreView"
  316. style="margin-top: 12px;"
  317. >
  318. <div class="result-view">
  319. 数据预览
  320. </div>
  321. <div
  322. v-loading="tableLoading"
  323. class="bs-table-box is-Edit bs-scrollbar"
  324. >
  325. <el-table
  326. align="center"
  327. :data="dataPreviewList"
  328. max-height="400"
  329. :border="true"
  330. class="bs-el-table bs-scrollbar"
  331. >
  332. <el-table-column
  333. v-for="(value, key) in dataPreviewList[0]"
  334. :key="key"
  335. :label="key"
  336. align="center"
  337. show-overflow-tooltip
  338. :render-header="renderHeader"
  339. >
  340. <template slot-scope="scope">
  341. <span>{{ scope.row[key] }}</span>
  342. </template>
  343. </el-table-column>
  344. </el-table>
  345. </div>
  346. <div class="bs-pagination">
  347. <el-pagination
  348. class="bs-el-pagination"
  349. popper-class="bs-el-pagination"
  350. :current-page="current"
  351. :page-sizes="[10, 20, 50, 100]"
  352. :page-size="size"
  353. :total="totalCount"
  354. background
  355. prev-text="上一页"
  356. next-text="下一页"
  357. layout="total, prev, pager, next,sizes"
  358. @size-change="sizeChangeHandle"
  359. @current-change="currentChangeHandle"
  360. />
  361. </div>
  362. </div>
  363. <el-dialog
  364. title="提示"
  365. :visible.sync="fieldDescVisible"
  366. width="420px"
  367. append-to-body
  368. :close-on-click-modal="false"
  369. custom-class="fieldDescCheck"
  370. class="bs-dialog-wrap bs-el-dialog"
  371. >
  372. <p style="color:var(--bs-el-text);line-height: 24px;padding-left: 10px;display: flex;">
  373. <i
  374. class="el-icon-warning"
  375. style="color: #E6A23C;font-size: 24px;margin-right: 5px;"
  376. />存在字段描述信息为空,请确认
  377. </p>
  378. <span
  379. slot="footer"
  380. class="dialog-footer"
  381. >
  382. <el-button
  383. class="bs-el-button-default"
  384. @click="fieldDescFill"
  385. >使用字段名填充</el-button>
  386. <el-button
  387. class="bs-el-button-default"
  388. @click="fieldDescEdit"
  389. >进入编辑</el-button>
  390. <el-button
  391. type="primary"
  392. @click="toSave"
  393. >继续保存</el-button>
  394. </span>
  395. </el-dialog>
  396. <!-- 字段填充 -->
  397. <el-dialog
  398. title="输出字段配置"
  399. :visible.sync="fieldsetVisible"
  400. width="1000px"
  401. append-to-body
  402. :close-on-click-modal="false"
  403. :before-close="cancelField"
  404. class="bs-dialog-wrap bs-el-dialog"
  405. >
  406. <div class="bs-table-box">
  407. <el-table
  408. :data="structurePreviewListCopy"
  409. :border="true"
  410. align="center"
  411. class="bs-el-table"
  412. >
  413. <el-empty slot="empty" />
  414. <el-table-column
  415. align="left"
  416. show-overflow-tooltip
  417. prop="fieldName"
  418. label="字段值"
  419. />
  420. <el-table-column
  421. align="center"
  422. show-overflow-tooltip
  423. prop="fieldType"
  424. label="字段类型"
  425. />
  426. <el-table-column
  427. align="center"
  428. prop="fieldDesc"
  429. label="字段描述"
  430. >
  431. <template slot-scope="scope">
  432. <el-input
  433. v-if="isEdit"
  434. v-model="scope.row.fieldDesc"
  435. size="small"
  436. class="labeldsc bs-el-input"
  437. />
  438. <span v-else>{{ scope.row.fieldDesc }}</span>
  439. </template>
  440. </el-table-column>
  441. <el-table-column
  442. align="center"
  443. prop="orderNum"
  444. label="字段排序"
  445. sortable
  446. >
  447. <template slot-scope="scope">
  448. <el-input
  449. v-if="isEdit"
  450. v-model="scope.row.orderNum"
  451. size="small"
  452. class="labeldsc bs-el-input"
  453. />
  454. <span v-else>{{ scope.row.orderNum }}</span>
  455. </template>
  456. </el-table-column>
  457. <el-table-column
  458. align="center"
  459. prop="sourceTable"
  460. label="字段来源"
  461. />
  462. <!-- 添加一个插槽,供其他人可扩展表格列,并把表格列的数据返回出去 -->
  463. <slot name="output-field-table-column" />
  464. </el-table>
  465. </div>
  466. <span
  467. slot="footer"
  468. class="dialog-footer"
  469. >
  470. <el-button
  471. class="bs-el-button-default"
  472. @click="cancelField"
  473. >
  474. 取消
  475. </el-button>
  476. <el-button
  477. type="primary"
  478. @click="setField"
  479. >
  480. 确定
  481. </el-button>
  482. </span>
  483. </el-dialog>
  484. </el-scrollbar>
  485. </div>
  486. </template>
  487. <script>
  488. import LabelSelect from 'data-room-ui/DataSetLabelManagement/src/LabelSelect.vue'
  489. import {
  490. getCategoryTree,
  491. nameCheckRepeat,
  492. datasetExecuteTest,
  493. getDataset, datasetUpdate, datasetAdd
  494. } from 'data-room-ui/js/utils/datasetConfigService'
  495. import { datasourceList, getSourceTable, getSourceView, getTableFieldList } from 'data-room-ui/js/utils/dataSourceService'
  496. import _ from 'lodash'
  497. import { datasetMixins } from 'data-room-ui/js/mixins/datasetMixin'
  498. export default {
  499. name: 'OriginalEditForm',
  500. components: {
  501. LabelSelect
  502. },
  503. mixins: [datasetMixins],
  504. data () {
  505. const validateName = (rule, value, callback) => {
  506. nameCheckRepeat({
  507. id: this.datasetId,
  508. name: value,
  509. moduleCode: this.appCode
  510. }).then((res) => {
  511. if (res) {
  512. callback(new Error('数据集名称已存在'))
  513. } else {
  514. callback()
  515. }
  516. })
  517. }
  518. return {
  519. dataForm: {
  520. id: '',
  521. name: '',
  522. typeId: '',
  523. datasetType: 'original',
  524. remark: '',
  525. labelIds: [],
  526. // 以下为config信息
  527. sourceId: '',
  528. repeatStatus: 1,
  529. tableName: '',
  530. fieldInfo: [],
  531. fieldDesc: {},
  532. fieldList: []
  533. },
  534. rules: {
  535. name: [
  536. { required: true, message: '数据集名称不能为空', trigger: 'blur' },
  537. { validator: validateName, trigger: 'blur' }
  538. ],
  539. sourceId: [
  540. { required: true, message: '请选择数据源', trigger: 'blur' }
  541. ],
  542. tableName: [
  543. { required: true, message: '请选择原始表', trigger: 'change' }
  544. ],
  545. repeatStatus: [
  546. { required: true, message: '请选择是否去重', trigger: 'blur' }
  547. ],
  548. typeId: [
  549. { required: true, message: '请选择分组', trigger: 'blur' }
  550. ]
  551. },
  552. // 数据源列表
  553. sourceList: [],
  554. // 表列表
  555. tableList: [],
  556. // 视图列表
  557. viewList: [],
  558. // 字段列表
  559. fieldList: [],
  560. isSelectAll: false,
  561. activeName: 'data',
  562. currentCount: 0,
  563. selectorLoading: false,
  564. oldStructurePreviewList: [],
  565. isInit: false
  566. }
  567. },
  568. watch: {
  569. 'dataForm.fieldInfo': {
  570. handler (value) {
  571. try {
  572. this.setCheck()
  573. const fieldDescMap = {}
  574. this.fieldList.forEach((item) => {
  575. if (value.length !== 0 && !value.includes(item.columnName)) {
  576. return
  577. }
  578. fieldDescMap[item.columnName] = item.columnComment
  579. })
  580. this.getPreViewData(fieldDescMap)
  581. } catch (error) {
  582. console.error(error)
  583. }
  584. },
  585. deep: true,
  586. immediate: true
  587. }
  588. },
  589. mounted () {
  590. this.init()
  591. },
  592. methods: {
  593. /**
  594. * 初始化
  595. * 1.获取分类树
  596. * 2.获取数据源列表
  597. * 3.获取数据集详情
  598. * 4.获取原始表列表
  599. * 5.获取字段列表
  600. */
  601. async init () {
  602. // 获取分类树
  603. this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
  604. // 如果传入了分类id,则设置分类id和分类名称
  605. if (this.typeId) {
  606. this.dataForm.typeId = this.typeId
  607. this.$nextTick(() => {
  608. try {
  609. this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
  610. } catch (error) {
  611. console.error(error)
  612. }
  613. })
  614. }
  615. this.queryAllSource()
  616. if (!this.datasetId) {
  617. return
  618. }
  619. // 获取详情
  620. getDataset(this.datasetId).then(res => {
  621. this.dataForm.id = res.id
  622. this.dataForm.name = res.name
  623. this.dataForm.typeId = res.typeId
  624. this.dataForm.remark = res.remark
  625. this.dataForm.datasetType = res.datasetType
  626. this.dataForm.moduleCode = res.moduleCode
  627. this.dataForm.editable = res.editable
  628. this.dataForm.sourceId = res.sourceId
  629. // config 配置
  630. this.dataForm.tableName = res.config.tableName
  631. this.dataForm.repeatStatus = res.config.repeatStatus
  632. this.dataForm.fieldList = res.config.fieldList
  633. this.dataForm.fieldDesc = res.config.fieldDesc
  634. this.oldStructurePreviewList = _.cloneDeep(res.config.fieldList)
  635. // 字段信息,转为数组
  636. this.dataForm.fieldInfo = res.config.fieldInfo ? res.config.fieldInfo.split(',') : []
  637. if (this.dataForm.typeId) {
  638. this.$nextTick(() => {
  639. try {
  640. this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
  641. } catch (error) {
  642. console.error(error)
  643. }
  644. })
  645. }
  646. this.isInit = true
  647. this.queryAllTable()
  648. this.queryAllField()
  649. })
  650. },
  651. /**
  652. * 获取预览数据
  653. */
  654. getData () {
  655. const executeParams = {
  656. dataSourceId: this.dataForm.sourceId,
  657. script: JSON.stringify({
  658. fieldInfo: this.dataForm.fieldInfo, // 未选中字段就传空数组
  659. tableName: this.dataForm.tableName,
  660. repeatStatus: this.dataForm.repeatStatus
  661. }),
  662. // 原始表数据集没有数据集参数
  663. params: [],
  664. dataSetType: 'original',
  665. size: this.size,
  666. current: this.current
  667. }
  668. this.tableLoading = true
  669. datasetExecuteTest(executeParams).then((data) => {
  670. if (this.dataForm.fieldList == null) {
  671. this.dataForm.fieldList = _.cloneDeep(res.structure)
  672. }
  673. this.dataPreviewList = data.data.list
  674. this.totalCount = data.data.totalCount
  675. this.tableLoading = false
  676. }).catch(() => {
  677. this.dataPreviewList = []
  678. this.totalCount = 0
  679. this.tableLoading = false
  680. })
  681. },
  682. /**
  683. * 保存数据集
  684. * @param formName 表单名称
  685. * @param noCheckToSave 是否不检查直接保存
  686. */
  687. save (formName, noCheckToSave = false) {
  688. if (!this.structurePreviewList.length) {
  689. this.$message.warning('该原始数据集未生成输出字段,请重新检查')
  690. return
  691. }
  692. if (!noCheckToSave) {
  693. const temp = this.structurePreviewList.some(item => {
  694. return item.fieldDesc === ''
  695. }) // true-存在为空
  696. if (temp) {
  697. this.fieldDescVisible = true
  698. return
  699. }
  700. }
  701. this.$refs[formName].validate((valid) => {
  702. if (!valid) {
  703. this.saveLoading = false
  704. this.saveText = ''
  705. return false
  706. }
  707. // 组装字段描述
  708. const columnMap = {}
  709. this.structurePreviewList.forEach(item => {
  710. columnMap[item.fieldName] = item.fieldDesc
  711. })
  712. // 组装保存参数
  713. const datasetParams = {
  714. id: this.dataForm.id,
  715. name: this.dataForm.name,
  716. typeId: this.dataForm.typeId,
  717. remark: this.dataForm.remark,
  718. datasetType: 'original',
  719. sourceId: this.dataForm.sourceId,
  720. labelIds: this.dataForm.labelIds,
  721. config: {
  722. className: 'com.gccloud.dataset.entity.config.OriginalDataSetConfig',
  723. sourceId: this.dataForm.sourceId,
  724. tableName: this.dataForm.tableName,
  725. fieldInfo: this.dataForm.fieldInfo.length ? this.dataForm.fieldInfo.join(',') : '',
  726. fieldDesc: columnMap,
  727. fieldList: this.structurePreviewList,
  728. repeatStatus: this.dataForm.repeatStatus
  729. },
  730. moduleCode: this.appCode,
  731. editable: this.appCode ? 1 : 0
  732. }
  733. this.saveLoading = true
  734. this.saveText = '正在保存...'
  735. const saveOriginal = this.dataForm.id ? datasetUpdate : datasetAdd
  736. saveOriginal(datasetParams).then(res => {
  737. this.goBack()
  738. this.$message.success('保存成功')
  739. this.$parent.init(false)
  740. this.$parent.setType = null
  741. this.saveLoading = false
  742. this.saveText = ''
  743. }).catch(() => {
  744. this.$message.error('保存失败')
  745. this.saveLoading = false
  746. this.saveText = ''
  747. })
  748. })
  749. },
  750. /**
  751. * 获取数据源列表
  752. */
  753. queryAllSource () {
  754. const params = {
  755. sourceName: '',
  756. sourceType: '',
  757. moduleCode: this.appCode
  758. }
  759. datasourceList(params).then(res => {
  760. this.sourceList = res
  761. })
  762. },
  763. /**
  764. * 选中数据源
  765. * @param value
  766. */
  767. setSource (value) {
  768. this.dataForm.tableName = ''
  769. this.dataForm.fieldInfo = []
  770. this.tableList = []
  771. this.fieldList = []
  772. if (!this.dataForm.sourceId) return
  773. this.queryAllTable()
  774. },
  775. /**
  776. * 获取原始表列表
  777. * 1.获取表列表
  778. * 2.获取视图列表
  779. */
  780. queryAllTable () {
  781. getSourceTable(this.dataForm.sourceId).then(res => {
  782. this.tableList = res
  783. }).catch(() => {
  784. this.tableList = []
  785. })
  786. this.selectorLoading = true
  787. getSourceView(this.dataForm.sourceId).then(res => {
  788. this.viewList = res
  789. this.selectorLoading = false
  790. }).catch(() => {
  791. this.viewList = []
  792. this.selectorLoading = false
  793. })
  794. },
  795. /**
  796. * 选中原始表
  797. * @param value
  798. */
  799. setTable (value) {
  800. this.fieldList = []
  801. this.dataForm.fieldInfo = []
  802. if (!this.dataForm.tableName) return
  803. this.queryAllField()
  804. },
  805. /**
  806. * 获取原始表字段列表
  807. */
  808. queryAllField () {
  809. getTableFieldList(this.dataForm.sourceId, this.dataForm.tableName).then((data) => {
  810. const fieldDescMap = {}
  811. this.fieldList = data.map(field => {
  812. fieldDescMap[field.columnName] = field.columnComment
  813. field.isCheck = false
  814. if (this.dataForm.fieldInfo.includes(field.columnName)) {
  815. field.isCheck = true
  816. }
  817. return field
  818. })
  819. // this.getPreViewData(fieldDescMap)
  820. }).catch(() => {
  821. this.fieldList = []
  822. })
  823. },
  824. /**
  825. * 选中字段
  826. * @param values 选中的字段列表
  827. */
  828. setFields (values) {
  829. if (values.includes('全选')) {
  830. if (values.length > this.fieldList.length) {
  831. this.dataForm.fieldInfo = []
  832. } else {
  833. this.dataForm.fieldInfo = this.fieldList.map(field => field.columnName)
  834. }
  835. }
  836. },
  837. /**
  838. * 设置字段选中状态
  839. */
  840. setCheck () {
  841. this.fieldList.forEach(field => {
  842. if (this.dataForm.fieldInfo.includes(field.columnName)) {
  843. field.isCheck = true
  844. } else {
  845. field.isCheck = false
  846. }
  847. })
  848. if (this.fieldList.length && this.dataForm.fieldInfo.length === this.fieldList.length) {
  849. this.isSelectAll = true
  850. } else {
  851. this.isSelectAll = false
  852. }
  853. },
  854. /**
  855. * 获取数据预览
  856. * @param fieldDescMap 字段描述
  857. */
  858. getPreViewData (fieldDescMap) {
  859. this.dataPreviewList = []
  860. this.structurePreviewList = []
  861. this.structurePreviewListCopy = []
  862. if (!this.dataForm.sourceId || !this.dataForm.tableName) return
  863. const executeParams = {
  864. dataSourceId: this.dataForm.sourceId,
  865. script: JSON.stringify({
  866. fieldInfo: this.dataForm.fieldInfo, // 未选中字段就传空数组
  867. tableName: this.dataForm.tableName,
  868. repeatStatus: this.dataForm.repeatStatus
  869. }),
  870. // 原始表数据集没有数据集参数
  871. params: [],
  872. dataSetType: 'original',
  873. size: this.size,
  874. current: this.current
  875. }
  876. this.tableLoading = true
  877. datasetExecuteTest(executeParams).then((data) => {
  878. this.dataPreviewList = data.data.list
  879. this.structurePreviewList = data.structure
  880. // 如果是初始化
  881. if (this.isInit) {
  882. this.structurePreviewList = this.dataForm.fieldList
  883. this.isInit = false
  884. } else {
  885. this.structurePreviewList.forEach(item => {
  886. if (!item.hasOwnProperty('orderNum')) {
  887. this.$set(item, 'orderNum', 0)
  888. }
  889. if (!item.hasOwnProperty('sourceTable')) {
  890. this.$set(item, 'sourceTable', this.dataForm.tableName)
  891. }
  892. if (!item.hasOwnProperty('fieldDesc')) {
  893. let fieldDesc = ''
  894. if (fieldDescMap && fieldDescMap[item.fieldName]) {
  895. fieldDesc = fieldDescMap[item.fieldName]
  896. }
  897. this.$set(item, 'fieldDesc', fieldDesc)
  898. // this.structurePreviewList 和 this.oldStructurePreviewList 比较,如果旧的数据里fieldDesc有值则重新赋值给新的数据
  899. this.structurePreviewList.forEach(item => {
  900. const oldItem = this.oldStructurePreviewList.find(oldItem => oldItem.fieldName === item.fieldName)
  901. if (oldItem && oldItem.fieldDesc) {
  902. item.fieldDesc = oldItem.fieldDesc
  903. }
  904. })
  905. }
  906. })
  907. }
  908. this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
  909. this.totalCount = data.data.totalCount
  910. this.currentCount = data.data.currentCount
  911. this.tableLoading = false
  912. }).catch((e) => {
  913. this.dataPreviewList = []
  914. this.structurePreviewList = []
  915. this.structurePreviewListCopy = []
  916. this.totalCount = 0
  917. this.currentCount = 0
  918. this.tableLoading = false
  919. })
  920. },
  921. // 每页大小改变触发
  922. sizeChangeHandle (value) {
  923. this.size = value
  924. this.current = 1
  925. this.getData()
  926. },
  927. // 当前页数改变
  928. currentChangeHandle (value) {
  929. this.current = value
  930. this.getData()
  931. },
  932. selectorFilter (value) {
  933. this.$refs.categorySelectTree.filter(value)
  934. },
  935. treeFilter (value, data) {
  936. if (!value) return true
  937. return data.name.indexOf(value) !== -1
  938. },
  939. setField () {
  940. this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
  941. this.oldStructurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
  942. this.fieldsetVisible = false
  943. }
  944. }
  945. }
  946. </script>
  947. <style lang="scss" scoped>
  948. @import '../../assets/style/bsTheme.scss';
  949. .data-set-scrollbar {
  950. height: 100%;
  951. overflow-y: auto;
  952. overflow-x: none;
  953. }
  954. ::v-deep .el-input__inner {
  955. width: 100% !important;
  956. }
  957. .page-header {
  958. display: flex;
  959. position: relative;
  960. .page-header-right {
  961. position: absolute;
  962. right: 16px;
  963. }
  964. }
  965. ::v-deep .fieldDescCheck {
  966. .el-dialog__body {
  967. height: fit-content !important;
  968. min-height: unset !important;
  969. }
  970. }
  971. .title-style {
  972. padding: 8px 12px;
  973. background-color: #f6f7fb;
  974. border-left: 5px solid var(--bs-el-color-primary);
  975. margin: 16px 16px 0 0;
  976. }
  977. .field-wrap {
  978. max-height: 156px;
  979. overflow: auto;
  980. margin-right: 16px;
  981. .field-item {
  982. line-height: 32px;
  983. padding: 0 12px 0 16px;
  984. cursor: pointer;
  985. .edit_field {
  986. display: none;
  987. }
  988. &:hover {
  989. background-color: #f2f7fe;
  990. .edit_field {
  991. display: block;
  992. }
  993. }
  994. }
  995. }
  996. ::v-deep .bs-table-box.is-Edit .el-table {
  997. .el-table__body-wrapper {
  998. max-height: unset !important;
  999. }
  1000. }
  1001. .result-view {
  1002. font-size: 14px;
  1003. font-weight: 600;
  1004. color: var(--bs-el-text);
  1005. position: relative;
  1006. padding: 16px 0;
  1007. padding-left: 12px;
  1008. border-bottom: 1px solid var(--bs-background-1);
  1009. &::before {
  1010. content: "";
  1011. height: 14px;
  1012. position: absolute;
  1013. left: 0;
  1014. top: 50%;
  1015. transform: translateY(-50%);
  1016. border-left: 4px solid var(--bs-el-color-primary);
  1017. }
  1018. }
  1019. .bs-table-box {
  1020. height: 100% !important;
  1021. margin-bottom: 0 !important;
  1022. }
  1023. .bs-pagination {
  1024. padding: 16px !important;
  1025. position: unset !important;
  1026. ::v-deep .el-input__inner {
  1027. width: 110px !important;
  1028. border: none;
  1029. background: var(--bs-el-background-1);
  1030. }
  1031. }
  1032. // 修改el-select样式 loading 位置
  1033. ::v-deep .el-loading-spinner{
  1034. top: 75%;
  1035. }
  1036. </style>