ImgPanel.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div
  3. style="display: flex;
  4. flex-wrap: wrap; align-content: baseline; justify-content: space-between ; padding-left: 21px; padding-right: 21px;padding-top: 27px;">
  5. <PicPicker class="ele-add" @uploaded="uploadImage" :themeId="themeId" :ismultiple="ismultiple" :isButton='isButton'>
  6. </PicPicker>
  7. <template v-if="ismultiple">
  8. <div class="ele" :style="{ backgroundImage: 'url(' + (element.morePic[0]?element.morePic[0].filePath:'') + ')' }"
  9. @click="selectedImg(element)" v-for="element in picList1"></div>
  10. </template>
  11. <template v-else-if="isButton">
  12. <div class="ele" :style="{ backgroundImage: 'url(' + element.filePath + ')' }" @click="selectedImg(element)"
  13. v-for="element in picList3"></div>
  14. </template>
  15. <template v-else>
  16. <div class="ele" :style="{ backgroundImage: 'url(' + element.filePath + ')' }" @click="selectedImg(element)"
  17. v-for="element in picList2"></div>
  18. </template>
  19. </div>
  20. </template>
  21. <script>
  22. import appConst from '../util/appConst'
  23. import PicPicker from './PicturePicker'
  24. export default {
  25. props: {
  26. selectedImg: {
  27. type: Function
  28. },
  29. themeId: {
  30. type: String
  31. },
  32. isButton: Boolean,
  33. ismultiple: Boolean
  34. },
  35. data() {
  36. return {
  37. http: appConst.BACKEND_DOMAIN
  38. }
  39. },
  40. computed: {
  41. picList() {
  42. return this.$store.state.editor.picList
  43. },
  44. picList1() {
  45. var arr = [];
  46. this.picList.forEach(function (item) {
  47. if (item.morePic) {
  48. arr.push(item)
  49. }
  50. })
  51. return arr
  52. },
  53. picList2() {
  54. var arr = [];
  55. this.picList.forEach(function (item) {
  56. if (!item.morePic && !item.isButton) {
  57. arr.push(item)
  58. }
  59. })
  60. return arr
  61. },
  62. picList3() {
  63. var arr = [];
  64. this.picList.forEach(function (item) {
  65. if (!item.morePic && item.isButton) {
  66. arr.push(item)
  67. }
  68. })
  69. return arr
  70. }
  71. },
  72. methods: {
  73. uploadImage(data) {
  74. this.$store.dispatch('savePic', {
  75. 'filePath': data['filePath'],
  76. 'themeId': this.themeId,
  77. 'width': data['width'],
  78. 'height': data['height'],
  79. 'morePic': data.morePic,
  80. 'isButton': data.isButton,
  81. })
  82. }
  83. },
  84. components: {
  85. PicPicker
  86. }
  87. }
  88. </script>
  89. <style lang="less" scoped>
  90. .ele-add {
  91. float: left;
  92. width: 45%;
  93. height: calc(324px *0.45 * 0.73);
  94. background-repeat: no-repeat;
  95. background-position: center;
  96. background-size: contain;
  97. margin-bottom: 16px;
  98. &:hover {
  99. cursor: pointer;
  100. }
  101. }
  102. .ele {
  103. float: left;
  104. width: 45%;
  105. height: calc(324px *0.45 * 0.73);
  106. background-repeat: no-repeat;
  107. background-position: center;
  108. background-size: contain;
  109. margin-bottom: 16px;
  110. &:hover {
  111. border: 2px solid #4E5DFF;
  112. cursor: pointer;
  113. }
  114. }
  115. </style>