gsx 3 лет назад
Родитель
Сommit
77262f5c4f

+ 1 - 1
electron/config/config.default.js

@@ -84,7 +84,7 @@ module.exports = (appInfo) => {
 
   /* 内置http服务 */
   config.httpServer = {
-    enable: true, // 是否启用
+    enable: false, // 是否启用
     port: 7071, // 默认端口(如果端口被使用,则随机获取一个)
     cors: {
       origin: "*" // 更多参数: https://www.npmjs.com/package/koa2-cors

+ 42 - 0
electron/controller/example.js

@@ -526,6 +526,48 @@ class ExampleController extends Controller {
 
     // return uploadRes;
   }
+
+  /**
+   * 检测http服务是否开启
+   */ 
+  async checkHttpServer () {
+    const httpServerConfig = this.app.config.httpServer;
+    const url = httpServerConfig.protocol + httpServerConfig.host + ':' + httpServerConfig.port;
+
+    const data = {
+      enable: httpServerConfig.enable,
+      server: url
+    }
+    return data;
+  }
+
+  /**
+   * 一个http请求访问此方法
+   */ 
+  async doHttpRequest () {
+    // http方法
+    const method = this.app.request.method;
+    // http get 参数
+    let params = this.app.request.query;
+    params = (params instanceof Object) ? JSON.parse(JSON.stringify(params)) : {};
+    // http post 参数
+    const body = this.app.request.body;
+
+    const httpInfo = {
+      method,
+      params,
+      body
+    }
+    console.log('httpInfo:', httpInfo);
+
+    if (!body.id) {
+      return false;
+    }
+    const dir = electronApp.getPath(body.id);
+    shell.openPath(dir);
+    
+    return true;
+  }  
 }
 
 module.exports = ExampleController;

+ 2 - 0
frontend/src/api/main.js

@@ -24,6 +24,8 @@ const ipcApiRoute = {
   downloadApp: 'controller.example.downloadApp',
   dbOperation: 'controller.example.dbOperation',
   uploadFile: 'controller.example.uploadFile',
+  checkHttpServer: 'controller.example.checkHttpServer',
+  doHttpRequest: 'controller.example.doHttpRequest'
 }
 
 const specialIpcRoute = {

+ 6 - 1
frontend/src/config/router.config.js

@@ -62,11 +62,16 @@ export const constantRouterMap = [
             component: () => import('@/views/base/theme/Index')
           },                               
           {
-            path: '/base/software/open',
+            path: '/base/software/index',
             name: 'BaseSoftwareIndex',
             component: () => import('@/views/base/software/Index')
           },
           {
+            path: '/base/httpserver/index',
+            name: 'BaseHttpServerIndex',
+            component: () => import('@/views/base/httpserver/Index')
+          },
+          {
             path: '/base/system/index',
             name: 'BaseSystemIndex',
             component: () => import('@/views/base/system/Index')

+ 6 - 0
frontend/src/config/subMenu.js

@@ -69,6 +69,12 @@ export default {
 			pageName: 'BaseSoftwareIndex',
 			params: {}
 		},
+		'menu_510' : {
+			icon: 'profile',
+			title: 'http服务',
+			pageName: 'BaseHttpServerIndex',
+			params: {}
+		},
 		'menu_900' : {
 			icon: 'profile',
 			title: '测试',

+ 0 - 4
frontend/src/layouts/AppSider.vue

@@ -47,17 +47,13 @@ export default {
     };
   },
   created () {
-    //console.log('[sider] [created] 1');
   },
   mounted () {
-    //console.log('[sider] [mounted] 2');
     this.menuHandle()
   },
   methods: {
     menuHandle (e) {
       this.current = e ? e.key : this.default_key;
-      //console.log('[sider] [methods] 3');
-      //console.log('[sider] [methods] current', this.current);
       const linkInfo = this.menu[this.current]
       console.log('[home] load page:', linkInfo.pageName);
       this.$router.push({ name: linkInfo.pageName, params: linkInfo.params})

+ 73 - 0
frontend/src/views/base/httpserver/Index.vue

@@ -0,0 +1,73 @@
+<template>
+  <div id="app-base-httpserver">
+    <div class="one-block-1">
+      <span>
+        1. 内置http server服务
+      </span>
+    </div>
+    <div class="one-block-2">
+      <a-space>
+        <p>* 状态:{{ currentStatus }}</p>
+      </a-space>
+      <p>* 地址:{{ servicAddress }}</p>
+    </div>
+    <div class="one-block-1">
+      <span>
+        2. 发送http请求
+      </span>
+    </div>    
+    <div class="one-block-2">
+      <a-space>
+        <a-button @click="sendRequest('pictures')"> 打开【我的图片】 </a-button>
+      </a-space>
+    </div>
+  </div>
+</template>
+<script>
+import { ipcApiRoute, requestHttp } from '@/api/main'
+
+export default {
+  data() {
+    return {
+      currentStatus: '关闭',
+      servicAddress: '无'
+    };
+  },
+  mounted () {
+    this.init();
+  },
+  methods: {
+    init () {
+      const self = this;
+      this.$ipcCall(ipcApiRoute.checkHttpServer, {}).then(r => {
+        if (r.enable) {
+          self.currentStatus = '开启';
+          self.servicAddress = r.server;
+        }
+      })
+    },
+    sendRequest (id) {
+      const params = {
+        id: id
+      }
+      requestHttp(ipcApiRoute.doHttpRequest, params).then(res => {
+        //console.log('res:', res)
+      }) 
+    },  
+  }
+};
+</script>
+<style lang="less" scoped>
+#app-base-httpserver {
+  padding: 0px 10px;
+  text-align: left;
+  width: 100%;
+  .one-block-1 {
+    font-size: 16px;
+    padding-top: 10px;
+  }
+  .one-block-2 {
+    padding-top: 10px;
+  }
+}
+</style>

+ 1 - 1
frontend/src/views/base/powermonitor/Index.vue

@@ -7,7 +7,7 @@
     </div>  
     <div class="one-block-2">
       <a-space>
-        <p>当前状态:{{ currentStatus }}</p>
+        <p>* 当前状态:{{ currentStatus }}</p>
       </a-space>
       <p>* 拔掉电源,使用电池供电</p>
       <p>* 接入电源</p>

+ 4 - 2
frontend/src/views/base/testapi/Index.vue

@@ -6,8 +6,10 @@
       </span>
     </div>  
     <div class="one-block-2">
-      <a-button @click="exec(1)"> 点击 </a-button>
-      <a-button @click="exec2(1)"> 点击2 </a-button>
+      <a-space>
+        <a-button @click="exec(1)"> 点击 </a-button>
+        <a-button @click="exec2(1)"> 点击2 </a-button>
+      </a-space>
     </div>
   </div>
 </template>