panqiuyao 11 hónapja
szülő
commit
872b49d19d

+ 10 - 0
electron/api/imageMatting.js

@@ -6,5 +6,15 @@ module.exports = {
       url: '/check_select_images',
       data: data
     })
+  },
+
+  segmentImages(data){
+    return post({
+      url: '/segment_images',
+      data: data,
+      headers:{
+        'Content-Type':"application/json",
+      }
+    })
   }
 }

+ 48 - 13
electron/controller/imageMatting.js

@@ -3,13 +3,13 @@
 const { Controller } = require('ee-core');
 const Log = require('ee-core/log');
 const { dialog } = require('electron');
-const { checkSelectImages }  = require('../api/imageMatting')
+const { checkSelectImages,segmentImages }  = require('../api/imageMatting')
 
 /**
  * example
  * @class
  */
-class ExampleController extends Controller {
+class ImageMattingController extends Controller {
 
   constructor(ctx) {
     super(ctx);
@@ -25,11 +25,11 @@ class ExampleController extends Controller {
   /**
    * upload
    */
-  async upload (param) {
+  async upload (params) {
    // const result = await Services.get('example').test('electron');
 
     let dialogParams = {}
-    if(param === 'file'){
+    if(params.path_type === 0){
       dialogParams = {
         title:"选择图片",
         properties: ['openFile'], filters: [
@@ -43,19 +43,54 @@ class ExampleController extends Controller {
       }
 
     }
-    const filePaths = dialog.showOpenDialogSync(dialogParams);
+    const filePaths = dialog.showOpenDialogSync(dialogParams)
+    if(!filePaths[0]){
+      return  false;
+    }
     Log.info(filePaths);
+    Log.info({
+          path_type: params.path_type,  //  path_type    地址类型;0图像;1目录
+          path: filePaths[0]
+        }
+    );
+
+    let selectParams = {
+      path_type:params.path_type ,  //  path_type    地址类型;0图像;1目录
+      path:filePaths[0]
+    }
+
+    if(params.path_type === 0){
+      selectParams = {
+        path_type:params.path_type ,  //  path_type    地址类型;0图像;1目录
+        image_list:filePaths
+      }
+    }
 
-    const res = await checkSelectImages({
-      path_type:1,
-      path:filePaths[0],
-    })
+    const res = await checkSelectImages(selectParams)
 
-    Log.info(res);
-    return 'hello upload';
+
+    Log.info(res.data);
+    if( res.data){
+      if( res.data.code === 0 && res.data.data){
+        const img  = await  segmentImages({
+          "token": params.token,
+          "image_type":  params.image_type,  //图像类型;0非服装;1服装
+          "segment_type":  params.segment_type,  //抠图精细度;0普通;1精细
+          "output_type":  params.output_type,  //出图模式 ;0透明;1白底
+          "need_cutout_images":  res.data.data
+        })
+        if(img.data){
+          return   img.data
+        }
+
+      }
+      return   res.data
+
+    }
+    return false;
 
   }
 }
 
-ExampleController.toString = () => '[class ExampleController]';
-module.exports = ExampleController;
+ImageMattingController.toString = () => '[class ExampleController]';
+module.exports = ImageMattingController;

+ 36 - 0
electron/controller/utils.js

@@ -0,0 +1,36 @@
+'use strict';
+
+const { Controller } = require('ee-core');
+const { shell  } = require('electron');
+const Log = require('ee-core/log');
+
+/**
+ * example
+ * @class
+ */
+class UtilsController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+  }
+
+
+  /**
+   * 所有方法接收两个参数
+   * @param args 前端传的参数
+   * @param event - ipc通信时才有值。详情见:控制器文档
+   */
+
+  /**
+   * upload
+   */
+  async openFileFolder (params) {
+   // const result = await Services.get('example').test('electron');
+    Log.info(params)
+    Log.info(decodeURIComponent(params))
+    shell.openPath(params);
+  }
+}
+
+UtilsController.toString = () => '[class ExampleController]';
+module.exports = UtilsController;