From 21698c91c9011fbce6fd8b8d6487f9e00ec9bb94 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 26 九月 2022 15:18:59 +0800
Subject: [PATCH] upkoa

---
 /dev/null                |  106 ---------------------
 vite.config.ts           |   18 +++
 src/views/home/index.vue |   44 ++++----
 src/samples/node-api.ts  |   61 ++++++++++++
 package.json             |    4 
 electron/main/index.ts   |   39 +++++++
 src/router/index.ts      |    1 
 src/stores/sockteInfo.ts |    5 
 src/App.vue              |    8 -
 src/main.ts              |    1 
 10 files changed, 140 insertions(+), 147 deletions(-)

diff --git a/electron/main/index.ts b/electron/main/index.ts
index 07702b9..d4ac784 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -3,6 +3,38 @@
 import { join } from 'path'
 import fs from 'fs'
 import iconv from 'iconv-lite'
+//koa----
+import  Koa from 'koa';
+import  Router from 'koa-router';
+const koaBody = require('koa-body');
+
+const creatorKoa=(win)=>{
+  const app = new Koa();
+  const router = new Router();
+  app.use(koaBody({
+  multipart: true
+  }));
+  
+  router.get('/', async (ctx) => {
+      ctx.body = 'Hello World!';
+  });
+  router.post('/postResult', async (ctx)=>{
+  const body=ctx.request.body
+  win?.webContents.send('message-koa',body)
+  ctx.body={
+      "code": 200,
+      "data": body,
+      "message": "接收成功"
+  }
+  //   writeResult(body)
+  })
+
+  app.use(router.routes());
+  
+  app.listen(3131,()=>{
+      console.log('koa Service start, port:3131')
+  });
+}
 
 // 配制文件的读写实例
 const Store = require('electron-store');
