index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template lang="html">
  2. <div class="component-wrapper">
  3. <v-tabs>
  4. <v-tab link to="sliders/slider-create">
  5. Создать слайдер
  6. </v-tab>
  7. </v-tabs>
  8. <v-expansion-panels multiple v-if="sliders">
  9. <v-expansion-panel v-for="slider in sliders" :key="slider.id" class="section__wrapper">
  10. <v-btn
  11. color="primary"
  12. @click="copy(slider.id)"
  13. class="inject-button"
  14. fab
  15. dark
  16. small
  17. >
  18. <v-icon class="mx-auto" left> mdi-content-copy </v-icon>
  19. </v-btn>
  20. <v-btn
  21. color="warning"
  22. @click="deleteSlider(slider.id)"
  23. class="delete-button"
  24. fab
  25. dark
  26. small
  27. >
  28. <v-icon class="mx-auto" left> mdi-delete </v-icon>
  29. </v-btn>
  30. <v-btn
  31. fab
  32. dark
  33. small
  34. color="success"
  35. class="add-button mx-2"
  36. @click="addNews(slider.id)"
  37. >
  38. <v-icon dark>
  39. mdi-plus
  40. </v-icon>
  41. </v-btn>
  42. <v-expansion-panel-header>
  43. {{slider.name }}
  44. </v-expansion-panel-header>
  45. <v-expansion-panel-content max-width="500">
  46. <div v-for="news in slider.news" >
  47. <SectionNews @update="update" :news="news" :news_container_id="slider.id" />
  48. </div>
  49. </v-expansion-panel-content>
  50. </v-expansion-panel>
  51. </v-expansion-panels>
  52. </div>
  53. </template>
  54. <script>
  55. export default {
  56. mounted() {
  57. this.$axios.get("admin/containers/type_slider").then((res) => {
  58. console.log(res.data);
  59. this.sliders = res.data.data;
  60. return res.data.data;
  61. });
  62. },
  63. data() {
  64. return {
  65. sliders: false,
  66. };
  67. },
  68. methods: {
  69. copy(id) {
  70. this.$clipboard(id)
  71. },
  72. async deleteSlider(id) {
  73. await this.$axios.$post("admin/containers/remove", {id: id}).then(() => {
  74. this.$axios.get("admin/containers/type_slider").then((res) => {
  75. this.sliders = res.data.data;
  76. return res.data.data;
  77. });
  78. })
  79. },
  80. async addNews(container_id) {
  81. // const newsReplace1 = news.replaceAll('##', '')
  82. // const newsReplace2 = newsReplace1.replaceAll('news_', '')
  83. // console.log(newsReplace2)
  84. const { value: text } = await this.$swal.fire({
  85. title: "Вставьте инжект новости",
  86. input: "text",
  87. inputPlaceholder: "Инжект",
  88. });
  89. if (text) {
  90. const newsReplace1 = text.replaceAll("##", "");
  91. const newsReplace2 = newsReplace1.replaceAll("news_", "");
  92. this.$axios
  93. .post("admin/containers/add/news", {
  94. news_id: newsReplace2,
  95. news_container_id: container_id,
  96. })
  97. .then(() => {
  98. this.$swal.fire(`Новость добавлена!`);
  99. this.update();
  100. return;
  101. }).then(() => {
  102. this.$axios.get("admin/containers/type_slider").then((res) => {
  103. this.sliders = res.data.data;
  104. return res.data.data;
  105. });
  106. });
  107. }
  108. },
  109. update() {
  110. this.$axios.get("admin/containers/type_slider").then((res) => {
  111. console.log(res.data);
  112. this.sliders = res.data.data;
  113. return res.data.data;
  114. }).then(() => {
  115. this.$axios.get("admin/containers/type_slider").then((res) => {
  116. this.sliders = res.data.data;
  117. return res.data.data;
  118. });
  119. })
  120. },
  121. },
  122. layout: "admin",
  123. };
  124. </script>
  125. <style lang="scss" scope>
  126. .v-sheet.v-card {
  127. width: 200px;
  128. margin-bottom: 55px;
  129. margin-right: 55px;
  130. }
  131. .v-expansion-panel-content__wrap {
  132. max-width: 100%;
  133. display: flex;
  134. flex-wrap: wrap;
  135. justify-content: flex-start;
  136. }
  137. .v-card__actions > .v-btn.v-btn {
  138. padding: 0 8px;
  139. margin: 0 auto;
  140. }
  141. .add-button {
  142. position: absolute;
  143. right: 50px;
  144. z-index: 10;
  145. }
  146. .inject-button {
  147. position: absolute;
  148. right: 120px;
  149. z-index: 10;
  150. }
  151. .delete-button {
  152. position: absolute;
  153. right: 190px;
  154. z-index: 10;
  155. }
  156. </style>