AdminContentCreate.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div class="AdminContentCreate"
  3. :style="localOptions.style">
  4. <div class="flex justify-end">
  5. <q-btn flat
  6. color="grey"
  7. @click="$router.go(-1)">
  8. بازگشت
  9. >
  10. </q-btn>
  11. </div>
  12. <entity-create v-if="mounted"
  13. ref="entityCreate"
  14. v-model:value="inputs"
  15. title="ایجاد محتوا"
  16. :api="api"
  17. :entity-id-key="entityIdKey"
  18. :entity-param-key="entityParamKey"
  19. :show-route-name="showRouteName"
  20. :show-close-button="false"
  21. :show-edit-button="false"
  22. :show-expand-button="false"
  23. :show-save-button="false"
  24. :show-reload-button="false" />
  25. </div>
  26. </template>
  27. <script>
  28. import { shallowRef } from 'vue'
  29. import { EntityCreate } from 'quasar-crud'
  30. import { mixinWidget } from 'src/mixin/Mixins.js'
  31. import { APIGateway } from 'src/api/APIGateway.js'
  32. import BtnControl from 'src/components/Control/btn.vue'
  33. import ContentMedias from 'src/components/FormBuilderCustumComponents/ContentMedias/ContentMedias.vue'
  34. import ContentCategorySelector from 'src/components/FormBuilderCustumComponents/ContentCategorySelector.vue'
  35. const BtnControlComp = shallowRef(BtnControl)
  36. const ContentMediasComp = shallowRef(ContentMedias)
  37. const ContentCategorySelectorComp = shallowRef(ContentCategorySelector)
  38. export default {
  39. name: 'AdminContentCreate',
  40. components: { EntityCreate },
  41. mixins: [mixinWidget],
  42. data: () => {
  43. return {
  44. mounted: false,
  45. entityLoading: false,
  46. api: APIGateway.content.APIAdresses.base,
  47. entityIdKey: 'id',
  48. entityParamKey: 'id',
  49. showRouteName: 'Admin.Content.Show',
  50. inputs: [
  51. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان', placeholder: ' ', col: 'col-md-6 col-12' },
  52. { type: 'file', name: 'thumbnail', responseKey: 'thumbnail', label: 'عکس', placeholder: ' ', col: 'col-md-6 col-12' },
  53. { type: 'checkbox', name: 'is_hidden', responseKey: 'is_hidden', label: 'پنهان باشد؟', placeholder: ' ', value: true, col: 'col-12' },
  54. { type: ContentCategorySelectorComp, name: 'category', responseKey: 'category', sendNull: true, col: 'col-12' },
  55. { type: 'inputEditor', name: 'description', responseKey: 'description', label: 'توضیحات', col: 'col-12' },
  56. { type: ContentMediasComp, name: 'medias', responseKey: 'medias_info', col: 'col-12' },
  57. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'ایجاد محتوا', placeholder: ' ', atClick: () => {}, col: 'col-md-6' }
  58. ]
  59. }
  60. },
  61. mounted() {
  62. this.setActionBtn()
  63. this.mounted = true
  64. },
  65. methods: {
  66. setActionBtn () {
  67. this.inputs.forEach((item, index) => {
  68. if (item.name === 'btn') {
  69. this.inputs[index].atClick = this.onSubmit
  70. }
  71. })
  72. },
  73. onSubmit () {
  74. this.create()
  75. },
  76. create() {
  77. this.entityLoading = true
  78. this.$refs.entityCreate.createEntity()
  79. .then(() => {
  80. this.entityLoading = false
  81. })
  82. .catch(() => {
  83. this.entityLoading = false
  84. })
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped lang="scss">
  90. .AdminContentCreate {
  91. .title {
  92. font-style: normal;
  93. font-weight: 700;
  94. font-size: 24px;
  95. line-height: 140%;
  96. color: #424242;
  97. margin-bottom: 27px;
  98. position: relative;
  99. .back-action {
  100. position: absolute;
  101. right: 0;
  102. top: 0;
  103. }
  104. }
  105. :deep(.form) {
  106. padding: 24px;
  107. }
  108. }
  109. </style>