luobisheng
2022-11-28 bb66fcc56438b9f123ee4029f807f672b8baede5
src/views/operate/images/updateUser/index.vue
@@ -24,16 +24,7 @@
            <el-input v-model="imagedata.id"></el-input>
          </el-form-item>
          <el-form-item prop="url" label="图片:" min-width="8">
            <el-upload
                class="avatar-uploader"
                action=""
                ref="image"
                :show-file-list="false"
                :auto-upload="true"
                :http-request="imageUpload">
              <img v-if="imagedata.url" :src="imagedata.url" class="avatar" width="100px" height="100px">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <my-upload :picture-list="imageList" :is-show-upload="dialogType !== 'view'" @setPictureUrl="setPictureUrl" @delPictureUrl="delPictureUrl"></my-upload>
          </el-form-item>
          <div v-if="!isDisabled" class="optionBtn">
            <el-button type="primary" class="btn submit" @click.native.prevent="onSubmit">提交</el-button>
@@ -47,8 +38,10 @@
import { deepClone, RESOURCE_TYPE } from "@/utils/helper";
import imageManagement from "@/api/operate/imageManagement";
import { FILE_ORIGINAL_URL } from "@/utils";
import MyUpload from "@/components/myUpload";
export default {
  components: { MyUpload },
  data() {
    const validateImageUrl = (rule, value, callback) => {
      if (this.imagedata.url) {
@@ -76,14 +69,15 @@
        url: [{ required: true, validator: validateImageUrl }],
        type: [{ required: true, trigger: ['blur', 'change'], message: '请选择类型' }]
      },
      isDisabled: false
      isDisabled: false,
      imageList: []
    }
  },
  created() {
    this.imagedata = deepClone(this.originalData);
    if (this.dialogType !== 'create') {
      this.imagedata.url = this.imagedata.url.split(',')[0];
      this.imageList = this.imagedata.url.split(',');
    }
    this.isDisabled = this.dialogType === 'view';
  },
@@ -117,19 +111,13 @@
        }
      })
    },
    imageUpload(file) {
      const formData = new FormData();
      formData.append('file', file.file);
      imageManagement.importImage(formData)
          .then(res => {
            this.$refs.image.clearFiles();
            this.$set(this.imagedata, 'url', FILE_ORIGINAL_URL + res.url1);
            this.$message.success('上传成功');
          })
          .catch(err => {
            this.$message.error(`${err}`);
            this.$refs.image.clearFiles();
          })
    setPictureUrl({ url }) {
      this.imageList.push(`${FILE_ORIGINAL_URL}${url}`);
      this.imagedata.url = this.imageList.join(',');
    },
    delPictureUrl({ url }) {
      this.imageList = this.imageList.filter(item => item !== url);
      this.imagedata.url = this.imageList.join(',');
    },
    getResourceType(value) {
      return value ? RESOURCE_TYPE.find(item => item.value === value) : RESOURCE_TYPE;