canvasShowPage.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="layout hom-layout">
  3. <div class="list-group-item" v-for="(item,index) in componentsData" :key="index">
  4. <component :is="componentMap[terminal-1].get(item.type)" :componentContent="item.componentContent" :terminal="terminal" :typeId="typeId" :shopId="shopId"></component>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import componentMap from './componentMap'
  10. import api from './config/api'
  11. import {sendReqMixin} from './config/mixin'
  12. export default {
  13. name: 'canvasPage',
  14. mixins: [sendReqMixin],
  15. data () {
  16. return {
  17. // terminal: 4, // 画布设备 1 小程序,2 H5,3 App 4 电脑
  18. // typeId: 3, // 画布类型 1 平台画布,2 自定义页面,3 商家店铺装修
  19. // shopId: 0, // 店铺id
  20. componentsData: [],
  21. activeComponent: -1,
  22. componentMap: componentMap
  23. }
  24. },
  25. props: {
  26. terminal: {
  27. type: Number,
  28. default: 4
  29. },
  30. typeId: {
  31. type: Number,
  32. default: 1
  33. },
  34. shopId: {
  35. type: Number,
  36. default: 0
  37. }
  38. },
  39. mounted () {
  40. // this.shopId = Cookies.get('shopID')
  41. this.canvasGet()
  42. },
  43. methods: {
  44. // 读取画布
  45. canvasGet () {
  46. var _this = this
  47. var apiUrl = api.getCanvas + '?terminal=' + this.terminal + '&type=' + this.typeId
  48. if (this.shopId) {
  49. apiUrl += '&shopId=' + this.shopId
  50. }
  51. let params = {
  52. url: apiUrl,
  53. method: 'GET'
  54. }
  55. this.sendReq(params, (res) => {
  56. if (JSON.stringify(res.data) !== '{}') {
  57. _this.canvasId = res.data.canvasId
  58. var componentsData = JSON.parse(res.data.json)
  59. for (let i = 0; i < componentsData.length; i++) {
  60. if (componentsData[i].type === 'shopHeader' && this.terminal === 4) {
  61. if (componentsData[i].componentContent.category && componentsData[i].componentContent.category.length !== 0) {
  62. var categoryArr = componentsData[i].componentContent.category
  63. _this.sendReq({
  64. url: `${api.getClassify}`,
  65. method: 'GET'
  66. }, (proRes) => {
  67. componentsData[i].componentContent.category = proRes.data.filter((item) => {
  68. for (let i = 0; i < categoryArr.length; i++) {
  69. if (categoryArr[i].id === item.id) {
  70. return true
  71. }
  72. }
  73. })
  74. })
  75. }
  76. }
  77. }
  78. _this.componentsData = componentsData
  79. } else {
  80. _this.canvasId = ''
  81. }
  82. // console.log(JSON.parse(res.data.json))
  83. })
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .hom-layout{
  90. background-color: #f5f5f5;
  91. }
  92. </style>
  93. <style lang="scss">
  94. .warp{
  95. width: 690px;
  96. margin: 0 auto;
  97. max-width: 100%;
  98. &.terminal4{
  99. width: 1200px;
  100. max-width: 100%;
  101. }
  102. }
  103. .flex-box{
  104. display: flex;
  105. }
  106. </style>