<template>
  <view>
    <button @click="selectFile">选择文件</button>
    <input type="file" ref="fileInput" @change="handleUpload" style="display:none">
    <image v-if="imageUrl" :src="imageUrl" mode="aspectFit"></image>
  </view>
</template>

<script>
// import ossUpload from '@/utils/ossUpload';

export default {
  data() {
    return {
      imageUrl: ''
    };
  },
  methods: {
    selectFile() {
      this.$refs.fileInput.click();
    },
    
    async handleUpload(e) {
      const file = e.target.files[0];
      
      const result = await ossUpload.upload(file);
      
      if (result.status === 200) {
        this.imageUrl = result.url;
        uni.showToast({ title: '上传成功' });
      } else {
        uni.showToast({ title: '上传失败', icon: 'none' });
      }
    }
  }
};
</script>