EditForm.vue 14 KB

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