index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div>
  3. <div>
  4. <v-tabs>
  5. <v-tab link to="publications/create"> Создать новость </v-tab>
  6. <v-tab link to="publications/create-category">
  7. Создать категорию
  8. </v-tab>
  9. <v-tab link to="publications/categories"> Категории </v-tab>
  10. <v-tab link to="publications/create-container"> Создать модуль </v-tab>
  11. <v-tab link to="publications/containers"> Модули </v-tab>
  12. <v-tab link to="publications/search"> Поиск </v-tab>
  13. </v-tabs>
  14. <v-btn class="my-5" @click="$modal.show('admin-filter-modal')">
  15. Открыть фильтр
  16. </v-btn>
  17. <v-btn class="my-5" @click="clearFilter"> Очистить фильтр </v-btn>
  18. <v-progress-linear
  19. v-if="load"
  20. indeterminate
  21. color="green"
  22. ></v-progress-linear>
  23. <v-expansion-panels multiple v-if="newsList.news">
  24. <v-expansion-panel v-for="news in newsList.news" :key="news.id">
  25. <div v-bind:class="!news.is_show ? 'disable_item_list' : ''">
  26. <div :class="news.news_timing">
  27. <v-expansion-panel-header>
  28. <v-col cols="1">
  29. <img
  30. class="catalog-item__img"
  31. :src="
  32. news.preview_image_for_admin
  33. ? news.preview_image_for_admin.url
  34. : ''
  35. "
  36. />
  37. </v-col>
  38. <v-col cols="5">
  39. <div>
  40. <b v-html="news.title"></b>
  41. </div>
  42. <div
  43. class="mt-2 text-uppercase caption primary--text"
  44. v-if="getContainerTitle(news)"
  45. >
  46. {{ getContainerTitle(news) }}
  47. </div>
  48. <div class="list-editors" v-html="news.news_user_editors"></div>
  49. </v-col>
  50. <v-col cols="1">
  51. <v-list-item-subtitle>
  52. <!--Категория:-->
  53. {{
  54. news.category_for_admin ? news.category_for_admin.title : ""
  55. }}
  56. </v-list-item-subtitle>
  57. </v-col>
  58. <v-col cols="2">
  59. <span> </span>
  60. <span> </span>
  61. <v-divider vertical></v-divider>
  62. <!--Время:-->
  63. {{ news.start_activity }}
  64. </v-col>
  65. <v-col cols="2" @click.stop="">
  66. <v-btn
  67. link
  68. tile
  69. color="success"
  70. :to="{
  71. name: 'admin-publications-id',
  72. params: { id: news.id },
  73. }"
  74. >
  75. <v-icon left> mdi-pencil </v-icon>
  76. <!--изменить-->
  77. </v-btn>
  78. <v-btn
  79. tile
  80. color="error"
  81. @click="deleteNews(news.id)"
  82. v-if="user_groups == 5"
  83. >
  84. <v-icon left> mdi-delete-outline </v-icon>
  85. <!--удалить-->
  86. </v-btn>
  87. <v-btn tile color="primary" @click="copy(news)">
  88. <v-icon left> mdi-content-copy </v-icon>
  89. Инжект
  90. </v-btn>
  91. </v-col>
  92. <v-col cols="1" @click.stop="">
  93. <div class="d-flex align-center">
  94. <v-switch
  95. @change="changeActivity(news, $event)"
  96. v-model="news.activity"
  97. class="mt-0"
  98. hide-details
  99. inset>
  100. </v-switch>
  101. <v-icon v-if="news.verified" left color="green">mdi-checkbox-marked</v-icon>
  102. </div>
  103. </v-col>
  104. </v-expansion-panel-header>
  105. <v-expansion-panel-content>
  106. <!--Превью новости-->
  107. <v-col cols="3">
  108. <div v-html="news.text" class="text"></div>
  109. </v-col>
  110. </v-expansion-panel-content>
  111. </div>
  112. </div>
  113. </v-expansion-panel>
  114. </v-expansion-panels>
  115. <v-pagination
  116. v-if="newsList.news"
  117. v-model="counter"
  118. :length="newsList.total_pages"
  119. @input="loadNewsFilter"
  120. :next-icon="'>'"
  121. :prev-icon="'<'"
  122. total-visible="10"
  123. ></v-pagination>
  124. <modal adaptive height="auto" name="admin-filter-modal">
  125. <div class="publications-filter">
  126. <h3>Фильтр</h3>
  127. <v-row>
  128. <v-col>
  129. <v-select
  130. :items="categoriesList"
  131. item-text="title"
  132. item-value="id"
  133. v-model="filterCategory"
  134. label="Категория"
  135. clearable
  136. ></v-select>
  137. <v-date-picker
  138. range
  139. :first-day-of-week="0"
  140. locale="ru"
  141. v-model="filterActivity"
  142. no-title
  143. scrollable
  144. full-width
  145. multiple
  146. >
  147. </v-date-picker>
  148. <v-btn class="ml-auto success mr-0" @click="filterNews">
  149. Фильтровать
  150. </v-btn>
  151. </v-col>
  152. </v-row>
  153. </div>
  154. </modal>
  155. </div>
  156. </div>
  157. </template>
  158. <script>
  159. export default {
  160. layout: "admin",
  161. data() {
  162. return {
  163. counter: 1,
  164. newsList: [],
  165. categories: [],
  166. filterCategory: "",
  167. filterActivity: [],
  168. load: true,
  169. filter: false,
  170. user_groups: null,
  171. };
  172. },
  173. async mounted() {
  174. await this.getCategory();
  175. await this.loadNews();
  176. this.user_groups = this.$store.state.auth.user.user_permission_group;
  177. },
  178. computed: {
  179. categoriesList() {
  180. if (!this.categories) return [];
  181. return this.categories;
  182. },
  183. },
  184. methods: {
  185. async getCategory() {
  186. this.categories = await this.$axios
  187. .$get("/admin/categories")
  188. .then((res) => res.data);
  189. },
  190. async loadNews() {
  191. this.newsList = await this.$axios
  192. .$get(`/admin/news/list?page=${this.counter}`)
  193. .then((res) => res.data)
  194. .catch((err) => console.log(err));
  195. this.load = false;
  196. },
  197. async loadNewsFilter() {
  198. this.filterActivity.sort();
  199. const [start = "", end = ""] = this.filterActivity;
  200. const category = this.filterCategory ? `/${this.filterCategory}` : "";
  201. const url = `/admin/news/list${category}?page=${this.counter}`;
  202. const urlWithFilter = `${url}&filter[date_start]=${start}&filter[date_end]=${end}`;
  203. this.newsList = await this.$axios
  204. .$get(urlWithFilter)
  205. .then((res) => res.data)
  206. .catch((err) => console.log(err));
  207. this.load = false;
  208. },
  209. async deleteNews(id) {
  210. const result = await this.$swal.fire({
  211. title: "Вы уверены, что хотите удалить новость?",
  212. showCancelButton: true,
  213. confirmButtonText: "Удалить",
  214. icon: "error",
  215. cancelButtonText: `Не удалять`,
  216. confirmButtonColor: `#ab003c`,
  217. denyButtonColor: `#2196f3`,
  218. });
  219. if (result.isConfirmed) {
  220. await this.$axios
  221. .post("/admin/news/remove", { id: id })
  222. .then((res) => res.data);
  223. await this.loadNews();
  224. this.$swal.fire("Удалено!", "", "error");
  225. } else if (result.isDenied) {
  226. this.$swal.fire("Отмена удаления", "", "info");
  227. }
  228. },
  229. copy(item) {
  230. let res = "##news_" + item.id + "##";
  231. this.$clipboard(res);
  232. },
  233. async filterNews() {
  234. this.counter = 1;
  235. this.load = true;
  236. this.$modal.hide("admin-filter-modal");
  237. await this.loadNewsFilter();
  238. },
  239. async clearFilter() {
  240. this.counter = 1;
  241. this.filterCategory = "";
  242. this.filterActivity = [];
  243. this.load = true;
  244. await this.loadNews();
  245. },
  246. async changeActivity(item, $event) {
  247. await this.$axios.post("admin/news/update", {
  248. ...item, activity: $event
  249. });
  250. },
  251. getContainerTitle(item) {
  252. return item.container_news_site ? item.container_news_site.container.name : '';
  253. }
  254. },
  255. };
  256. </script>
  257. <style>
  258. .text {
  259. display: block;
  260. }
  261. .tree-select {
  262. margin-bottom: 15px;
  263. }
  264. .publications-filter {
  265. padding: 20px;
  266. }
  267. .v-tabs-slider-wrapper {
  268. display: none;
  269. }
  270. .disable_item_list {
  271. opacity: 0.5;
  272. }
  273. .yesterday, .today, .tomorrow{
  274. position: relative;
  275. }
  276. .yesterday::before, .today::before, .tomorrow::before{
  277. content: " ";
  278. position: absolute;
  279. width: 10px;
  280. height: 100%;
  281. top: 0;
  282. left: 0;
  283. }
  284. .yesterday::before{
  285. background-color: purple;
  286. }
  287. .today::before{
  288. background-color: #4caf50;
  289. }
  290. .tomorrow::before{
  291. background-color: orange;
  292. }
  293. .list-editors{
  294. color: #999;
  295. margin-top: 11px;
  296. }
  297. </style>