index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div>
  3. <v-expansion-panels multiple>
  4. <v-expansion-panel v-for="container in containers" :key="container.id">
  5. <v-expansion-panel-header>
  6. <client-only>
  7. <v-col>{{ container.name }}</v-col>
  8. <v-col> Начало: {{ container.start_activity }} </v-col>
  9. <v-col> Конец: {{ container.end_activity }} </v-col>
  10. <v-col xl="auto">
  11. <v-btn fab small color="success" @click.stop="addNews(container.id)">
  12. <v-icon dark> mdi-plus </v-icon>
  13. </v-btn>
  14. </v-col>
  15. </client-only>
  16. </v-expansion-panel-header>
  17. <v-expansion-panel-content class="text" max-width="500">
  18. <AdminModule @update="loadModules" :module="container" />
  19. </v-expansion-panel-content>
  20. </v-expansion-panel>
  21. </v-expansion-panels>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. layout: "admin",
  27. data() {
  28. return {
  29. containers: [],
  30. };
  31. },
  32. async fetch() {
  33. await this.loadModules();
  34. },
  35. methods: {
  36. async addNews(containerId) {
  37. const { value: text } = await this.$swal.fire({
  38. title: "Вставьте инжект новости",
  39. input: "text",
  40. inputPlaceholder: "Инжект",
  41. });
  42. if (!text) return;
  43. const newsId = text.replaceAll("##", "").replaceAll("news_", "");
  44. await this.$axios.post("admin/containers/add/news", {
  45. news_id: newsId,
  46. news_container_id: containerId,
  47. });
  48. this.loadModules();
  49. this.$swal.fire(`Новость добавлена!`);
  50. },
  51. async loadModules() {
  52. this.containers = await this.$axios
  53. .get("https://api.amic.ru/api/v1/admin/containers/type_module")
  54. .then((res) => {
  55. console.log(res);
  56. return res.data.data;
  57. })
  58. .catch((e) => console.log(e));
  59. },
  60. },
  61. };
  62. </script>
  63. <style>
  64. </style>