Explorar o código

mod:测试跑通主线流程和socket流程

panqiuyao hai 9 meses
pai
achega
fc43ecad19

+ 58 - 0
electron/api/camera.js

@@ -0,0 +1,58 @@
+const axios = require('axios')
+
+const service = axios.create()
+const baseUrl = 'http://localhost:5513/'
+const timeout = 60000
+
+
+
+function get(config = {
+  url: '',
+}) {
+  return service.get(baseUrl  + config.url, {
+    headers: config.headers || {},
+    timeout: config.timeout ||  timeout
+  })
+}
+
+
+
+module.exports = {
+  liveShow(){
+    return get({
+      url: '?CMD=LiveViewWnd_Show'
+    })
+  },
+  liveHide(){
+    return get({
+      url: '?CMD=LiveViewWnd_Hide'
+    })
+  },
+  capture(){
+    return get({
+      url: '?CMD=LiveView_Capture'
+    })
+  },
+  setParams(params){
+    return get({
+      url: `?slc=set&param1=${params.key}&param2=${params.value}`
+    })
+  },
+}
+
+
+/*
+*
+* 设置   iso
+* 光圈  aperture
+* 拍摄模式  mode
+* 快门速度  shutterSpeed
+* 白平衡    whitebalance
+* 曝光补偿  ExposureCompensation
+* 对焦模式 focusmode
+*
+*
+曝光度:exposure
+压缩:compression
+测光点:metering
+* */

+ 47 - 0
electron/api/imageMatting.js

@@ -0,0 +1,47 @@
+const { post } = require('./request')
+
+module.exports = {
+  checkSelectImages(data){
+    return post({
+      url: '/check_select_images',
+      data: data
+    })
+  },
+
+  segmentImages(data){
+    return post({
+      url: '/segment_images',
+      data: data,
+      headers:{
+        'Content-Type':"application/json",
+      }
+    })
+  },
+
+
+  //ÈĘ̈ͼ
+  modelFormSegment(data){
+    return post({
+      url: '/model_form_segment',
+      data: data,
+      headers:{
+        'Content-Type':"application/json",
+      }
+    })
+  },
+
+ // ²é½ø¶È
+  searchBacthProgress(data){
+    return post({
+      url: '/search_bacth_progress',
+      data: data,
+      headers:{
+        'Content-Type':"application/json",
+      }
+    })
+  },
+
+
+
+
+}

+ 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
+}

+ 24 - 18
electron/config/config.default.js

