ali 2 tahun lalu
induk
melakukan
d0c80a8513

+ 23 - 0
src/components/Widgets/Test/TestParticipation/components/AllQuestions.vue

@@ -73,7 +73,30 @@ export default {
       FormBuilderAssist.setAttributeByName(this.inputs, 'answer_text', 'value', this.answerBook.overall_answer_text)
       FormBuilderAssist.setAttributeByName(this.inputs, 'answer_attachment', 'value', this.answerBook.overall_answer_attachment)
     },
+    isFileSizeGtThan (targetSize) {
+      const file = FormBuilderAssist.getInputsByName(this.inputs, 'answer_attachment').value
+      const fileSizeinMb = file.size ? file.size / 1000000 : 0
+      return fileSizeinMb > targetSize
+    },
+    isPdfFile () {
+      const file = FormBuilderAssist.getInputsByName(this.inputs, 'answer_attachment').value
+      return file.type ? file.type === 'application/pdf' : true
+    },
     sendAnswers () {
+      if (this.isFileSizeGtThan(10)) {
+        this.$q.notify({
+          type: 'negative',
+          message: 'حجم فایل نباید بیشتر از 10 مگابایت باشد.'
+        })
+        return
+      }
+      if (!this.isPdfFile()) {
+        this.$q.notify({
+          type: 'negative',
+          message: 'تنها امکان ارسال فایل pdf وجود دارد.'
+        })
+        return
+      }
       // const answerText = FormBuilderAssist.getInputsByName(this.inputs, 'answer_text').value
       // if (!answerText) {
       //   this.$q.notify({

+ 24 - 0
src/components/Widgets/Test/TestParticipation/components/SingleQuestion.vue

@@ -133,7 +133,31 @@ export default {
     goToPrevQuestion () {
       this.goToQuestion(this.questionNumber - 1)
     },
+    isFileSizeGtThan (targetSize) {
+      const file = FormBuilderAssist.getInputsByName(this.inputs, 'answer_attachment').value
+      const fileSizeinMb = file.size ? file.size / 1000000 : 0
+      return fileSizeinMb > targetSize
+    },
+    isImageFile () {
+      const file = FormBuilderAssist.getInputsByName(this.inputs, 'answer_attachment').value
+      const fileType = file.type ? file.type : 'image/'
+      return fileType.startsWith('image/')
+    },
     sendAnswer () {
+      if (this.isFileSizeGtThan(3)) {
+        this.$q.notify({
+          type: 'negative',
+          message: 'حجم فایل نباید بیشتر از 10 مگابایت باشد.'
+        })
+        return
+      }
+      if (!this.isImageFile()) {
+        this.$q.notify({
+          type: 'negative',
+          message: 'تنها امکان ارسال فایل تصویری وجود دارد.'
+        })
+        return
+      }
       this.$emit('sending')
       this.$refs.entityCreate.createEntity(false)
         .then((response) => {