EditForm.vue 17 KB

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