EditForm.vue 15 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="!!dataForm.id"
  34. label="大屏编码"
  35. >
  36. <el-input
  37. style="width: 200px"
  38. v-model="dataForm.code"
  39. readonly
  40. class="bs-el-input"
  41. />
  42. <el-button
  43. style="margin-left: 10px;"
  44. type="text"
  45. @click="copyCode"
  46. class="bs-el-button"
  47. >
  48. <i class="el-icon-document-copy" />
  49. </el-button>
  50. </el-form-item>
  51. <el-form-item
  52. label="推荐分辨率"
  53. >
  54. <el-select
  55. v-model="resolutionRatioValue"
  56. class="bs-el-select"
  57. popper-class="bs-el-select"
  58. placeholder="请选择分辨率"
  59. clearable
  60. >
  61. <el-option
  62. v-for="resolutionRatioItem in resolutionRatioOptions"
  63. :key="resolutionRatioItem.value"
  64. :label="resolutionRatioItem.label"
  65. :value="resolutionRatioItem.value"
  66. />
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item
  70. label="大屏宽度"
  71. >
  72. <el-input-number
  73. v-model="resolutionRatio.w"
  74. :min="100"
  75. :max="8000"
  76. class="bs-el-input-number"
  77. />
  78. </el-form-item>
  79. <el-form-item
  80. label="大屏高度"
  81. >
  82. <el-input-number
  83. v-model="resolutionRatio.h"
  84. :min="100"
  85. :max="8000"
  86. class="bs-el-input-number"
  87. />
  88. </el-form-item>
  89. <el-form-item label="分组">
  90. <el-select
  91. v-model="dataForm.parentCode"
  92. class="bs-el-select"
  93. popper-class="bs-el-select"
  94. clearable
  95. filterable
  96. >
  97. <el-option
  98. v-for="catalogItem in catalogList"
  99. :key="catalogItem.id"
  100. :label="catalogItem.name"
  101. :value="catalogItem.code"
  102. />
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item label="排序">
  106. <el-input-number
  107. v-model="dataForm.orderNum"
  108. :min="0"
  109. :max="30000"
  110. controls-position="right"
  111. class="bs-el-input-number"
  112. />
  113. </el-form-item>
  114. </el-form>
  115. <div
  116. slot="footer"
  117. class="dialog-footer"
  118. >
  119. <el-button
  120. class="bs-el-button-default"
  121. @click="closeAddDialog"
  122. >
  123. 取消
  124. </el-button>
  125. <el-button
  126. v-if="title"
  127. type="primary"
  128. :loading="toDesignLoading"
  129. :disabled="toDesignDisabled"
  130. @click="addOrUpdate(true)"
  131. >
  132. 设计
  133. </el-button>
  134. <el-button
  135. type="primary"
  136. :loading="sureLoading"
  137. :disabled="sureDisabled"
  138. @click="addOrUpdate(!title)"
  139. >
  140. 确定
  141. </el-button>
  142. </div>
  143. </el-dialog>
  144. </div>
  145. </template>
  146. <script>
  147. import Icon from 'data-room-ui/assets/images/dataSourceIcon/export'
  148. export default {
  149. name: 'EditForm',
  150. components: {
  151. },
  152. props: {
  153. type: {
  154. type: String,
  155. default: ''
  156. }
  157. },
  158. data () {
  159. return {
  160. resolutionRatioValue: '',
  161. resolutionRatio: {},
  162. catalogList: [],
  163. resolutionRatioOptions: [
  164. {
  165. value: '1024*768',
  166. label: '1024*768'
  167. },
  168. {
  169. value: '1280*720',
  170. label: '1280*720'
  171. },
  172. {
  173. value: '1920*1080',
  174. label: '1920*1080'
  175. },
  176. {
  177. value: '2560*1440',
  178. label: '2560*1440'
  179. },
  180. {
  181. value: '3840*2160',
  182. label: '3840*2160'
  183. },
  184. {
  185. value: '5120*2880',
  186. label: '5120*2880'
  187. },
  188. {
  189. value: '7680*4320',
  190. label: '7680*4320'
  191. }
  192. ],
  193. formVisible: false,
  194. title: '', // 弹框标题(新增/编辑)
  195. dataForm: {
  196. id: '',
  197. type: '',
  198. name: '',
  199. icon: '',
  200. code: '',
  201. remark: '',
  202. iconColor: '#007aff',
  203. components: '',
  204. style: '',
  205. formType: '',
  206. formConfig: '',
  207. pageTemplateId: ''
  208. },
  209. dataFormRules: {
  210. name: [
  211. { required: true, message: '名称不能为空', trigger: 'blur' },
  212. // 名称重复自定义校验
  213. {
  214. validator: (rule, value, callback) => {
  215. if (value) {
  216. this.$dataRoomAxios.post('/bigScreen/design/name/repeat', {
  217. name: value,
  218. type: this.type,
  219. id: this.dataForm.id
  220. }).then((resp) => {
  221. if (resp) {
  222. callback(new Error('名称已存在'))
  223. } else {
  224. callback()
  225. }
  226. })
  227. } else {
  228. callback()
  229. }
  230. },
  231. trigger: 'change'
  232. }
  233. ]
  234. },
  235. sureLoading: false,
  236. toDesignLoading: false,
  237. sureDisabled: false,
  238. toDesignDisabled: false
  239. }
  240. },
  241. computed: {
  242. },
  243. watch: {
  244. resolutionRatioValue (val) {
  245. if (val) {
  246. this.resolutionRatio.w = val.split('*')[0]
  247. this.resolutionRatio.h = val.split('*')[1]
  248. } else {
  249. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  250. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  251. }
  252. }
  253. },
  254. mounted () {
  255. this.initResolution()
  256. },
  257. methods: {
  258. initResolution () {
  259. this.resolutionRatioValue = this.type === 'component' ? '1024*768' : '1920*1080'
  260. if (this.type === 'component') {
  261. this.resolutionRatio = {
  262. w: 1024,
  263. h: 768
  264. }
  265. } else {
  266. this.resolutionRatio = {
  267. w: 1920,
  268. h: 1080
  269. }
  270. }
  271. },
  272. // 关闭弹窗时
  273. closeAddDialog () {
  274. this.formVisible = false
  275. this.$refs.dataForm.resetFields()
  276. },
  277. // 初始化
  278. init (nodeData, parentNode) {
  279. this.title = ''
  280. const code = nodeData ? nodeData.code : ''
  281. this.formVisible = true
  282. this.$nextTick(() => {
  283. this.$dataRoomAxios.get('/bigScreen/type/list/bigScreenCatalog').then((resp) => {
  284. this.catalogList = resp
  285. })
  286. if (code) {
  287. this.$dataRoomAxios.get(`/bigScreen/design/info/code/${code}`).then((resp) => {
  288. this.$set(this, 'title', resp.name)
  289. this.$set(this.dataForm, 'name', resp.name)
  290. this.$set(this.dataForm, 'chartList', resp.chartList)
  291. this.$set(this.dataForm, 'code', resp.code)
  292. this.$set(this.dataForm, 'icon', resp.icon)
  293. this.$set(this.dataForm, 'iconColor', resp.iconColor)
  294. this.$set(this.dataForm, 'id', resp.id)
  295. this.$set(this.dataForm, 'parentCode', resp.parentCode === '0' ? '' : resp.parentCode)
  296. this.$set(this.dataForm, 'remark', resp.remark)
  297. this.$set(this.dataForm, 'style', resp.style)
  298. this.$set(this.dataForm, 'type', resp.type)
  299. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  300. this.$set(this.dataForm, 'pageTemplateId', resp?.pageTemplateId)
  301. this.$set(this.dataForm, 'pageConfig', resp?.pageConfig)
  302. const { w, h } = resp.pageConfig
  303. this.resolutionRatio.w = w
  304. this.resolutionRatio.h = h
  305. this.resolutionRatioValue = `${w}*${h}`
  306. })
  307. } else {
  308. this.$set(this.dataForm, 'name', '')
  309. this.$set(this.dataForm, 'chartList', [])
  310. this.$set(this.dataForm, 'code', '')
  311. this.$set(this.dataForm, 'icon', Icon.getNameList()[0])
  312. this.$set(this.dataForm, 'iconColor', '#007aff')
  313. this.$set(this.dataForm, 'id', '')
  314. this.$set(this.dataForm, 'parentCode', parentNode.code)
  315. this.$set(this.dataForm, 'remark', '')
  316. this.$set(this.dataForm, 'style', '')
  317. this.$set(this.dataForm, 'type', this.type)
  318. this.$set(this.dataForm, 'orderNum', 0)
  319. this.$set(this.dataForm, 'pageTemplateId', '')
  320. this.$set(this.dataForm, 'pageConfig', {
  321. w: this.type === 'component' ? 1024 : 1920,
  322. h: this.type === 'component' ? 768 : 1080,
  323. bgColor: '#151a26',
  324. lightBgColor: '#f5f7fa',
  325. opacity: 100,
  326. customTheme: 'dark',
  327. bg: null,
  328. lightBg: null,
  329. fitMode: 'auto'
  330. })
  331. this.resolutionRatio.w = this.type === 'component' ? 1024 : 1920
  332. this.resolutionRatio.h = this.type === 'component' ? 768 : 1080
  333. }
  334. })
  335. },
  336. // 点击确定时
  337. addOrUpdate (isToDesign = false) {
  338. this.addOrUpdateBigScreen(isToDesign)
  339. },
  340. // 大屏 新增/编辑
  341. async addOrUpdateBigScreen (isToDesign) {
  342. this.$refs.dataForm.validate(async (valid) => {
  343. if (!valid) {
  344. return
  345. }
  346. const addOrUpdateHandel = !this.dataForm.code
  347. ? (form) => this.$dataRoomAxios.post('/bigScreen/design/add', form)
  348. : (form) => this.$dataRoomAxios.post('/bigScreen/design/update', form)
  349. const form = {
  350. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  351. chartList: this.dataForm.chartList,
  352. code: this.dataForm.code,
  353. icon: this.dataForm.icon,
  354. iconColor: this.dataForm.iconColor,
  355. id: this.dataForm.id,
  356. name: this.dataForm.name,
  357. parentCode: this.dataForm.parentCode,
  358. remark: this.dataForm.remark,
  359. style: this.dataForm.style,
  360. orderNum: this.dataForm.orderNum,
  361. pageConfig: { ...this.dataForm.pageConfig, w: this.resolutionRatio.w, h: this.resolutionRatio.h },
  362. pageTemplateId: this.dataForm.pageTemplateId,
  363. type: this.type || 'bigScreen'
  364. }
  365. if (isToDesign) {
  366. this.toDesignLoading = true
  367. this.sureDisabled = true
  368. } else {
  369. this.sureLoading = true
  370. this.toDesignDisabled = true
  371. }
  372. addOrUpdateHandel(form)
  373. .then((code) => {
  374. this.formVisible = false
  375. const message = this.dataForm.code ? '更新成功' : '新增成功'
  376. this.$message.success(message)
  377. this.$emit('refreshData', form, this.dataForm.id)
  378. if (isToDesign) {
  379. this.toDesignLoading = false
  380. this.sureDisabled = false
  381. form.code = code || this.dataForm.code
  382. this.toDesign({ ...form })
  383. } else {
  384. this.sureLoading = false
  385. this.toDesignDisabled = false
  386. }
  387. })
  388. .catch(() => {
  389. this.sureLoading = false
  390. this.toDesignLoading = false
  391. this.sureDisabled = false
  392. this.toDesignDisabled = false
  393. })
  394. })
  395. },
  396. // 跳转设计态
  397. toDesign (form) {
  398. // const { href: bigScreenHref } = this.$router.resolve({
  399. // path: window.BS_CONFIG?.routers?.designUrl || '/big-screen/design',
  400. // query: {
  401. // code: form.code
  402. // }
  403. // })
  404. // window.open(bigScreenHref, '_self')
  405. this.$router.push({
  406. path: window.BS_CONFIG?.routers?.designUrl || '/big-screen/design',
  407. query: {
  408. code: form.code
  409. }
  410. })
  411. },
  412. /**
  413. * 复制大屏编码
  414. */
  415. copyCode () {
  416. try {
  417. let code = this.dataForm.code
  418. const transfer = document.createElement('input')
  419. document.body.appendChild(transfer)
  420. transfer.value = code
  421. transfer.focus()
  422. transfer.select()
  423. if (document.execCommand('copy')) {
  424. document.execCommand('copy')
  425. }
  426. transfer.blur()
  427. transfer.style.display = 'none'
  428. this.$message.success('复制成功')
  429. } catch (e) {
  430. this.$message.error('复制失败, 请手动复制')
  431. }
  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>