ImageUploader.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <q-card class="ImageUploader">
  3. <q-card-section>
  4. <div class="address">
  5. <q-input v-model="displayAddress"
  6. readonly />
  7. </div>
  8. <entity-create ref="entityCreate"
  9. v-model:value="inputs"
  10. title="آپلود تصویر"
  11. :api="api"
  12. :default-layout="false"
  13. :entity-id-key-in-response="entityIdKeyInResponse"
  14. :show-route-param-key="showRouteParamKey"
  15. :index-route-name="indexRouteName"
  16. :show-route-name="showRouteName"
  17. :after-send-data="afterSendData" />
  18. <div class="action">
  19. <div class="row q-mt-lg justify-end">
  20. <div class="col-md-4 col-12">
  21. <q-btn color="primary"
  22. class="full-width"
  23. :loading="entityLoading"
  24. @click="create">
  25. آپلود
  26. </q-btn>
  27. </div>
  28. </div>
  29. </div>
  30. <q-separator class="q-my-md" />
  31. <div>
  32. <div>
  33. آدرس عکس دلخواه
  34. <br>
  35. (در صورتی که قبلا عکس را آپلود کرده اید می توانید به جای آپلود مجدد، آدرس عکس را در این قسمت قرار دهید)
  36. </div>
  37. <q-input v-model="customUrl" />
  38. </div>
  39. </q-card-section>
  40. </q-card>
  41. </template>
  42. <script>
  43. import { EntityCreate } from 'quasar-crud'
  44. import { APIGateway } from 'src/api/APIGateway.js'
  45. export default {
  46. name: 'ImageUploader',
  47. components: { EntityCreate },
  48. props: {
  49. value: {
  50. type: String,
  51. default: null
  52. },
  53. file: {
  54. type: String,
  55. default: null
  56. }
  57. },
  58. data: () => {
  59. return {
  60. customUrl: null,
  61. entityLoading: false,
  62. api: APIGateway.media.APIAdresses.base,
  63. entityIdKeyInResponse: 'id',
  64. showRouteParamKey: 'id',
  65. showRouteName: 'AdminPanel.Service.Show',
  66. indexRouteName: 'AdminPanel.Service.List',
  67. inputs: [
  68. { type: 'file', name: 'file', responseKey: 'file', label: 'فایل تصویر', col: 'col-12' },
  69. { type: 'hidden', name: 'source_type', value: 'SETTING' },
  70. { type: 'hidden', name: 'type', value: 'VIDEO' }
  71. ]
  72. }
  73. },
  74. computed: {
  75. displayAddress: {
  76. get () {
  77. return this.value || this.file
  78. }
  79. }
  80. },
  81. watch: {
  82. customUrl (newValue) {
  83. if (!newValue) {
  84. return
  85. }
  86. this.$emit('update:file', newValue)
  87. this.$emit('update:value', "url('" + newValue + "')")
  88. }
  89. },
  90. methods: {
  91. create() {
  92. this.entityLoading = true
  93. this.$refs.entityCreate.createEntity(false)
  94. .then(() => {
  95. this.entityLoading = false
  96. })
  97. .catch(() => {
  98. this.entityLoading = false
  99. })
  100. },
  101. afterSendData (response) {
  102. this.$emit('update:file', response.data.file)
  103. this.$emit('update:value', "url('" + response.data.file + "')")
  104. }
  105. }
  106. }
  107. </script>
  108. <style scoped lang="scss">
  109. .ImageUploader {
  110. .address {
  111. max-width: 100%;
  112. }
  113. }
  114. </style>