Browse Source

fix: 接口实现;系统架构优化

feature/three
guoapeng 3 months ago
parent
commit
0a893f4fd8
  1. 4
      server/index.js
  2. 4
      server/routes/auth.js
  3. 34
      server/routes/control.js
  4. 33
      server/routes/ore.js
  5. 2
      src/apis/ore.ts
  6. 1
      src/apis/system.ts
  7. 1
      src/assets/images/logout.svg
  8. 9
      src/assets/styles/element.scss
  9. 6
      src/assets/styles/main.scss
  10. 5
      src/assets/styles/variable.scss
  11. 4
      src/components/common/FTDialog/index.vue
  12. 13
      src/layouts/default.vue
  13. 1
      src/main.ts
  14. 44
      src/stores/homeStore.ts
  15. 8
      src/views/login/index.vue
  16. 4
      vite.config.ts

4
server/index.js

@ -1,7 +1,8 @@
// const express = require('express')
import express from 'express'
import { authRoutes } from './routes/auth.js'
import { debugRoutes } from './routes/debug.js'
import { debugRoutes } from './routes/control.js'
import { oreRoutes } from './routes/ore.js'
import { initWebSocketServer } from './utils/websocket.js'
const app = express()
@ -18,3 +19,4 @@ initWebSocketServer()
// 注册路由模块
debugRoutes(app)
authRoutes(app)
oreRoutes(app)

4
server/routes/auth.js

@ -17,7 +17,9 @@ export const authRoutes = (app) => {
fixedUser: 'ENABLE',
},
}
res.json(mockResponse)
setTimeout(() => {
res.json(mockResponse)
}, 2000)
})
app.post(`${baseUrl}/logout`, (req, res) => {
// const { username, password } = req.body

34
server/routes/debug.js → server/routes/control.js

@ -37,4 +37,38 @@ export const debugRoutes = (app) => {
}, Math.floor(Math.random() * (1000 - 500 + 1)) + 500)
}, 1000)
})
app.post('/api/cmd', (req, res) => {
const { commandId, command, params } = req.body
console.log('收到命令:', command, '参数:', params)
// 模拟返回数据
const mockResponse = {
code: '0',
msg: '成功',
data: null,
}
let messageNum = 0
// 异步广播消息
setTimeout(() => {
res.json(mockResponse)
const poll = setInterval(() => {
if (messageNum === 10) {
clearInterval(poll)
}
broadcast({
type: 'cmd_debug',
data: {
commandId,
command,
status: statusList[Math.floor(Math.random() * statusList.length)],
title: `步骤${messageNum}执行完成`,
content: `具体信息${messageNum}`,
},
})
messageNum++
}, Math.floor(Math.random() * (1000 - 500 + 1)) + 500)
}, 1000)
})
}

33
server/routes/ore.js

@ -0,0 +1,33 @@
const baseUrl = '/api/ores'
export const oreRoutes = (app) => {
app.get(`${baseUrl}/list`, (req, res) => {
const mockResponse = {
code: '0',
data: {
list: [
{
id: 1,
oresName: '金矿石2',
createTime: '2025-04-27 15:54:32',
updateTime: '2025-04-27 15:54:32',
craftsList: [
{
id: 1,
createTime: '2025-04-27 15:55:13',
updateTime: '2025-04-27 15:55:13',
name: '工艺2',
steps: '[{"method":"upTray"},{"method":"downTray"},{"method":"addLiquid","params":{"tubeSolList":[{"tubeNum":15,"addLiquidList":[{"solId":15,"volume":20}]}]}},{"method":"moveToSol"},{"method":"moveToHeat"},{"method":"shaking","params":{"second":6}},{"method":"startHeating","params":{"temperature":200}},{"method":"stopHeating"},{"method":"takePhoto"},{"method":"delay","params":{"second":2}}]',
oresId: 1,
},
],
},
],
total: 1,
},
msg: '成功',
}
setTimeout(() => {
res.json(mockResponse)
}, 1000)
})
}

2
src/apis/ore.ts

