Selaa lähdekoodia

售后登记增加图片粘贴上传功能

fangq 2 vuotta sitten
vanhempi
commit
1c96aa2c55
1 muutettua tiedostoa jossa 30 lisäystä ja 0 poistoa
  1. 30 0
      src/views/modules/afterSales/thirdAfterSales-add-or-update.vue

+ 30 - 0
src/views/modules/afterSales/thirdAfterSales-add-or-update.vue

@@ -148,6 +148,7 @@
         <el-upload
           :disabled="isView"
           ref="upload"
+          :multiple="true"
           :action="$http.adornUrl('/admin/file/simpleUpload')"
           list-type="picture-card"
           accept="image/*"
@@ -158,6 +159,9 @@
           :on-preview="handlePicPreview">
           <i class="el-icon-plus"></i>
         </el-upload>
+        <div  @paste="pasteImg($event)">
+          <textarea placeholder="点击这里,然后把图片粘贴" style="width: 100%;height: 100px;border: 1px solid #c9c9c9;border-radius: 5px;"></textarea>
+        </div>
       </el-form-item>
     </el-form>
     <span slot="footer" class="dialog-footer">
@@ -174,6 +178,7 @@
 <script>
   import ImgUpload from '@/components/img-upload';
   import OrderInfo from "../order/orderInfo";
+  import { uploadFile } from '@/utils/httpRequest.js'
 export default {
   components: {
     ImgUpload,OrderInfo
@@ -305,6 +310,31 @@ export default {
     handlePicRemove(file, fileList){
       this.fileList = fileList;
     },
+    /**
+     * textarea图片粘贴事件
+     */
+    pasteImg(e) {
+      console.log(e)
+      const { items } = e.clipboardData; // 获取粘贴板文件对象
+      if (items.length) {
+        for (const item of items) {
+          if (item.type.indexOf('image') !== -1) {
+            const file = item.getAsFile(); // 获取图片文件
+            if (file) {
+              uploadFile(
+                this.$http.adornUrl('/admin/file/simpleUpload'),
+                file
+              ).then(({ data }) => {
+                // this.$refs['file'].value = null // 解决上传同一图片不显示bug
+                // { url: this.resourcesUrl + picArray[i], response: {filePath: picArray[i] }
+                let obj = {url: data.resourcesUrl + data.filePath, response: {filePath: data.filePath }}
+                this.fileList.push(obj)
+              })
+            }
+          }
+        }
+      }
+    },
     dialogClose(){
       this.fileList = [];
       this.dataForm = {};