EditForm.vue 15 KB

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