yangfeng
2023-11-09 d35533b1b42df7e1808a19a8ea72613e605cd6ef
添加、编辑上传图片接口联调及编辑和查看和列表图片回显
4个文件已修改
104 ■■■■ 已修改文件
src/api/common/other.js 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productManage/product/AddProductDialog.vue 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productManage/product/IconCropper.vue 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productManage/product/index.vue 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/common/other.js
@@ -1,5 +1,5 @@
// import request from "@/common/untils/request.js"
import request from "@/common/untils/request";
import request from "@/common/untils/request"
// 查询公司列表
export const getCompanyList = (data) => {
@@ -9,3 +9,12 @@
    params: data
  })
}
// 上传附件
export const uploadFiles = (data) => {
  return request({
    url: "/api-wms/v1/attachment/uploadFiles",
    method: "post",
    data
  })
}
src/views/productManage/product/AddProductDialog.vue
@@ -140,7 +140,7 @@
                      :min="0"
                      :controls="false"
                      size="mini"
                      style="width: 81%"
                      style="width: 85%"
                      :disabled="!showFooter"
                    ></el-input-number>
                  </el-form-item>
@@ -162,7 +162,7 @@
                      :min="0"
                      :controls="false"
                      size="mini"
                      style="width: 81%"
                      style="width: 85%"
                      :disabled="!showFooter"
                    ></el-input-number>
                  </el-form-item>
@@ -473,6 +473,7 @@
import IconCropper from "./IconCropper"
import { getProductCategoryList } from "@/api/product/productCategory"
import { getProductList, addProduct, updateProduct } from "@/api/product/product"
import { uploadFiles } from "@/api/common/other"
export default {
  name: "AddProductDialog",
@@ -550,18 +551,14 @@
      statisticsMap: {
        inLibrary: 0 // 在库
      },
      isView: false
      isView: false,
      fileFormdata: null // 上传图片入参
    }
  },
  created() {
    if (this.editConfig.title === "编辑" && !this.editConfig.autoEdit) {
      this.isView = true
    }
    // if (this.editConfig.title === "新建") {
    //   this.editConfig.infomation.imageSrc = ""
    // } else {
    //   this.editConfig.infomation.imageSrc = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
    // }
    this.getProductCategoryList()
    this.getProductList()
    this.setTableForm()
@@ -654,20 +651,45 @@
      console.log(this.editConfig.infomation)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let requestUrl = this.editConfig.title === "新建" ? addProduct : updateProduct
          this.unsetFieldsToNumber()
          requestUrl({
            ...this.editConfig.infomation
          }).then((res) => {
            console.log(res)
            this.editConfig.visible = false
            if (res.code === 200) {
              this.$message.success("添加成功")
              this.$parent.getData()
          console.log(this.fileFormdata == null)
          let attachmentIDs = []
          if (this.fileFormdata == null) {
            if (this.editConfig.infomation.attachmentList?.length > 0) {
              this.editConfig.infomation.attachmentList.forEach((ele) => {
                attachmentIDs.push(ele.id)
              })
            } else {
              attachmentIDs = []
            }
          }, console.error)
            this.saveEditRequest(attachmentIDs)
          } else {
            uploadFiles(this.fileFormdata).then((res) => {
              if (res.code == 200) {
                res.data.forEach((ele) => {
                  attachmentIDs.push(ele.id)
                })
              }
              this.saveEditRequest(attachmentIDs)
            })
          }
        }
      })
    },
    // 保存/编辑接口请求
    saveEditRequest(attachmentIDs) {
      let requestUrl = this.editConfig.title === "新建" ? addProduct : updateProduct
      this.unsetFieldsToNumber()
      requestUrl({
        ...this.editConfig.infomation,
        attachmentIDs
      }).then((res) => {
        console.log(res)
        this.editConfig.visible = false
        if (res.code === 200) {
          this.$message.success("添加成功")
          this.$parent.getData()
        }
      }, console.error)
    },
    // 删除
    delClick() {},
@@ -728,8 +750,9 @@
      this.tableData.splice(scope.$index, 1)
    },
    // 上传图片
    getImageData(data) {
      console.log(data, "图片数据")
    getImageData(formdata) {
      this.fileFormdata = formdata
      // console.log(formdata, "图片数据")
    },
    // 进出点击
    inOutBoundClick() {
src/views/productManage/product/IconCropper.vue
@@ -2,7 +2,7 @@
  <div class="cropper-wrapper">
    <div v-if="isView">
      <el-image :src="imageUrl" class="view-image">
        <div slot="error" class="image-slot">
        <div slot="error" class="image-slot no-cursor">
          <i class="el-icon-picture-outline"></i>
        </div>
      </el-image>
@@ -123,7 +123,8 @@
        infoTrue: true // true 为展示真实输出图片宽高 false 展示看到的截图框宽高
      },
      // 防止重复提交
      loading: false
      loading: false,
      fileName: ""
    }
  },
  mounted() {
@@ -149,6 +150,7 @@
        return false
      }
      console.log(file, fileList)
      this.fileName = file.name
      // 上传成功后将图片地址赋值给裁剪框显示图片
      this.$nextTick(async () => {
        // base64方式
@@ -205,8 +207,12 @@
        this.dialogVisible = false
        this.previewImg = URL.createObjectURL(blob)
        this.isPreview = true
        console.log(blob)
        this.$emit("getImageData", blob)
        // blob转file
        let file = new File([blob], this.fileName, { type: blob.type })
        // file转formData
        let formData = new FormData()
        formData.append("files", file)
        this.$emit("getImageData", formData)
      })
      // 获取截图的 base64 数据
      // this.$refs.cropper.getCropData(data => {
src/views/productManage/product/index.vue
@@ -33,8 +33,12 @@
      <div v-if="isIconIndex === '1'" class="product-view">
        <div class="product-box" v-for="item in tableList.tableInfomation" :key="item.id" @click="showDetail(item)">
          <div class="left">
            <!-- <el-image style="width: 60px; height: 80px" :src="url"></el-image> -->
            <div class="img-view">
            <el-image
              v-if="item.attachmentList?.length > 0"
              style="width: 60px; height: 80px"
              :src="item.attachmentList[0].FileUrl"
            ></el-image>
            <div v-else class="img-view">
              <i class="el-icon-picture-outline"></i>
            </div>
          </div>
@@ -269,14 +273,16 @@
      console.log(row)
      this.editConfig.autoEdit = false
      this.editConfig.title = "编辑"
      this.editConfig.infomation = { ...row }
      let imageSrc = row.attachmentList?.length > 0 ? row.attachmentList[0].FileUrl : ""
      this.editConfig.infomation = { ...row, imageSrc: imageSrc }
      this.editConfig.visible = true
    },
    // 编辑
    editRow(row) {
      this.editConfig.autoEdit = true
      this.editConfig.title = "编辑"
      this.editConfig.infomation = { ...row }
      let imageSrc = row.attachmentList?.length > 0 ? row.attachmentList[0].FileUrl : ""
      this.editConfig.infomation = { ...row, imageSrc: imageSrc }
      this.editConfig.visible = true
    },
    // 切换列表展现形式