detailDialog.vue 14 KB

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