AdminEventCreate.vue 5.3 KB

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