OriginalEditForm.vue 33 KB

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