uploadFile.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <ion-item v-if="!readonly">
  3. <ion-thumbnail slot="start">
  4. <img :src="takenImageUrl" />
  5. </ion-thumbnail>
  6. <ion-button type="button" fill="clear" @click="takePicture">
  7. <ion-icon slot="end" :icon="camera"></ion-icon>
  8. Take Photo
  9. </ion-button>
  10. </ion-item>
  11. </template>
  12. <script lang="ts">
  13. import {defineComponent, ref} from "vue";
  14. import {camera,cameraOutline} from "ionicons/icons";
  15. import {alertController, IonIcon, IonThumbnail} from '@ionic/vue';
  16. import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
  17. import {uploadBase64} from '@/api/system/file';
  18. import {presentAlert} from "@/api/common";
  19. export default defineComponent({
  20. name: 'b-upload-file',
  21. components: {IonIcon},
  22. props: {
  23. fileRefId: {type: String, default: ''},
  24. readonly: {type: Boolean, default: true},
  25. accept: {
  26. type: String,
  27. default: 'image/png, image/jpeg,image/jpg,image/gif,doc,docx,xls,xlsx,ppt,pptx,pdf,zip,txt',
  28. },
  29. },
  30. setup(props) {
  31. const takenImageUrl = ref();
  32. const takePicture = async () => {
  33. const image = await Camera.getPhoto({
  34. quality: 90,
  35. allowEditing: true,
  36. source: CameraSource.Camera,
  37. // resultType: CameraResultType.DataUrl,
  38. resultType: CameraResultType.Uri,
  39. });
  40. const imageUrl = image.webPath;
  41. takenImageUrl.value = imageUrl;
  42. console.log(image)
  43. //
  44. // if (!props.accept?.split(',').includes(image.format)){
  45. // presentAlert("只能上传格式为:"+props.accept+"的文件");
  46. // return null;
  47. // }
  48. //
  49. // const formData = new FormData();
  50. // formData.append('base64Str', image.dataUrl as any);
  51. // formData.append("fileRefId", props.fileRefId);
  52. // formData.append("fileType", "0");
  53. // console.log(formData);
  54. // uploadBase64(formData).then((result)=>{
  55. // if (result) {
  56. // presentAlert("上传成功");
  57. // }
  58. // })
  59. };
  60. return {
  61. camera,
  62. IonThumbnail,
  63. takenImageUrl,
  64. takePicture
  65. }
  66. }
  67. }
  68. );
  69. </script>