AdminPostCreate.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="AdminPostCreate"
  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 PostCategorySelector from 'src/components/FormBuilderCustumComponents/PostCategorySelector.vue'
  34. import FormBuilderTiptapEditor from 'src/components/FormBuilderCustumComponents/FormBuilderTiptapEditor.vue'
  35. const BtnControlComp = shallowRef(BtnControl)
  36. const PostCategorySelectorComp = shallowRef(PostCategorySelector)
  37. const FormBuilderTiptapEditorComp = shallowRef(FormBuilderTiptapEditor)
  38. export default {
  39. name: 'AdminPostCreate',
  40. components: { EntityCreate },
  41. mixins: [mixinWidget],
  42. data () {
  43. const authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
  44. return {
  45. mounted: false,
  46. entityLoading: false,
  47. api: APIGateway.post.APIAdresses.base,
  48. entityIdKey: 'id',
  49. entityParamKey: 'id',
  50. showRouteName: 'Admin.Post.Show',
  51. inputs: [
  52. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان', placeholder: ' ', col: 'col-12' },
  53. { type: 'input', name: 'order', responseKey: 'order', label: 'ترتیب', placeholder: ' ', col: 'col-md-6 col-12' },
  54. { type: 'file', name: 'thumbnail', responseKey: 'thumbnail', label: 'عکس', placeholder: ' ', col: 'col-md-6 col-12' },
  55. { type: PostCategorySelectorComp, name: 'category', responseKey: 'category', col: 'col-12' },
  56. {
  57. // type: 'tiptap-editor',
  58. type: FormBuilderTiptapEditorComp,
  59. name: 'summary',
  60. responseKey: 'summary',
  61. label: 'خلاصه',
  62. options: {
  63. bubbleMenu: false,
  64. floatingMenu: false,
  65. poem: false,
  66. reading: false,
  67. persianKeyboard: true,
  68. mathliveOptions: { smartFence: false },
  69. uploadServer: {
  70. url: '/api' + APIGateway.media.APIAdresses.base,
  71. instantUpload: true,
  72. responseKey: 'file',
  73. headers: { Authorization: authorization }
  74. }
  75. },
  76. col: 'col-md-12 col-12'
  77. },
  78. {
  79. // type: 'tiptap-editor',
  80. type: FormBuilderTiptapEditorComp,
  81. name: 'text',
  82. responseKey: 'text',
  83. label: 'متن',
  84. options: {
  85. bubbleMenu: false,
  86. floatingMenu: false,
  87. poem: false,
  88. reading: false,
  89. persianKeyboard: true,
  90. mathliveOptions: { smartFence: false },
  91. uploadServer: {
  92. url: '/api' + APIGateway.media.APIAdresses.base,
  93. instantUpload: true,
  94. responseKey: 'file',
  95. headers: { Authorization: authorization }
  96. }
  97. },
  98. col: 'col-md-12 col-12'
  99. },
  100. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'ایجاد محتوا', placeholder: ' ', atClick: () => {}, col: 'col-md-6' }
  101. ]
  102. }
  103. },
  104. mounted() {
  105. this.setActionBtn()
  106. this.mounted = true
  107. },
  108. methods: {
  109. setActionBtn () {
  110. this.inputs.forEach((item, index) => {
  111. if (item.name === 'btn') {
  112. this.inputs[index].atClick = this.onSubmit
  113. }
  114. })
  115. },
  116. onSubmit () {
  117. this.create()
  118. },
  119. create() {
  120. this.entityLoading = true
  121. this.$refs.entityCreate.createEntity()
  122. .then(() => {
  123. this.entityLoading = false
  124. })
  125. .catch(() => {
  126. this.entityLoading = false
  127. })
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped lang="scss">
  133. .AdminPostCreate {
  134. .title {
  135. font-style: normal;
  136. font-weight: 700;
  137. font-size: 24px;
  138. line-height: 140%;
  139. color: #424242;
  140. margin-bottom: 27px;
  141. position: relative;
  142. .back-action {
  143. position: absolute;
  144. right: 0;
  145. top: 0;
  146. }
  147. }
  148. :deep(.form) {
  149. padding: 24px;
  150. }
  151. }
  152. </style>