ソースを参照

feat: 机载数据展示,websocket 修改

wanggaokun 10 ヶ月 前
コミット
7c0aaa1df7

+ 2 - 2
src/api/modules/manage/instructionInfo.ts

@@ -82,6 +82,6 @@ export const connectApi = () => {
  * @param content 内容
  * @returns returns
  */
-export const sendApi = (content: String) => {
-  return http.post<any>(`/netty/client/send`, content, { loading: false })
+export const sendApi = (id: any) => {
+  return http.post<any>(`/netty/client/send`, id, { loading: false })
 }

+ 8 - 0
src/layouts/components/Header/components/Message.vue

@@ -45,6 +45,14 @@ import { storeToRefs } from 'pinia'
 import { reactive, ref, onMounted, watch, nextTick } from 'vue'
 import useNoticeStore from '@/stores/modules/notice'
 import { useRouter } from 'vue-router'
+import { useUserStore } from '@/stores/modules/user'
+import { initWebSocket } from '@/utils/websocket'
+onMounted(() => {
+  const userStore = useUserStore()
+  let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'
+  // initWebSocket(protocol + 'localhost:8089' + '/resource/websocket')
+  initWebSocket(protocol + window.location.host + import.meta.env.VITE_API_URL + '/websocket/message/' + userStore.name)
+})
 const router = useRouter()
 const noticeStore = storeToRefs(useNoticeStore())
 // const { readAll } = useNoticeStore()

+ 9 - 9
src/layouts/index.vue

@@ -5,7 +5,7 @@
 </template>
 
 <script setup lang="ts" name="layout">
-import { computed, type Component, onMounted } from 'vue'
+import { computed, type Component } from 'vue'
 import { LayoutType } from '@/stores/interface'
 import { useGlobalStore } from '@/stores/modules/global'
 import ThemeDrawer from './components/ThemeDrawer/index.vue'
@@ -13,14 +13,14 @@ import LayoutVertical from './LayoutVertical/index.vue'
 import LayoutClassic from './LayoutClassic/index.vue'
 import LayoutTransverse from './LayoutTransverse/index.vue'
 import LayoutColumns from './LayoutColumns/index.vue'
-import { useUserStore } from '@/stores/modules/user'
-import { initWebSocket } from '@/utils/websocket'
-onMounted(() => {
-  const userStore = useUserStore()
-  let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'
-  // initWebSocket(protocol + 'localhost:8089' + '/resource/websocket')
-  initWebSocket(protocol + window.location.host + import.meta.env.VITE_API_URL + '/websocket/message/' + userStore.name)
-})
+// import { useUserStore } from '@/stores/modules/user'
+// import { initWebSocket } from '@/utils/websocket'
+// onMounted(() => {
+//   const userStore = useUserStore()
+//   let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'
+//   // initWebSocket(protocol + 'localhost:8089' + '/resource/websocket')
+//   initWebSocket(protocol + window.location.host + import.meta.env.VITE_API_URL + '/websocket/message/' + userStore.name)
+// })
 const LayoutComponents: Record<LayoutType, Component> = {
   vertical: LayoutVertical,
   classic: LayoutClassic,

+ 18 - 0
src/stores/modules/air.ts

@@ -0,0 +1,18 @@
+import { defineStore } from 'pinia'
+
+export const useAirStore = defineStore('admin-air', {
+  state: (): any => ({
+    // 机载返回结果
+    airResult: []
+  }),
+  getters: {
+    // 按钮权限列表
+    airResultGet: state => state.airResult
+  },
+  actions: {
+    // Set RouteName
+    async setAirResult(airResultStr: string) {
+      this.airResult = JSON.parse(airResultStr)
+    }
+  }
+})

+ 9 - 1
src/utils/websocket.ts

@@ -1,3 +1,6 @@
+import { useAirStore } from '@/stores/modules/air'
+import audioSrc from '@/assets/audio/tip.mp3'
+
 /**
  * @module initWebSocket 初始化
  * @module websocketOnopen 连接成功
@@ -114,7 +117,7 @@ export const sendMsg = (data: any) => {
 }
 
 const playSound = () => {
-  const audio = new Audio('src/assets/audio/tip.mp3')
+  const audio = new Audio(audioSrc)
   audio.play()
 }
 
@@ -131,6 +134,11 @@ export const websocketOnmessage = () => {
     if (e.data.indexOf('连接成功') >= 0) {
       return
     }
+    if (e.data.indexOf('机载PHM数据:') >= 0) {
+      const result = e.data.split('机载PHM数据:')
+      useAirStore().setAirResult(result[1])
+      return
+    }
     useNoticeStore().addNotice({
       message: e.data,
       read: false,

+ 97 - 0
src/views/manage/instructionInfo/components/index.vue

@@ -0,0 +1,97 @@
+<template>
+  <el-dialog
+    v-model="dialogVisible"
+    :close-on-click-modal="false"
+    :title="parameter.title"
+    :destroy-on-close="true"
+    :fullscreen="parameter.fullscreen"
+    draggable
+  >
+    <div class="params-box">
+      <el-descriptions title="">
+        <div v-for="item in airResult" :key="item.code">
+          <el-descriptions-item :label="getTitle(item.code)">
+            <el-switch v-model="item.value" disabled active-value="1" inactive-value="0" />
+          </el-descriptions-item>
+        </div>
+      </el-descriptions>
+    </div>
+    <template #footer>
+      <span class="dialog-footer">
+        <el-button @click="handleCancel">取消</el-button>
+      </span>
+    </template>
+  </el-dialog>
+</template>
+
+<script setup lang="ts" name="airResult">
+import { ref, computed, onMounted } from 'vue'
+import { useAirStore } from '@/stores/modules/air'
+import { getDictsApi } from '@/api/modules/system/dictData'
+import { useUserStore } from '@/stores/modules/user'
+import { initWebSocket } from '@/utils/websocket'
+onMounted(() => {
+  const userStore = useUserStore()
+  let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'
+  // initWebSocket(protocol + 'localhost:8089' + '/resource/websocket')
+  initWebSocket(protocol + window.location.host + import.meta.env.VITE_API_URL + '/websocket/message/' + userStore.name)
+})
+let paramsDicts = ref()
+getDictsApi('air_order_result').then(res => {
+  paramsDicts.value = res.data
+})
+export interface ParameterProps {
+  title: string // 标题
+  fullscreen?: boolean // 是否全屏
+  sortieNo?: any
+  parameters?: any[]
+}
+const airResult = computed(() => {
+  return useAirStore().airResult.params
+})
+const getTitle = val => {
+  // console.log(val)
+  // console.log('paramsDict', paramsDicts.value)
+
+  const item = paramsDicts.value.filter(item => {
+    // console.log('item.dictValue', item.dictValue)
+    // console.log('item.dictValue == val', item.dictValue == val)
+
+    return item.dictValue == val
+  })
+  // paramsDict
+  return item[0].dictLabel
+}
+// dialog状态
+const dialogVisible = ref(false)
+const butLoading = ref(false)
+// 父组件传过来的参数
+const parameter = ref<ParameterProps>({
+  title: '',
+  fullscreen: true
+})
+
+// 取消按钮,重置表单,关闭弹框
+const handleCancel = () => {
+  dialogVisible.value = false
+}
+
+// 接收父组件参数
+const openDialog = async (params: ParameterProps) => {
+  parameter.value = { ...parameter.value, ...params }
+  butLoading.value = false
+  dialogVisible.value = true
+}
+
+defineExpose({
+  openDialog
+})
+</script>
+<style scoped lang="scss">
+.params-box {
+  min-height: 500px;
+}
+.dialog-footer {
+  margin-bottom: 20px;
+}
+</style>

+ 33 - 27
src/views/manage/instructionInfo/index.vue

@@ -10,10 +10,13 @@
     >
       <!-- 表格 header 按钮 -->
       <template #tableHeader="scope">
-        <el-button type="primary" v-auth="['manage:instructionInfo:add']" :icon="CirclePlus" @click="connect()"> 连接 </el-button>
         <el-button type="primary" v-auth="['manage:instructionInfo:add']" :icon="CirclePlus" @click="openDialog(1, '指令信息新增')"> 新增 </el-button>
-        <el-button type="primary" v-auth="['manage:instructionInfo:import']" :icon="Upload" plain @click="batchAdd"> 导入 </el-button>
-        <el-button type="primary" v-auth="['manage:instructionInfo:export']" :icon="Download" plain @click="downloadFile"> 导出 </el-button>
+        <el-button type="primary" :icon="CirclePlus" @click="connect()"> 连接 </el-button>
+        <el-button type="primary" :icon="CirclePlus" @click="openAirDialog()"> 实时结果 </el-button>
+        <el-button type="primary" v-if="0" v-auth="['manage:instructionInfo:import111']" :icon="Upload" plain @click="batchAdd"> 导入 </el-button>
+        <el-button type="primary" v-if="0" v-auth="['manage:instructionInfo:export111']" :icon="Download" plain @click="downloadFile">
+          导出
+        </el-button>
         <el-button
           type="danger"
           v-auth="['system:user:remove']"
@@ -27,7 +30,7 @@
       </template>
       <!-- 表格操作 -->
       <template #operation="scope">
-        <el-button type="primary" link :icon="View" v-auth="['manage:instructionInfo:query']" @click="send(scope.row)"> 发送 </el-button>
+        <el-button type="primary" link :icon="View" v-auth="['manage:instructionInfo:query']" @click="send(scope.row.id)"> 发送 </el-button>
         <el-button type="primary" link :icon="View" v-auth="['manage:instructionInfo:query']" @click="openDialog(3, '指令信息查看', scope.row)">
           查看
         </el-button>
@@ -41,6 +44,7 @@
     </ProTable>
     <FormDialog ref="formDialogRef" />
     <ImportExcel ref="dialogRef" />
+    <AirResult ref="airResultRef" />
   </div>
 </template>
 
@@ -49,6 +53,7 @@ import { ref, reactive } from 'vue'
 import { useHandleData } from '@/hooks/useHandleData'
 import { useDownload } from '@/hooks/useDownload'
 import { ElMessage, ElMessageBox } from 'element-plus'
+import AirResult from './components/index.vue'
 import ProTable from '@/components/ProTable/index.vue'
 import ImportExcel from '@/components/ImportExcel/index.vue'
 import FormDialog from '@/components/DialogOld/form.vue'
@@ -137,6 +142,14 @@ const openDialog = async (type: number, title: string, row?: any) => {
   }
   formDialogRef.value?.openDialog(params)
 }
+const airResultRef = ref<InstanceType<typeof AirResult> | null>(null)
+// 打开弹框的功能
+const openAirDialog = async () => {
+  const params = {
+    title: '结果'
+  }
+  airResultRef.value?.openDialog(params)
+}
 
 const connect = async () => {
   const res = await connectApi()
@@ -145,10 +158,8 @@ const connect = async () => {
   }
 }
 
-const send = async (data: any) => {
-  console.log(data)
-
-  const res = await sendApi('ssdsd')
+const send = async (id: any) => {
+  const res = await sendApi(id)
   if (res.code == 200) {
     ElMessage.success('发送成功')
   }
@@ -159,13 +170,7 @@ const columns = reactive<ColumnProps<any>[]>([
   { type: 'selection', fixed: 'left', width: 70 },
   {
     prop: 'attribute',
-    label: '指令属性',
-    search: {
-      el: 'input'
-    }
-  },
-  {
-    prop: 'attribute',
+    label: '指令',
     tag: true,
     enum: () => getDictsApi('air_order'),
     search: {
@@ -184,17 +189,18 @@ const columns = reactive<ColumnProps<any>[]>([
     prop: 'createTime',
     label: '创建时间'
   },
-  { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
+  { prop: 'operation', label: '操作', width: 250, fixed: 'right' }
 ])
+// air_order_result
 // 表单配置项
 let fieldList: Form.FieldItem[] = []
 const setFieldList = () => {
   fieldList = [
-    {
-      label: '指令属性',
-      field: 'attribute',
-      placeholder: '请输入指令属性'
-    },
+    // {
+    //   label: '指令属性',
+    //   field: 'attribute',
+    //   placeholder: '请输入指令属性'
+    // },
     {
       label: '指令属性',
       field: 'attribute',
@@ -211,13 +217,13 @@ const setFieldList = () => {
       label: '指令内容',
       field: 'content',
       placeholder: '请输入指令内容'
-    },
-    {
-      label: 'XML格式文件',
-      field: 'xml',
-      type: 'textarea',
-      placeholder: '请输入内容'
     }
+    // {
+    //   label: 'XML格式文件',
+    //   field: 'xml',
+    //   type: 'textarea',
+    //   placeholder: '请输入内容'
+    // }
   ]
 }
 </script>

+ 4 - 0
src/views/manage/orderInfo/index.vue

@@ -37,6 +37,10 @@ const toExe = async (row: any) => {
     ElMessage.error('未找到对应的指令配置项,请核对指令配置信息。')
     return
   }
+  if (row.orderType == 10) {
+    router.push({ path: '/manage/instructionInfo' })
+    return
+  }
   router.push({ path: `/order/task/${data.sortie}`, query: { type: row.orderType, orderId: row.id, taskId: row.orderBatchId } })
 }
 

+ 1 - 0
src/views/manage/orderInfo/task/CustomDialog.vue

@@ -34,6 +34,7 @@ export interface FormParameterProps {
   isEdit?: boolean // 是否编辑
   top?: string // 离顶部距离
   model: Record<string, any>
+  data?: any
   api?: (params: any) => Promise<any> // 提交api
 }
 // dialog状态