@@ -12,7 +12,7 @@ module.exports = (appInfo) => {
   /**
    * 开发者工具
    */
-  config.openDevTools = false;
+  config.openDevTools = true;
 
   /**
    * 应用程序顶部菜单
@@ -24,24 +24,30 @@ module.exports = (appInfo) => {
    */
   config.windowsOption = {
     title: 'EE框架',
-    width: 980,
-    height: 650,
+    width: 3840,
+    height: 2160,
     minWidth: 400,
     minHeight: 300,
+    frame: true,
+  //  fullscreen: true,
+   // titleBarStyle: 'hiddenInset', // 部分系统可能需要自定义标题栏样式
     webPreferences: {
       //webSecurity: false,
       contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
       nodeIntegration: true,
       //preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
     },
-    frame: true,
     show: false,
     icon: path.join(appInfo.home, 'public', 'images', 'logo-32.png'),
+
+    // 添加全屏配置
+  //  fullscreen: true, // 启用全屏
+  //  resizable: false // 禁用窗口缩放(全屏时通常不需要)
   };
 
   /**
    * ee框架日志
-   */  
+   */
   config.logger = {
     encoding: 'utf8',
     level: 'INFO',
@@ -51,20 +57,20 @@ module.exports = (appInfo) => {
     rotator: 'day',
     appLogName: 'ee.log',
     coreLogName: 'ee-core.log',
-    errorLogName: 'ee-error.log' 
+    errorLogName: 'ee-error.log'
   }
 
   /**
    * 远程模式-web地址
-   */    
+   */
   config.remoteUrl = {
-    enable: false,
-    url: 'http://electron-egg.kaka996.com/'
+    enable: true,
+    url: 'http://localhost:3000/home'
   };
 
   /**
    * 内置socket服务
-   */   
+   */
   config.socketServer = {
     enable: false,
     port: 7070,
@@ -82,11 +88,11 @@ module.exports = (appInfo) => {
 
   /**
    * 内置http服务
-   */     
+   */
   config.httpServer = {
     enable: false,
     https: {
-      enable: false, 
+      enable: false,
       key: '/public/ssl/localhost+1.key',
       cert: '/public/ssl/localhost+1.pem'
     },
@@ -111,11 +117,11 @@ module.exports = (appInfo) => {
 
   /**
    * 主进程
-   */     
+   */
   config.mainServer = {
     protocol: 'file://',
     indexPath: '/public/dist/index.html',
-  }; 
+  };
 
   /**
    * 硬件加速
@@ -138,7 +144,7 @@ module.exports = (appInfo) => {
    */
   config.jobs = {
     messageLog: true
-  };  
+  };
 
   /**
    * 插件功能
@@ -162,11 +168,11 @@ module.exports = (appInfo) => {
     },
     autoUpdater: {
       enable: true,
-      windows: false, 
-      macOS: false, 
+      windows: false,
+      macOS: false,
       linux: false,
       options: {
-        provider: 'generic', 
+        provider: 'generic',
         url: 'http://kodo.qiniu.com/'
       },
       force: false,

+ 12 - 4
electron/config/config.local.js

@@ -6,12 +6,11 @@
 module.exports = (appInfo) => {
   const config = {};
 
+
   /**
    * 开发者工具
    */
-  config.openDevTools = {
-    mode: 'undocked'
-  };
+  config.openDevTools = true;
 
   /**
    * 应用程序顶部菜单
@@ -23,7 +22,16 @@ module.exports = (appInfo) => {
    */
   config.jobs = {
     messageLog: true
-  };   
+  };
+
+
+  /**
+   * 远程模式-web地址
+   */
+  config.remoteUrl = {
+    enable: true,
+    url: 'http://localhost:3000/home'
+  };
 
   return {
     ...config

+ 3 - 3
electron/config/config.prod.js

@@ -9,19 +9,19 @@ module.exports = (appInfo) => {
   /**
    * 开发者工具
    */
-  config.openDevTools = false;
+  config.openDevTools = true;
 
   /**
    * 应用程序顶部菜单
    */
-  config.openAppMenu = false;
+  config.openAppMenu = true;
 
   /**
    * jobs
    */
   config.jobs = {
     messageLog: false
-  }; 
+  };
 
   return {
     ...config

+ 69 - 0
electron/controller/camera.js

@@ -0,0 +1,69 @@
+'use strict';
+
+const { Controller } = require('ee-core');
+const { liveShow,liveHide,setParams,capture }  = require('../api/camera')
+
+
+
+
+class CameraController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+  }
+
+  /**
+   * 启动预览
+   */
+  async liveShow() {
+    try {
+      await liveShow();
+      const win = this.app.electron.mainWindow;
+      win.setAlwaysOnTop(true); // 置顶
+      return true;
+    } catch (error) {
+      console.error('eeee启动直播失败:', error);
+      throw error;
+    }
+  }
+
+
+  /**
+   * 结束预览
+   */
+  async liveHide() {
+    try {
+      await liveHide();
+      const win = this.app.electron.mainWindow;
+      win.setAlwaysOnTop(false); // 置顶
+      return true;
+    } catch (error) {
+      throw error;
+    }
+  }
+
+
+  /**
+   * 设置参数
+   */
+  async setParams(params) {
+    try {
+      console.log(params);
+      await setParams(params);
+      return true;
+    } catch (error) {
+      throw error;
+    }
+  }
+
+  async takePictures() {
+    try {
+      await capture();
+      return true;
+    } catch (error) {
+      throw error;
+    }
+  }
+}
+
+CameraController.toString = () => '[class CameraController]';
+module.exports = CameraController;

+ 83 - 0
electron/controller/socket.js

@@ -0,0 +1,83 @@
+'use strict';
+
+const { Controller } = require('ee-core');
+const Log = require('ee-core/log');
+const CoreWindow = require('ee-core/electron/window');
+const WebSocket = require('ws'); // 引入原生 ws 库
+
+class SocketController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.socket = null;
+  }
+
+  /**
+   * Connect to WebSocket server
+   */
+  connect() {
+    this.socket = new WebSocket('ws://10.56.42.176:7074/ws');
+
+    // 监听连接成功事件
+    this.socket.on('open', () => {
+      Log.info('Connected to WebSocket server');
+      this.sendPing(); // 连接成功后发送 ping
+    });
+
+    // 监听消息事件
+    this.socket.on('message', (data) => {
+      Log.info('Received:', data.toString());
+    });
+
+    // 监听连接关闭事件
+    this.socket.on('close', () => {
+      Log.info('Disconnected from WebSocket server');
+    });
+
+    // 监听错误事件
+    this.socket.on('error', (err) => {
+      Log.error('WebSocketError:', err);
+    });
+
+
+    setInterval(()=>{
+
+      const win = CoreWindow.getMainWindow();
+      win.webContents.send('controller.socket.message', '这是一个消息');
+    },2000)
+  }
+
+  /**
+   * 发送 ping 消息
+   */
+  sendPing() {
+    Log.info('sendPing:');
+    const message = JSON.stringify({ data: 'node', type: 'ping' });
+    this.sendMessage(message);
+  }
+
+  /**
+   * 发送消息到服务器
+   * @param {string} message - JSON 字符串
+   */
+  sendMessage(message) {
+    // 检查连接状态
+    if (this.socket.readyState === WebSocket.OPEN) {
+      this.socket.send(message); // 使用 send() 发送
+      Log.info('Sent:', message);
+    } else {
+      Log.error('WebSocket未连接或未就绪');
+    }
+  }
+
+  /**
+   * 断开连接
+   */
+  disconnect() {
+    if (this.socket) {
+      this.socket.close(); // 使用 close() 方法
+    }
+  }
+}
+
+SocketController.toString = () => '[class SocketController]';
+module.exports = SocketController;

+ 14 - 0
frontend/src/stores/modules/client.ts

@@ -0,0 +1,14 @@
+
+import { defineStore } from 'pinia';
+const electron = window.require && window.require('electron') || {}
+
+
+const client = defineStore('client', {
+    state: () => ({
+        electron: electron,
+        ipc: electron.ipcRenderer || undefined,
+        isClient: electron.ipcRenderer  ? true : false,
+    }),
+});
+
+export default client;

+ 16 - 0
frontend/src/utils/ipc.ts

@@ -0,0 +1,16 @@
+const icpList = {
+    camera:{
+        PreviewShow: 'controller.camera.liveShow',
+        PreviewHide: 'controller.camera.liveHide',
+        setParams:"controller.camera.setParams",
+        takePictures:"controller.camera.takePictures"
+    },
+    socket:{
+        connect: 'controller.socket.connect',
+        message: 'controller.socket.message',
+        disconnect: 'controller.socket.disconnect',
+    }
+}
+
+
+export default icpList;

+ 145 - 8
frontend/src/views/Home/index.vue

@@ -1,24 +1,45 @@
 <template>
 
-  <div>{{useUserInfoStore.userInfo.account_name}}</div>
-  <div>{{useUserInfoStore.userInfo.phone}}</div>
-
+  <template v-if="!show">
+    <div>{{useUserInfoStore.userInfo.account_name}}</div>
+    <div>{{useUserInfoStore.userInfo.phone}}</div>
+  </template>
+  <template v-else>
+    <img :src="src" width="500px" height="500px"/>
+    <img :src="preview" width="500px" height="500px"/>
+  </template>
 
 
   <div class="mb-4">
+
+    <el-button @click="showVideo">实时预览</el-button>
+    <el-button @click="hideVideo">关闭预览</el-button>
+    <el-button @click="takePictures">拍照</el-button>
+    <el-button @click="socketConnect">socket 连接</el-button>
+    <el-button @click="socketDisconnect">socket 断开</el-button>
+
+
     <el-button @click="loginError">登录失败</el-button>
     <el-button type="primary"  @click="loginIn">登录成功</el-button>
-    <el-button type="success">Success</el-button>
-    <el-button type="info">Info</el-button>
-    <el-button type="warning">Warning</el-button>
-    <el-button type="danger">Danger</el-button>
+  </div>
+
+
+  <div class="mb-4">
+      <el-input v-model="paramsKey" placeholder="参数名称"></el-input>
+      <el-input v-model="paramsValue" placeholder="参数值"></el-input>
+      <el-button @click="setParams">保存</el-button>
   </div>
 </template>
 
 <script setup lang="ts">
+import { ref } from 'vue'
 import useUserInfo from "@/stores/modules/user";
 const useUserInfoStore = useUserInfo();
 import { login,getUserInfo } from '@/apis/user'
+import client from "@/stores/modules/client";
+import  icpList from '@/utils/ipc'
+const clientStore = client();
+console.log(icpList);
 
 
 async  function loginIn() {
@@ -42,7 +63,6 @@ async  function loginIn() {
 
 }
 async function loginError() {
-  console.log('bbb')
   const res = await login({
     "site":1,
     "username":"18679381902",
@@ -51,6 +71,123 @@ async function loginError() {
   })
   console.log(res)
 }
+
+const show = ref(false)
+const imgKey = ref(0)
+const src = ref('http://localhost:5513/liveview.jpg')
+let interval:any = null
+function showVideo(){
+  if(clientStore.isClient){
+
+    console.log(clientStore.ipc)
+    clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
+
+    clientStore.ipc.send(icpList.camera.PreviewShow);
+    clientStore.ipc.on(icpList.camera.PreviewShow, async (event, result) => {
+
+      show.value = true;
+      src.value = `http://localhost:5513/liveview.jpg?key=${imgKey.value}`
+      interval = setInterval(()=>{
+        imgKey.value++;
+        src.value = `http://localhost:5513/liveview.jpg?key=${imgKey.value}`
+      },100)
+
+    })
+  }
+
+}
+
+const preview = ref('http://localhost:5513/preview.jpg')
+const previewKey = ref(0)
+
+function hideVideo(){
+  if(clientStore.isClient){
+
+    clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
+
+    clientStore.ipc.send(icpList.camera.PreviewHide);
+    clientStore.ipc.on(icpList.camera.PreviewHide, async (event, result) => {
+      show.value = false;
+      if(interval) clearInterval(interval)
+    })
+  }
+
+}
+
+const paramsKey = ref('')
+const paramsValue = ref('')
+
+
+function setParams(){
+  if(clientStore.isClient){
+
+    clientStore.ipc.removeAllListeners(icpList.camera.setParams);
+
+    clientStore.ipc.send(icpList.camera.setParams,{
+      key:paramsKey.value,
+      value:paramsValue.value
+    });
+  }
+
+}
+
+
+function takePictures(){
+  if(clientStore.isClient){
+
+    clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
+
+    clientStore.ipc.send(icpList.camera.takePictures);
+
+    clientStore.ipc.on(icpList.camera.takePictures, async (event, result) => {
+
+
+      setTimeout(()=>{
+        previewKey.value++;
+        preview.value = `http://localhost:5513/preview.jpg?key=${previewKey.value}`
+      },1000)
+    })
+  }
+}
+
+
+function socketConnect(){
+
+  if(clientStore.isClient){
+
+    clientStore.ipc.removeAllListeners(icpList.socket.connect);
+
+    clientStore.ipc.send(icpList.socket.connect);
+
+    clientStore.ipc.on(icpList.socket.connect, async (event, result) => {
+      console.log(result);
+    })
+
+    clientStore.ipc.on(icpList.socket.message, async (event, result) => {
+      console.log('message');
+      console.log(result);
+    })
+  }
+
+
+
+}
+
+
+
+function socketDisconnect(){
+
+  if(clientStore.isClient){
+
+    clientStore.ipc.removeAllListeners(icpList.socket.disconnect);
+
+    clientStore.ipc.send(icpList.socket.disconnect);
+
+    clientStore.ipc.on(icpList.socket.disconnect, async (event, result) => {
+      console.log(result);
+    })
+  }
+}
 </script>
 
 <style scoped>

+ 13 - 11
package.json

@@ -45,19 +45,21 @@
   "author": "哆啦好梦, Inc <530353222@qq.com>",
   "license": "Apache",
   "devDependencies": {
-    "@electron/rebuild": "^3.2.13",
-    "debug": "^4.3.3",
+    "@electron/rebuild": "3.2.13",
+    "debug": "4.3.3",
     "ee-bin": "1.8.3",
-    "electron": "^21.4.4",
-    "electron-builder": "^23.6.0",
-    "eslint": "^5.13.0",
-    "eslint-plugin-prettier": "^3.0.1",
-    "nodemon": "^2.0.16"
+    "electron": "21.4.4",
+    "electron-builder": "23.6.0",
+    "eslint": "5.13.0",
+    "eslint-plugin-prettier": " -3.0.1",
+    "nodemon": "2.0.16"
   },
   "dependencies": {
-    "dayjs": "^1.10.7",
+    "axios": "^1.7.9",
+    "dayjs": "1.10.7",
     "ee-core": "2.12.0",
-    "electron-updater": "^5.3.0",
-    "lodash": "^4.17.21"
+    "electron-updater": "5.3.0",
+    "lodash": "4.17.21",
+    "ws": "8.18.1"
   }
-}
+}