addDialog.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. >
  18. <el-form-item label="上级目录">
  19. <el-select
  20. ref="select"
  21. v-model="dataForm.parentCode"
  22. placeholder="请选择上级目录"
  23. clearable
  24. >
  25. <el-option
  26. :key="dataForm.parentCode"
  27. hidden
  28. :value="dataForm.parentCode"
  29. :label="selectName"
  30. />
  31. <el-tree
  32. :data="catalogList"
  33. :props="defaultProps"
  34. node-key="code"
  35. :check-on-click-node="true"
  36. :expand-on-click-node="false"
  37. @node-click="handleNodeClick"
  38. >
  39. <span
  40. slot-scope="{ data }"
  41. class="menu-span"
  42. >
  43. <span
  44. style="padding-left:4px;font-size:14px"
  45. class="tree-node-name"
  46. >{{ data.name }}</span>
  47. </span>
  48. </el-tree>
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item
  52. label="名称"
  53. prop="name"
  54. >
  55. <el-input
  56. v-model="dataForm.name"
  57. autocomplete="off"
  58. placeholder="请输入名称"
  59. clearable
  60. maxlength="30"
  61. />
  62. </el-form-item>
  63. <el-form-item
  64. v-if="dataForm.type === 'bigScreen'"
  65. label="推荐分辨率"
  66. >
  67. <el-select
  68. v-model="resolutionRatioValue"
  69. class="select"
  70. placeholder="请选择分辨率"
  71. clearable
  72. >
  73. <el-option
  74. v-for="resolutionRatioItem in resolutionRatioOptions"
  75. :key="resolutionRatioItem.value"
  76. :label="resolutionRatioItem.label"
  77. :value="resolutionRatioItem.value"
  78. />
  79. </el-select>
  80. </el-form-item>
  81. <el-form-item
  82. v-if="dataForm.type === 'bigScreen'"
  83. label="大屏宽度"
  84. >
  85. <el-input-number
  86. v-model="resolutionRatio.w"
  87. :min="100"
  88. :max="8000"
  89. />
  90. </el-form-item>
  91. <el-form-item
  92. v-if="dataForm.type === 'bigScreen'"
  93. label="大屏高度"
  94. >
  95. <el-input-number
  96. v-model="resolutionRatio.h"
  97. :min="100"
  98. :max="8000"
  99. />
  100. </el-form-item>
  101. <el-form-item label="排序">
  102. <el-input-number
  103. v-model="dataForm.orderNum"
  104. :min="0"
  105. :max="30000"
  106. controls-position="right"
  107. />
  108. </el-form-item>
  109. </el-form>
  110. <div
  111. slot="footer"
  112. class="dialog-footer"
  113. >
  114. <el-button
  115. class="bs-el-button-default"
  116. @click="closeAddDialog"
  117. >
  118. 取消
  119. </el-button>
  120. <el-button
  121. v-if="title"
  122. type="primary"
  123. :loading="toDesignLoading"
  124. :disabled="toDesignDisabled"
  125. @click="addOrUpdate(true)"
  126. >
  127. 设计
  128. </el-button>
  129. <el-button
  130. type="primary"
  131. :loading="sureLoading"
  132. :disabled="sureDisabled"
  133. @click="addOrUpdate(!title)"
  134. >
  135. 确定
  136. </el-button>
  137. </div>
  138. </el-dialog>
  139. </div>
  140. </template>
  141. <script>
  142. import { get, post } from 'packages/js/utils/http'
  143. import Icon from 'packages/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. 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. 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) => post('/bigScreen/design/add', form)
  349. : (form) => post('/bigScreen/design/update', form)
  350. const form = {
  351. className: 'com.gccloud.bigscreen.core.module.manage.dto.BigScreenPageDTO',
  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. opacity: 100,
  368. customTheme: 'auto'
  369. },
  370. pageTemplateId: this.dataForm.pageTemplateId
  371. }
  372. if (isToDesign) {
  373. this.toDesignLoading = true
  374. this.sureDisabled = true
  375. } else {
  376. this.sureLoading = true
  377. this.toDesignDisabled = true
  378. }
  379. addOrUpdateHandel(form)
  380. .then((code) => {
  381. this.formVisible = false
  382. const message = this.dataForm.code ? '更新成功' : '新建成功'
  383. this.$message.success(message)
  384. this.$emit('refreshData', form, this.dataForm.id)
  385. if (isToDesign) {
  386. this.toDesignLoading = false
  387. this.sureDisabled = false
  388. form.code = code || this.dataForm.code
  389. this.toDesign({ ...form })
  390. } else {
  391. this.sureLoading = false
  392. this.toDesignDisabled = false
  393. }
  394. })
  395. .catch(() => {
  396. this.sureLoading = false
  397. this.toDesignLoading = false
  398. this.sureDisabled = false
  399. this.toDesignDisabled = false
  400. })
  401. })
  402. },
  403. // 跳转设计态
  404. toDesign (form) {
  405. // eslint-disable-next-line no-case-declarations
  406. const { href: bigScreenHref } = this.$router.resolve({
  407. path: window.BS_CONFIG?.routers?.designUrl || '/big-screen/design',
  408. query: {
  409. code: form.code
  410. }
  411. })
  412. window.open(bigScreenHref, '_self')
  413. },
  414. // 得到模板列表
  415. getTemplateList (type) {
  416. this.$nextTick(() => {
  417. // this.$refs.TemplateList.init(type)
  418. })
  419. },
  420. // 选择模版后覆盖配置
  421. selectTemplate (template) {
  422. // TODO: 选择模版后覆盖配置
  423. }
  424. }
  425. }
  426. </script>
  427. <style lang="scss" scoped>
  428. ::v-deep .el-dialog__body {
  429. overflow-y: auto;
  430. }
  431. .el-scrollbar {
  432. height: 300px;
  433. overflow-x: hidden;
  434. /deep/ .el-scrollbar__view {
  435. overflow-x: hidden;
  436. }
  437. }
  438. .color-picker {
  439. display: flex;
  440. align-items: center;
  441. }
  442. .icon-svg {
  443. width: 25px;
  444. height: 25px;
  445. }
  446. .color-select {
  447. width: 350px;
  448. display: flex;
  449. margin-top: 5px;
  450. align-items: center;
  451. justify-content: space-between;
  452. div {
  453. width: 20px;
  454. height: 20px;
  455. cursor: pointer;
  456. position: relative;
  457. }
  458. ::v-deep .el-color-picker__trigger {
  459. top: 0;
  460. right: 0;
  461. width: 21px;
  462. height: 21px;
  463. padding: 0;
  464. }
  465. .el-icon-check {
  466. font-size: 20px;
  467. color: #ffffff;
  468. position: absolute;
  469. }
  470. }
  471. .icon-list {
  472. margin-top: 15px;
  473. padding: 5px;
  474. border-radius: 5px;
  475. border: 1px solid #e8e8e8;
  476. .el-button--mini {
  477. min-width: 37px;
  478. padding: 5px !important;
  479. border: 1px solid transparent !important;
  480. &:hover {
  481. background-color: rgba(217, 217, 217, 0.3);
  482. }
  483. }
  484. }
  485. .icon-uploader {
  486. width: 60px;
  487. height: 60px;
  488. border: 1px dashed #d9d9d9;
  489. border-radius: 6px;
  490. cursor: pointer;
  491. position: relative;
  492. overflow: hidden;
  493. /*.icon-svg {*/
  494. /* padding: 5px;*/
  495. /* width: 60px !important;*/
  496. /* height: 60px !important;*/
  497. /*}*/
  498. }
  499. .icon-uploader-icon {
  500. font-size: 28px;
  501. color: #8c939d;
  502. width: 60px;
  503. height: 60px;
  504. line-height: 60px;
  505. text-align: center;
  506. }
  507. .icon {
  508. width: 60px;
  509. height: 60px;
  510. display: block;
  511. }
  512. .default-layout-box {
  513. display: flex;
  514. flex-wrap: wrap;
  515. .default-layout-item {
  516. cursor: pointer;
  517. margin: 9px;
  518. display: flex;
  519. flex-direction: column;
  520. align-items: center;
  521. .component-name {
  522. font-size: 12px;
  523. }
  524. .sampleImg {
  525. margin: 0 auto;
  526. width: 102px;
  527. height: 73px;
  528. display: block;
  529. }
  530. .img_dispaly {
  531. margin: 0 auto;
  532. text-align: center;
  533. width: 100px;
  534. height: 70px;
  535. line-height: 70px;
  536. background-color: #D7D7D7;
  537. color: #999;
  538. }
  539. .demonstration {
  540. text-align: center;
  541. }
  542. }
  543. .default-layout-item:hover {
  544. cursor: pointer;
  545. }
  546. /deep/.el-radio__label {
  547. display: none;
  548. }
  549. }
  550. /*滚动条样式*/
  551. /deep/::-webkit-scrollbar {
  552. width: 6px;
  553. border-radius: 4px;
  554. height: 4px;
  555. }
  556. /deep/::-webkit-scrollbar-thumb {
  557. background: #dddddd !important;
  558. border-radius: 10px;
  559. }
  560. .catalog-cascader {
  561. width: 100% !important;
  562. }
  563. </style>