detailDialog.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template v-if="isShow">
  2. <!-- 列表选择弹窗 -->
  3. <f-dialog
  4. ref="dialog"
  5. title="遥控器设计器配置"
  6. :initData="handleInitData"
  7. :isDetermine="dialogType!=='detail'"
  8. :beforeClose="handleBeforeClose"
  9. width="1550px"
  10. >
  11. <template #contain>
  12. <el-card>
  13. <h3 slot="header">遥控器基础配置</h3>
  14. <f-form
  15. ref="ruleForm"
  16. :form="fromData"
  17. :disabled="dialogType==='detail'"
  18. :config="fromDataConfig"
  19. :rules="fromRules"
  20. label-position="left"
  21. :key="fromKey"
  22. :online="true"
  23. :column="4"
  24. required
  25. @change="handleRuleFormChange"
  26. />
  27. </el-card>
  28. <br><br>
  29. <el-card >
  30. <h3>遥控器布局配置</h3>
  31. <div class="box">
  32. <el-card class="box-btns">
  33. <div slot="header" class="clearfix">组件库</div>
  34. <div class="box-btns-cpns">
  35. <div v-for="(item, index) in cpnsList" :key="index" class="box-btns-cpns-cpn" @click="addCpns(item)">
  36. <span class="iconfont" :class="item.classType"></span>
  37. <p>{{ item.text }}</p>
  38. </div>
  39. </div>
  40. </el-card>
  41. <div class="box-canvs">
  42. <div class="box-canvs-main" :style="{ backgroundImage: `url(${fromData.backgroundPictureUrl?baseUrl+fromData.backgroundPictureUrl:''})` }">
  43. <grid-layout
  44. :key="pageArray.length+'_'+layoutKey"
  45. :layout.sync="pageArray"
  46. :col-num="3"
  47. :row-height="30"
  48. :is-draggable="true"
  49. :is-resizable="false"
  50. :is-mirrored="false"
  51. :vertical-compact="false"
  52. :prevent-collision="true"
  53. :margin="[10, 0]"
  54. :use-css-transforms="false"
  55. :auto-size="false"
  56. class="box-canvs-main-screen"
  57. >
  58. <grid-item
  59. v-for="(item, index) in pageArray"
  60. :key="index+'_'+item.h+'_'+item.w"
  61. :is-bounded="false"
  62. :x="Number(item.x)"
  63. :y="Number(item.y)"
  64. :w="Number(item.w)"
  65. :h="Number(item.h)"
  66. :i="item.i"
  67. :class="{gridActived:index===currentCpn}"
  68. @dblclick.native="showSeting(index)"
  69. >
  70. <div class="box-canvs-main-span">
  71. <div
  72. style="width: 100%; height: 100%;display: flex;align-items: center;justify-content: center; background-size: contain; background-repeat: no-repeat;"
  73. :style="{
  74. borderColor:item.borderColor,
  75. borderWidth:item.border,
  76. borderStyle:'solid',
  77. borderRadius:item.borderRadius,
  78. fontSize:item.fontSize,
  79. backgroundColor:item.background,
  80. color:item.color,
  81. backgroundImage:item.backgroundImage?`url(${baseUrl}${item.backgroundImage})`:'',
  82. }"
  83. >
  84. {{item.content}}
  85. </div>
  86. <i class="el-icon-close" @click.stop="removeBtn(index)" />
  87. </div>
  88. </grid-item>
  89. </grid-layout>
  90. </div>
  91. </div>
  92. <div class="box-set">
  93. <el-tabs v-if="isShowSeting" v-model="activeName" type="border-card">
  94. <el-tab-pane v-if="pageArray[currentCpn]&&pageArray[currentCpn].type === 'button'" label="组件基础配置" name="first">
  95. <f-form
  96. ref="btnForm"
  97. :key="btnFromKey"
  98. :form="pageArray[currentCpn]"
  99. :config="btnDataConfig"
  100. :rules="btnRules"
  101. label-position="left"
  102. :column="1"
  103. @change="handleBtnFormChange"
  104. />
  105. </el-tab-pane>
  106. <el-tab-pane label="组件样式配置" name="second">
  107. <f-form
  108. ref="btnClassForm"
  109. :key="btnFromKey"
  110. :form="pageArray[currentCpn]"
  111. :config="btnClassConfig"
  112. label-position="left"
  113. :column="1"
  114. @blur="handleBlur"
  115. />
  116. </el-tab-pane>
  117. </el-tabs>
  118. </div>
  119. </div>
  120. </el-card>
  121. </template>
  122. </f-dialog>
  123. </template>
  124. <script>
  125. import { addTemplateApi } from '@/api/template/addTemplate'
  126. import { formConfig, btnFormConfig } from './config'
  127. import { cpnsList } from '../../../../mock/cpnsList'
  128. export default {
  129. name: "DetailDialog",
  130. props: {
  131. // 表单数据
  132. rowData:{
  133. type:Object,
  134. default: () => ({})
  135. },
  136. // 表单类型 add detail edit
  137. dialogType:{
  138. type:String,
  139. default:'add'
  140. },
  141. allBase: {
  142. type: Array,
  143. default: () => []
  144. },
  145. allButton: {
  146. type: Array,
  147. default: () => []
  148. },
  149. useStatus: {
  150. type: Array,
  151. default: () => []
  152. }
  153. },
  154. data() {
  155. return {
  156. layoutKey:0,
  157. // tab
  158. activeName: 'second',
  159. cpnsList,
  160. // 数据对象
  161. fromData:{},
  162. fromDataConfig: [],
  163. // 表单验证
  164. fromRules: {
  165. name: [{required: true, message: '请输入模版名称'}],
  166. status: [{required: true, message: '请选择状态'}],
  167. baseId: [{required: true, message: '请选择基础库'}],
  168. },
  169. // 表单key
  170. fromKey:0,
  171. pageArray: [],
  172. // 按钮配置相关
  173. btnFromShow: false,
  174. btnData: {
  175. typeNum: ''
  176. },
  177. btnRules: {
  178. typeNum: [{required: true, message: '请选择按钮类型'}],
  179. defValue: [{required: true, message: '请输入默认值'}],
  180. bandValue: [{required: true, message: '请输入波段值,默认38000'}],
  181. bootCode: [{required: true, message: '请输入引导码'}],
  182. bootCodeSend: [{required: true, message: '请输入引导码发送次数'}],
  183. dateCode: [{required: true, message: '请输入数据码'}]
  184. // overCode:[{required: true, message: '请输入结束码'}],
  185. },
  186. btnFromKey: 0,
  187. currentCpn: '', // 已选择的组件下标
  188. isShowSeting: false,
  189. baseUrl: process.env.VUE_APP_FILE_STATIC,
  190. baseItem: {}, // 选择的基础库信息
  191. }
  192. },
  193. computed: {
  194. btnDataConfig() {
  195. const {typeNum} = this.btnData
  196. return btnFormConfig(typeNum)
  197. },
  198. pageArrayCount() {
  199. return this.pageArray.length
  200. },
  201. btnClassConfig() {
  202. let config = [
  203. {
  204. itemType: 'input',
  205. prop: 'w',
  206. label: '宽度',
  207. attrs: {
  208. placeholder: '请输入宽度',
  209. type: 'number'
  210. }
  211. },
  212. {
  213. itemType: 'input',
  214. prop: 'h',
  215. label: '高度',
  216. attrs: {
  217. placeholder: '请输入高度',
  218. type: 'number'
  219. }
  220. }
  221. ]
  222. const { currentCpn, pageArray } = this
  223. if (!pageArray[currentCpn]) return []
  224. const { type } = pageArray[currentCpn]
  225. if (type === 'button') {
  226. config = [
  227. ...config,
  228. {
  229. itemType: 'input',
  230. prop: 'content',
  231. label: '按钮文字'
  232. },
  233. {
  234. itemType: 'input',
  235. prop: 'border',
  236. label: '边框粗细'
  237. },
  238. {
  239. itemType: 'color',
  240. prop: 'borderColor',
  241. label: '边框颜色'
  242. },
  243. {
  244. itemType: 'input',
  245. prop: 'borderRadius',
  246. label: '圆角尺寸'
  247. },
  248. {
  249. itemType: 'input',
  250. prop: 'fontSize',
  251. label: '字体大小'
  252. },
  253. {
  254. itemType: 'color',
  255. prop: 'background',
  256. label: '背景颜色'
  257. },
  258. {
  259. itemType: 'color',
  260. prop: 'color',
  261. label: '字体颜色'
  262. }
  263. ]
  264. }
  265. if (type === 'text') {
  266. config = [
  267. ...config,
  268. {
  269. itemType: 'input',
  270. prop: 'content',
  271. label: '文字'
  272. },
  273. {
  274. itemType: 'input',
  275. prop: 'fontSize',
  276. label: '字体大小'
  277. },
  278. {
  279. itemType: 'color',
  280. prop: 'color',
  281. label: '字体颜色'
  282. }
  283. ]
  284. }
  285. if(type === 'image') {
  286. config = [
  287. ...config,
  288. {
  289. itemType: 'fileUpload',
  290. prop: 'backgroundImage',
  291. label: '图片'
  292. }
  293. ]
  294. }
  295. return config
  296. }
  297. },
  298. methods: {
  299. // 遥控器基础配置change事件
  300. handleRuleFormChange(item, form) {
  301. const { prop } = item
  302. if (prop === 'baseId') {
  303. const { allBase } = this
  304. const baseItem = allBase.filter(item => item.value === form.baseId)[0]
  305. this.baseItem = baseItem
  306. // let pageArray = this.pageArray
  307. // const {bandValue, bootCode, bootCodeSend, dateCode, overCode} = baseItem
  308. // pageArray = pageArray.map(item => {
  309. // if (item.type === 'button') {
  310. // item.bandValue = bandValue
  311. // item.bootCode = bootCode
  312. // item.bootCodeSend = bootCodeSend
  313. // item.dateCode = dateCode
  314. // item.overCode = overCode
  315. // }
  316. // return item
  317. // })
  318. // this.pageArray = pageArray
  319. // this.isShowSeting = false
  320. // this.$nextTick(() => {
  321. // if (this.currentCpn !== '') {
  322. // this.isShowSeting = true
  323. // }
  324. // this.btnFromKey++
  325. // })
  326. }
  327. },
  328. // 组件基础配置change事件
  329. handleBtnFormChange(item, form) {
  330. const { prop } = item
  331. this.btnData[prop] = form[prop]
  332. if (form.typeNum !== '0') {
  333. form.addSubMax = ''
  334. form.addSubMin = ''
  335. }
  336. },
  337. // focus事件
  338. handleBlur(item,form) {
  339. const { prop } = item
  340. if (['h', 'w'].includes(prop)) {
  341. form[prop] = Number(form[prop])
  342. this.$nextTick(() => {
  343. this.layoutKey++
  344. })
  345. }
  346. },
  347. // 显示弹窗
  348. show() {
  349. this.fromDataConfig = formConfig.call(this)
  350. this.currentCpn='';
  351. this.$refs.dialog.show();
  352. },
  353. // 初始化表单数据
  354. initFormData(fromData) {
  355. this.fromData = {
  356. content: '',
  357. ...fromData
  358. }
  359. this.fromKey++
  360. },
  361. // 初始化按钮表单数据
  362. initBtnFormData(index) {
  363. this.isShowSeting = false
  364. this.currentCpn = index
  365. this.btnData = {
  366. typeNum: ''
  367. }
  368. this.activeName = 'second'
  369. if (this.pageArray[index].type === 'button') {
  370. this.activeName = 'first'
  371. }
  372. this.$nextTick(() => {
  373. this.isShowSeting = true
  374. this.btnFromKey++
  375. })
  376. },
  377. // 详情
  378. async handleInitData() {
  379. const {dialogType,rowData} = this
  380. if (dialogType === 'add') {
  381. this.pageArray = []
  382. this.initFormData({ })
  383. return
  384. }
  385. // 调接口获取详情
  386. const res = await addTemplateApi.configDetail({ id: rowData.id });
  387. if (res.code !== 200) return this.initFormData({ })
  388. const form = { ...res.data, baseId: res.data.baseId.toString() }
  389. this.pageArray = JSON.parse(res.data.components).map((item, index) => ({
  390. ...item,
  391. x: Number(item.x),
  392. y: Number(item.y),
  393. w: Number(item.w),
  394. h: Number(item.h),
  395. i: index,
  396. text: item.content
  397. }))
  398. const { allBase } = this
  399. const baseItem = allBase.filter(item => item.value === form.baseId)[0]
  400. this.baseItem = baseItem
  401. this.initFormData(form)
  402. },
  403. // 关闭之前回调.
  404. async handleBeforeClose(type) {
  405. if (type !== 'ok') {
  406. return true
  407. };
  408. // 按钮配置项校验
  409. let validateResult = null
  410. for (let index = 0; index <= this.pageArray.length-1; index++) {
  411. validateResult = this.validateBtn(this.pageArray[index])
  412. if (validateResult !== true) {
  413. this.isShowSeting = true
  414. this.currentCpn = index
  415. this.activeName = 'first'
  416. this.$message({
  417. message: validateResult,
  418. type: 'error'
  419. })
  420. return false
  421. }
  422. }
  423. // 布局配置项
  424. const validate = await this.$refs.ruleForm.validate();
  425. if (!validate) return false;
  426. const params = {
  427. ...this.fromData,
  428. components: JSON.stringify(this.pageArray),
  429. baseId: Number(this.fromData.baseId)
  430. }
  431. // 调接口更新数据
  432. const res = await addTemplateApi.configAddOrEdit(params);
  433. if (res.code !== 200) {
  434. this.$modal.msgError(res.msg)
  435. return false
  436. }
  437. this.$emit('updateList')
  438. this.initFormData({})
  439. return true
  440. },
  441. // 添加
  442. addCpns(item) {
  443. if (!this.baseItem.id) {
  444. this.$message.error('请先选择基础库')
  445. return
  446. }
  447. const newItem = { w: 2, h: 1, x: 1, y: this.pageArray.map(item => item?.y).sort()[this.pageArray.length-1] || 1, i: this.pageArrayCount, ...item }
  448. if (this.baseItem.id !== undefined) {
  449. const { bandValue, bootCode, bootCodeSend, dateCode, overCode, synchronizeCode, synchronizeCodeSend, dateBinary0, dateBinary1, repeatCode } = this.baseItem
  450. if (item.type === 'button') {
  451. newItem.bandValue = bandValue
  452. newItem.repeatCode = repeatCode
  453. newItem.bootCode = bootCode
  454. newItem.bootCodeSend = bootCodeSend
  455. newItem.dateCode = dateCode
  456. newItem.overCode = overCode
  457. newItem.synchronizeCode = synchronizeCode
  458. newItem.synchronizeCodeSend = synchronizeCodeSend
  459. newItem.dateBinary0 = dateBinary0
  460. newItem.dateBinary1 = dateBinary1
  461. newItem.addSubMax = ''
  462. newItem.addSubMin = ''
  463. }
  464. }
  465. this.pageArray.push(newItem)
  466. this.initBtnFormData(this.pageArray.length - 1)
  467. },
  468. removeBtn(index) {
  469. const tmpList = this.pageArray.concat();
  470. tmpList.splice(index, 1)
  471. this.isShowSeting = false
  472. this.currentCpn = ''
  473. this.pageArray = tmpList
  474. },
  475. showSeting(index) {
  476. this.activeName = 'second'
  477. this.initBtnFormData(index)
  478. },
  479. // 校验按钮属性
  480. validateBtn(obj) {
  481. if (obj.type != 'button') return true
  482. for(const item of Object.keys(this.btnRules)) {
  483. if (!obj[item]) return this.btnRules[item][0].message
  484. if (obj.typeNum == '0' && !obj?.addSubMax) return '加减型需输入最大值'
  485. if (obj.typeNum == '0' && !obj?.addSubMin) return '加减型需输入最小值'
  486. if (obj.typeNum == '0' && obj?.addSubMax <= obj?.addSubMin) return '加减型最大值要大于最小值'
  487. }
  488. return true
  489. }
  490. },
  491. }
  492. </script>
  493. <style scoped lang="scss">
  494. h3 {
  495. font-weight: 700;
  496. border-left: 4px solid #1890ff;
  497. color: #000;
  498. padding-left: 5px;
  499. line-height: 25px;
  500. margin-bottom: 12px;
  501. }
  502. .box {
  503. box-sizing: border-box;
  504. display: flex;
  505. align-items: center;
  506. justify-content: center;
  507. width: 100%;
  508. height: 100%;
  509. &-btns, &-canvs {
  510. height: 770px;
  511. }
  512. &-canvs{
  513. width: 375px;
  514. border: 1px solid #000;
  515. }
  516. &-btns {
  517. display: flex;
  518. flex-direction: column;
  519. width: 200px;
  520. >h4, >h3 {
  521. text-align: center;
  522. }
  523. &-cpns {
  524. flex: 1;
  525. display: flex;
  526. flex-direction: column;
  527. align-items: center;
  528. .box-btns-cpns-cpn {
  529. display: flex;
  530. flex-direction: column;
  531. align-items: center;
  532. justify-content: space-evenly;
  533. width: 80px;
  534. height: 80px;
  535. background: #f5f5f5;
  536. margin-bottom: 15px;
  537. border: 1px solid #cdcdcd;
  538. border-radius: 4px;
  539. cursor: pointer;
  540. span {
  541. font-size: 28px;
  542. }
  543. p {
  544. margin: 0;
  545. padding: 0;
  546. }
  547. }
  548. }
  549. &-items {
  550. overflow-y: scroll;
  551. &::-webkit-scrollbar {
  552. display: none;
  553. }
  554. }
  555. &-item {
  556. display: flex;
  557. justify-content: center;
  558. align-items: center;
  559. font-size: 20px;
  560. background-color:#0a0a23;
  561. color: #fff;
  562. border:none;
  563. border-radius: 10px;
  564. box-shadow: 0px 0px 2px 2px rgb(0,0,0);
  565. span {
  566. position: relative;
  567. display: flex;
  568. justify-content: center;
  569. align-items: center;
  570. width: 100%;
  571. height: 100%;
  572. i {
  573. position: absolute;
  574. top: 50%;
  575. right: 0;
  576. transform: translateY(-50%);
  577. font-size: 16px;
  578. }
  579. }
  580. }
  581. }
  582. &-canvs {
  583. position: relative;
  584. background: url(../../../../assets/images/mobile-bg.jpg) no-repeat;
  585. background-size: 100%;
  586. border: none;
  587. margin: 0 40px;
  588. &-main {
  589. position: absolute;
  590. top: 90px;
  591. left: 20px;
  592. width: 334px;
  593. height: 585px;
  594. border: 1px solid #000;
  595. border-radius: 4px;
  596. overflow-y: scroll;
  597. background-color: #fff;
  598. background-size: cover;
  599. &::-webkit-scrollbar {
  600. display: none;
  601. }
  602. .box-canvs-main-span {
  603. position: relative;
  604. background: #ffc0cb29;
  605. border: 1px dashed #00000033;
  606. height: 100%;
  607. width: 100%;
  608. i{
  609. position: absolute;
  610. right: -4px;
  611. top: -4px;
  612. color: #fff;
  613. font-size: 14px;
  614. background: #5c5c5c;
  615. border-radius: 50%;
  616. padding: 3px;
  617. cursor: pointer;
  618. }
  619. }
  620. }
  621. }
  622. &-set {
  623. flex: 1;
  624. display: flex;
  625. flex-direction: column;
  626. justify-content: flex-start;
  627. min-height: 667px;
  628. overflow-y: scroll;
  629. &::-webkit-scrollbar {
  630. display: none;
  631. }
  632. h3 {
  633. font-weight: bold;
  634. }
  635. }
  636. }
  637. .gridActived {
  638. box-shadow: #ff0000eb 0px 0px 4px 1px;
  639. }
  640. </style>