Browse Source

图片裁剪

xiuli.gao 1 year ago
parent
commit
b6657e49d0

+ 10 - 3
project/src/components/assembly/editCon.vue

197
           <el-upload class="avatar-uploader" :action="URL.BASEURL + URL.material_upload" name="material_file"
197
           <el-upload class="avatar-uploader" :action="URL.BASEURL + URL.material_upload" name="material_file"
198
             :show-file-list="false" :data="fileData2" :on-success="uploadSuccess" :on-progress='beforeUploadUpload'
198
             :show-file-list="false" :data="fileData2" :on-success="uploadSuccess" :on-progress='beforeUploadUpload'
199
             :on-error='uploadFail' accept=".jpg,.jpeg,.png">
199
             :on-error='uploadFail' accept=".jpg,.jpeg,.png">
200
-            <img v-if="miniprogram.pic_url" :src="miniprogram.pic_url" class="fm_img">
200
+            <img v-if="miniprogram.pic_url" :src="miniprogram.pic_url" class="fm_img" style="height:80px;">
201
             <i v-else class="el-icon-plus avatar-uploader-icon"></i>
201
             <i v-else class="el-icon-plus avatar-uploader-icon"></i>
202
           </el-upload>
202
           </el-upload>
203
           <div style="margin-left:40px;">
203
           <div style="margin-left:40px;">
282
     />
282
     />
283
     <!-- 图片裁剪弹框 -->
283
     <!-- 图片裁剪弹框 -->
284
     <el-dialog width="840px" title="图片裁剪" :visible.sync="imgCutterVisible" append-to-body>
284
     <el-dialog width="840px" title="图片裁剪" :visible.sync="imgCutterVisible" append-to-body>
285
-      <imgCutter v-if="imgCutterVisible" :target="oss_url"></imgCutter>
285
+      <imgCutter v-if="imgCutterVisible" :target="oss_url" @imgCutterCallback="imgCutterCallback"></imgCutter>
286
     </el-dialog>
286
     </el-dialog>
287
   </div>
287
   </div>
288
 </template>
288
 </template>
394
     }
394
     }
395
   },
395
   },
396
   methods: {
396
   methods: {
397
+    // 图片裁剪回调
398
+    imgCutterCallback(obj){
399
+      this.imgCutterVisible = false;
400
+      if ( obj.flag ){
401
+        this.miniprogram.pic_url = obj.data.url
402
+        this.miniprogram.pic_media_id = obj.data.material_id;
403
+      }
404
+    },
397
     openImgCutter(){ // 打开图片裁剪
405
     openImgCutter(){ // 打开图片裁剪
398
       if ( this.miniprogram.pic_url ) {
406
       if ( this.miniprogram.pic_url ) {
399
         this.$loading(this.$loadingConfig)
407
         this.$loading(this.$loadingConfig)
773
     },
781
     },
774
     // 批量导入链接 - 确定
782
     // 批量导入链接 - 确定
775
     onConfirmMultipleLink(res) {
783
     onConfirmMultipleLink(res) {
776
-      console.log('onConfirmMultipleLink => ', res)
777
       this.multipleLinkVisible = false
784
       this.multipleLinkVisible = false
778
       if (Array.isArray(res) && res.length) {
785
       if (Array.isArray(res) && res.length) {
779
         res.forEach(item => {
786
         res.forEach(item => {

+ 14 - 7
project/src/components/assembly/imgCutter.vue

1
 <template>
1
 <template>
2
 <div>
2
 <div>
3
-  <ImgCutter ref="imgCutterModal" v-loading="loadCut" :isModal="false" :sizeChange="true" :scaleAble="false" :originalGraph="true" rate="65:52" @cutDown="cutDown" @onClearAll="onClearAll">
3
+  <ImgCutter ref="imgCutterModal" v-loading="loadCut" :isModal="false" :sizeChange="true" :scaleAble="false" :originalGraph="true" rate="65:52" @cutDown="cutDown">
4
     <template slot="open"><slot></slot></template>
4
     <template slot="open"><slot></slot></template>
5
+    <template slot="choose">
6
+      <el-button type="primary" plain size="mini">选择图片</el-button>
7
+    </template>
8
+    <template slot="cancel">
9
+      <el-button type="primary" plain size="mini" style="display:none">取消</el-button>
10
+    </template>
11
+    <template slot="confirm">
12
+      <el-button type="primary" size="mini">确定</el-button>
13
+    </template>
5
   </ImgCutter>
14
   </ImgCutter>
6
 </div>
15
 </div>
7
 </template>
16
 </template>
71
       },
80
       },
72
        //通过cutDown事件接收选择的图片信息
81
        //通过cutDown事件接收选择的图片信息
73
        cutDown(event) {
82
        cutDown(event) {
74
-           console.log(event)
75
           if (!event.file) {
83
           if (!event.file) {
84
+            this.$emit('imgCutterCallback',{flag:false})
76
             this.$message({ message: '图片剪裁失败!', type: "error" })
85
             this.$message({ message: '图片剪裁失败!', type: "error" })
77
             return
86
             return
78
           };
87
           };
94
           instance.post(this.URL.BASEURL + this.URL.material_upload,formData).then((res) => {
103
           instance.post(this.URL.BASEURL + this.URL.material_upload,formData).then((res) => {
95
             var res = res.data
104
             var res = res.data
96
             if (res && res.errno == 0) {
105
             if (res && res.errno == 0) {
97
-
106
+              this.$emit('imgCutterCallback',{flag:true,data:res.rst})
98
             } else if (res.errno != 4002) {
107
             } else if (res.errno != 4002) {
108
+              this.$emit('imgCutterCallback',{flag:false})
99
               this.$message({ message: res.err, type: "error" })
109
               this.$message({ message: res.err, type: "error" })
100
             }
110
             }
101
           }).catch((err) => {
111
           }).catch((err) => {
112
+            this.$emit('imgCutterCallback',{flag:false})
102
             this.$message({ message: '服务器错误,获取裁剪图片失败', type: "error" })
113
             this.$message({ message: '服务器错误,获取裁剪图片失败', type: "error" })
103
           });
114
           });
104
 
115
 
105
        },
116
        },
106
-      // 清空画布
107
-      onClearAll(){
108
-        console.log('点击了取消')
109
-      },
110
     }
117
     }
111
 
118
 
112
 }
119
 }