ImgPanel.vue 3.1 KB

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