crop.vue 2.33 KB
<template>
    <el-dialog
      title="证件照编辑"
      :visible.sync="isShow"
      :close-on-click-modal="false"
      class="manage-dialog crop-dialog"
      @close="closeDialog">
        <profile-component field="file" :profiles="profiles" @cropedImg="getCropedPic"></profile-component>
        <div slot="footer" class="dialog-footer">
            <el-button @click="isShow = false" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
            <el-button type="primary" @click="cropSubmit" class="dialog-btn dialog-confirm-btn">{{$t('dialog.confirm')}}</el-button>
        </div>
    </el-dialog>
</template>

<script>
// import profileUpload from 'vue-image-crop-upload'
import localProfile from './cropimg'
export default {
    components: {
        // 'profile-upload': profileUpload,
        'profile-component': localProfile
    },
    props: {
    },
    data() {
        return {
            isShow: false,
            profiles: {},
            employeeId: null,
            profileFormData: null,
            blobProfile: ''
        }
    },
    computed: {
    },
    created() {
    },
    mounted() {
        //
    },
    methods: {
        cropDialogInit(file, employeeId) {
            // console.log('cropDialogInit', file);
            this.profiles = file;
            this.employeeId = employeeId || null;
            this.isShow = true;
        },
        getCropedPic(isSupport, cropedPath, cropedBlobUrl) {
            // console.log('cropedImg', cropedPath, cropedBlobUrl)
            if(!isSupport) {
                this.$alert('浏览器不支持裁剪功能,请使用IE10以上或其他主流浏览器', '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        console.log(`action: ${action}`)
                        this.isShow = false;
                    }
                });
                return
            }
            this.profileFormData = cropedPath;
            this.blobProfile = cropedBlobUrl;
        },
        cropSubmit() {
            this.$emit('profilePath', this.profileFormData, this.blobProfile);
            this.isShow = false;
        },
        closeDialog() {
            this.blobProfile = '';
            this.profileFormData = this.employeeId = null;
            this.profiles = null;
        },
    }
}
</script>

<style scoped>
</style>