EditForm.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. <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: 'echart'
  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. const reqUrl = {
  217. component: '/bigScreen/design/name/repeat',
  218. bizComponent: '/bigScreen/bizComponent/name/repeat'
  219. }
  220. this.$dataRoomAxios.post(reqUrl[this.type], {
  221. name: value,
  222. type: this.type,
  223. id: this.dataForm.id
  224. }).then((resp) => {
  225. if (resp) {
  226. callback(new Error('名称已存在'))
  227. } else {
  228. callback()
  229. }
  230. })
  231. } else {
  232. callback()
  233. }
  234. },
  235. trigger: ['blur', 'change']
  236. }
  237. ]
  238. },
  239. sureLoading: false,
  240. toDesignLoading: false,
  241. sureDisabled: false,
  242. toDesignDisabled: false
  243. }
  244. },
  245. computed: {
  246. },
  247. watch: {
  248. resolutionRatioValue (val) {
  249. if (val) {
  250. this.resolutionRatio.w = val.split('*')[0]
  251. this.resolutionRatio.h = val.split('*')[1]
  252. } else {
  253. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  254. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  255. }
  256. }
  257. },
  258. mounted () {
  259. this.initResolution()
  260. },
  261. methods: {
  262. initResolution () {
  263. this.resolutionRatioValue = this.type === 'component' ? '1024*768' : '1920*1080'
  264. if (this.type === 'component') {
  265. this.resolutionRatio = {
  266. w: 1024,
  267. h: 768
  268. }
  269. } else {
  270. this.resolutionRatio = {
  271. w: 1920,
  272. h: 1080
  273. }
  274. }
  275. },
  276. // 关闭弹窗时
  277. closeAddDialog () {
  278. this.formVisible = false
  279. this.$refs.dataForm.resetFields()
  280. this.bizType = 'native'
  281. },
  282. // 初始化
  283. init (nodeData, parentCode) {
  284. if (this.type === 'component') {
  285. this.comInit(nodeData, parentCode)
  286. } else {
  287. this.bizInit(nodeData, parentCode)
  288. }
  289. },
  290. bizInit (nodeData, parentCode) {
  291. this.title = ''
  292. const code = nodeData ? nodeData.code : ''
  293. this.formVisible = true
  294. this.$nextTick(() => {
  295. if (code) {
  296. this.$dataRoomAxios.get(`/bigScreen/bizComponent/info/${code}`).then((resp) => {
  297. this.$set(this, 'title', resp.name)
  298. this.$set(this.dataForm, 'name', resp.name)
  299. this.$set(this.dataForm, 'code', resp.code)
  300. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  301. this.$set(this.dataForm, 'type', resp.type)
  302. this.$set(this.dataForm, 'id', resp.id)
  303. })
  304. } else {
  305. this.$set(this.dataForm, 'name', '')
  306. this.$set(this.dataForm, 'code', '')
  307. this.$set(this.dataForm, 'type', parentCode)
  308. this.$set(this.dataForm, 'orderNum', 0)
  309. this.$set(this.dataForm, 'id', '')
  310. }
  311. })
  312. },
  313. comInit (nodeData, parentCode) {
  314. this.title = ''
  315. const code = nodeData ? nodeData.code : ''
  316. this.formVisible = true
  317. this.$nextTick(() => {
  318. if (code) {
  319. this.$dataRoomAxios.get(`/bigScreen/design/info/code/${code}`).then((resp) => {
  320. this.$set(this, 'title', resp.name)
  321. this.$set(this.dataForm, 'name', resp.name)
  322. this.$set(this.dataForm, 'chartList', resp.chartList)
  323. this.$set(this.dataForm, 'code', resp.code)
  324. this.$set(this.dataForm, 'icon', resp.icon)
  325. this.$set(this.dataForm, 'iconColor', resp.iconColor)
  326. this.$set(this.dataForm, 'id', resp.id)
  327. this.$set(this.dataForm, 'parentCode', resp.parentCode === '0' ? '' : resp.parentCode)
  328. this.$set(this.dataForm, 'remark', resp.remark)
  329. this.$set(this.dataForm, 'style', resp.style)
  330. this.$set(this.dataForm, 'type', resp.type)
  331. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  332. this.$set(this.dataForm, 'pageTemplateId', resp?.pageTemplateId)
  333. this.$set(this.dataForm, 'pageConfig', resp?.pageConfig)
  334. const { w, h } = resp.pageConfig
  335. this.resolutionRatio.w = w
  336. this.resolutionRatio.h = h
  337. this.resolutionRatioValue = `${w}*${h}`
  338. })
  339. } else {
  340. this.$set(this.dataForm, 'name', '')
  341. this.$set(this.dataForm, 'chartList', [])
  342. this.$set(this.dataForm, 'code', '')
  343. this.$set(this.dataForm, 'icon', Icon.getNameList()[0])
  344. this.$set(this.dataForm, 'iconColor', '#007aff')
  345. this.$set(this.dataForm, 'id', '')
  346. this.$set(this.dataForm, 'parentCode', parentCode)
  347. this.$set(this.dataForm, 'remark', '')
  348. this.$set(this.dataForm, 'style', '')
  349. this.$set(this.dataForm, 'type', this.type)
  350. this.$set(this.dataForm, 'orderNum', 0)
  351. this.$set(this.dataForm, 'pageTemplateId', '')
  352. this.$set(this.dataForm, 'pageConfig', {
  353. w: this.type === 'component' ? 1024 : 1920,
  354. h: this.type === 'component' ? 768 : 1080,
  355. bgColor: '#151a26',
  356. opacity: 100,
  357. customTheme: 'dark',
  358. bg: null,
  359. lightBgColor: '#f5f7fa',
  360. lightBg: null,
  361. fitMode: 'auto'
  362. })
  363. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  364. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  365. }
  366. })
  367. },
  368. // 点击确定时
  369. addOrUpdate (isToDesign = false) {
  370. if (this.type === 'component') {
  371. this.addOrUpdateBigScreen(isToDesign)
  372. } else {
  373. this.addOrUpdateBizComponent(isToDesign)
  374. }
  375. },
  376. // 业务组件 新增/编辑
  377. addOrUpdateBizComponent (isToDesign) {
  378. this.$refs.dataForm.validate(async (valid) => {
  379. if (!valid) {
  380. return
  381. }
  382. const addOrUpdateHandel = !this.dataForm.code
  383. ? (form) => this.$dataRoomAxios.post('/bigScreen/bizComponent/add', form)
  384. : (form) => this.$dataRoomAxios.post('/bigScreen/bizComponent/update', form)
  385. const form = {
  386. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  387. id: this.dataForm.id,
  388. code: this.dataForm.code,
  389. name: this.dataForm.name,
  390. type: this.dataForm.type,
  391. orderNum: this.dataForm.orderNum
  392. }
  393. if (isToDesign) {
  394. this.toDesignLoading = true
  395. this.sureDisabled = true
  396. } else {
  397. this.sureLoading = true
  398. this.toDesignDisabled = true
  399. }
  400. addOrUpdateHandel(form)
  401. .then((code) => {
  402. this.formVisible = false
  403. const message = this.dataForm.code ? '更新成功' : '新增成功'
  404. this.$message.success(message)
  405. this.$emit('refreshData', form, this.dataForm.id)
  406. if (isToDesign) {
  407. this.toDesignLoading = false
  408. this.sureDisabled = false
  409. form.code = code || this.dataForm.code
  410. this.toDesign({ ...form })
  411. } else {
  412. this.sureLoading = false
  413. this.toDesignDisabled = false
  414. }
  415. })
  416. .catch(() => {
  417. this.sureLoading = false
  418. this.toDesignLoading = false
  419. this.sureDisabled = false
  420. this.toDesignDisabled = false
  421. })
  422. })
  423. },
  424. // 自定义组件 新增/编辑
  425. addOrUpdateBigScreen (isToDesign) {
  426. this.$refs.dataForm.validate(async (valid) => {
  427. if (!valid) {
  428. return
  429. }
  430. const addOrUpdateHandel = !this.dataForm.code
  431. ? (form) => this.$dataRoomAxios.post('/bigScreen/design/add', form)
  432. : (form) => this.$dataRoomAxios.post('/bigScreen/design/update', form)
  433. const form = {
  434. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  435. chartList: this.dataForm.chartList,
  436. code: this.dataForm.code,
  437. icon: this.dataForm.icon,
  438. iconColor: this.dataForm.iconColor,
  439. id: this.dataForm.id,
  440. name: this.dataForm.name,
  441. parentCode: this.dataForm.parentCode,
  442. remark: this.dataForm.remark,
  443. style: this.dataForm.style,
  444. orderNum: this.dataForm.orderNum,
  445. pageConfig: { ...this.dataForm.pageConfig, w: this.resolutionRatio.w, h: this.resolutionRatio.h },
  446. pageTemplateId: this.dataForm.pageTemplateId,
  447. type: this.type || 'component'
  448. }
  449. if (isToDesign) {
  450. this.toDesignLoading = true
  451. this.sureDisabled = true
  452. } else {
  453. this.sureLoading = true
  454. this.toDesignDisabled = true
  455. }
  456. addOrUpdateHandel(form)
  457. .then((code) => {
  458. this.formVisible = false
  459. const message = this.dataForm.code ? '更新成功' : '新增成功'
  460. this.$message.success(message)
  461. this.$emit('refreshData', form, this.dataForm.id)
  462. if (isToDesign) {
  463. this.toDesignLoading = false
  464. this.sureDisabled = false
  465. form.code = code || this.dataForm.code
  466. this.toDesign({ ...form })
  467. } else {
  468. this.sureLoading = false
  469. this.toDesignDisabled = false
  470. }
  471. })
  472. .catch(() => {
  473. this.sureLoading = false
  474. this.toDesignLoading = false
  475. this.sureDisabled = false
  476. this.toDesignDisabled = false
  477. })
  478. })
  479. },
  480. // 跳转设计态
  481. toDesign (form) {
  482. const path = this.type === 'component' ? (window.BS_CONFIG?.routers?.designUrl || '/big-screen/design') : 'big-screen-biz-component-design'
  483. const { href: bigScreenHref } = this.type === 'bizComponent' ? this.$router.resolve({
  484. path,
  485. query: {
  486. code: form.code,
  487. type: this.bizType
  488. }
  489. }) : this.$router.resolve({
  490. path,
  491. query: {
  492. code: form.code
  493. }
  494. })
  495. // 新窗口打开
  496. window.open(bigScreenHref, '_self')
  497. }
  498. }
  499. }
  500. </script>
  501. <style lang="scss" scoped>
  502. @import '../assets/style/bsTheme.scss';
  503. .el-scrollbar {
  504. height: 300px;
  505. overflow-x: hidden;
  506. ::v-deep .el-scrollbar__view {
  507. overflow-x: hidden;
  508. }
  509. }
  510. .color-picker {
  511. display: flex;
  512. align-items: center;
  513. }
  514. .icon-svg {
  515. width: 25px;
  516. height: 25px;
  517. }
  518. .color-select {
  519. width: 350px;
  520. display: flex;
  521. margin-top: 5px;
  522. align-items: center;
  523. justify-content: space-between;
  524. div {
  525. width: 20px;
  526. height: 20px;
  527. cursor: pointer;
  528. position: relative;
  529. }
  530. ::v-deep .el-color-picker__trigger {
  531. top: 0;
  532. right: 0;
  533. width: 21px;
  534. height: 21px;
  535. padding: 0;
  536. }
  537. .el-icon-check {
  538. font-size: 20px;
  539. color: #ffffff;
  540. position: absolute;
  541. }
  542. }
  543. .icon-list {
  544. margin-top: 15px;
  545. padding: 5px;
  546. border-radius: 5px;
  547. border: 1px solid #e8e8e8;
  548. .el-button--mini {
  549. min-width: 37px;
  550. padding: 5px !important;
  551. border: 1px solid transparent !important;
  552. &:hover {
  553. background-color: rgba(217, 217, 217, 0.3);
  554. }
  555. }
  556. }
  557. .icon-uploader {
  558. width: 60px;
  559. height: 60px;
  560. border: 1px dashed #d9d9d9;
  561. border-radius: 6px;
  562. cursor: pointer;
  563. position: relative;
  564. overflow: hidden;
  565. }
  566. .icon-uploader-icon {
  567. font-size: 28px;
  568. color: #8c939d;
  569. width: 60px;
  570. height: 60px;
  571. line-height: 60px;
  572. text-align: center;
  573. }
  574. .icon {
  575. width: 60px;
  576. height: 60px;
  577. display: block;
  578. }
  579. .default-layout-box {
  580. display: flex;
  581. flex-wrap: wrap;
  582. .default-layout-item {
  583. cursor: pointer;
  584. margin: 9px;
  585. display: flex;
  586. flex-direction: column;
  587. align-items: center;
  588. .component-name {
  589. font-size: 12px;
  590. }
  591. .sampleImg {
  592. margin: 0 auto;
  593. width: 102px;
  594. height: 73px;
  595. display: block;
  596. }
  597. .img_dispaly {
  598. margin: 0 auto;
  599. text-align: center;
  600. width: 100px;
  601. height: 70px;
  602. line-height: 70px;
  603. background-color: #D7D7D7;
  604. color: #999;
  605. }
  606. .demonstration {
  607. text-align: center;
  608. }
  609. }
  610. .default-layout-item:hover {
  611. cursor: pointer;
  612. }
  613. ::v-deep .el-radio__label {
  614. display: none;
  615. }
  616. }
  617. /*滚动条样式*/
  618. ::v-deep ::-webkit-scrollbar {
  619. width: 6px;
  620. border-radius: 4px;
  621. height: 4px;
  622. }
  623. ::v-deep ::-webkit-scrollbar-thumb {
  624. background: #dddddd !important;
  625. border-radius: 10px;
  626. }
  627. .catalog-cascader {
  628. width: 100% !important;
  629. }
  630. </style>