zhanghua
2025-07-16 7c20fd15b7fbc2bd5756b39d5ab655cc849ffcc3
src/components/Upload/index.vue
@@ -1,5 +1,5 @@
<template>
    <el-upload :file-list="fileList" class="upload-demo" action="http://42.193.1.25:8082/sccg/file/medias" multiple
    <el-upload :file-list="fileList" class="upload-demo" action="/sccg/file/medias" multiple
        :show-file-list="flag" :before-upload="beforeUpload" :limit="50" :on-success="handleSuccess"
        :headers="getToken()">
        <div class="uploadBtn" v-if="picUrl===''">
@@ -23,23 +23,21 @@
    },
    methods: {
        beforeUpload(rawFile) {
            console.log(rawFile);
            if (rawFile.type !== 'image/png' && rawFile.type !== 'image/svg+xml' && rawFile.type !== 'image/jpg' && rawFile.type !== 'image/jpeg') {
                this.$message.error('Avatar picture must be jpg/svg/jpeg/png format!')
                this.$message.error('图片必须是 jpg/svg/jpeg/png 格式!')
                return false
            } else if (rawFile.size / 105 / 105 > 2) {
                this.$message.error('Avatar picture size can not exceed 2MB!')
            } else if (rawFile.size / 1024  / 1024  > 5) {
                this.$message.error('上传图片不能超过 5MB!')
                return false
            }
            return true
        },
        handleSuccess(res, file, filelist) {
            console.log(res);
            this.$emit('getPicUrl', { obj: res.data, value: this.mykey });
        },
        getToken() {
            const token = localStorage.getItem('token');
            const tokenHead = localStorage.getItem('tokenHead');
            const token = sessionStorage.getItem('token');
            const tokenHead = sessionStorage.getItem('tokenHead');
            if (token && tokenHead) {
                return { Authorization: tokenHead + token }
            }