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 { get, post } from 'packages/js/utils/http'
  144. import Icon from 'packages/assets/images/dataSourceIcon/export'
  145. export default {
  146. name: 'EditForm',
  147. components: {
  148. },
  149. props: {
  150. },
  151. data () {
  152. return {
  153. selectName: '',
  154. defaultProps: { // el-tree的配置
  155. children: 'children',
  156. label: 'name'
  157. },
  158. resolutionRatioValue: '1920*1080',
  159. resolutionRatio: {
  160. w: 1920,
  161. h: 1080
  162. },
  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. catalogList: [],
  194. type: '',
  195. parentCode: '', // 父节点的code
  196. formVisible: false,
  197. title: '', // 弹框标题(新增/编辑)
  198. dataForm: {
  199. id: '',
  200. type: '',
  201. name: '',
  202. icon: '',
  203. code: '',
  204. remark: '',
  205. iconColor: '#007aff',
  206. components: '',
  207. style: '',
  208. modelCode: '',
  209. formType: '',
  210. formConfig: '',
  211. pageTemplateId: ''
  212. },
  213. formTypeList: [
  214. {
  215. value: 'modelForm',
  216. label: '模型表单',
  217. disabled: false
  218. },
  219. {
  220. value: 'bizForm',
  221. label: '业务表单',
  222. disabled: true
  223. }
  224. ],
  225. iconList: [],
  226. dataFormRules: {
  227. name: [
  228. { required: true, message: '页面名称不能为空', trigger: 'blur' }
  229. ],
  230. modelCode: [
  231. { required: true, message: '数据模型不能为空', trigger: 'change' }
  232. ]
  233. },
  234. currentPageType: '基础表格',
  235. sureLoading: false,
  236. toDesignLoading: false,
  237. sureDisabled: false,
  238. toDesignDisabled: false
  239. }
  240. },
  241. computed: {},
  242. watch: {
  243. formVisible: {
  244. handler (value) {
  245. if (value) {
  246. this.openCascader()
  247. }
  248. }
  249. },
  250. resolutionRatioValue (val) {
  251. if (val) {
  252. this.resolutionRatio.w = val.split('*')[0]
  253. this.resolutionRatio.h = val.split('*')[1]
  254. } else {
  255. this.resolutionRatio.w = 1920
  256. this.resolutionRatio.h = 1080
  257. }
  258. }
  259. },
  260. mounted () {},
  261. methods: {
  262. // 点击选择上级目录树节点
  263. handleNodeClick (node) {
  264. this.$set(this.dataForm, 'parentCode', node.code)
  265. this.selectName = node.name
  266. this.$refs.select.blur() // 点击后关闭下拉框,因为点击树形控件后select不会自动折叠
  267. },
  268. // 获取所有的目录
  269. openCascader () {
  270. post('/bigScreen/category/tree', { searchKey: '', typeList: ['catalog'], sort: false }).then(data => {
  271. const list = [{ name: '根目录', code: '', children: data }]
  272. this.catalogList = list
  273. }).catch(() => {
  274. })
  275. },
  276. // 关闭弹窗时
  277. closeAddDialog () {
  278. this.formVisible = false
  279. this.$refs.dataForm.resetFields()
  280. },
  281. // 初始化
  282. init (nodeData, parentNode, type, categories) {
  283. this.selectName = parentNode.name
  284. this.title = ''
  285. this.dataForm.code = nodeData ? nodeData.code : ''
  286. this.dataForm.type = nodeData ? nodeData.type : type
  287. const code = nodeData ? nodeData.code : ''
  288. this.formVisible = true
  289. this.$nextTick(() => {
  290. if (this.dataForm.type === 'bigScreen') {
  291. if (code) {
  292. get(`/${this.dataForm.type}/design/info/code/${code}`).then((resp) => {
  293. this.$set(this, 'title', resp.name)
  294. this.$set(this.dataForm, 'name', resp.name)
  295. this.$set(this.dataForm, 'chartList', resp.chartList)
  296. this.$set(this.dataForm, 'code', resp.code)
  297. this.$set(this.dataForm, 'icon', resp.icon)
  298. this.$set(this.dataForm, 'iconColor', resp.iconColor)
  299. this.$set(this.dataForm, 'id', resp.id)
  300. this.$set(this.dataForm, 'parentCode', resp.parentCode === '0' ? '' : resp.parentCode)
  301. this.$set(this.dataForm, 'remark', resp.remark)
  302. this.$set(this.dataForm, 'style', resp.style)
  303. this.$set(this.dataForm, 'type', resp.type)
  304. this.$set(this.dataForm, 'orderNum', nodeData.orderNum)
  305. this.$set(this.dataForm, 'pageTemplateId', resp?.pageTemplateId)
  306. if (this.dataForm.type === 'bigScreen') {
  307. const { w, h } = resp.pageConfig
  308. this.resolutionRatio.w = w
  309. this.resolutionRatio.h = h
  310. this.resolutionRatioValue = `${w}*${h}`
  311. }
  312. this.getTemplateList(this.dataForm.type)
  313. })
  314. } else {
  315. this.$set(this.dataForm, 'name', '')
  316. this.$set(this.dataForm, 'chartList', [])
  317. this.$set(this.dataForm, 'code', '')
  318. this.$set(this.dataForm, 'icon', Icon.getNameList()[0])
  319. this.$set(this.dataForm, 'iconColor', '#007aff')
  320. this.$set(this.dataForm, 'id', '')
  321. this.$set(this.dataForm, 'parentCode', parentNode.code)
  322. this.$set(this.dataForm, 'remark', '')
  323. this.$set(this.dataForm, 'style', '')
  324. this.$set(this.dataForm, 'type', this.dataForm.type)
  325. this.$set(this.dataForm, 'orderNum', 0)
  326. this.$set(this.dataForm, 'pageTemplateId', '')
  327. if (this.dataForm.type === 'bigScreen') {
  328. this.resolutionRatio.w = '1920'
  329. this.resolutionRatio.h = '1080'
  330. }
  331. this.getTemplateList(this.dataForm.type)
  332. }
  333. }
  334. })
  335. },
  336. // 点击确定时
  337. addOrUpdate (isToDesign = false) {
  338. if (this.dataForm.type === 'bigScreen') {
  339. this.addOrUpdateBigScreen(isToDesign)
  340. }
  341. },
  342. // 大屏 新增/编辑
  343. async addOrUpdateBigScreen (isToDesign) {
  344. this.$refs.dataForm.validate(async (valid) => {
  345. if (!valid) {
  346. return
  347. }
  348. const addOrUpdateHandel = !this.dataForm.code
  349. ? (form) => post('/bigScreen/design/add', form)
  350. : (form) => post('/bigScreen/design/update', form)
  351. const form = {
  352. className: 'com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO',
  353. chartList: this.dataForm.chartList,
  354. code: this.dataForm.code,
  355. icon: this.dataForm.icon,
  356. iconColor: this.dataForm.iconColor,
  357. id: this.dataForm.id,
  358. name: this.dataForm.name,
  359. parentCode: this.dataForm.parentCode,
  360. remark: this.dataForm.remark,
  361. style: this.dataForm.style,
  362. type: 'bigScreen',
  363. orderNum: this.dataForm.orderNum,
  364. pageConfig: {
  365. w: this.resolutionRatio.w || '1920',
  366. h: this.resolutionRatio.h || '1080',
  367. bgColor: '#151a26',
  368. opacity: 100,
  369. customTheme: 'auto'
  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. /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. /deep/.el-radio__label {
  548. display: none;
  549. }
  550. }
  551. /*滚动条样式*/
  552. /deep/::-webkit-scrollbar {
  553. width: 6px;
  554. border-radius: 4px;
  555. height: 4px;
  556. }
  557. /deep/::-webkit-scrollbar-thumb {
  558. background: #dddddd !important;
  559. border-radius: 10px;
  560. }
  561. .catalog-cascader {
  562. width: 100% !important;
  563. }
  564. </style>