'use strict'; const { Controller } = require('ee-core'); const Log = require('ee-core/log'); const { dialog } = require('electron'); const { checkSelectImages,segmentImages } = require('../api/imageMatting') /** * example * @class */ class ImageMattingController extends Controller { constructor(ctx) { super(ctx); } /** * 所有方法接收两个参数 * @param args 前端传的参数 * @param event - ipc通信时才有值。详情见:控制器文档 */ /** * upload */ async upload (params) { // const result = await Services.get('example').test('electron'); let dialogParams = {} if(params.path_type === 0){ dialogParams = { title:"选择图片", properties: ['openFile'], filters: [ { name: '支持JPG', extensions: ['jpg'] }, ] } }else{ dialogParams = { title:"选择文件夹", properties: ['openDirectory'] } } const filePaths = dialog.showOpenDialogSync(dialogParams) Log.info('filePaths:::::::::'+filePaths); if(!filePaths || !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(selectParams) 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 false; } return res.data } return false; } } ImageMattingController.toString = () => '[class ExampleController]'; module.exports = ImageMattingController;