EditForm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. >
  18. <el-form-item
  19. label="名称"
  20. prop="name"
  21. >
  22. <el-input
  23. v-model="dataForm.name"
  24. autocomplete="off"
  25. placeholder="请输入名称"
  26. clearable
  27. maxlength="30"
  28. class="bs-el-input"
  29. />
  30. </el-form-item>
  31. <el-form-item
  32. v-if="type === 'component'"
  33. label="推荐分辨率"
  34. >
  35. <el-select
  36. v-model="resolutionRatioValue"
  37. class="bs-el-select"
  38. popper-class="bs-el-select"
  39. placeholder="请选择分辨率"
  40. clearable
  41. >
  42. <el-option
  43. v-for="resolutionRatioItem in resolutionRatioOptions"
  44. :key="resolutionRatioItem.value"
  45. :label="resolutionRatioItem.label"
  46. :value="resolutionRatioItem.value"
  47. />
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item
  51. v-if="type === 'component'"
  52. label="大屏宽度"
  53. >
  54. <el-input-number
  55. v-model="resolutionRatio.w"
  56. :min="100"
  57. :max="8000"
  58. class="bs-el-input-number"
  59. />
  60. </el-form-item>
  61. <el-form-item
  62. v-if="type === 'component'"
  63. label="大屏高度"
  64. >
  65. <el-input-number
  66. v-model="resolutionRatio.h"
  67. :min="100"
  68. :max="8000"
  69. class="bs-el-input-number"
  70. />
  71. </el-form-item>
  72. <el-form-item label="排序">
  73. <el-input-number
  74. v-model="dataForm.orderNum"
  75. :min="0"
  76. :max="30000"
  77. controls-position="right"
  78. class="bs-el-input-number"
  79. />
  80. </el-form-item>
  81. </el-form>
  82. <div
  83. slot="footer"
  84. class="dialog-footer"
  85. >
  86. <el-button
  87. class="bs-el-button-default"
  88. @click="closeAddDialog"
  89. >
  90. 取消
  91. </el-button>
  92. <el-button
  93. v-if="title"
  94. type="primary"
  95. :loading="toDesignLoading"
  96. :disabled="toDesignDisabled"
  97. @click="addOrUpdate(true)"
  98. >
  99. 设计
  100. </el-button>
  101. <el-button
  102. type="primary"
  103. :loading="sureLoading"
  104. :disabled="sureDisabled"
  105. @click="addOrUpdate(!title)"
  106. >
  107. 确定
  108. </el-button>
  109. </div>
  110. </el-dialog>
  111. </div>
  112. </template>
  113. <script>
  114. import { get, post } from 'packages/js/utils/http'
  115. import Icon from 'packages/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. 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. 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) => post('/bigScreen/bizComponent/add', form)
  323. : (form) => 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) => post('/bigScreen/design/add', form)
  371. : (form) => 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. window.open(bigScreenHref, '_self')
  429. }
  430. }
  431. }
  432. </script>
  433. <style lang="scss" scoped>
  434. @import '~packages/assets/style/bsTheme.scss';
  435. .el-scrollbar {
  436. height: 300px;
  437. overflow-x: hidden;
  438. /deep/ .el-scrollbar__view {
  439. overflow-x: hidden;
  440. }
  441. }
  442. .color-picker {
  443. display: flex;
  444. align-items: center;
  445. }
  446. .icon-svg {
  447. width: 25px;
  448. height: 25px;
  449. }
  450. .color-select {
  451. width: 350px;
  452. display: flex;
  453. margin-top: 5px;
  454. align-items: center;
  455. justify-content: space-between;
  456. div {
  457. width: 20px;
  458. height: 20px;
  459. cursor: pointer;
  460. position: relative;
  461. }
  462. ::v-deep .el-color-picker__trigger {
  463. top: 0;
  464. right: 0;
  465. width: 21px;
  466. height: 21px;
  467. padding: 0;
  468. }
  469. .el-icon-check {
  470. font-size: 20px;
  471. color: #ffffff;
  472. position: absolute;
  473. }
  474. }
  475. .icon-list {
  476. margin-top: 15px;
  477. padding: 5px;
  478. border-radius: 5px;
  479. border: 1px solid #e8e8e8;
  480. .el-button--mini {
  481. min-width: 37px;
  482. padding: 5px !important;
  483. border: 1px solid transparent !important;
  484. &:hover {
  485. background-color: rgba(217, 217, 217, 0.3);
  486. }
  487. }
  488. }
  489. .icon-uploader {
  490. width: 60px;
  491. height: 60px;
  492. border: 1px dashed #d9d9d9;
  493. border-radius: 6px;
  494. cursor: pointer;
  495. position: relative;
  496. overflow: hidden;
  497. }
  498. .icon-uploader-icon {
  499. font-size: 28px;
  500. color: #8c939d;
  501. width: 60px;
  502. height: 60px;
  503. line-height: 60px;
  504. text-align: center;
  505. }
  506. .icon {
  507. width: 60px;
  508. height: 60px;
  509. display: block;
  510. }
  511. .default-layout-box {
  512. display: flex;
  513. flex-wrap: wrap;
  514. .default-layout-item {
  515. cursor: pointer;
  516. margin: 9px;
  517. display: flex;
  518. flex-direction: column;
  519. align-items: center;
  520. .component-name {
  521. font-size: 12px;
  522. }
  523. .sampleImg {
  524. margin: 0 auto;
  525. width: 102px;
  526. height: 73px;
  527. display: block;
  528. }
  529. .img_dispaly {
  530. margin: 0 auto;
  531. text-align: center;
  532. width: 100px;
  533. height: 70px;
  534. line-height: 70px;
  535. background-color: #D7D7D7;
  536. color: #999;
  537. }
  538. .demonstration {
  539. text-align: center;
  540. }
  541. }
  542. .default-layout-item:hover {
  543. cursor: pointer;
  544. }
  545. /deep/.el-radio__label {
  546. display: none;
  547. }
  548. }
  549. /*滚动条样式*/
  550. /deep/::-webkit-scrollbar {
  551. width: 6px;
  552. border-radius: 4px;
  553. height: 4px;
  554. }
  555. /deep/::-webkit-scrollbar-thumb {
  556. background: #dddddd !important;
  557. border-radius: 10px;
  558. }
  559. .catalog-cascader {
  560. width: 100% !important;
  561. }
  562. </style>