index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <v-form max-width="400px" class="form-module">
  3. <v-text-field v-model="module.name" label="Название модуля"> </v-text-field>
  4. <v-checkbox
  5. max-width="400"
  6. v-model="module.activity"
  7. label="Показывать модуль"
  8. ></v-checkbox>
  9. <v-img :src="'https://api.amic.ru/'+img.relative_path"></v-img>
  10. <v-file-input
  11. @change="handleFile('img', 1280, 660)"
  12. label="Картинка:"
  13. type="file"
  14. accept="image/*"
  15. ref="input"
  16. ></v-file-input>
  17. <v-row>
  18. <v-col>
  19. <h4>Начало активности</h4>
  20. <v-date-picker v-model="date" no-title scrollable>
  21. <v-spacer></v-spacer>
  22. <v-btn text color="primary" @click="menu = false"> Cancel </v-btn>
  23. <v-btn
  24. text
  25. color="primary"
  26. @click="$refs.menu.save(startActivity.date)"
  27. >
  28. OK
  29. </v-btn>
  30. </v-date-picker>
  31. <vue-timepicker v-model="time" format="HH:mm:ss"></vue-timepicker>
  32. </v-col>
  33. <v-col>
  34. <h4>Конец активности</h4>
  35. <v-date-picker v-model="endDate" no-title scrollable>
  36. <v-spacer></v-spacer>
  37. <v-btn text color="primary" @click="menu = false"> Cancel </v-btn>
  38. <v-btn
  39. text
  40. color="primary"
  41. @click="$refs.menu.save(startActivity.date)"
  42. >
  43. OK
  44. </v-btn>
  45. </v-date-picker>
  46. <vue-timepicker v-model="endTime" format="HH:mm:ss"></vue-timepicker>
  47. </v-col>
  48. </v-row>
  49. <v-btn @click="createModule">Создать модуль</v-btn>
  50. </v-form>
  51. </template>
  52. <script>
  53. import VueTimepicker from "vue2-timepicker";
  54. import "vue2-timepicker/dist/VueTimepicker.css";
  55. export default {
  56. layout: "admin",
  57. components: {
  58. VueTimepicker,
  59. },
  60. data() {
  61. return {
  62. module: {
  63. activity: true,
  64. type: "module",
  65. name: "",
  66. start_activity: "",
  67. end_activity: "",
  68. background_image_id: this.img ? this.img.url : "",
  69. },
  70. img: {},
  71. endTime: "",
  72. endDate: "",
  73. date: "",
  74. time: "",
  75. };
  76. },
  77. async asyncData({ $axios }) {
  78. const containers = await $axios
  79. .get("/admin/containers/type_module")
  80. .then((res) => {
  81. return res.data.data;
  82. });
  83. return { containers };
  84. },
  85. methods: {
  86. handleFile(type, width, height) {
  87. let formData = new FormData();
  88. console.log(this.$refs.input.$refs.input.files[0]);
  89. formData.append("file", this.$refs.input.$refs.input.files[0]);
  90. formData.append("destination_width", width);
  91. formData.append("destination_height", height);
  92. formData.append("title", "example img");
  93. this.$axios
  94. .$post("authorized/admin/files/upload/image/news/raw", formData, {
  95. headers: {
  96. "Content-Type": `multipart/form-data;`,
  97. 'Access-Control-Allow-Origin': 'origin'
  98. },
  99. })
  100. .then((res) => {
  101. this.img = res.data;
  102. return res;
  103. })
  104. .catch((err) => console.log(err));
  105. },
  106. createModule() {
  107. this.$axios.post("admin/containers/create", {
  108. type: "module",
  109. name: this.module.name,
  110. start_activity: this.start_activity,
  111. end_activity: this.end_activity,
  112. background_image_id: this.img.image_id,
  113. activity: this.module.activity
  114. })
  115. }
  116. },
  117. computed: {
  118. start_activity() {
  119. return this.date + " " + this.time;
  120. },
  121. end_activity() {
  122. return this.endDate + ' ' + this.endTime
  123. }
  124. },
  125. };
  126. </script>
  127. <style lang="less">
  128. .form-module {
  129. margin: 0 auto;
  130. max-width: 800px;
  131. width: 100%;
  132. }
  133. </style>