Browse Source

mod:选择文件和文件夹

panqiuyao 11 tháng trước cách đây
mục cha
commit
a33fb0b287
4 tập tin đã thay đổi với 138 bổ sung1 xóa
  1. 10 0
      electron/api/imageMatting.js
  2. 65 0
      electron/api/request.js
  3. 61 0
      electron/controller/imageMatting.js
  4. 2 1
      package.json

+ 10 - 0
electron/api/imageMatting.js

@@ -0,0 +1,10 @@
+const { post } = require('./request')
+
+module.exports = {
+  checkSelectImages(data){
+    return post({
+      url: '/check_select_images',
+      data: data
+    })
+  }
+}

+ 65 - 0
electron/api/request.js

@@ -0,0 +1,65 @@
+const axios = require('axios')
+
+
+/* axios.defaults.withCredentials = true*/
+
+// create an axios instance
+const service = axios.create()
+const baseUrl = 'http://127.0.0.1:7074/'
+const basePrefixUrl = 'api'
+const timeout = 600000
+const uploadTimeout = 600000
+
+ function request(config) {
+  return service(config)
+}
+
+/* get 默认取数据 */
+ function get(config) {
+  return _get({ ...config, baseUrl })
+}
+ function getPay(config) {
+  return _get({ ...config, basePayUrl })
+}
+function _get(config = {
+  baseUrl,
+  url: '',
+  data: {}
+}) {
+
+  const thisBasePrefixUrl = config.basePrefixUrl !== undefined ? config.basePrefixUrl : basePrefixUrl
+  return service.get(config.baseUrl + thisBasePrefixUrl + config.url, {
+    params: {
+      ...config.data
+    },
+    headers: config.headers || {},
+    timeout: config.timeout ||  timeout
+  })
+}
+ function post(config) {
+  return _post({ ...config, baseUrl })
+}
+ function postPay(config) {
+  return _post({ ...config, baseUrl: basePayUrl })
+}
+/* post 默认提交数据 */
+function _post(config = {
+  baseUrl,
+  url: '',
+  data: {}
+}) {
+  const thisBasePrefixUrl = config.basePrefixUrl !== undefined ? config.basePrefixUrl : basePrefixUrl
+  return service.post(config.baseUrl + thisBasePrefixUrl + config.url, {
+    ...config.data
+  }, {
+    headers: config.headers || {},
+    timeout: config.timeout ||  timeout,
+    roles:config.roles,
+  })
+}
+
+
+module.exports = {
+  get,
+  post
+}

+ 61 - 0
electron/controller/imageMatting.js

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

+ 2 - 1
package.json

@@ -57,9 +57,10 @@
     "nodemon": "^2.0.16"
   },
   "dependencies": {
+    "axios": "^1.7.9",
     "dayjs": "^1.10.7",
     "ee-core": "2.12.0",
     "electron-updater": "^5.3.0",
     "lodash": "^4.17.21"
   }
-}
+}