index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <div
  3. id="box"
  4. class="bs-container"
  5. @mousemove="mousemoveOnBox"
  6. @mouseup="mouseupOnBox"
  7. >
  8. <el-row
  9. v-show="datasetType === null"
  10. type="flex"
  11. class="layout"
  12. >
  13. <div
  14. id="left-box"
  15. class="left-box"
  16. :style="{ 'transition': transition + 's' }"
  17. >
  18. <div class="inner-container">
  19. <TypeTree
  20. ref="datasetsTypeTree"
  21. :dataset-type-list="datasetTypeList"
  22. :app-code="appCode"
  23. @nodeClick="nodeClick"
  24. @refreshData="refreshData"
  25. @expandedNodes="expandedNodes"
  26. @reCategory="getTreeList"
  27. />
  28. </div>
  29. </div>
  30. <div
  31. class="right-box inner-container"
  32. :style="{ 'transition': transition + 's' }"
  33. >
  34. <div
  35. id="resize"
  36. class="resize pack-up-box"
  37. @mousedown="mousedown"
  38. @mouseup="mouseup"
  39. @mousemove="mousemove"
  40. >
  41. <a
  42. v-if="isPackUpTree"
  43. @click="packUpTree"
  44. @mousedown="resize = null"
  45. @mouseup="resize = null"
  46. @mousemove="resize = null"
  47. >
  48. <i :class="isPackUpTree === false ? 'el-icon-caret-left' : 'el-icon-caret-right'" />
  49. </a>
  50. <a
  51. v-else
  52. class="visible-pack-up"
  53. >
  54. <span>||</span>
  55. </a>
  56. </div>
  57. <el-form
  58. ref="queryForm"
  59. :model="queryForm"
  60. class="filter-container"
  61. @submit.native.prevent
  62. >
  63. <el-form-item
  64. class="filter-item"
  65. prop="name"
  66. >
  67. <el-input
  68. v-model="queryForm.name"
  69. class="bs-el-input"
  70. placeholder="请输入数据集名称"
  71. clearable
  72. @keyup.enter.native="handleSearch()"
  73. @clear="handleSearch()"
  74. />
  75. </el-form-item>
  76. <el-form-item class="filter-item">
  77. <el-button
  78. :loading="dataListLoading"
  79. type="primary"
  80. icon="el-icon-search"
  81. @click="handleSearch()"
  82. >
  83. 查询
  84. </el-button>
  85. </el-form-item>
  86. <el-form-item class="filter-item">
  87. <el-button
  88. class="bs-el-button-default"
  89. @click="addDataset"
  90. >
  91. 新增
  92. </el-button>
  93. </el-form-item>
  94. </el-form>
  95. <div class="bs-table-box">
  96. <el-table
  97. ref="userTable"
  98. v-table
  99. v-loading="dataListLoading"
  100. height="100%"
  101. class="bs-el-table bs-scrollbar"
  102. :element-loading-text="loadingText"
  103. :data="tableData"
  104. :header-cell-style="sortStyle"
  105. @sort-change="reSort"
  106. @current-change="handleCurrentChange"
  107. @select="selectDs"
  108. @select-all="selectAll"
  109. >
  110. <el-empty slot="empty" />
  111. <el-table-column
  112. v-if="isDialog && multiple"
  113. type="selection"
  114. width="55"
  115. />
  116. <el-table-column
  117. prop="name"
  118. label="数据集名称"
  119. align="left"
  120. show-overflow-tooltip
  121. >
  122. <template slot-scope="scope">
  123. <el-radio
  124. v-if="isDialog && !multiple"
  125. v-model="curRow"
  126. :label="scope.row"
  127. >
  128. {{ scope.row.name }}
  129. </el-radio>
  130. <span v-else>{{ scope.row.name }}</span>
  131. </template>
  132. </el-table-column>
  133. <el-table-column
  134. prop="datasetType"
  135. label="数据集类型"
  136. align="center"
  137. show-overflow-tooltip
  138. >
  139. <template slot-scope="scope">
  140. <span>{{ datasetTypeList.find(type=>type.datasetType===scope.row.datasetType).name || '其他' }}</span>
  141. </template>
  142. </el-table-column>
  143. <el-table-column
  144. prop="remark"
  145. label="备注"
  146. align="left"
  147. show-overflow-tooltip
  148. />
  149. <!--操作栏-->
  150. <el-table-column
  151. label="操作"
  152. width="200"
  153. align="center"
  154. >
  155. <template
  156. v-if="showOperate(scope.row.datasetType)"
  157. slot-scope="scope"
  158. >
  159. <el-button
  160. class="bs-el-button-default"
  161. :disabled="scope.row.editable === 1 && !appCode"
  162. @click="toEdit(scope.row.id, scope.row.datasetType, scope.row.name, scope.row.typeId)"
  163. >
  164. 编辑
  165. </el-button>
  166. <el-button
  167. class="bs-el-button-default"
  168. :disabled="scope.row.editable === 1 && !appCode"
  169. @click="delDataset(scope.row.id)"
  170. >
  171. 删除
  172. </el-button>
  173. </template>
  174. </el-table-column>
  175. </el-table>
  176. </div>
  177. <div class="bs-pagination">
  178. <el-pagination
  179. class="bs-el-pagination"
  180. popper-class="bs-el-pagination"
  181. :current-page="current"
  182. :page-sizes="[10, 20, 50, 100]"
  183. :page-size="size"
  184. :total="totalCount"
  185. background
  186. prev-text="上一页"
  187. next-text="下一页"
  188. layout="total, prev, pager, next, sizes"
  189. @size-change="sizeChangeHandle"
  190. @current-change="currentChangeHandle"
  191. />
  192. </div>
  193. </div>
  194. </el-row>
  195. <!-- 新增-类型窗口 -->
  196. <DatasetTypeDialog
  197. ref="DatasetTypeDialog"
  198. :dataset-type-list="datasetTypeList"
  199. @openAddForm="openAddForm"
  200. />
  201. <component
  202. :is="componentData.component"
  203. ref="EditForm"
  204. :key="componentData.key"
  205. :config="componentData.config"
  206. :dataset-id="datasetId"
  207. :dataset-name="datasetName"
  208. :type-id="typeId"
  209. :is-edit="isEdit"
  210. :app-code="appCode"
  211. @back="back"
  212. />
  213. </div>
  214. </template>
  215. <script>
  216. import TypeTree from './TypeTree.vue'
  217. import JsonEditForm from './JsonEditForm.vue'
  218. import table from 'packages/js/utils/table.js'
  219. import ScriptEditForm from './ScriptEditForm.vue'
  220. import CustomEditForm from './CustomEditForm.vue'
  221. import { pageMixins } from 'packages/js/mixins/page'
  222. import OriginalEditForm from './OriginalEditForm.vue'
  223. import DatasetTypeDialog from './DatasetTypeDialog.vue'
  224. // import remoteComponents from '@/customDatasetComponents/exports.js'
  225. import StoredProcedureEditForm from './StoredProcedureEditForm.vue'
  226. import { datasetPage, datasetRemove } from 'packages/js/utils/datasetConfigService'
  227. export default {
  228. name: 'DataSetManagement',
  229. directives: {
  230. table // 注册自定义指令
  231. },
  232. components: {
  233. TypeTree,
  234. DatasetTypeDialog,
  235. OriginalEditForm,
  236. CustomEditForm,
  237. JsonEditForm,
  238. StoredProcedureEditForm,
  239. ScriptEditForm
  240. },
  241. mixins: [pageMixins],
  242. props: {
  243. multiple: {
  244. type: Boolean,
  245. default: false
  246. },
  247. isDialog: {
  248. type: Boolean,
  249. default: false
  250. },
  251. dsValue: {
  252. type: [Array, Object],
  253. default: null
  254. },
  255. appCode: {
  256. type: String,
  257. default: ''
  258. },
  259. isBorder: {
  260. type: Boolean,
  261. default: false
  262. }
  263. },
  264. data () {
  265. return {
  266. datasetType: null,
  267. isEdit: false,
  268. categoryData: [],
  269. tableData: [], // 表格数据
  270. queryForm: {
  271. name: '',
  272. datasetType: '',
  273. typeId: '' // 分类id
  274. }, // 查询条件
  275. // 数据集类型
  276. datasetTypeList: [],
  277. isPackUpTree: false,
  278. transition: 0.1,
  279. loadingText: '正在加载数据',
  280. dataListLoading: false,
  281. leftBox: null,
  282. rightBox: null,
  283. startX: null,
  284. event: null,
  285. endX: null,
  286. resize: null,
  287. datasetId: '', // 数据集Id,用于详情与编辑
  288. datasetName: '', // 数据集名称
  289. typeId: '', // 详情typeId
  290. curRow: null,
  291. multipleSelection: [],
  292. // 远程组件
  293. componentData: {
  294. component: null,
  295. config: null,
  296. key: new Date().getTime()
  297. }
  298. }
  299. },
  300. watch: {
  301. datasetType (value) {
  302. if (value === null) {
  303. this.datasetId = ''
  304. this.datasetName = ''
  305. this.isEdit = false
  306. }
  307. }
  308. },
  309. mounted () {
  310. this.init()
  311. if (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)) {
  312. // 当前浏览器为Safari浏览器
  313. // 执行相关操作
  314. document.addEventListener('mousemove', function (event) {
  315. if (event.buttons === 1) {
  316. event.preventDefault()
  317. }
  318. })
  319. }
  320. },
  321. methods: {
  322. toggleRowSelection () {
  323. this.$nextTick(() => {
  324. const dsIds = this.multipleSelection.map(ds => ds.id)
  325. this.$refs.userTable.clearSelection()
  326. this.tableData.forEach(item => {
  327. if (dsIds.includes(item.id)) {
  328. this.$refs.userTable.toggleRowSelection(item, true)
  329. }
  330. })
  331. })
  332. },
  333. // 全选
  334. selectAll (selection) {
  335. if (this.isDialog && this.multiple) {
  336. if (selection.length) {
  337. const dsIds = this.multipleSelection.map(ds => ds.id)
  338. selection.forEach(ds => {
  339. if (!dsIds.includes(ds.id)) {
  340. this.multipleSelection.push(ds)
  341. }
  342. })
  343. } else {
  344. this.tableData.forEach(row => {
  345. const dsIds = this.multipleSelection.map(ds => ds.id)
  346. const i = dsIds.indexOf(row.id)
  347. if (i > -1) this.multipleSelection.splice(i, 1)
  348. })
  349. }
  350. }
  351. },
  352. // 手动勾选
  353. selectDs (selection, row) {
  354. if (this.isDialog && this.multiple) {
  355. let dsIndex = null
  356. const ds = this.multipleSelection.find((ds, index) => {
  357. if (ds.id === row.id) {
  358. dsIndex = index
  359. return ds
  360. }
  361. })
  362. if (!ds) {
  363. this.multipleSelection.push(row)
  364. } else {
  365. this.multipleSelection.splice(dsIndex, 1)
  366. }
  367. }
  368. },
  369. // 获取选中数据集信息
  370. getSelectDs () {
  371. if (!this.isDialog) return
  372. if (this.multiple) {
  373. // 多选返回
  374. return this.multipleSelection
  375. } else {
  376. // 单选返回
  377. return this.curRow ? this.curRow : null
  378. }
  379. },
  380. // 单选数据集
  381. handleCurrentChange (currentRow) {
  382. this.curRow = currentRow
  383. },
  384. // 删除数据集
  385. delDataset (id) {
  386. this.$confirm('确定删除当前数据集吗?', '提示', {
  387. confirmButtonText: '确定',
  388. cancelButtonText: '取消',
  389. type: 'warning',
  390. customClass: 'bs-el-message-box'
  391. }).then(() => {
  392. datasetRemove(id).then(res => {
  393. this.init(false)
  394. this.$message.success('删除成功')
  395. })
  396. }).catch(() => {
  397. })
  398. },
  399. // 详情
  400. toPreview (id, type, name, typeId) {
  401. this.datasetId = id
  402. this.datasetType = type
  403. this.datasetName = name
  404. this.typeId = typeId
  405. this.isEdit = false
  406. },
  407. toEdit (id, type, name, typeId) {
  408. this.datasetId = id
  409. this.datasetType = type
  410. this.componentData = this.getComponents(this.datasetTypeList.find(item => item?.datasetType === type).componentName)
  411. this.datasetName = name
  412. this.typeId = typeId
  413. this.isEdit = true
  414. },
  415. // 回到管理端
  416. back () {
  417. this.datasetType = null
  418. this.isEdit = false
  419. },
  420. // 新增数据集-类型
  421. openAddForm (type, componentName) {
  422. this.datasetType = type
  423. this.componentData = this.getComponents(componentName)
  424. this.typeId = this.queryForm.typeId
  425. this.isEdit = true
  426. },
  427. showOperate (datasetType) {
  428. return this.getComponents(this.datasetTypeList.find(type => type.datasetType === datasetType).componentName)?.config?.showOperate ?? true
  429. },
  430. getComponents (componentName) {
  431. const components = Object.values(this.$options.components)
  432. let remoteComponentData = null
  433. if (window.BS_CONFIG?.customDatasetComponents.length > 0) {
  434. // 获取远程组件
  435. remoteComponentData = window.BS_CONFIG?.customDatasetComponents.find(item => item.config.componentName === componentName)
  436. }
  437. return {
  438. component: components.find(component => component.name === componentName) || remoteComponentData?.vueFile,
  439. config: remoteComponentData?.config || null,
  440. key: new Date().getTime()
  441. }
  442. },
  443. // 初始化
  444. init (temp = true) {
  445. if (temp) {
  446. this.getTreeList()
  447. }
  448. if (this.isDialog) {
  449. if (this.multiple) {
  450. this.multipleSelection = this.dsValue ? this.dsValue : []
  451. } else {
  452. this.curRow = this.dsValue
  453. }
  454. }
  455. this.current = 1
  456. this.getDataList()
  457. this.datasetTypeList = [
  458. { name: '全部', datasetType: '' },
  459. { name: '原始数据集', datasetType: 'original', componentName: 'OriginalEditForm' },
  460. { name: '自助数据集', datasetType: 'custom', componentName: 'CustomEditForm' },
  461. { name: '存储过程数据集', datasetType: 'storedProcedure', componentName: 'CustomEditForm' },
  462. { name: 'JSON数据集', datasetType: 'json', componentName: 'JsonEditForm' },
  463. { name: '脚本数据集', datasetType: 'script', componentName: 'ScriptEditForm' }
  464. ]
  465. // 将获得到的远程数据集进行组装
  466. window.BS_CONFIG?.customDatasetComponents.forEach((item) => {
  467. this.datasetTypeList.push({ name: item.config.name, datasetType: item.config.datasetType, componentName: item.config.componentName })
  468. })
  469. },
  470. // 新增数据集
  471. addDataset () {
  472. this.$refs.DatasetTypeDialog.dialogVisible = true
  473. },
  474. selectChange () {
  475. this.getDataList()
  476. },
  477. getTreeList () {
  478. },
  479. // 获取表格数据
  480. getDataList () {
  481. this.dataListLoading = true
  482. datasetPage({
  483. current: this.current,
  484. size: this.size,
  485. moduleCode: this.appCode,
  486. ...this.queryForm
  487. }).then((data) => {
  488. this.tableData = data.list
  489. if (this.isDialog) {
  490. if (this.multiple && this.multipleSelection.length) {
  491. this.toggleRowSelection()
  492. } else if (this.curRow.id) {
  493. const ds = this.tableData.find(item => item.id === this.curRow.id)
  494. if (ds) this.curRow = ds
  495. }
  496. }
  497. this.totalCount = data.totalCount
  498. this.dataListLoading = false
  499. }).catch(() => {
  500. this.dataListLoading = false
  501. })
  502. },
  503. expandedNodes (data) {
  504. if (data && data > 50) {
  505. this.transition = 0
  506. } else {
  507. this.transition = 0.1
  508. }
  509. },
  510. nodeClick (row, type) {
  511. this.current = 1
  512. if (type === 'group') {
  513. this.queryForm.typeId = row.id
  514. this.queryForm.datasetType = ''
  515. } else if (type === 'type') {
  516. this.queryForm.typeId = ''
  517. this.queryForm.datasetType = row
  518. }
  519. this.getDataList()
  520. },
  521. refreshData (node) {
  522. if (node && node.id === this.queryForm.typeId) {
  523. this.queryForm.typeId = ''
  524. }
  525. this.getDataList()
  526. },
  527. handleSearch () {
  528. this.current = 1
  529. this.queryForm.typeId = ''
  530. // 清除左侧机构树的选中状态
  531. this.$refs.datasetsTypeTree.ztreeObj.cancelSelectedNode()
  532. this.getDataList()
  533. },
  534. // 拖拽修改div宽度
  535. mousedown (e) {
  536. this.resize = document.getElementsByClassName('resize')[0]
  537. this.resize.left = document.getElementById('left-box').getBoundingClientRect().width
  538. this.leftBox = document.getElementsByClassName('left-box')[0]
  539. this.rightBox = document.getElementsByClassName('right-box')[0]
  540. this.startX = e.clientX
  541. },
  542. mousemove (e) {
  543. this.event = e
  544. if (this.resize) {
  545. const boxWidth = document.getElementById('box').getBoundingClientRect().width
  546. this.endX = e.clientX
  547. const offset = document.getElementById('box').getBoundingClientRect().left > 300 ? 0 : 25
  548. const moveLen = this.resize.left + (this.endX - this.startX) + offset
  549. this.leftBox.style.width = moveLen / boxWidth * 100 + '%'
  550. this.rightBox.style.width = ((1 - moveLen / boxWidth) * 100) + '%'
  551. this.isPackUpTree = false
  552. if (moveLen < 100 && this.endX - this.startX < 0) {
  553. this.isPackUpTree = true
  554. this.leftBox.style.width = '0%'
  555. this.rightBox.style.width = '100%'
  556. } else if (moveLen / boxWidth > 0.5) {
  557. this.leftBox.style.width = '50%'
  558. this.rightBox.style.width = '50%'
  559. }
  560. }
  561. },
  562. packUpTree () {
  563. this.$refs.datasetsTypeTree.expandedNodes()
  564. this.isPackUpTree = !this.isPackUpTree
  565. if (!this.isPackUpTree) {
  566. this.leftBox.style.width = '25%'
  567. this.rightBox.style.width = '75%'
  568. } else {
  569. this.leftBox.style.width = '0%'
  570. this.rightBox.style.width = '100%'
  571. }
  572. },
  573. mouseup () {
  574. if (this.resize) {
  575. this.resize = null
  576. if (this.endX < 350 && this.endX - this.startX > 0) {
  577. this.isPackUpTree = false
  578. this.leftBox.style.width = '25%'
  579. this.rightBox.style.width = '75%'
  580. }
  581. }
  582. },
  583. mousemoveOnBox (e) {
  584. this.mousemove(e)
  585. },
  586. mouseupOnBox () {
  587. this.resize = null
  588. if (this.endX < 350 && this.endX - this.startX > 0) {
  589. this.isPackUpTree = false
  590. this.leftBox.style.width = '25%'
  591. this.rightBox.style.width = '75%'
  592. }
  593. this.resize = null
  594. }
  595. }
  596. }
  597. </script>
  598. <style lang="scss" scoped>
  599. @import '~packages/assets/style/bsTheme.scss';
  600. @import '~packages/assets/style/zTree/treePackUp.scss';
  601. .bs-pagination {
  602. ::v-deep .el-input__inner {
  603. width: 110px !important;
  604. border:none;
  605. background: var(--bs-el-background-1);
  606. }
  607. }
  608. .bs-container .inner-container .el-form .filter-item {
  609. /deep/ .el-input__inner {
  610. width: 200px;
  611. }
  612. }
  613. .right-box {
  614. margin-left: 20px;
  615. // ::v-deep .ztreeNodeMenu {
  616. // ul {
  617. // background-color: var(--bs-background-1);
  618. // }
  619. // li:hover {
  620. // background-color: var(--bs-el-color-primary);
  621. // }
  622. // span {
  623. // color: var(--bs-el-text);
  624. // }
  625. // .triangle {
  626. // background-color: var(--bs-background-1) !important;
  627. // }
  628. // }
  629. }
  630. ::v-deep .left-tab-box {
  631. span {
  632. color: var(--bs-el-text);
  633. }
  634. }
  635. ::v-deep .left-tab-box ul li.tab-active {
  636. background-color: var(--bs-el-background-3);
  637. }
  638. ::v-deep .left-tab-box ul li:hover {
  639. background-color: var(--bs-el-background-3);
  640. }
  641. .el-dialog {
  642. .bs-container {
  643. max-height: calc(90vh - 236px) !important;
  644. .el-table {
  645. height: calc(90vh - 340px);
  646. }
  647. /deep/ .ztree {
  648. max-height: calc(90vh - 325px) !important;
  649. }
  650. /deep/ .el-tabs__item.is-active {
  651. border-bottom: none !important;
  652. }
  653. }
  654. }
  655. ::v-deep .ztreeNodeMenu {
  656. ul {
  657. background-color: var(--bs-background-1);
  658. }
  659. li:hover {
  660. background-color: var(--bs-el-background-3);
  661. span {
  662. color: var(--bs-el-color-primary);
  663. }
  664. }
  665. span {
  666. color: var(--bs-el-text);
  667. }
  668. .triangle {
  669. background-color: var(--bs-background-1) !important;
  670. }
  671. }
  672. .layout {
  673. width: 100%;
  674. height: 100%;
  675. }
  676. </style>