@ -1,6 +1,6 @@
import http from 'libs/http'
export const getOreList = (): Promise<any> => http.get(`/ores/list`)
export const getOreList = (): Promise<System.PageResponse<Ore.OreItem>> => http.get(`/ores/list`)
export const saveOre = (params: { name: string }): Promise<any> => http.post(`/ores`, params)

1
src/apis/system.ts

@ -1,3 +1,4 @@
import http from 'libs/http'
export const debugControl = <T>(params: System.CmdControlParams<T>): Promise<null> => http.post('/debug/cmd', params)
export const control = <T>(params: System.CmdControlParams<T>): Promise<null> => http.post('/cmd', params)

1
src/assets/images/logout.svg

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="42" height="43" viewBox="0 0 42 43"><g><g><path d="M23.9012,26.80821171875L23.5184,26.80821171875C19.5186,26.80821171875,15.5189,26.80861171875,11.519,26.80821171875C10.926,26.80801171875,10.5396,26.52971171875,10.4443,26.03191171875C10.4255,25.93251171875,10.4273,25.82801171875,10.4273,25.72631171875C10.4266,22.08721171875,10.4265,18.44831171875,10.4268,14.80931171875C10.4269,14.11901171875,10.792,13.75181171875,11.4767,13.75181171875C15.4946,13.75161171875,19.5126,13.75161171875,23.5307,13.75161171875L23.9012,13.75161171875L23.9012,13.42041171875C23.9012,10.18168171875,23.9008,6.94273171875,23.9016,3.70375171875C23.9016,3.25804771875,24.1092,2.90257571875,24.4607,2.76641631875C24.8652,2.60961481875,25.224,2.68183999875,25.5289,3.01164571875C25.7037,3.20077071875,25.8941,3.3747387187499998,26.0736,3.55867171875C28.3386,5.87259171875,30.6032,8.18756171875,32.8676,10.50147171875C35.7762,13.47271171875,38.6848,16.44331171875,41.5933,19.41441171875C42.0776,19.90851171875,42.0802,20.42981171875,41.6017,20.91861171875C37.4394,25.17281171875,33.2774,29.42731171875,29.1138,33.67981171875C27.9297,34.88921171875,26.7392,36.09131171875,25.5561,37.30171171875C25.2516,37.61371171875,24.912,37.75041171875,24.4963,37.58871171875C24.092,37.43171171875,23.9017,37.10601171875,23.9017,36.59371171875C23.901,33.45751171875,23.9012,30.32081171875,23.9012,27.18461171875L23.9012,26.80821171875L23.9012,26.80821171875ZM16.4243,2.86945471875L16.4243,6.546731718749999L16.0943,6.546731718749999C13.049,6.546731718749999,10.0037,6.54631171875,6.95843,6.54694171875C5.02868,6.54723171875,3.60763,8.00513171875,3.60755,9.98472171875C3.60726,16.83461171875,3.61953,23.68451171875,3.59949,30.53391171875C3.59397,32.34621171875,4.94067,33.65191171875,6.18574,33.89041171875C6.46085,33.94251171875,6.74508,33.96611171875,7.02513,33.96681171875C10.0431,33.97221171875,13.0612,33.970111718750005,16.0793,33.970111718750005L16.4189,33.970111718750005L16.4189,37.62641171875C16.3759,37.63521171875,16.3258,37.65491171875,16.2756,37.65491171875C13.0666,37.65491171875,9.85733,37.68831171875,6.64918,37.64061171875C3.51369,37.59461171875,0.737073,35.15841171875,0.138685,32.005211718750004C0.0542352,31.56101171875,0.0129305,31.10101171875,0.0124397,30.64841171875C0.00466952,23.72381171875,-0.0132019,16.79961171875,0.0166111,9.87552171875C0.0290843,6.98330171875,1.43263,4.90707171875,3.88372,3.55774671875C4.74846,3.08148071875,5.70366,2.86639671875,6.68823,2.86388471875C9.8698,2.85509271875,13.0514,2.86053471875,16.2331,2.86074471875C16.2868,2.86078671875,16.3405,2.86560171875,16.4243,2.86945471875Z" fill="#1989FA" fill-opacity="1"/></g></g></svg>

9
src/assets/styles/element.scss