@@ -53,7 +85,8 @@
   // Test active push message to Renderer-process
   // 测试推送消息到Renderer进程
   win.webContents.on('did-finish-load', () => {
-    // win?.webContents.send('main-process-message', new Date().toLocaleString())
+    creatorKoa(win)
+    win?.webContents.send('message-koa','nihao0-----')
     win?.webContents.send('getScreenTimeout',store.get('screenTimeout'))
     win?.webContents.send('getPcName',store.get('machineName'))
     win?.webContents.send('getConfigData',store.get('clientCode'),store.get('devices'),store.path)
@@ -75,7 +108,7 @@
 
 app.on('second-instance', () => {
   if (win) {
-    // Focus on the main window if the user tried to open another
+    // 如果用户试图打开另一个窗口,则将焦点放在主窗口上
     if (win.isMinimized()) win.restore()
     win.focus()
   }
@@ -90,7 +123,7 @@
   }
 })
 
-// new window example arg: new windows url
+// 新窗口示例arg:新的Windows url
 ipcMain.handle("open-win", (event, arg) => {
   const childWindow = new BrowserWindow({
     webPreferences: {
diff --git a/package.json b/package.json
index e65862d..1d69514 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "sign-tool",
-  "version": "2.1.0",
+  "version": "2.2.0",
   "icon": "public/favicon.ico",
   "main": "dist/electron/main/index.js",
   "author": "",
@@ -8,7 +8,7 @@
   "private": true,
   "scripts": {
     "dev": "vite",
-    "build": "vue-tsc --noEmit && vite build && electron-builder"
+    "build": "vite build && electron-builder"
   },
   "engines": {
     "node": ">=14.17.0"
diff --git a/src/App.vue b/src/App.vue
index 326de6e..9bc317e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -11,12 +11,4 @@
 </template>
 
 <style>
-#app {
-  /* font-family: Avenir, Helvetica, Arial, sans-serif;
-  -webkit-font-smoothing: antialiased;
-  -moz-osx-font-smoothing: grayscale;
-  text-align: center;
-  color: #2c3e50;
-  margin-top: 60px; */
-}
 </style>
diff --git a/src/main.ts b/src/main.ts
index 7879f13..688c9df 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -5,7 +5,6 @@
 import { createPinia } from 'pinia'
 import App from './App.vue'
 import './samples/node-api'
-import './samples/httpServer'
 
 createApp(App)
   .use(createPinia())
diff --git a/src/router/index.ts b/src/router/index.ts
index 2ba1f62..10d587c 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -6,7 +6,6 @@
 const routes: Array<RouteRecordRaw> = [
     // { path: '/', name: 'Home', component: () => import('@/views/home/index.vue')},
     { path: '/', name: 'test', component: () => import('@/views/home/index.vue')},
-    { path: '/test', name: 'Home', component: () => import('@/views/test/index.vue')},
 ]
 
 const router = createRouter({
diff --git a/src/samples/httpServer.ts b/src/samples/httpServer.ts
deleted file mode 100644
index aed1a73..0000000
--- a/src/samples/httpServer.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import  Koa from 'koa';
-import  Router from 'koa-router';
-const koaBody = require('koa-body');
-import {sockteStore} from '@/stores/sockteInfo'
-
-interface ResultInfo{
-    clientCode:string;
-    commCode :string;
-    deviceType:string;
-    deviceName :string;
-    result :string;
-    resultTime :string
-}
- 
-const app = new Koa();
-const router = new Router();
-app.use(koaBody({
-  multipart: true
-}));
- 
-router.get('/', async (ctx) => {
-    ctx.body = 'Hello World!';
-});
-router.post('/postResult', async (ctx)=>{
-  const body=ctx.request.body
-  console.log(body,'收到的参数')
-  writeResult(body)
-  ctx.body={
-    "code": 200,
-    "data": body,
-    "message": "接收成功"
-  }
-//   writeResult(body)
-})
-
-app.use(router.routes());
- 
-app.listen(3131,()=>{
-    console.log('koa服务已经启动了,端口号是3131')
-});
-const writeResult=(res: ResultInfo)=>{
-    console.log(res)
-    console.log(`写入结果类型${res.deviceType},写入结果=${res.result}`)
-    switch(res.deviceType){
-        case '读卡器':
-            console.log('读卡器收到消息')
-            if(res.clientCode!==null){
-                sockteStore().setdkqSockte(
-                    {
-                        deviceName:res.deviceNumber,
-                        type:"读卡器",
-                        result:res.result,
-                        resultTime:res.resultTime,
-                        state:2
-                    }
-                )
-            }
-            break
-        case "体重秤":
-            sockteStore().setweightSockte(
-                {
-                    deviceName:res.deviceNumber,
-                    type:"体重秤",
-                    result:Number(res.result).toString(),
-                    resultTime:res.resultTime,
-                    state:2
-                }
-            )
-            break
-        case "血压计":
-            sockteStore().setxyjSockte(
-                {
-                    deviceName:res.deviceNumber,
-                    type:"血压计",
-                    result:res.result,
-                    resultTime:res.resultTime,
-                    state:2
-                }
-            )
-            break
-        default:
-            console.log('有配置类型没有匹配')
-    }
-}
diff --git a/src/samples/node-api.ts b/src/samples/node-api.ts
index 0e2db2f..51059bd 100644
--- a/src/samples/node-api.ts
+++ b/src/samples/node-api.ts
@@ -10,9 +10,26 @@
 import { ElMessage, ElMessageBox } from 'element-plus'
 import { on } from 'events'
 
+interface ResultInfo{
+  clientCode:string;
+  commCode :string;
+  deviceType:string;
+  deviceName :string;
+  result :string;
+  resultTime :string
+}
 let deviceList=[]
 let clientCode=''
 // 主进程发送消息到渲染进程
+ipcRenderer.on('message-koa', (_event, ...args) => {
+  
+  console.log('koa返回http请求消息', ...args)
+  const Result:ResultInfo=args[0]
+  writeResult(Result)
+})
+ipcRenderer.on('main-process-message', (_event, ...args) => {
+  console.log('[Receive Main-process message]:', ...args)
+})
 ipcRenderer.on('main-process-message', (_event, ...args) => {
   console.log('[Receive Main-process message]:', ...args)
 })
@@ -68,4 +85,48 @@
     console.log("网路链接失败")
   })
 },10000)
+const writeResult=(res: ResultInfo)=>{
+  console.log(res)
+  console.log(`写入结果类型${res.deviceType},写入结果=${res.result}`)
+  switch(res.deviceType){
+      case '读卡器':
+          console.log('读卡器收到消息')
+          if(res.clientCode!==null){
+              sockteStore().setdkqSockte(
+                  {
+                      deviceName:res.deviceName,
+                      type:"读卡器",
+                      result:res.result,
+                      resultTime:res.resultTime,
+                      state:2
+                  }
+              )
+          }
+          break
+      case "体重秤":
+          sockteStore().setweightSockte(
+              {
+                  deviceName:res.deviceName,
+                  type:"体重秤",
+                  result:Number(res.result).toString(),
+                  resultTime:res.resultTime,
+                  state:2
+              }
+          )
+          break
+      case "血压计":
+          sockteStore().setxyjSockte(
+              {
+                  deviceName:res.deviceName,
+                  type:"血压计",
+                  result:res.result,
+                  resultTime:res.resultTime,
+                  state:2
+              }
+          )
+          break
+      default:
+          console.log('有配置类型没有匹配')
+  }
+}
 
diff --git a/src/samples/timerServer.ts b/src/samples/timerServer.ts
deleted file mode 100644
index 8b13789..0000000
--- a/src/samples/timerServer.ts
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/stores/sockteInfo.ts b/src/stores/sockteInfo.ts
index ba6d471..0948389 100644
--- a/src/stores/sockteInfo.ts
+++ b/src/stores/sockteInfo.ts
@@ -50,12 +50,13 @@
      * 更新体重秤结果
      * @param info 体重结果
      */
-    function setweightSockte(info:info){
+    function setweightSockte(info:weightInfo){
+        console.log(info,'入参')
         weightSockte.value.deviceName=info.deviceName
         weightSockte.value.result=info.result
         weightSockte.value.resultTime=info.resultTime
         weightSockte.value.state=info.state
-        console.debug('体重秤更新')
+        console.log('体重秤更新')
     }
      /**
      * 更新体重秤工作状态
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index a9ff12f..d8a0e30 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -128,10 +128,6 @@
             () => patientInfo.value.datetime,
             () => {
               console.log('患者信息变化',patientInfo.value)
-                if(patientInfo.value.isScheduled===0){
-                      AudioRef5.value.play();
-                      return
-                }
                 if (patientInfo.value.id !== 0) {
                     AudioRef.value.play();
                     sockteStore().setweightSockte({
@@ -150,23 +146,26 @@
                     })
                     settime()
 
-                }else{ 
-                  if(patientInfo.value.name===''){
+                }
+                else if(patientInfo.value.name===''){
                     AudioRef4.value.play();
+                    return
                   }
-                  
+                else if(patientInfo.value.isScheduled===0){
+                      AudioRef5.value.play();
+                      return
                 }
             }
-        )
+        );
         watch(
-            () => weightInfo.value.result,
+            () => weightInfo.value.resultTime,
             () => {
-                settime()
                 console.log("体重变化了",weightInfo.value)
                 // AudioRef2.value.play()
                 if (patientInfo.value.id === 0) {
                     AudioRef0.value.play()
                     inputRef.value.focus();
+                    
                 }
                 else {
                     AudioRef2.value.play()
@@ -185,7 +184,7 @@
                     }
                 }
             }
-        )
+        );
         watch(
             () => xyjInfo.value.resultTime,
             () => {
@@ -218,7 +217,7 @@
                     state.mai_bu = ""
                 }
             }
-        )
+        );
         watch(
             () => dkqInfo.value.resultTime,
             () => {
@@ -229,12 +228,12 @@
                   sendPationCode(code)
                 }
             }
-        )
+        );
         watch(() => viewNumber,
             () => {
                 state.clockNum = viewNumber.value
             }
-        )
+        );
         const inputChabge = () => {
             sendPationCode(state.inputCode)
             setTimeout(function () {
@@ -253,13 +252,10 @@
             state.haodu=(document.documentElement.clientHeight-180)/2+'px'
 
             state.clockNum = patientInfoStore().viewNumber
-            setTimeout(function () {
-                console.log('7秒后操作')
-                inputRef.value.focus();
-            }, 7000)
             setInterval(function () {
-                state.Newdate = formatDate(new Date(), "YYYY-mm-dd HH:MM:SS")
+                inputRef.value.focus();
             }, 1000)
+            
         })
         return {
             ...toRefs(state), guyanbi,isLink, netLink, weightInfo, patientInfo, xyjInfo, inputRef, AudioRef0, AudioRef, AudioRef4,AudioRef5, AudioRef2, AudioRef3, inputChabge
@@ -270,15 +266,15 @@
 <template>
     <div class="pagehome">
          <!-- 提醒刷卡 -->
-        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step1.mp3" ref="AudioRef0" id="eventAudio2"></audio>
+        <audio :src="step1" ref="AudioRef0" id="eventAudio1"></audio>
         <!-- 患者信息读取成功 -->
-        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step2.mp3" ref="AudioRef" id="eventAudio2"></audio>
+        <audio :src="step2" ref="AudioRef" id="eventAudio2"></audio>
         <!-- 体重结果回传成功 -->
-        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step3.mp3" ref="AudioRef2" id="eventAudio3"></audio>
+        <audio :src="step3" ref="AudioRef2" id="eventAudio3"></audio>
         <!-- 血压结果回传成功 -->
-        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step4.mp3" ref="AudioRef3" id="eventAudio4"></audio>
+        <audio :src="step4" ref="AudioRef3" id="eventAudio4"></audio>
         <!-- 没有找到患者 -->
-        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step5.mp3" ref="AudioRef4" id="eventAudio5"></audio>
+        <audio :src="step5" ref="AudioRef4" id="eventAudio5"></audio>
          <!-- 没有找到排班 -->
          <audio :src="step6" ref="AudioRef5" id="eventAudio6"></audio>
         <!-- <el-dialog title="提示" v-model="netLink" width="30%">
diff --git a/src/views/test/index.vue b/src/views/test/index.vue
deleted file mode 100644
index a0400a7..0000000
--- a/src/views/test/index.vue
+++ /dev/null
@@ -1,106 +0,0 @@
-<script lang="ts">
-import { userInfoStore } from '@/stores/userInfo'
-import Stomp from 'stompjs'
-import { ipcRenderer } from 'electron'
-
- export default {
-        setup() {
-            const user = userInfoStore()
-            var stompClient: Stomp.Client | null=null
-            console.log(user.userInfo)
-            const  callback = function(message:any) {
-                if (message.body) {
-                console.log(message.body,'接收到的数据')
-                } else {
-                alert("接收数据异常");
-                }
-            };
-            const connectCallback=function(){
-                console.log("链接成功")
-                if(stompClient!==null){
-                    stompClient.subscribe('/queue/12345/67890/keepalive',callback)
-                    stompClient.send("/app/device/keepalive/12345/67890", {}, JSON.stringify({"deviceNumber":"testfsfd"}));
-                }
-            }
-            const error_callback=function(error:any){
-                console.log('链接错误',error);
-                setTimeout(()=>{
-                    console.log('10秒之后重连')
-                   ubtCilert() 
-
-                },10000)
-            }
-            
-            const ubtCilert=()=>{
-                 console.log('ss')
-                 ipcRenderer.send('msg_renderer_to_main', { 'param1': "hello" });
-                // const socket = new WebSocket('ws://hemobs.icoldchain.cn/broadcast')
-                // stompClient = Stomp.over(socket)
-                // stompClient.connect({}, connectCallback,error_callback)
-               }
-            return{
-                ubtCilert
-            }
-        },
-            
-            
-}
-    
-</script>
-<template>
-    <div class="home">
-        <el-button @click="ubtCilert">
-            test
-        </el-button>
-    </div>
-</template>
-<style>
-body {
-    background: #f3f7fb;
-}
-.coldev {
-    height: 200px;
-    background: #ffff;
-}
-.grid-container {
-    display: grid;
-    grid-template-columns: 33% 33% 33%;
-    grid-gap: 20px;
-    background: #f3f7fb;
-    padding: 10px;
-}
-.grid-container > div {
-    background: #ffffff;
-    height: 150px;
-    text-align: center;
-    border-radius: 10px;
-    padding: 10px;
-}
-.lableText {
-    text-align: left;
-    /* height: 50px; */
-    /* line-height: 50px; */
-    padding-top: 30px;
-    font-size: 13pt;
-}
-.conText {
-    height: 50px;
-    line-height: 50px;
-    padding-top: 30px;
-    color: #769aff;
-    font-size: 20pt;
-}
-.imgss {
-    height: 30px;
-}
-.tale {
-    height: 30px;
-    line-height: 50px;
-    /* text-align: center; */
-}
-.zsf {
-    font-size: 18pt;
-    margin-top: 15pt;
-    color: #769aff;
-}
-</style>
\ No newline at end of file
diff --git a/vite.config.ts b/vite.config.ts
index 311d491..332195b 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -41,6 +41,24 @@
     renderer(),
   ],
   base:'./',
+  server: {
+    host: '127.0.0.1',
+    port: 8991,
+    // 是否开启 https
+    https: false,
+  },
+  proxy: {
+    '/api1': {
+      // 后台地址
+      target: 'http://127.0.0.1:3131/',
+      changeOrigin: true,
+    },
+    '/api2': {
+      // 后台地址
+      target: 'http://127.0.0.1:3132/',
+      changeOrigin: true,
+    }
+  },
   resolve:{
     alias: {
         '@': pathResolve('./src'),  // 设置 `@` 指向 `src` 目录

--
Gitblit v1.8.0