addDialog.vue 14 KB

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