AdminContentList.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="AdminContentList"
  3. :style="localOptions.style">
  4. <q-linear-progress v-if="loading"
  5. indeterminate />
  6. <div class="more-action">
  7. <q-btn label="محتوای جدید"
  8. color="primary"
  9. :to="{name: 'Admin.Content.Create'}" />
  10. </div>
  11. <entity-index v-if="mounted"
  12. ref="entityIndex"
  13. v-model:value="inputs"
  14. title="لیست محتواها"
  15. :api="api"
  16. :table="table"
  17. :table-keys="tableKeys"
  18. :create-route-name="createRouteName"
  19. :show-search-button="false"
  20. :show-expand-button="false"
  21. :show-reload-button="false">
  22. <template #entity-index-table-cell="{inputData, showConfirmRemoveDialog}">
  23. <template v-if="inputData.col.name === 'number'">
  24. {{ inputData.rowNumber }}
  25. </template>
  26. <template v-else-if="inputData.col.name === 'thumbnail'">
  27. <q-img :src="inputData.col.value"
  28. width="100px" />
  29. </template>
  30. <template v-else-if="inputData.col.name === 'action'">
  31. <div class="action-column-entity-index">
  32. <q-btn color="primary"
  33. :to="{name: 'Admin.Content.Show', params: {id: inputData.props.row.id}}">
  34. مشاهده جزییات
  35. </q-btn>
  36. <delete-btn @click="showConfirmRemoveDialog(inputData.props.row, 'id', getRemoveMessage(inputData.props.row))" />
  37. </div>
  38. </template>
  39. <template v-else>
  40. {{ inputData.col.value }}
  41. </template>
  42. </template>
  43. </entity-index>
  44. </div>
  45. </template>
  46. <script>
  47. import { shallowRef } from 'vue'
  48. import { EntityIndex } from 'quasar-crud'
  49. import { mixinWidget } from 'src/mixin/Mixins.js'
  50. import { APIGateway } from 'src/api/APIGateway.js'
  51. import DeleteBtn from 'src/components/Control/DeleteBtn.vue'
  52. import BtnControl from 'src/components/Control/btn.vue'
  53. import { FormBuilderAssist } from 'quasar-form-builder'
  54. const BtnControlComp = shallowRef(BtnControl)
  55. export default {
  56. name: 'AdminContentList',
  57. components: { DeleteBtn, EntityIndex },
  58. mixins: [mixinWidget],
  59. data () {
  60. return {
  61. loading: false,
  62. api: APIGateway.content.APIAdresses.base,
  63. tableKeys: {
  64. data: 'results',
  65. total: 'count',
  66. currentPage: 'current',
  67. perPage: 'per_page',
  68. pageKey: 'page'
  69. },
  70. inputs: [
  71. { type: 'select', name: 'category', label: 'دسته بندی', placeholder: ' ', optionLabel: 'title', optionValue: 'id', col: 'col-md-3 col-12' },
  72. { type: 'input', name: 'search', value: null, col: 'col-md-3 col-12', label: 'جست و جو', placeholder: ' ' },
  73. { type: BtnControlComp, name: 'btn', label: 'جستجو', placeholder: ' ', atClick: this.search, col: 'col-md-2 col-12' }
  74. ],
  75. table: {
  76. columns: [
  77. {
  78. name: 'number',
  79. required: true,
  80. label: 'شماره',
  81. align: 'left',
  82. field: () => ''
  83. },
  84. {
  85. name: 'thumbnail',
  86. required: true,
  87. label: 'تصویر',
  88. align: 'left',
  89. field: row => row.thumbnail
  90. },
  91. {
  92. name: 'title',
  93. required: true,
  94. label: 'عنوان',
  95. align: 'left',
  96. field: row => row.title
  97. },
  98. {
  99. name: 'category_info',
  100. required: true,
  101. label: 'دسته',
  102. align: 'left',
  103. field: row => row.category_info?.title
  104. },
  105. {
  106. name: 'action',
  107. required: true,
  108. label: 'جزییات',
  109. align: 'left',
  110. field: row => ''
  111. }
  112. ]
  113. },
  114. mounted: false,
  115. createRouteName: ''
  116. }
  117. },
  118. mounted() {
  119. this.getCategories()
  120. },
  121. methods: {
  122. getCategories () {
  123. this.loading = true
  124. APIGateway.contentCategory.index({ per_page: 9999 })
  125. .then((contentCategories) => {
  126. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', contentCategories.list.list)
  127. })
  128. .finally(() => {
  129. this.loading = false
  130. this.mounted = true
  131. })
  132. },
  133. search () {
  134. this.$refs.entityIndex.search()
  135. },
  136. getRemoveMessage (row) {
  137. return 'آیا از حذف ' + row.title + ' اطمینان دارید؟'
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .AdminContentList {
  144. .more-action {
  145. display: flex;
  146. flex-flow: row;
  147. justify-content: flex-end;
  148. margin-bottom: 10px;
  149. }
  150. .action-column-entity-index {
  151. display: flex;
  152. align-items: center;
  153. justify-content: flex-start;
  154. }
  155. }
  156. </style>