EditForm.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <div>
  3. <el-dialog
  4. :close-on-click-modal="false"
  5. :title="title ? '编辑组件' : '新增组件'"
  6. :visible.sync="formVisible"
  7. :append-to-body="true"
  8. class="bs-dialog-wrap bs-el-dialog"
  9. @close="closeAddDialog"
  10. >
  11. <el-form
  12. ref="dataForm"
  13. :model="dataForm"
  14. :rules="dataFormRules"
  15. label-position="right"
  16. label-width="100px"
  17. class="bs-el-form"
  18. >
  19. <el-form-item
  20. label="名称"
  21. prop="name"
  22. >
  23. <el-input
  24. v-model="dataForm.name"
  25. autocomplete="off"
  26. placeholder="请输入名称"
  27. clearable
  28. maxlength="30"
  29. class="bs-el-input"
  30. />
  31. </el-form-item>
  32. <el-form-item
  33. v-if="type === 'bizComponent'&&!title"
  34. label="组件类型"
  35. >
  36. <el-select
  37. v-model="bizType"
  38. class="bs-el-select"
  39. popper-class="bs-el-select"
  40. placeholder="请选择组件类型"
  41. clearable
  42. >
  43. <el-option
  44. v-for="resolutionRatioItem in BizList"
  45. :key="resolutionRatioItem.value"
  46. :label="resolutionRatioItem.label"
  47. :value="resolutionRatioItem.value"
  48. />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item
  52. v-if="type === 'component'"
  53. label="推荐分辨率"
  54. >
  55. <el-select
  56. v-model="resolutionRatioValue"
  57. class="bs-el-select"
  58. popper-class="bs-el-select"
  59. placeholder="请选择分辨率"
  60. clearable
  61. >
  62. <el-option
  63. v-for="resolutionRatioItem in resolutionRatioOptions"
  64. :key="resolutionRatioItem.value"
  65. :label="resolutionRatioItem.label"
  66. :value="resolutionRatioItem.value"
  67. />
  68. </el-select>
  69. </el-form-item>
  70. <el-form-item
  71. v-if="type === 'component'"
  72. label="大屏宽度"
  73. >
  74. <el-input-number
  75. v-model="resolutionRatio.w"
  76. :min="100"
  77. :max="8000"
  78. class="bs-el-input-number"
  79. />
  80. </el-form-item>
  81. <el-form-item
  82. v-if="type === 'component'"
  83. label="大屏高度"
  84. >
  85. <el-input-number
  86. v-model="resolutionRatio.h"
  87. :min="100"
  88. :max="8000"
  89. class="bs-el-input-number"
  90. />
  91. </el-form-item>
  92. <el-form-item label="分组">
  93. <div v-if="type === 'component'">
  94. <el-select
  95. v-model="dataForm.parentCode"
  96. class="bs-el-select"
  97. popper-class="bs-el-select"
  98. clearable
  99. filterable
  100. >
  101. <el-option
  102. v-for="catalogItem in catalogList"
  103. :key="catalogItem.id"
  104. :label="catalogItem.name"
  105. :value="catalogItem.code"
  106. />
  107. </el-select>
  108. </div>
  109. <div v-else>
  110. <el-select
  111. v-model="dataForm.type"
  112. class="bs-el-select"
  113. popper-class="bs-el-select"
  114. clearable
  115. filterable
  116. >
  117. <el-option
  118. v-for="catalogItem in catalogList"
  119. :key="catalogItem.id"
  120. :label="catalogItem.name"
  121. :value="catalogItem.code"
  122. />
  123. </el-select>
  124. </div>
  125. </el-form-item>
  126. <el-form-item label="排序">
  127. <el-input-number
  128. v-model="dataForm.orderNum"
  129. :min="0"
  130. :max="30000"
  131. controls-position="right"
  132. class="bs-el-input-number"
  133. />
  134. </el-form-item>
  135. </el-form>
  136. <div
  137. slot="footer"
  138. class="dialog-footer"
  139. >
  140. <el-button
  141. class="bs-el-button-default"
  142. @click="closeAddDialog"
  143. >
  144. 取消
  145. </el-button>
  146. <el-button
  147. v-if="title"
  148. type="primary"
  149. :loading="toDesignLoading"
  150. :disabled="toDesignDisabled"
  151. @click="addOrUpdate(true)"
  152. >
  153. 设计
  154. </el-button>
  155. <el-button
  156. type="primary"
  157. :loading="sureLoading"
  158. :disabled="sureDisabled"
  159. @click="addOrUpdate(!title)"
  160. >
  161. 确定
  162. </el-button>
  163. </div>
  164. </el-dialog>
  165. </div>
  166. </template>
  167. <script>
  168. import Icon from 'data-room-ui/assets/images/dataSourceIcon/export'
  169. export default {
  170. name: 'EditForm',
  171. components: {
  172. },
  173. props: {
  174. type: {
  175. type: String,
  176. default: ''
  177. }
  178. },
  179. data () {
  180. return {
  181. bizType: 'native',
  182. resolutionRatioValue: '',
  183. resolutionRatio: {},
  184. catalogList: [],
  185. BizList: [
  186. {
  187. label: 'echarts组件',
  188. value: 'echart'
  189. }, {
  190. label: 'g2Plot组件',
  191. value: 'g2plot'
  192. }, {
  193. label: '基础组件',
  194. value: 'native'
  195. }
  196. ],
  197. resolutionRatioOptions: [
  198. {
  199. value: '1024*768',
  200. label: '1024*768'
  201. },
  202. {
  203. value: '1280*720',
  204. label: '1280*720'
  205. },
  206. {
  207. value: '1920*1080',
  208. label: '1920*1080'
  209. },
  210. {
  211. value: '2560*1440',
  212. label: '2560*1440'
  213. },
  214. {
  215. value: '3840*2160',
  216. label: '3840*2160'
  217. },
  218. {
  219. value: '5120*2880',
  220. label: '5120*2880'
  221. },
  222. {
  223. value: '7680*4320',
  224. label: '7680*4320'
  225. }
  226. ],
  227. formVisible: false,
  228. title: '', // 弹框标题(新增/编辑)
  229. dataForm: {
  230. id: '',
  231. type: '',
  232. name: '',
  233. icon: '',
  234. code: '',
  235. parentCode: '',
  236. remark: '',
  237. iconColor: '#007aff',
  238. components: '',
  239. style: '',
  240. formType: '',
  241. formConfig: '',
  242. pageTemplateId: ''
  243. },
  244. dataFormRules: {
  245. name: [
  246. { required: true, message: '名称不能为空', trigger: 'blur' },
  247. // 组件名称判重
  248. // 名称重复自定义校验
  249. {
  250. validator: (rule, value, callback) => {
  251. if (value) {
  252. const reqUrl = {
  253. component: '/bigScreen/design/name/repeat',
  254. bizComponent: '/bigScreen/bizComponent/name/repeat'
  255. }
  256. this.$dataRoomAxios.post(reqUrl[this.type], {
  257. name: value,
  258. type: this.type,
  259. id: this.dataForm.id
  260. }).then((resp) => {
  261. if (resp) {
  262. callback(new Error('名称已存在'))
  263. } else {
  264. callback()
  265. }
  266. })
  267. } else {
  268. callback()
  269. }
  270. },
  271. trigger: ['blur', 'change']
  272. }
  273. ]
  274. },
  275. sureLoading: false,
  276. toDesignLoading: false,
  277. sureDisabled: false,
  278. toDesignDisabled: false
  279. }
  280. },
  281. computed: {
  282. },
  283. watch: {
  284. resolutionRatioValue (val) {
  285. if (val) {
  286. this.resolutionRatio.w = val.split('*')[0]
  287. this.resolutionRatio.h = val.split('*')[1]
  288. } else {
  289. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  290. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  291. }
  292. }
  293. },
  294. mounted () {
  295. this.initResolution()
  296. },
  297. methods: {
  298. initResolution () {
  299. this.resolutionRatioValue = this.type === 'component' ? '1024*768' : '1920*1080'
  300. if (this.type === 'component') {
  301. this.resolutionRatio = {
  302. w: 1024,
  303. h: 768
  304. }
  305. } else {
  306. this.resolutionRatio = {
  307. w: 1920,
  308. h: 1080
  309. }
  310. }
  311. },
  312. // 关闭弹窗时
  313. closeAddDialog () {
  314. this.formVisible = false
  315. this.$refs.dataForm.resetFields()
  316. this.bizType = 'native'
  317. },
  318. // 初始化
  319. init (nodeData, parentCode) {
  320. if (this.type === 'component') {
  321. this.comInit(nodeData, parentCode)
  322. } else {
  323. this.bizInit(nodeData, parentCode)
  324. }
  325. },
  326. bizInit (nodeData, parentCode) {
  327. this.title = ''
  328. const code = nodeData ? nodeData.code : ''
  329. this.formVisible = true
  330. this.$nextTick(() => {
  331. this.$dataRoomAxios.get('/bigScreen/type/list/bizComponentCatalog').then((resp) => {
  332. this.catalogList = resp
  333. })
  334. if (code) {
  335. this.$dataRoomAxios.get(`/bigScreen/bizComponent/info/${code}`).then((resp) => {
  336. this.$set(this, 'title', resp.name)
  337. this.$set(this.dataForm, 'name', resp.name)
  338. this.$set(this.dataForm, 'code', resp.code)
  339. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  340. this.$set(this.dataForm, 'type', resp.type)
  341. this.$set(this.dataForm, 'id', resp.id)
  342. this.$set(this.dataForm, 'parentCode', resp.parentCode)
  343. })
  344. } else {
  345. this.$set(this.dataForm, 'name', '')
  346. this.$set(this.dataForm, 'code', '')
  347. this.$set(this.dataForm, 'type', parentCode)
  348. this.$set(this.dataForm, 'orderNum', 0)
  349. this.$set(this.dataForm, 'id', '')
  350. this.$set(this.dataForm, 'parentCode', parentCode)
  351. }
  352. })
  353. },
  354. comInit (nodeData, parentCode) {
  355. this.title = ''
  356. const code = nodeData ? nodeData.code : ''
  357. this.formVisible = true
  358. this.$nextTick(() => {
  359. this.$dataRoomAxios.get('/bigScreen/type/list/componentCatalog').then((resp) => {
  360. this.catalogList = resp
  361. })
  362. if (code) {
  363. this.$dataRoomAxios.get(`/bigScreen/design/info/code/${code}`).then((resp) => {
  364. this.$set(this, 'title', resp.name)
  365. this.$set(this.dataForm, 'name', resp.name)
  366. this.$set(this.dataForm, 'chartList', resp.chartList)
  367. this.$set(this.dataForm, 'code', resp.code)
  368. this.$set(this.dataForm, 'icon', resp.icon)
  369. this.$set(this.dataForm, 'iconColor', resp.iconColor)
  370. this.$set(this.dataForm, 'id', resp.id)
  371. this.$set(this.dataForm, 'parentCode', resp.parentCode === '0' ? '' : resp.parentCode)
  372. this.$set(this.dataForm, 'remark', resp.remark)
  373. this.$set(this.dataForm, 'style', resp.style)
  374. this.$set(this.dataForm, 'type', resp.type)
  375. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  376. this.$set(this.dataForm, 'pageTemplateId', resp?.pageTemplateId)
  377. this.$set(this.dataForm, 'pageConfig', resp?.pageConfig)
  378. this.$set(this.dataForm, 'parentCode', resp?.parentCode)
  379. const { w, h } = resp.pageConfig
  380. this.resolutionRatio.w = w
  381. this.resolutionRatio.h = h
  382. this.resolutionRatioValue = `${w}*${h}`
  383. })
  384. } else {
  385. this.$set(this.dataForm, 'name', '')
  386. this.$set(this.dataForm, 'chartList', [])
  387. this.$set(this.dataForm, 'code', '')
  388. this.$set(this.dataForm, 'icon', Icon.getNameList()[0])
  389. this.$set(this.dataForm, 'iconColor', '#007aff')
  390. this.$set(this.dataForm, 'id', '')
  391. this.$set(this.dataForm, 'parentCode', parentCode)
  392. this.$set(this.dataForm, 'remark', '')
  393. this.$set(this.dataForm, 'style', '')
  394. this.$set(this.dataForm, 'type', this.type)
  395. this.$set(this.dataForm, 'orderNum', 0)
  396. this.$set(this.dataForm, 'pageTemplateId', '')
  397. this.$set(this.dataForm, 'pageConfig', {
  398. w: this.type === 'component' ? 1024 : 1920,
  399. h: this.type === 'component' ? 768 : 1080,
  400. bgColor: '#151a26',
  401. opacity: 100,
  402. customTheme: 'dark',
  403. bg: null,
  404. lightBgColor: '#f5f7fa',
  405. lightBg: null,
  406. fitMode: 'auto'
  407. })
  408. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  409. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  410. }
  411. })
  412. },
  413. // 点击确定时
  414. addOrUpdate (isToDesign = false) {
  415. if (this.type === 'component') {
  416. this.addOrUpdateBigScreen(isToDesign)
  417. } else {
  418. this.addOrUpdateBizComponent(isToDesign)
  419. }
  420. },
  421. // 业务组件 新增/编辑
  422. addOrUpdateBizComponent (isToDesign) {
  423. this.$refs.dataForm.validate(async (valid) => {
  424. if (!valid) {
  425. return
  426. }
  427. const addOrUpdateHandel = !this.dataForm.code
  428. ? (form) => this.$dataRoomAxios.post('/bigScreen/bizComponent/add', form)
  429. : (form) => this.$dataRoomAxios.post('/bigScreen/bizComponent/update', form)
  430. const form = {
  431. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  432. id: this.dataForm.id,
  433. code: this.dataForm.code,
  434. name: this.dataForm.name,
  435. type: this.dataForm.type,
  436. orderNum: this.dataForm.orderNum
  437. }
  438. if (isToDesign) {
  439. this.toDesignLoading = true
  440. this.sureDisabled = true
  441. } else {
  442. this.sureLoading = true
  443. this.toDesignDisabled = true
  444. }
  445. addOrUpdateHandel(form)
  446. .then((code) => {
  447. this.formVisible = false
  448. const message = this.dataForm.code ? '更新成功' : '新增成功'
  449. this.$message.success(message)
  450. this.$emit('refreshData', form, this.dataForm.id)
  451. if (isToDesign) {
  452. this.toDesignLoading = false
  453. this.sureDisabled = false
  454. form.code = code || this.dataForm.code
  455. this.toDesign({ ...form })
  456. } else {
  457. this.sureLoading = false
  458. this.toDesignDisabled = false
  459. }
  460. })
  461. .catch(() => {
  462. this.sureLoading = false
  463. this.toDesignLoading = false
  464. this.sureDisabled = false
  465. this.toDesignDisabled = false
  466. })
  467. })
  468. },
  469. // 自定义组件 新增/编辑
  470. addOrUpdateBigScreen (isToDesign) {
  471. this.$refs.dataForm.validate(async (valid) => {
  472. if (!valid) {
  473. return
  474. }
  475. const addOrUpdateHandel = !this.dataForm.code
  476. ? (form) => this.$dataRoomAxios.post('/bigScreen/design/add', form)
  477. : (form) => this.$dataRoomAxios.post('/bigScreen/design/update', form)
  478. const form = {
  479. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  480. chartList: this.dataForm.chartList,
  481. code: this.dataForm.code,
  482. icon: this.dataForm.icon,
  483. iconColor: this.dataForm.iconColor,
  484. id: this.dataForm.id,
  485. name: this.dataForm.name,
  486. parentCode: this.dataForm.parentCode,
  487. remark: this.dataForm.remark,
  488. style: this.dataForm.style,
  489. orderNum: this.dataForm.orderNum,
  490. pageConfig: { ...this.dataForm.pageConfig, w: this.resolutionRatio.w, h: this.resolutionRatio.h },
  491. pageTemplateId: this.dataForm.pageTemplateId,
  492. type: this.type || 'component'
  493. }
  494. if (isToDesign) {
  495. this.toDesignLoading = true
  496. this.sureDisabled = true
  497. } else {
  498. this.sureLoading = true
  499. this.toDesignDisabled = true
  500. }
  501. addOrUpdateHandel(form)
  502. .then((code) => {
  503. this.formVisible = false
  504. const message = this.dataForm.code ? '更新成功' : '新增成功'
  505. this.$message.success(message)
  506. this.$emit('refreshData', form, this.dataForm.id)
  507. if (isToDesign) {
  508. this.toDesignLoading = false
  509. this.sureDisabled = false
  510. form.code = code || this.dataForm.code
  511. this.toDesign({ ...form })
  512. } else {
  513. this.sureLoading = false
  514. this.toDesignDisabled = false
  515. }
  516. })
  517. .catch(() => {
  518. this.sureLoading = false
  519. this.toDesignLoading = false
  520. this.sureDisabled = false
  521. this.toDesignDisabled = false
  522. })
  523. })
  524. },
  525. // 跳转设计态
  526. toDesign (form) {
  527. const path = this.type === 'component' ? (window.BS_CONFIG?.routers?.designUrl || '/big-screen/design') : 'big-screen-biz-component-design'
  528. const { href: bigScreenHref } = this.type === 'bizComponent' ? this.$router.resolve({
  529. path,
  530. query: {
  531. code: form.code,
  532. type: this.bizType
  533. }
  534. }) : this.$router.resolve({
  535. path,
  536. query: {
  537. code: form.code
  538. }
  539. })
  540. // 新窗口打开
  541. window.open(bigScreenHref, '_self')
  542. }
  543. }
  544. }
  545. </script>
  546. <style lang="scss" scoped>
  547. @import '../assets/style/bsTheme.scss';
  548. .el-scrollbar {
  549. height: 300px;
  550. overflow-x: hidden;
  551. ::v-deep .el-scrollbar__view {
  552. overflow-x: hidden;
  553. }
  554. }
  555. .color-picker {
  556. display: flex;
  557. align-items: center;
  558. }
  559. .icon-svg {
  560. width: 25px;
  561. height: 25px;
  562. }
  563. .color-select {
  564. width: 350px;
  565. display: flex;
  566. margin-top: 5px;
  567. align-items: center;
  568. justify-content: space-between;
  569. div {
  570. width: 20px;
  571. height: 20px;
  572. cursor: pointer;
  573. position: relative;
  574. }
  575. ::v-deep .el-color-picker__trigger {
  576. top: 0;
  577. right: 0;
  578. width: 21px;
  579. height: 21px;
  580. padding: 0;
  581. }
  582. .el-icon-check {
  583. font-size: 20px;
  584. color: #ffffff;
  585. position: absolute;
  586. }
  587. }
  588. .icon-list {
  589. margin-top: 15px;
  590. padding: 5px;
  591. border-radius: 5px;
  592. border: 1px solid #e8e8e8;
  593. .el-button--mini {
  594. min-width: 37px;
  595. padding: 5px !important;
  596. border: 1px solid transparent !important;
  597. &:hover {
  598. background-color: rgba(217, 217, 217, 0.3);
  599. }
  600. }
  601. }
  602. .icon-uploader {
  603. width: 60px;
  604. height: 60px;
  605. border: 1px dashed #d9d9d9;
  606. border-radius: 6px;
  607. cursor: pointer;
  608. position: relative;
  609. overflow: hidden;
  610. }
  611. .icon-uploader-icon {
  612. font-size: 28px;
  613. color: #8c939d;
  614. width: 60px;
  615. height: 60px;
  616. line-height: 60px;
  617. text-align: center;
  618. }
  619. .icon {
  620. width: 60px;
  621. height: 60px;
  622. display: block;
  623. }
  624. .default-layout-box {
  625. display: flex;
  626. flex-wrap: wrap;
  627. .default-layout-item {
  628. cursor: pointer;
  629. margin: 9px;
  630. display: flex;
  631. flex-direction: column;
  632. align-items: center;
  633. .component-name {
  634. font-size: 12px;
  635. }
  636. .sampleImg {
  637. margin: 0 auto;
  638. width: 102px;
  639. height: 73px;
  640. display: block;
  641. }
  642. .img_dispaly {
  643. margin: 0 auto;
  644. text-align: center;
  645. width: 100px;
  646. height: 70px;
  647. line-height: 70px;
  648. background-color: #D7D7D7;
  649. color: #999;
  650. }
  651. .demonstration {
  652. text-align: center;
  653. }
  654. }
  655. .default-layout-item:hover {
  656. cursor: pointer;
  657. }
  658. ::v-deep .el-radio__label {
  659. display: none;
  660. }
  661. }
  662. /*滚动条样式*/
  663. ::v-deep ::-webkit-scrollbar {
  664. width: 6px;
  665. border-radius: 4px;
  666. height: 4px;
  667. }
  668. ::v-deep ::-webkit-scrollbar-thumb {
  669. background: #dddddd !important;
  670. border-radius: 10px;
  671. }
  672. .catalog-cascader {
  673. width: 100% !important;
  674. }
  675. </style>