addDialog.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 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. icon: '',
  202. code: '',
  203. remark: '',
  204. iconColor: '#007aff',
  205. components: '',
  206. style: '',
  207. modelCode: '',
  208. formType: '',
  209. formConfig: '',
  210. pageTemplateId: ''
  211. },
  212. formTypeList: [
  213. {
  214. value: 'modelForm',
  215. label: '模型表单',
  216. disabled: false
  217. },
  218. {
  219. value: 'bizForm',
  220. label: '业务表单',
  221. disabled: true
  222. }
  223. ],
  224. iconList: [],
  225. dataFormRules: {
  226. name: [
  227. { required: true, message: '页面名称不能为空', trigger: 'blur' }
  228. ],
  229. modelCode: [
  230. { required: true, message: '数据模型不能为空', trigger: 'change' }
  231. ]
  232. },
  233. currentPageType: '基础表格',
  234. sureLoading: false,
  235. toDesignLoading: false,
  236. sureDisabled: false,
  237. toDesignDisabled: false
  238. }
  239. },
  240. computed: {},
  241. watch: {
  242. formVisible: {
  243. handler (value) {
  244. if (value) {
  245. this.openCascader()
  246. }
  247. }
  248. },
  249. resolutionRatioValue (val) {
  250. if (val) {
  251. this.resolutionRatio.w = val.split('*')[0]
  252. this.resolutionRatio.h = val.split('*')[1]
  253. } else {
  254. this.resolutionRatio.w = 1920
  255. this.resolutionRatio.h = 1080
  256. }
  257. }
  258. },
  259. mounted () {},
  260. methods: {
  261. // 点击选择上级目录树节点
  262. handleNodeClick (node) {
  263. this.$set(this.dataForm, 'parentCode', node.code)
  264. this.selectName = node.name
  265. this.$refs.select.blur() // 点击后关闭下拉框,因为点击树形控件后select不会自动折叠
  266. },
  267. // 获取所有的目录
  268. openCascader () {
  269. this.$dataRoomAxios.post('/bigScreen/category/tree', { searchKey: '', typeList: ['catalog'], sort: false }).then(data => {
  270. const list = [{ name: '根目录', code: '', children: data }]
  271. this.catalogList = list
  272. }).catch(() => {
  273. })
  274. },
  275. // 关闭弹窗时
  276. closeAddDialog () {
  277. this.formVisible = false
  278. this.$refs.dataForm.resetFields()
  279. },
  280. // 初始化
  281. init (nodeData, parentNode, type, categories) {
  282. this.selectName = parentNode.name
  283. this.title = ''
  284. this.dataForm.code = nodeData ? nodeData.code : ''
  285. this.dataForm.type = nodeData ? nodeData.type : type
  286. const code = nodeData ? nodeData.code : ''
  287. this.formVisible = true
  288. this.$nextTick(() => {
  289. if (this.dataForm.type === 'bigScreen') {
  290. if (code) {
  291. this.$dataRoomAxios.get(`/${this.dataForm.type}/design/info/code/${code}`).then((resp) => {
  292. this.$set(this, 'title', resp.name)
  293. this.$set(this.dataForm, 'name', resp.name)
  294. this.$set(this.dataForm, 'chartList', resp.chartList)
  295. this.$set(this.dataForm, 'code', resp.code)
  296. this.$set(this.dataForm, 'icon', resp.icon)
  297. this.$set(this.dataForm, 'iconColor', resp.iconColor)
  298. this.$set(this.dataForm, 'id', resp.id)
  299. this.$set(this.dataForm, 'parentCode', resp.parentCode === '0' ? '' : resp.parentCode)
  300. this.$set(this.dataForm, 'remark', resp.remark)
  301. this.$set(this.dataForm, 'style', resp.style)
  302. this.$set(this.dataForm, 'type', resp.type)
  303. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  304. this.$set(this.dataForm, 'pageTemplateId', resp?.pageTemplateId)
  305. if (this.dataForm.type === 'bigScreen') {
  306. const { w, h } = resp.pageConfig
  307. this.resolutionRatio.w = w
  308. this.resolutionRatio.h = h
  309. this.resolutionRatioValue = `${w}*${h}`
  310. }
  311. this.getTemplateList(this.dataForm.type)
  312. })
  313. } else {
  314. this.$set(this.dataForm, 'name', '')
  315. this.$set(this.dataForm, 'chartList', [])
  316. this.$set(this.dataForm, 'code', '')
  317. this.$set(this.dataForm, 'icon', Icon.getNameList()[0])
  318. this.$set(this.dataForm, 'iconColor', '#007aff')
  319. this.$set(this.dataForm, 'id', '')
  320. this.$set(this.dataForm, 'parentCode', parentNode.code)
  321. this.$set(this.dataForm, 'remark', '')
  322. this.$set(this.dataForm, 'style', '')
  323. this.$set(this.dataForm, 'type', this.dataForm.type)
  324. this.$set(this.dataForm, 'orderNum', 0)
  325. this.$set(this.dataForm, 'pageTemplateId', '')
  326. if (this.dataForm.type === 'bigScreen') {
  327. this.resolutionRatio.w = '1920'
  328. this.resolutionRatio.h = '1080'
  329. }
  330. this.getTemplateList(this.dataForm.type)
  331. }
  332. }
  333. })
  334. },
  335. // 点击确定时
  336. addOrUpdate (isToDesign = false) {
  337. if (this.dataForm.type === 'bigScreen') {
  338. this.addOrUpdateBigScreen(isToDesign)
  339. }
  340. },
  341. // 大屏 新增/编辑
  342. async addOrUpdateBigScreen (isToDesign) {
  343. this.$refs.dataForm.validate(async (valid) => {
  344. if (!valid) {
  345. return
  346. }
  347. const addOrUpdateHandel = !this.dataForm.code
  348. ? (form) => this.$dataRoomAxios.post('/bigScreen/design/add', form)
  349. : (form) => this.$dataRoomAxios.post('/bigScreen/design/update', form)
  350. const form = {
  351. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  352. chartList: this.dataForm.chartList,
  353. code: this.dataForm.code,
  354. icon: this.dataForm.icon,
  355. iconColor: this.dataForm.iconColor,
  356. id: this.dataForm.id,
  357. name: this.dataForm.name,
  358. parentCode: this.dataForm.parentCode,
  359. remark: this.dataForm.remark,
  360. style: this.dataForm.style,
  361. type: 'bigScreen',
  362. orderNum: this.dataForm.orderNum,
  363. pageConfig: {
  364. w: this.resolutionRatio.w || '1920',
  365. h: this.resolutionRatio.h || '1080',
  366. bgColor: '#151a26',
  367. lightBgColor: '#f5f7fa',
  368. opacity: 100,
  369. customTheme: 'dark'
  370. },
  371. pageTemplateId: this.dataForm.pageTemplateId
  372. }
  373. if (isToDesign) {
  374. this.toDesignLoading = true
  375. this.sureDisabled = true
  376. } else {
  377. this.sureLoading = true
  378. this.toDesignDisabled = true
  379. }
  380. addOrUpdateHandel(form)
  381. .then((code) => {
  382. this.formVisible = false
  383. const message = this.dataForm.code ? '更新成功' : '新建成功'
  384. this.$message.success(message)
  385. this.$emit('refreshData', form, this.dataForm.id)
  386. if (isToDesign) {
  387. this.toDesignLoading = false
  388. this.sureDisabled = false
  389. form.code = code || this.dataForm.code
  390. this.toDesign({ ...form })
  391. } else {
  392. this.sureLoading = false
  393. this.toDesignDisabled = false
  394. }
  395. })
  396. .catch(() => {
  397. this.sureLoading = false
  398. this.toDesignLoading = false
  399. this.sureDisabled = false
  400. this.toDesignDisabled = false
  401. })
  402. })
  403. },
  404. // 跳转设计态
  405. toDesign (form) {
  406. // eslint-disable-next-line no-case-declarations
  407. const { href: bigScreenHref } = this.$router.resolve({
  408. path: window.BS_CONFIG?.routers?.designUrl || '/big-screen/design',
  409. query: {
  410. code: form.code
  411. }
  412. })
  413. window.open(bigScreenHref, '_self')
  414. },
  415. // 得到模板列表
  416. getTemplateList (type) {
  417. this.$nextTick(() => {
  418. // this.$refs.TemplateList.init(type)
  419. })
  420. },
  421. // 选择模版后覆盖配置
  422. selectTemplate (template) {
  423. // TODO: 选择模版后覆盖配置
  424. }
  425. }
  426. }
  427. </script>
  428. <style lang="scss" scoped>
  429. ::v-deep .el-dialog__body {
  430. overflow-y: auto;
  431. }
  432. .el-scrollbar {
  433. height: 300px;
  434. overflow-x: hidden;
  435. ::v-deep .el-scrollbar__view {
  436. overflow-x: hidden;
  437. }
  438. }
  439. .color-picker {
  440. display: flex;
  441. align-items: center;
  442. }
  443. .icon-svg {
  444. width: 25px;
  445. height: 25px;
  446. }
  447. .color-select {
  448. width: 350px;
  449. display: flex;
  450. margin-top: 5px;
  451. align-items: center;
  452. justify-content: space-between;
  453. div {
  454. width: 20px;
  455. height: 20px;
  456. cursor: pointer;
  457. position: relative;
  458. }
  459. ::v-deep .el-color-picker__trigger {
  460. top: 0;
  461. right: 0;
  462. width: 21px;
  463. height: 21px;
  464. padding: 0;
  465. }
  466. .el-icon-check {
  467. font-size: 20px;
  468. color: #ffffff;
  469. position: absolute;
  470. }
  471. }
  472. .icon-list {
  473. margin-top: 15px;
  474. padding: 5px;
  475. border-radius: 5px;
  476. border: 1px solid #e8e8e8;
  477. .el-button--mini {
  478. min-width: 37px;
  479. padding: 5px !important;
  480. border: 1px solid transparent !important;
  481. &:hover {
  482. background-color: rgba(217, 217, 217, 0.3);
  483. }
  484. }
  485. }
  486. .icon-uploader {
  487. width: 60px;
  488. height: 60px;
  489. border: 1px dashed #d9d9d9;
  490. border-radius: 6px;
  491. cursor: pointer;
  492. position: relative;
  493. overflow: hidden;
  494. /*.icon-svg {*/
  495. /* padding: 5px;*/
  496. /* width: 60px !important;*/
  497. /* height: 60px !important;*/
  498. /*}*/
  499. }
  500. .icon-uploader-icon {
  501. font-size: 28px;
  502. color: #8c939d;
  503. width: 60px;
  504. height: 60px;
  505. line-height: 60px;
  506. text-align: center;
  507. }
  508. .icon {
  509. width: 60px;
  510. height: 60px;
  511. display: block;
  512. }
  513. .default-layout-box {
  514. display: flex;
  515. flex-wrap: wrap;
  516. .default-layout-item {
  517. cursor: pointer;
  518. margin: 9px;
  519. display: flex;
  520. flex-direction: column;
  521. align-items: center;
  522. .component-name {
  523. font-size: 12px;
  524. }
  525. .sampleImg {
  526. margin: 0 auto;
  527. width: 102px;
  528. height: 73px;
  529. display: block;
  530. }
  531. .img_dispaly {
  532. margin: 0 auto;
  533. text-align: center;
  534. width: 100px;
  535. height: 70px;
  536. line-height: 70px;
  537. background-color: #D7D7D7;
  538. color: #999;
  539. }
  540. .demonstration {
  541. text-align: center;
  542. }
  543. }
  544. .default-layout-item:hover {
  545. cursor: pointer;
  546. }
  547. ::v-deep .el-radio__label {
  548. display: none;
  549. }
  550. }
  551. /*滚动条样式*/
  552. ::v-deep ::-webkit-scrollbar {
  553. width: 6px;
  554. border-radius: 4px;
  555. height: 4px;
  556. }
  557. ::v-deep ::-webkit-scrollbar-thumb {
  558. background: #dddddd !important;
  559. border-radius: 10px;
  560. }
  561. .catalog-cascader {
  562. width: 100% !important;
  563. }
  564. </style>