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 { get, post } from 'packages/js/utils/http'
  116. import Icon from 'packages/assets/images/dataSourceIcon/export'
  117. export default {
  118. name: 'EditForm',
  119. components: {
  120. },
  121. props: {
  122. type: {
  123. type: String,
  124. default: ''
  125. }
  126. },
  127. data () {
  128. return {
  129. resolutionRatioValue: '',
  130. resolutionRatio: {},
  131. resolutionRatioOptions: [
  132. {
  133. value: '1024*768',
  134. label: '1024*768'
  135. },
  136. {
  137. value: '1280*720',
  138. label: '1280*720'
  139. },
  140. {
  141. value: '1920*1080',
  142. label: '1920*1080'
  143. },
  144. {
  145. value: '2560*1440',
  146. label: '2560*1440'
  147. },
  148. {
  149. value: '3840*2160',
  150. label: '3840*2160'
  151. },
  152. {
  153. value: '5120*2880',
  154. label: '5120*2880'
  155. },
  156. {
  157. value: '7680*4320',
  158. label: '7680*4320'
  159. }
  160. ],
  161. formVisible: false,
  162. title: '', // 弹框标题(新增/编辑)
  163. dataForm: {
  164. id: '',
  165. type: '',
  166. name: '',
  167. icon: '',
  168. code: '',
  169. remark: '',
  170. iconColor: '#007aff',
  171. components: '',
  172. style: '',
  173. formType: '',
  174. formConfig: '',
  175. pageTemplateId: ''
  176. },
  177. dataFormRules: {
  178. name: [
  179. { required: true, message: '名称不能为空', trigger: 'blur' }
  180. ]
  181. },
  182. sureLoading: false,
  183. toDesignLoading: false,
  184. sureDisabled: false,
  185. toDesignDisabled: false
  186. }
  187. },
  188. computed: {
  189. },
  190. watch: {
  191. resolutionRatioValue (val) {
  192. if (val) {
  193. this.resolutionRatio.w = val.split('*')[0]
  194. this.resolutionRatio.h = val.split('*')[1]
  195. } else {
  196. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  197. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  198. }
  199. }
  200. },
  201. mounted () {
  202. this.initResolution()
  203. },
  204. methods: {
  205. initResolution () {
  206. this.resolutionRatioValue = this.type === 'component' ? '1024*768' : '1920*1080'
  207. if (this.type === 'component') {
  208. this.resolutionRatio = {
  209. w: 1024,
  210. h: 768
  211. }
  212. } else {
  213. this.resolutionRatio = {
  214. w: 1920,
  215. h: 1080
  216. }
  217. }
  218. },
  219. // 关闭弹窗时
  220. closeAddDialog () {
  221. this.formVisible = false
  222. this.$refs.dataForm.resetFields()
  223. },
  224. // 初始化
  225. init (nodeData, parentCode) {
  226. if (this.type === 'component') {
  227. this.comInit(nodeData, parentCode)
  228. } else {
  229. this.bizInit(nodeData, parentCode)
  230. }
  231. },
  232. bizInit (nodeData, parentCode) {
  233. this.title = ''
  234. const code = nodeData ? nodeData.code : ''
  235. this.formVisible = true
  236. this.$nextTick(() => {
  237. if (code) {
  238. get(`/bigScreen/bizComponent/info/${code}`).then((resp) => {
  239. this.$set(this, 'title', resp.name)
  240. this.$set(this.dataForm, 'name', resp.name)
  241. this.$set(this.dataForm, 'code', resp.code)
  242. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  243. this.$set(this.dataForm, 'type', resp.type)
  244. this.$set(this.dataForm, 'id', resp.id)
  245. })
  246. } else {
  247. this.$set(this.dataForm, 'name', '')
  248. this.$set(this.dataForm, 'code', '')
  249. this.$set(this.dataForm, 'type', parentCode)
  250. this.$set(this.dataForm, 'orderNum', 0)
  251. this.$set(this.dataForm, 'id', '')
  252. }
  253. })
  254. },
  255. comInit (nodeData, parentCode) {
  256. this.title = ''
  257. const code = nodeData ? nodeData.code : ''
  258. this.formVisible = true
  259. this.$nextTick(() => {
  260. if (code) {
  261. get(`/bigScreen/design/info/code/${code}`).then((resp) => {
  262. this.$set(this, 'title', resp.name)
  263. this.$set(this.dataForm, 'name', resp.name)
  264. this.$set(this.dataForm, 'chartList', resp.chartList)
  265. this.$set(this.dataForm, 'code', resp.code)
  266. this.$set(this.dataForm, 'icon', resp.icon)
  267. this.$set(this.dataForm, 'iconColor', resp.iconColor)
  268. this.$set(this.dataForm, 'id', resp.id)
  269. this.$set(this.dataForm, 'parentCode', resp.parentCode === '0' ? '' : resp.parentCode)
  270. this.$set(this.dataForm, 'remark', resp.remark)
  271. this.$set(this.dataForm, 'style', resp.style)
  272. this.$set(this.dataForm, 'type', resp.type)
  273. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  274. this.$set(this.dataForm, 'pageTemplateId', resp?.pageTemplateId)
  275. this.$set(this.dataForm, 'pageConfig', resp?.pageConfig)
  276. const { w, h } = resp.pageConfig
  277. this.resolutionRatio.w = w
  278. this.resolutionRatio.h = h
  279. this.resolutionRatioValue = `${w}*${h}`
  280. })
  281. } else {
  282. this.$set(this.dataForm, 'name', '')
  283. this.$set(this.dataForm, 'chartList', [])
  284. this.$set(this.dataForm, 'code', '')
  285. this.$set(this.dataForm, 'icon', Icon.getNameList()[0])
  286. this.$set(this.dataForm, 'iconColor', '#007aff')
  287. this.$set(this.dataForm, 'id', '')
  288. this.$set(this.dataForm, 'parentCode', parentCode)
  289. this.$set(this.dataForm, 'remark', '')
  290. this.$set(this.dataForm, 'style', '')
  291. this.$set(this.dataForm, 'type', this.type)
  292. this.$set(this.dataForm, 'orderNum', 0)
  293. this.$set(this.dataForm, 'pageTemplateId', '')
  294. this.$set(this.dataForm, 'pageConfig', {
  295. w: this.type === 'component' ? 1024 : 1920,
  296. h: this.type === 'component' ? 768 : 1080,
  297. bgColor: '#151a26',
  298. opacity: 100,
  299. customTheme: 'auto',
  300. bg: null,
  301. fitMode: 'auto'
  302. })
  303. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  304. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  305. }
  306. })
  307. },
  308. // 点击确定时
  309. addOrUpdate (isToDesign = false) {
  310. if (this.type === 'component') {
  311. this.addOrUpdateBigScreen(isToDesign)
  312. } else {
  313. this.addOrUpdateBizComponent(isToDesign)
  314. }
  315. },
  316. // 业务组件 新增/编辑
  317. addOrUpdateBizComponent (isToDesign) {
  318. this.$refs.dataForm.validate(async (valid) => {
  319. if (!valid) {
  320. return
  321. }
  322. const addOrUpdateHandel = !this.dataForm.code
  323. ? (form) => post('/bigScreen/bizComponent/add', form)
  324. : (form) => post('/bigScreen/bizComponent/update', form)
  325. const form = {
  326. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  327. id: this.dataForm.id,
  328. code: this.dataForm.code,
  329. name: this.dataForm.name,
  330. type: this.dataForm.type,
  331. orderNum: this.dataForm.orderNum
  332. }
  333. if (isToDesign) {
  334. this.toDesignLoading = true
  335. this.sureDisabled = true
  336. } else {
  337. this.sureLoading = true
  338. this.toDesignDisabled = true
  339. }
  340. addOrUpdateHandel(form)
  341. .then((code) => {
  342. this.formVisible = false
  343. const message = this.dataForm.code ? '更新成功' : '新建成功'
  344. this.$message.success(message)
  345. this.$emit('refreshData', form, this.dataForm.id)
  346. if (isToDesign) {
  347. this.toDesignLoading = false
  348. this.sureDisabled = false
  349. form.code = code || this.dataForm.code
  350. this.toDesign({ ...form })
  351. } else {
  352. this.sureLoading = false
  353. this.toDesignDisabled = false
  354. }
  355. })
  356. .catch(() => {
  357. this.sureLoading = false
  358. this.toDesignLoading = false
  359. this.sureDisabled = false
  360. this.toDesignDisabled = false
  361. })
  362. })
  363. },
  364. // 自定义组件 新增/编辑
  365. addOrUpdateBigScreen (isToDesign) {
  366. this.$refs.dataForm.validate(async (valid) => {
  367. if (!valid) {
  368. return
  369. }
  370. const addOrUpdateHandel = !this.dataForm.code
  371. ? (form) => post('/bigScreen/design/add', form)
  372. : (form) => post('/bigScreen/design/update', form)
  373. const form = {
  374. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  375. chartList: this.dataForm.chartList,
  376. code: this.dataForm.code,
  377. icon: this.dataForm.icon,
  378. iconColor: this.dataForm.iconColor,
  379. id: this.dataForm.id,
  380. name: this.dataForm.name,
  381. parentCode: this.dataForm.parentCode,
  382. remark: this.dataForm.remark,
  383. style: this.dataForm.style,
  384. orderNum: this.dataForm.orderNum,
  385. pageConfig: { ...this.dataForm.pageConfig, w: this.resolutionRatio.w, h: this.resolutionRatio.h },
  386. pageTemplateId: this.dataForm.pageTemplateId,
  387. type: this.type || 'component'
  388. }
  389. if (isToDesign) {
  390. this.toDesignLoading = true
  391. this.sureDisabled = true
  392. } else {
  393. this.sureLoading = true
  394. this.toDesignDisabled = true
  395. }
  396. addOrUpdateHandel(form)
  397. .then((code) => {
  398. this.formVisible = false
  399. const message = this.dataForm.code ? '更新成功' : '新建成功'
  400. this.$message.success(message)
  401. this.$emit('refreshData', form, this.dataForm.id)
  402. if (isToDesign) {
  403. this.toDesignLoading = false
  404. this.sureDisabled = false
  405. form.code = code || this.dataForm.code
  406. this.toDesign({ ...form })
  407. } else {
  408. this.sureLoading = false
  409. this.toDesignDisabled = false
  410. }
  411. })
  412. .catch(() => {
  413. this.sureLoading = false
  414. this.toDesignLoading = false
  415. this.sureDisabled = false
  416. this.toDesignDisabled = false
  417. })
  418. })
  419. },
  420. // 跳转设计态
  421. toDesign (form) {
  422. const path = this.type === 'component' ? (window.BS_CONFIG?.routers?.designUrl || '/big-screen/design') : 'big-screen-biz-component-design'
  423. const { href: bigScreenHref } = this.$router.resolve({
  424. path,
  425. query: {
  426. code: form.code
  427. }
  428. })
  429. window.open(bigScreenHref, '_self')
  430. }
  431. }
  432. }
  433. </script>
  434. <style lang="scss" scoped>
  435. @import '~packages/assets/style/bsTheme.scss';
  436. .el-scrollbar {
  437. height: 300px;
  438. overflow-x: hidden;
  439. /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. /deep/.el-radio__label {
  547. display: none;
  548. }
  549. }
  550. /*滚动条样式*/
  551. /deep/::-webkit-scrollbar {
  552. width: 6px;
  553. border-radius: 4px;
  554. height: 4px;
  555. }
  556. /deep/::-webkit-scrollbar-thumb {
  557. background: #dddddd !important;
  558. border-radius: 10px;
  559. }
  560. .catalog-cascader {
  561. width: 100% !important;
  562. }
  563. </style>