EditForm.vue 17 KB

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