@ -4,7 +4,7 @@
// --el-color-primary: #26509C;
--el-color-primary: #26509C;
//--el-button-active-bg-color: linear-gradient(90deg, #0657C0 24%, #096AE0 101%);
--text-color-primary: #17213c;
//--el-color-success: rgba(88, 162, 95, 1);
@ -16,4 +16,11 @@
//--color-yellow: #e6a23c;
//--color-blue: --el-color-primary;
--el-font-family: 'PingFangSC-Regular', 'PingFang SC', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
}
.el-dialog {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
}

6
src/assets/styles/main.scss

@ -1,9 +1,3 @@
$primary-color: #1989FA;
$success-color: #14A656;
$danger-color: #DF1515;
$warn-color: #EE8223;
$info-color: #909399;
@use './common.scss';
@use './element.scss';

5
src/assets/styles/variable.scss

@ -0,0 +1,5 @@
$primary-color: #1989FA;
$success-color: #14A656;
$danger-color: #DF1515;
$warn-color: #EE8223;
$info-color: #909399;

4
src/components/common/FTDialog/index.vue

@ -63,10 +63,10 @@ watch(
<slot name="footer" />
</div>
<div v-else class="dialog-footer">
<ft-button @click="cancel">
<ft-button :click-handle="cancel">
取消
</ft-button>
<ft-button type="primary" :loading="okLoading" @click="ok">
<ft-button type="primary" :loading="okLoading" :click-handle="ok">
确认
</ft-button>
</div>

13
src/layouts/default.vue

@ -1,5 +1,6 @@
<script setup lang="ts">
import { logout } from 'apis/login'
import logoutIcon from 'assets/images/logout.svg'
import { isClose } from 'libs/socket'
import { delToken } from 'libs/token'
import { formatDateTime } from 'libs/utils'
@ -54,7 +55,10 @@ const logoutHandle = () => {
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="logoutHandle">
退出登录
<div class="logout">
<img :src="logoutIcon" alt="">
<span>退出登录</span>
</div>
</el-dropdown-item>
</el-dropdown-menu>
</template>
@ -292,6 +296,13 @@ const logoutHandle = () => {
animation: swing 1s ease-in-out;
}
}
.logout {
display: flex;
img {
width: 15px;
margin-right: 10px;
}
}
@keyframes swing {
0% {

1
src/main.ts

@ -10,6 +10,7 @@ import { createApp } from 'vue'
import App from './app.vue'
import router from './router'
import 'element-plus/dist/index.css'
import 'assets/styles/main.scss'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {

44
src/stores/homeStore.ts

@ -0,0 +1,44 @@
import { defineStore } from 'pinia'
export const useHomeStore = defineStore('home', {
state: (): Home.HomeStore => ({
heatAreaList: [
{
label: 'A-1',
value: 'heat_module_01',
selected: false,
},
{
label: 'A-2',
value: 'heat_module_01',
selected: false,
},
{
label: 'A-3',
value: 'heat_module_01',
selected: false,
},
{
label: 'A-4',
value: 'heat_module_01',
selected: false,
},
{
label: 'A-5',
value: 'heat_module_01',
selected: false,
},
{
label: 'A-6',
value: 'heat_module_01',
selected: false,
},
],
}),
actions: {
selectChange(index: number) {
this.heatAreaList[index].selected = !this.heatAreaList[index].selected
},
},
persist: true,
})

8
src/views/login/index.vue

@ -26,7 +26,8 @@ const rules = {
}
const loginHandle = async () => {
formRef.value.validate(async (valid: any) => {
try {
const valid = await formRef.value.validate()
if (!valid) {
return
}
@ -34,7 +35,10 @@ const loginHandle = async () => {
setToken('login success')
sys.updateSystemUser({ username: res.username })
await router.push('/')
})
}
catch (e) {
console.log(e)
}
}
</script>

4
vite.config.ts

@ -87,7 +87,7 @@ export default defineConfig(({ mode }) => {
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "@/assets/styles/main.scss" as *;',
additionalData: '@use "@/assets/styles/variable.scss" as *;',
},
},
},
@ -107,4 +107,4 @@ export default defineConfig(({ mode }) => {
},
},
}
})
})
Loading…
Cancel
Save