CameraUpload.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <Popup ref="popRef" mode="center" isClose>
  3. <template #content>
  4. <view class="content">
  5. <view class="modal-header" v-if="isCamera">
  6. <view class="title">
  7. <trans _t="相机权限说明" />
  8. </view>
  9. <view class="tip">
  10. <trans _t="用于上传用户头像、或依据图片信息搜索内容" />
  11. </view>
  12. </view>
  13. <view class="modal-header">
  14. <view class="title">
  15. <trans _t="存储权限说明" />
  16. </view>
  17. <view class="tip">
  18. <trans _t="用于选择照片" />
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <template #footer>
  24. <slot name="footer">
  25. <view class="footer">
  26. <view class="submit_btn" @click="select('camera')" v-if="isCamera">
  27. <trans _t="拍照" />
  28. </view>
  29. <view class="submit_btn" @click="select('album')">
  30. <trans _t="相册" />
  31. </view>
  32. </view>
  33. </slot>
  34. </template>
  35. </Popup>
  36. </template>
  37. <script setup>
  38. import { ref, nextTick } from "vue";
  39. import Popup from "./popup.vue";
  40. import { uploadChooseImage, $upload, Toast } from "@/utils";
  41. const popRef = ref(null);
  42. const emit = defineEmits(["confirm", "close", "open"]);
  43. const props = defineProps({
  44. isCamera: {
  45. type: Boolean,
  46. default: true,
  47. },
  48. });
  49. const open = () => {
  50. popRef.value && popRef.value.open();
  51. emit("open");
  52. };
  53. const close = () => {
  54. emit("close");
  55. popRef.value && popRef.value.close();
  56. };
  57. const select = async (type) => {
  58. try {
  59. let file = await uploadChooseImage(type);
  60. if (file.errMsg == "chooseImage:ok") {
  61. const res = await $upload(file.tempFilePath);
  62. nextTick(() => {
  63. emit("confirm", res.data.url);
  64. });
  65. }
  66. } catch (error) {}
  67. close();
  68. };
  69. defineExpose({ open, close });
  70. </script>
  71. <style lang="less" scoped>
  72. @import url("@/style.less");
  73. :deep(.conts) {
  74. max-width: 75vw;
  75. }
  76. .content {
  77. .modal-header {
  78. margin-bottom: 20rpx;
  79. .title {
  80. font-size: 32rpx;
  81. font-weight: bold;
  82. }
  83. .tip {
  84. font-size: 24rpx;
  85. }
  86. }
  87. }
  88. .footer {
  89. .hor(space-between);
  90. column-gap: 20rpx;
  91. .submit_btn {
  92. height: 76rpx;
  93. padding: 16rpx 60rpx;
  94. background-color: var(--black);
  95. color: var(--light);
  96. .flex_center();
  97. border-radius: 16rpx;
  98. .size(24rpx);
  99. &.submit_shop {
  100. background-color: var(--bg);
  101. border: 1rpx solid var(--black);
  102. color: var(--black);
  103. }
  104. }
  105. }
  106. </style>