index.vue 21 KB

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