<template>
    <div>
        <photo :photographUrl="photographUrl" @photograph="takePhoto"></photo>
        <p-button type="primary" @click="uploadFile" style="margin-top:10px;">上传</p-button>
    </div>
</template>
<script>
import photo from '@/components/photograph/index'
import request  from '@/utils/request'

export default {
    components:{photo},
    data(){
        return {
           photographUrl:"http://127.0.0.1:6060/camera",
           file:null
        }
    },
    methods:{
        takePhoto(file){
           this.file = file;
        },
        uploadFile(){
            if(!this.file){
                this.$message.error("图片文件为空")
                return;
            }
            var data = new FormData();
            data.append("file",this.file)
            data.append("storageType",0)
            data.append("isFileName",1)
            data.append("directory","/昆中药/测试")
            request.post(
				"/api/service-filemanagement/file/upload-file",
				data,
				{onUploadProgress:e=>{
					//that.pre =Math.floor(e.loaded/e.total*100);
					// e.loaded 已经上传的字节数据，e.total 字节数据  转换为1-100的比例值 赋值个pre	 
				}}
				)
            .then((d)=>{
                console.log(d);
            })
        }
    }
    
}
</script>