OriginalEditForm.vue 32 KB

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