EditForm.vue 12 KB

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