EditForm.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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: 'dark',
  299. bg: null,
  300. lightBgColor: '#f5f7fa',
  301. lightBg: null,
  302. fitMode: 'auto'
  303. })
  304. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  305. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  306. }
  307. })
  308. },
  309. // 点击确定时
  310. addOrUpdate (isToDesign = false) {
  311. if (this.type === 'component') {
  312. this.addOrUpdateBigScreen(isToDesign)
  313. } else {
  314. this.addOrUpdateBizComponent(isToDesign)
  315. }
  316. },
  317. // 业务组件 新增/编辑
  318. addOrUpdateBizComponent (isToDesign) {
  319. this.$refs.dataForm.validate(async (valid) => {
  320. if (!valid) {
  321. return
  322. }
  323. const addOrUpdateHandel = !this.dataForm.code
  324. ? (form) => this.$dataRoomAxios.post('/bigScreen/bizComponent/add', form)
  325. : (form) => this.$dataRoomAxios.post('/bigScreen/bizComponent/update', form)
  326. const form = {
  327. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  328. id: this.dataForm.id,
  329. code: this.dataForm.code,
  330. name: this.dataForm.name,
  331. type: this.dataForm.type,
  332. orderNum: this.dataForm.orderNum
  333. }
  334. if (isToDesign) {
  335. this.toDesignLoading = true
  336. this.sureDisabled = true
  337. } else {
  338. this.sureLoading = true
  339. this.toDesignDisabled = true
  340. }
  341. addOrUpdateHandel(form)
  342. .then((code) => {
  343. this.formVisible = false
  344. const message = this.dataForm.code ? '更新成功' : '新建成功'
  345. this.$message.success(message)
  346. this.$emit('refreshData', form, this.dataForm.id)
  347. if (isToDesign) {
  348. this.toDesignLoading = false
  349. this.sureDisabled = false
  350. form.code = code || this.dataForm.code
  351. this.toDesign({ ...form })
  352. } else {
  353. this.sureLoading = false
  354. this.toDesignDisabled = false
  355. }
  356. })
  357. .catch(() => {
  358. this.sureLoading = false
  359. this.toDesignLoading = false
  360. this.sureDisabled = false
  361. this.toDesignDisabled = false
  362. })
  363. })
  364. },
  365. // 自定义组件 新增/编辑
  366. addOrUpdateBigScreen (isToDesign) {
  367. this.$refs.dataForm.validate(async (valid) => {
  368. if (!valid) {
  369. return
  370. }
  371. const addOrUpdateHandel = !this.dataForm.code
  372. ? (form) => this.$dataRoomAxios.post('/bigScreen/design/add', form)
  373. : (form) => this.$dataRoomAxios.post('/bigScreen/design/update', form)
  374. const form = {
  375. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  376. chartList: this.dataForm.chartList,
  377. code: this.dataForm.code,
  378. icon: this.dataForm.icon,
  379. iconColor: this.dataForm.iconColor,
  380. id: this.dataForm.id,
  381. name: this.dataForm.name,
  382. parentCode: this.dataForm.parentCode,
  383. remark: this.dataForm.remark,
  384. style: this.dataForm.style,
  385. orderNum: this.dataForm.orderNum,
  386. pageConfig: { ...this.dataForm.pageConfig, w: this.resolutionRatio.w, h: this.resolutionRatio.h },
  387. pageTemplateId: this.dataForm.pageTemplateId,
  388. type: this.type || 'component'
  389. }
  390. if (isToDesign) {
  391. this.toDesignLoading = true
  392. this.sureDisabled = true
  393. } else {
  394. this.sureLoading = true
  395. this.toDesignDisabled = true
  396. }
  397. addOrUpdateHandel(form)
  398. .then((code) => {
  399. this.formVisible = false
  400. const message = this.dataForm.code ? '更新成功' : '新建成功'
  401. this.$message.success(message)
  402. this.$emit('refreshData', form, this.dataForm.id)
  403. if (isToDesign) {
  404. this.toDesignLoading = false
  405. this.sureDisabled = false
  406. form.code = code || this.dataForm.code
  407. this.toDesign({ ...form })
  408. } else {
  409. this.sureLoading = false
  410. this.toDesignDisabled = false
  411. }
  412. })
  413. .catch(() => {
  414. this.sureLoading = false
  415. this.toDesignLoading = false
  416. this.sureDisabled = false
  417. this.toDesignDisabled = false
  418. })
  419. })
  420. },
  421. // 跳转设计态
  422. toDesign (form) {
  423. const path = this.type === 'component' ? (window.BS_CONFIG?.routers?.designUrl || '/big-screen/design') : 'big-screen-biz-component-design'
  424. const { href: bigScreenHref } = this.$router.resolve({
  425. path,
  426. query: {
  427. code: form.code
  428. }
  429. })
  430. // 新窗口打开
  431. window.open(bigScreenHref, '_blank')
  432. }
  433. }
  434. }
  435. </script>
  436. <style lang="scss" scoped>
  437. @import '../assets/style/bsTheme.scss';
  438. .el-scrollbar {
  439. height: 300px;
  440. overflow-x: hidden;
  441. ::v-deep .el-scrollbar__view {
  442. overflow-x: hidden;
  443. }
  444. }
  445. .color-picker {
  446. display: flex;
  447. align-items: center;
  448. }
  449. .icon-svg {
  450. width: 25px;
  451. height: 25px;
  452. }
  453. .color-select {
  454. width: 350px;
  455. display: flex;
  456. margin-top: 5px;
  457. align-items: center;
  458. justify-content: space-between;
  459. div {
  460. width: 20px;
  461. height: 20px;
  462. cursor: pointer;
  463. position: relative;
  464. }
  465. ::v-deep .el-color-picker__trigger {
  466. top: 0;
  467. right: 0;
  468. width: 21px;
  469. height: 21px;
  470. padding: 0;
  471. }
  472. .el-icon-check {
  473. font-size: 20px;
  474. color: #ffffff;
  475. position: absolute;
  476. }
  477. }
  478. .icon-list {
  479. margin-top: 15px;
  480. padding: 5px;
  481. border-radius: 5px;
  482. border: 1px solid #e8e8e8;
  483. .el-button--mini {
  484. min-width: 37px;
  485. padding: 5px !important;
  486. border: 1px solid transparent !important;
  487. &:hover {
  488. background-color: rgba(217, 217, 217, 0.3);
  489. }
  490. }
  491. }
  492. .icon-uploader {
  493. width: 60px;
  494. height: 60px;
  495. border: 1px dashed #d9d9d9;
  496. border-radius: 6px;
  497. cursor: pointer;
  498. position: relative;
  499. overflow: hidden;
  500. }
  501. .icon-uploader-icon {
  502. font-size: 28px;
  503. color: #8c939d;
  504. width: 60px;
  505. height: 60px;
  506. line-height: 60px;
  507. text-align: center;
  508. }
  509. .icon {
  510. width: 60px;
  511. height: 60px;
  512. display: block;
  513. }
  514. .default-layout-box {
  515. display: flex;
  516. flex-wrap: wrap;
  517. .default-layout-item {
  518. cursor: pointer;
  519. margin: 9px;
  520. display: flex;
  521. flex-direction: column;
  522. align-items: center;
  523. .component-name {
  524. font-size: 12px;
  525. }
  526. .sampleImg {
  527. margin: 0 auto;
  528. width: 102px;
  529. height: 73px;
  530. display: block;
  531. }
  532. .img_dispaly {
  533. margin: 0 auto;
  534. text-align: center;
  535. width: 100px;
  536. height: 70px;
  537. line-height: 70px;
  538. background-color: #D7D7D7;
  539. color: #999;
  540. }
  541. .demonstration {
  542. text-align: center;
  543. }
  544. }
  545. .default-layout-item:hover {
  546. cursor: pointer;
  547. }
  548. ::v-deep .el-radio__label {
  549. display: none;
  550. }
  551. }
  552. /*滚动条样式*/
  553. ::v-deep ::-webkit-scrollbar {
  554. width: 6px;
  555. border-radius: 4px;
  556. height: 4px;
  557. }
  558. ::v-deep ::-webkit-scrollbar-thumb {
  559. background: #dddddd !important;
  560. border-radius: 10px;
  561. }
  562. .catalog-cascader {
  563. width: 100% !important;
  564. }
  565. </style>