canvasShowPage.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // 商品列表
  61. if (componentsData[i].type === 'productList') {
  62. if (componentsData[i].componentContent.productData.sourceType === '1') {
  63. _this.sendReq({
  64. url: `${api.getProducts}?page=1&pageSize=99&ids=${componentsData[i].componentContent.productData.productIdList}`,
  65. method: 'GET'
  66. }, (proRes) => {
  67. componentsData[i].componentContent.productData.imgTextData = proRes.data.list
  68. })
  69. } else if(componentsData[i].componentContent.productData.sourceType === '2'){
  70. _this.sendReq({
  71. url: `${api.getProducts}?page=1&pageSize=99&classifyId=${componentsData[i].componentContent.productData.categoryId}`,
  72. method: 'GET'
  73. }, (proRes) => {
  74. componentsData[i].componentContent.productData.imgTextData = proRes.data.list
  75. })
  76. }
  77. }
  78. if (componentsData[i].type === 'shopHeader' && this.terminal === 4) {
  79. if (componentsData[i].componentContent.category && componentsData[i].componentContent.category.length !== 0) {
  80. var categoryArr = componentsData[i].componentContent.category
  81. _this.sendReq({
  82. url: `${api.getClassify}`,
  83. method: 'GET'
  84. }, (proRes) => {
  85. componentsData[i].componentContent.category = proRes.data.filter((item) => {
  86. for (let i = 0; i < categoryArr.length; i++) {
  87. if (categoryArr[i].id === item.id) {
  88. return true
  89. }
  90. }
  91. })
  92. })
  93. }
  94. }
  95. }
  96. _this.componentsData = componentsData
  97. } else {
  98. _this.canvasId = ''
  99. }
  100. // console.log(JSON.parse(res.data.json))
  101. })
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .hom-layout{
  108. background-color: #f5f5f5;
  109. }
  110. </style>
  111. <style lang="scss">
  112. .warp{
  113. width: 710px;
  114. margin: 0 auto;
  115. max-width: 100%;
  116. &.terminal4{
  117. width: 1200px;
  118. max-width: 100%;
  119. }
  120. }
  121. .flex-box{
  122. display: flex;
  123. }
  124. </style>