index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <template>
  2. <el-dialog
  3. title="组件库"
  4. :visible.sync="dialogVisible"
  5. width="80%"
  6. :modal="true"
  7. :modal-append-to-body="false"
  8. :appen-to-body="true"
  9. class="bs-dialog-wrap bs-el-dialog"
  10. @closed="close"
  11. >
  12. <div class="content">
  13. <el-tabs v-model="activeName">
  14. <el-tab-pane
  15. label="自定义组件"
  16. name="combination"
  17. >
  18. <div class="big-screen-list-wrap">
  19. <div class="top-search-wrap">
  20. <el-select
  21. v-model="code"
  22. class="bs-el-select"
  23. popper-class="bs-el-select"
  24. placeholder="请选择分组"
  25. filterable
  26. clearable
  27. @change="reSearch"
  28. >
  29. <el-option
  30. v-for="item in options"
  31. :key="item.code"
  32. :label="item.name"
  33. :value="item.code"
  34. />
  35. </el-select>
  36. <el-input
  37. v-model="searchKey"
  38. class="bs-el-input"
  39. placeholder="请输入组件名称"
  40. prefix-icon="el-icon-search"
  41. clearable
  42. @clear="reSearch"
  43. @keyup.enter.native="reSearch"
  44. />
  45. <el-button
  46. type="primary"
  47. @click="reSearch"
  48. >
  49. 搜索
  50. </el-button>
  51. </div>
  52. <div
  53. v-if="list.length !== 0"
  54. v-loading="loading"
  55. class="list-wrap bs-scrollbar"
  56. element-loading-text="加载中"
  57. :style="{
  58. display: gridComputed ? 'grid' : 'flex',
  59. justifyContent: gridComputed ? 'space-around' : 'flex-start',
  60. height: 'calc(100vh - 430px)'
  61. }"
  62. >
  63. <!-- <div v-if="list.length !== 0"> -->
  64. <div
  65. v-for="screen in list"
  66. :key="screen.id"
  67. class="big-screen-card-wrap"
  68. :style="{
  69. width: gridComputed ? 'auto' : '290px'
  70. }"
  71. @click="chooseComponent(screen)"
  72. >
  73. <div
  74. :class="focus.id == screen.id ? 'focus' : ''"
  75. class="big-screen-card-inner"
  76. >
  77. <div class="big-screen-card-img">
  78. <el-image
  79. :src="screen.coverPicture"
  80. fit="contain"
  81. style="width: 100%; height: 100%"
  82. >
  83. <div
  84. slot="placeholder"
  85. class="image-slot"
  86. >
  87. 加载中···
  88. </div>
  89. <div
  90. slot="error"
  91. class="image-slot"
  92. style="font-size: 20px"
  93. >
  94. <div class="error-img-text">
  95. {{ screen.name }}
  96. </div>
  97. </div>
  98. </el-image>
  99. </div>
  100. <div class="big-screen-bottom">
  101. <div
  102. class="left-bigscreen-title"
  103. :title="screen.name"
  104. >
  105. {{ screen.name }}
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. <div
  112. v-else
  113. class="empty"
  114. >
  115. 暂无数据
  116. </div>
  117. <div class="footer-pagination-wrap">
  118. <div class="bs-pagination">
  119. <el-pagination
  120. class="bs-el-pagination"
  121. popper-class="bs-el-pagination"
  122. background
  123. layout="total, prev, pager, next, sizes"
  124. :page-size="size"
  125. prev-text="上一页"
  126. next-text="下一页"
  127. :total="totalCount"
  128. :page-sizes="[10, 20, 50, 100]"
  129. :current-page="current"
  130. @current-change="currentChangeHandle"
  131. @size-change="sizeChangeHandle"
  132. />
  133. </div>
  134. </div>
  135. </div>
  136. </el-tab-pane>
  137. <el-tab-pane
  138. label="业务组件"
  139. name="bizComponent"
  140. >
  141. <div class="big-screen-list-wrap">
  142. <div class="top-search-wrap">
  143. <el-select
  144. v-model="code"
  145. class="bs-el-select"
  146. popper-class="bs-el-select"
  147. placeholder="请选择分组"
  148. filterable
  149. clearable
  150. @change="reSearch"
  151. >
  152. <el-option
  153. v-for="item in options"
  154. :key="item.code"
  155. :label="item.name"
  156. :value="item.code"
  157. />
  158. </el-select>
  159. <el-input
  160. v-model="name"
  161. class="bs-el-input"
  162. placeholder="请输入组件名称"
  163. prefix-icon="el-icon-search"
  164. clearable
  165. @clear="reSearch"
  166. @keyup.enter.native="reSearch"
  167. />
  168. <el-button
  169. type="primary"
  170. @click="reSearch"
  171. >
  172. 搜索
  173. </el-button>
  174. </div>
  175. <div
  176. v-if="bizComponentList.length !== 0"
  177. v-loading="loading"
  178. class="list-wrap bs-scrollbar"
  179. element-loading-text="加载中"
  180. :style="{
  181. display: bizFridComputed ? 'grid' : 'flex',
  182. justifyContent: bizFridComputed ? 'space-around' : 'flex-start',
  183. height: 'calc(100vh - 430px)'
  184. }"
  185. >
  186. <!-- <div v-if="list.length !== 0"> -->
  187. <div
  188. v-for="screen in bizComponentList"
  189. :key="screen.id"
  190. class="big-screen-card-wrap"
  191. :style="{
  192. width: bizFridComputed ? 'auto' : '290px'
  193. }"
  194. @click="chooseComponent(screen)"
  195. >
  196. <div
  197. :class="focus.id == screen.id ? 'focus' : ''"
  198. class="big-screen-card-inner"
  199. >
  200. <div class="big-screen-card-img">
  201. <el-image
  202. :src="screen.coverPicture"
  203. fit="contain"
  204. style="width: 100%; height: 100%"
  205. >
  206. <div
  207. slot="placeholder"
  208. class="image-slot"
  209. >
  210. 加载中···
  211. </div>
  212. <div
  213. slot="error"
  214. class="image-slot"
  215. style="font-size: 20px"
  216. >
  217. <div class="error-img-text">
  218. {{ screen.name }}
  219. </div>
  220. </div>
  221. </el-image>
  222. </div>
  223. <div class="big-screen-bottom">
  224. <div
  225. class="left-bigscreen-title"
  226. :title="screen.name"
  227. >
  228. {{ screen.name }}
  229. </div>
  230. </div>
  231. </div>
  232. </div>
  233. </div>
  234. <div
  235. v-else
  236. class="empty"
  237. >
  238. 暂无数据
  239. </div>
  240. <div class="footer-pagination-wrap">
  241. <div class="bs-pagination">
  242. <el-pagination
  243. class="bs-el-pagination"
  244. popper-class="bs-el-pagination"
  245. background
  246. layout="total, prev, pager, next, sizes"
  247. :page-size="size"
  248. prev-text="上一页"
  249. next-text="下一页"
  250. :total="bizComponenTotalCount"
  251. :page-sizes="[10, 20, 50, 100]"
  252. :current-page="current"
  253. @current-change="currentChangeHandle"
  254. @size-change="sizeChangeHandle"
  255. />
  256. </div>
  257. </div>
  258. </div>
  259. </el-tab-pane>
  260. <el-tab-pane
  261. label="系统组件"
  262. name="remote"
  263. >
  264. <div class="big-screen-list-wrap">
  265. <div
  266. v-if="remoteComponentlist.length !== 0"
  267. class="list-wrap bs-scrollbar"
  268. :style="{
  269. display: remoteComponentsGridComputed ? 'grid' : 'flex',
  270. justifyContent: remoteComponentsGridComputed ? 'space-around' : 'flex-start',
  271. height: 'calc(100vh - 385px)'
  272. }"
  273. >
  274. <div
  275. v-for="component in remoteComponentlist"
  276. :key="component.title"
  277. class="big-screen-card-wrap"
  278. :style="{
  279. width: remoteComponentsGridComputed ? 'auto' : '290px'
  280. }"
  281. @click="chooseComponent(component)"
  282. >
  283. <div
  284. :class="component.title == focus.title ? 'focus' : ''"
  285. class="big-screen-card-inner"
  286. >
  287. <div class="big-screen-card-img">
  288. <el-image
  289. :src="component.img"
  290. fit="contain"
  291. style="width: 100%; height: 100%"
  292. >
  293. <div
  294. slot="placeholder"
  295. class="image-slot"
  296. >
  297. 加载中···
  298. </div>
  299. </el-image>
  300. </div>
  301. <div class="big-screen-bottom">
  302. <div
  303. class="left-bigscreen-title"
  304. :title="component.title"
  305. >
  306. {{ component.title }}
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. </div>
  312. <div
  313. v-else
  314. class="empty"
  315. >
  316. 暂无数据
  317. </div>
  318. </div>
  319. </el-tab-pane>
  320. </el-tabs>
  321. </div>
  322. <div
  323. slot="footer"
  324. class="dialog-footer"
  325. >
  326. <el-button
  327. class="bs-el-button-default"
  328. @click="dialogVisible = false"
  329. >
  330. 取消
  331. </el-button>
  332. <el-button
  333. type="primary"
  334. @click="confirm"
  335. >
  336. 确定
  337. </el-button>
  338. <el-button
  339. type="primary"
  340. @click="jumpto"
  341. >
  342. 组件管理
  343. </el-button>
  344. </div>
  345. </el-dialog>
  346. </template>
  347. <script>
  348. import * as echarts from 'echarts'
  349. import { displayOption } from 'data-room-ui/js/config'
  350. import { pageMixins } from 'data-room-ui/js/mixins/page'
  351. // import _ from 'lodash'
  352. import isEmpty from 'lodash/isEmpty'
  353. import cloneDeep from 'lodash/cloneDeep'
  354. import innerRemoteComponents, { getRemoteComponents, getRemoteComponentConfig } from 'data-room-ui/RemoteComponents/remoteComponentsList'
  355. import { getBizComponentPage } from 'data-room-ui/js/api/bigScreenApi'
  356. export default {
  357. name: 'ComponentDialog',
  358. mixins: [pageMixins],
  359. props: {},
  360. data () {
  361. return {
  362. dialogVisible: false,
  363. loading: false,
  364. options: [], // 分组列表
  365. code: '',
  366. focus: -1,
  367. list: [],
  368. searchKey: '',
  369. name: '', // 业务组件搜索关键字
  370. activeName: 'combination',
  371. remoteComponentlist: [],
  372. // 业务组件列表
  373. bizComponentList: [],
  374. bizComponenTotalCount: 0
  375. }
  376. },
  377. computed: {
  378. gridComputed () {
  379. return this.list.length > 3
  380. },
  381. remoteComponentsGridComputed () {
  382. return this.remoteComponentlist.length > 3
  383. },
  384. bizFridComputed () {
  385. return this.bizComponentList.length > 3
  386. }
  387. },
  388. watch: {
  389. activeName () {
  390. this.getCatalogList()
  391. this.current = 1
  392. this.size = 10
  393. this.getDataList()
  394. }
  395. },
  396. mounted () {
  397. this.remoteComponentlist = [...innerRemoteComponents, ...getRemoteComponents()]
  398. },
  399. methods: {
  400. jumpto () {
  401. const { href } = this.$router.resolve('/dataRoom-redirect?edit=component')
  402. window.open(href, '_blank')
  403. },
  404. chooseComponent (component) {
  405. this.focus = cloneDeep(component)
  406. },
  407. close () { },
  408. init () {
  409. this.dialogVisible = true
  410. this.current = 1
  411. this.searchKey = ''
  412. this.code = ''
  413. this.focus = -1
  414. this.getDataList()
  415. this.getCatalogList()
  416. },
  417. // 点击确定
  418. confirm () {
  419. this.dialogVisible = false
  420. if (this.activeName === 'combination') {
  421. if (Object.keys(this.focus).length) {
  422. this.$emit('setComponent', this.focus)
  423. }
  424. } else if (['remote'].includes(this.activeName)) {
  425. if (isEmpty(this.focus)) {
  426. return
  427. }
  428. this.$emit('setRemoteComponent', this.focus)
  429. } if (['bizComponent'].includes(this.activeName)) {
  430. let config = {
  431. setting: [],
  432. option: {}
  433. }
  434. if (isEmpty(this.focus)) {
  435. return
  436. }
  437. config.code = this.focus.code
  438. config.name = this.focus.name
  439. config = cloneDeep(getRemoteComponentConfig(this.focus.code, this.focus.name))
  440. const settingContent = cloneDeep(this.resolveStrSetting(this.focus.settingContent))
  441. config.setting = settingContent.setting
  442. config.option = settingContent.option
  443. this.$emit('setRemoteComponent', config)
  444. // config = getRemoteComponentConfig(this.focus.code, this.focus.name)
  445. // this.$emit('setRemoteComponent', config)
  446. }
  447. },
  448. getDataList () {
  449. if (this.activeName === 'combination') {
  450. this.loading = true
  451. this.$dataRoomAxios.get('/bigScreen/design/page', {
  452. parentCode: this.code || null,
  453. current: this.current,
  454. size: this.size,
  455. searchKey: this.searchKey,
  456. type: 'component'
  457. })
  458. .then((data) => {
  459. this.loading = false
  460. this.list = data.list
  461. this.totalCount = data.totalCount
  462. })
  463. .catch(() => {
  464. this.loading = false
  465. })
  466. } else if (this.activeName === 'bizComponent') {
  467. this.loading = true
  468. getBizComponentPage({
  469. parentCode: this.code || null,
  470. current: this.current,
  471. size: this.size,
  472. searchKey: this.searchKey,
  473. name: this.name
  474. })
  475. .then((data) => {
  476. this.loading = false
  477. this.bizComponentList = data.list
  478. this.bizComponenTotalCount = data.totalCount
  479. })
  480. .catch(() => {
  481. this.loading = false
  482. })
  483. }
  484. },
  485. /**
  486. * 处理当前组件的字符串配置
  487. */
  488. resolveStrSetting (settingContent) {
  489. // eslint-disable-next-line prefer-const
  490. let option = {}
  491. // eslint-disable-next-line prefer-const
  492. let setting = []
  493. // eslint-disable-next-line prefer-const, no-unused-vars
  494. let title = []
  495. // eslint-disable-next-line prefer-const, no-unused-vars
  496. let data = []
  497. // eslint-disable-next-line prefer-const
  498. settingContent = settingContent.replaceAll('const ', '')
  499. // 去掉 export default及后面代码
  500. settingContent = settingContent.replace(/export default[\s\S]*/, '')
  501. eval(settingContent)
  502. option = {
  503. data,
  504. displayOption,
  505. ...option
  506. }
  507. return {
  508. option,
  509. setting
  510. }
  511. },
  512. // 获取目录的列表
  513. getCatalogList () {
  514. const url = this.activeName === 'combination' ? '/bigScreen/type/list/componentCatalog' : '/bigScreen/type/list/bizComponentCatalog'
  515. this.$dataRoomAxios.get(url)
  516. .then((data) => {
  517. this.options = data
  518. })
  519. .catch(() => { })
  520. }
  521. }
  522. }
  523. </script>
  524. <style lang="scss" scoped>
  525. @import '../../assets/style/bsTheme.scss';
  526. .content{
  527. height: calc(100vh - 290px);
  528. }
  529. .big-screen-list-wrap {
  530. .el-select {
  531. display: inline-block !important;
  532. position: relative !important;
  533. width: auto !important;
  534. }
  535. position: relative;
  536. height: 100%;
  537. // margin:0 16px;
  538. // padding: 16px;
  539. margin-bottom: 56px;
  540. color: #9ea9b2;
  541. background-color: var(--bs-background-2) !important;
  542. .top-search-wrap {
  543. display: flex;
  544. align-items: center;
  545. justify-content: flex-end;
  546. margin-bottom: 12px;
  547. .el-input {
  548. width: 200px;
  549. margin-right: 20px;
  550. ::v-deep.el-input__inner {
  551. background-color: var(--bs-background-1) !important;
  552. }
  553. }
  554. .el-select {
  555. margin-right: 20px;
  556. ::v-deep.el-input__inner {
  557. background-color: var(--bs-background-1) !important;
  558. }
  559. }
  560. }
  561. .list-wrap {
  562. /* display: grid; */
  563. overflow: auto;
  564. // 间隙自适应
  565. justify-content: space-around;
  566. // max-height: calc(100vh - 270px);
  567. display: grid;
  568. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  569. grid-gap: 15px;
  570. .big-screen-card-wrap {
  571. position: relative;
  572. height: 230px;
  573. cursor: pointer;
  574. &:hover {
  575. .screen-card__hover {
  576. height: 180px;
  577. }
  578. }
  579. .screen-card__hover {
  580. position: absolute;
  581. z-index: 999;
  582. top: 0;
  583. right: 0;
  584. left: 0;
  585. display: flex;
  586. overflow: hidden;
  587. align-items: center;
  588. justify-content: center;
  589. height: 0;
  590. transition: height 0.4s;
  591. background: #00000099;
  592. }
  593. .focus {
  594. color: var(--bs-el-text) !important;
  595. border: 1px solid var(--bs-el-color-primary) !important;
  596. }
  597. .big-screen-card-inner {
  598. overflow: hidden;
  599. width: 100%;
  600. height: 100%;
  601. cursor: pointer;
  602. background-color: var(--bs-background-2);
  603. box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
  604. color: var(--bs-el-title);
  605. border: 1px solid var(--bs-background-1);
  606. &:hover {
  607. color: var(--bs-el-text);
  608. border: 1px solid var(--bs-el-color-primary);
  609. }
  610. .add-big-screen-card-text {
  611. color: var(--bs-el-color-primary);
  612. font-size: 24px;
  613. }
  614. .big-screen-card-img {
  615. width: 100%;
  616. height: 180px;
  617. img {
  618. width: 100%;
  619. height: 100%;
  620. object-fit: cover;
  621. }
  622. ::v-deep.image-slot {
  623. height: 100%;
  624. background-color: var(--bs-background-2);
  625. display: flex;
  626. align-items: center;
  627. justify-content: center;
  628. }
  629. ::v-deep.el-image__error {
  630. background-color: #1d1d1d;
  631. }
  632. }
  633. .big-screen-bottom {
  634. display: flex;
  635. align-items: center;
  636. flex-direction: row;
  637. justify-content: space-between;
  638. box-sizing: border-box;
  639. width: 100%;
  640. /*height: 26px;*/
  641. padding: 0 10px;
  642. height: calc(100% - 180px);
  643. color: var(--bs-el-title);
  644. background-color: var(--bs-background-2);
  645. .left-bigscreen-title {
  646. font-size: 14px;
  647. overflow: hidden;
  648. width: 120px;
  649. white-space: nowrap;
  650. text-overflow: ellipsis;
  651. }
  652. .right-bigscreen-time-title {
  653. font-size: 14px;
  654. overflow: hidden;
  655. width: 140px;
  656. white-space: nowrap;
  657. text-overflow: ellipsis;
  658. }
  659. }
  660. .big-screen-card-text {
  661. font-size: 14px;
  662. padding: 10px;
  663. text-align: center;
  664. color: #333;
  665. }
  666. }
  667. .big-screen-card-inner-add {
  668. display: flex;
  669. align-items: center;
  670. justify-content: center;
  671. }
  672. }
  673. }
  674. .el-loading-parent--relative {
  675. position: unset !important;
  676. }
  677. .footer-pagination-wrap {
  678. margin-top: 16px;
  679. position: absolute;
  680. width: 100%;
  681. }
  682. }
  683. .bs-pagination {
  684. ::v-deep .el-input__inner {
  685. width: 110px !important;
  686. border: none;
  687. background: var(--bs-el-background-1);
  688. }
  689. }
  690. .empty {
  691. width: 100%;
  692. height: 70%;
  693. min-height: 300px;
  694. display: flex;
  695. justify-content: center;
  696. align-items: center;
  697. }
  698. ::v-deep .el-tabs__item {
  699. color: var(--bs-el-text);
  700. }
  701. .error-img-text {
  702. overflow: hidden;
  703. padding: 0 10px;
  704. white-space: nowrap;
  705. text-overflow: ellipsis;
  706. -o-text-overflow: ellipsis;
  707. }
  708. ::v-deep .el-tabs__nav-wrap {
  709. &:after {
  710. display: none;
  711. }
  712. }
  713. .empty{
  714. height: calc(100vh - 430px);
  715. }
  716. </style>