Browse Source

优化ts

master
LiLongLong 5 months ago
parent
commit
0eb3c932c0
  1. 6
      src/components/HeaderBar.vue
  2. 12
      src/services/globalCmd/cmdTypes.ts
  3. 23
      src/services/globalCmd/globalCmd.ts
  4. 6
      src/services/matrix/craft.ts
  5. 2
      src/services/matrix/manage.ts
  6. 12
      src/services/matrix/type.ts
  7. 10
      src/stores/setting.ts
  8. 20
      src/views/History.vue
  9. 106
      src/views/debug/index.vue
  10. 21
      src/views/matrixCraft/index.vue
  11. 2
      src/views/matrixManage/add.vue
  12. 25
      src/views/matrixManage/matrixList.vue
  13. 7
      src/views/matrixManage/type.ts

6
src/components/HeaderBar.vue

@ -1,6 +1,6 @@
<template>
<header class="h-[--headerHeight] bg-primary flex items-center text-white">
<img class="w-[83px] ml-6" src="@/assets/logo.png" alt="logo" />
<img class="w-[83px] ml-6" src="@/assets/logo.png" alt="logo" @click="goHome"/>
<div v-if="route.path !== '/home'" class="w-0.5 h-5 bg-white mx-3"></div>
<p class="text-lg">{{ pageNameMap[route.path] }}</p>
@ -60,6 +60,10 @@ onMounted(() => {
});
});
function goHome(){
router.push('/home')
}
const pageNameMap: Record<string, string> = {
"/": "基质喷涂转印仪",
"/environment": "环境设置",

12
src/services/globalCmd/cmdTypes.ts

@ -78,3 +78,15 @@ export type ControlValueType = {
isOpen: boolean;
};
};
export type Light = {
brightness:number
}
export type Axis ={
index: number;
x1: number;
y1: number;
x2: number;
y2: number;
}

23
src/services/globalCmd/globalCmd.ts

@ -1,13 +1,13 @@
import httpRequest, { type BaseResponse } from "../httpRequest";
import { addTxnRecord } from "../txn";
import type { VoltageType, ControlValueType, SyringeType, WorkType } from "./cmdTypes";
import type { VoltageType, ControlValueType, SyringeType, WorkType, Light, MachineryType } from "./cmdTypes";
//移动电机
export function moveMotorToPosition(params: { commandName: string; params: Record<string, any> }) {
export function moveMotorToPosition(params:MachineryType) {
const commandId = addTxnRecord({ ...params, category: "debug" });
return httpRequest<BaseResponse<string>>({
url: "/api/cmd/moveMotorToPosition",
params: { ...params, commandId },
params: { params, commandId, commandName: "moveMotorToPosition"},
method: "POST",
});
}
@ -17,7 +17,7 @@ export function switchThreeWayValve(params: { type: string }) {
const commandId = addTxnRecord({ ...params, category: "debug" });
return httpRequest<BaseResponse<string>>({
url: "/api/cmd/switchThreeWayValve",
params: { ...params, commandId },
params: { params, commandId },
method: "POST",
});
}
@ -55,7 +55,7 @@ export function turnOffSyringePump() {
//开始喷涂
export function startWork(params: WorkType) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/startWork", params, method: "POST" });
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/startWork", params:{params}, method: "POST" });
}
export function stopWork() {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/stopWork", params: {}, method: "POST" });
@ -71,6 +71,7 @@ export function pushInTray(params: Record<string, any>) {
export function rotate(params: any) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/rotate", params, method: "POST" });
}
export function setMotorSpeed(params: { axis: "X" | "Y" | "Z"; speed: number }) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/setMotorSpeed", params: { params }, method: "POST" });
}
@ -106,16 +107,16 @@ export function stopDehumidify() {
}
//停止电机
export function stopMotor(params: any) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/stopMotor", params, method: "POST" });
export function stopMotor(params: {axis:string}) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/stopMotor", params:{params}, method: "POST" });
}
//关闭照明灯
export function turnOffLightPanel(params: any) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/turnOffLightPanel", params, method: "POST" });
export function turnOffLightPanel(params: Light) {
return httpRequest<BaseResponse>({ url: "/api/cmd/turnOffLightPanel", params:{params}, method: "POST" });
}
//开启照明灯
export function turnOnLightPanel(params: any) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/turnOnLightPanel", params, method: "POST" });
export function turnOnLightPanel(params: {brightness:number}) {
return httpRequest<BaseResponse<string>>({ url: "/api/cmd/turnOnLightPanel", params:{params}, method: "POST" });
}

6
src/services/matrix/craft.ts

@ -1,9 +1,9 @@
import type { WorkType } from "../globalCmd/cmdTypes";
import httpRequest, { type BaseResponse } from "../httpRequest";
import type { CraftItem } from "@/services/matrix/type";
import type { CraftItem, HistoryItem } from "@/services/matrix/type";
export function getList(params: { pageSize: number; pageNum: number }) {
return httpRequest<BaseResponse>({
return httpRequest<BaseResponse<{list:CraftItem[], total:number}>>({
url: "/api/matrixCraft/list",
params: { ...params },
method: "POST",
@ -42,7 +42,7 @@ export function delCraft(ids:string){
}
export function getHistoryList(params:{pageSize:number, pageNum:number}){
return httpRequest<BaseResponse>({
return httpRequest<BaseResponse<{list: HistoryItem[], total:number}>>({
url: `/api/log/list`,
params: { ...params },
method: "GET",

2
src/services/matrix/manage.ts

@ -27,7 +27,7 @@ export function updateMatrix(params:{name: string, id: number}){
}
export function del(ids:string){
return httpRequest<BaseResponse>({
return httpRequest<BaseResponse<{matrixName:string[]}>>({
url: `/api/matrix/${ids}`,
method: "DELETE",
});

12
src/services/matrix/type.ts

@ -1,4 +1,5 @@
import type { WorkType } from "../globalCmd/cmdTypes";
import History from '@/views/History.vue';
export type ResponseParams = {
pageNum: number;
@ -13,7 +14,7 @@ export const defaultParams = {
export type MatrixItem = {
id: number;
name: string;
isSelected?: boolean;
matrixName:string;
};
export type MatrixItemList = {
@ -24,5 +25,12 @@ export type MatrixItemList = {
export type CraftItem = {
id: number;
name: string;
matrixId: number;
matrixId: number | null;
} & WorkType;
export type HistoryItem = {
id: number;
matrixId: number;
matrixInfo:string;
status: 1 | 2;
}

10
src/stores/setting.ts

@ -1,16 +1,24 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import * as R from "ramda";
import type { MatrixItem } from "@/services/matrix/type";
import type { CraftItem, MatrixItem } from "@/services/matrix/type";
export const useSettingStore = defineStore("setting", () => {
//基质列表
const matrixList = ref<MatrixItem[]>([]);
const setMatrixList = (data: MatrixItem[]) => {
matrixList.value = data;
};
//工艺列表
const matrixCraftList = ref<CraftItem[]>([]);
const setMatrixCraftList = (data: CraftItem[]) => {
matrixCraftList.value = data;
};
return {
matrixList,
setMatrixList,
matrixCraftList,
setMatrixCraftList
};
});

20
src/views/History.vue

@ -33,14 +33,14 @@
import { ref, onMounted } from 'vue'
import { getHistoryList, delHistoryLog} from '@/services/matrix/craft'
import { useSettingStore } from '@/stores/setting'
import type { CraftItem } from "@/services/matrix/type";
import type { CraftItem, HistoryItem } from "@/services/matrix/type";
import { ElMessage, ElMessageBox } from "element-plus";
import route_v from "@/assets/route_vertical.png";
import route_h from "@/assets/route_horizontal.png";
let total = ref()
const loading = ref(false)
const settingStore = useSettingStore()
let tableData = ref<any>([])
let tableData = ref<HistoryItem[]>([])
const defaultCraft: CraftItem = {
id: 1,
name: '',
@ -58,7 +58,6 @@
};
onMounted(()=>{
tableData.value = settingStore.matrixList
getLogList()
})
@ -69,16 +68,15 @@
pageSize:10,
}
loading.value = true;
getHistoryList(params).then((res:any)=>{
let list = <any>[]
res.data.list.forEach((item:any)=>{
getHistoryList(params).then((res)=>{
let list = <HistoryItem[]>[]
res.data.list.forEach((item)=>{
let { matrixInfo } = item
if(matrixInfo){
matrixInfo = JSON.parse(matrixInfo)
let matrixData = JSON.parse(matrixInfo)
item ={
...item,
...matrixInfo,
...matrixData,
}
}
list.push(item)
@ -92,12 +90,12 @@
const historyTableRef = ref()
const onDel = () => {
const selectRows = historyTableRef.value.getSelectionRows()
const selectRows = historyTableRef.value.getSelectionRows() as HistoryItem[]
if(!selectRows.length){
ElMessage.error('请选择要删除的数据')
return;
}
const ids = selectRows.map((item:any) => item.id)
const ids = selectRows.map((item) => item.id)
ElMessageBox.confirm('确认删除此条数据吗?','提示',{
confirmButtonText: '确认',
cancelButtonText: '取消',

106
src/views/debug/index.vue

@ -338,6 +338,7 @@ import type {
SyringeParams,
VoltageType,
ControlValueType,
Axis,
} from "@/services/globalCmd/cmdTypes";
import {
moveMotorToPosition,
@ -349,7 +350,6 @@ import {
turnOffSyringePump,
startWork,
stopWork,
rotate,
stopMotor,
turnOffLightPanel,
turnOnLightPanel,
@ -359,6 +359,8 @@ import {
type WashType,
startWash
} from "@/services/globalCmd/globalCmd";
import type { BaseResponse } from "@/services/httpRequest";
import type { WorkType } from '../../services/globalCmd/cmdTypes';
const activeName = ref("debug");
const voltageValue = ref();
const syringeForm = ref<SyringeParams>({
@ -366,15 +368,27 @@ const syringeForm = ref<SyringeParams>({
time: 0,
direction: "1",
});
const workForm = ref<Record<string, any>>({
const workForm = ref<WorkType>({
routeType: 1,
space: 2,
nitrogenFlowVelocity: 1,
nitrogenAirPressure: 1,
matrixFlowVelocity: 1,
voltage: 1,
needPower: false,
height: 6,
movementSpeed: 10,
position: [],
});
const axis = ref<any>({
const axis = ref<Axis>({
index: 0,
x1: 10,
y1: 10,
x2: 20,
y2: 20,
});
const rotateForm = ref<{ axis: "X" | "Y" | "Z"; speed: number }>({ axis: "X", speed: 20 });
let subscription: any;
watch(voltageValue,(newVal)=>{
if(newVal > 5000){
@ -389,41 +403,35 @@ watch(voltageValue,(newVal)=>{
onMounted(() => {
//websocket
const wsClient = createWebSocket(sharedWsUrl);
subscription = wsClient.dataOb.subscribe(data => {
//@ts-ignore
if (data.type == "moveMotorToPosition") {
//@ts-ignore
ElMessage.success(data.data.text);
}
const subscription = wsClient.dataOb.subscribe(data => {
});
wsClient.connect();
});
onUnmounted(() => {
subscription && subscription.unsubscribe();
onUnmounted(() => {
subscription && subscription.unsubscribe();
});
});
const machineryForm = ref<Record<string, string>>({});
const onMoveMachinery = (axis: string) => {
if (!axis) return;
const params = {
commandName: "moveMotorToPosition",
params: <MachineryType>{
const params = <MachineryType>{
axis,
position: parseFloat(machineryForm.value[axis]),
},
};
moveMotorToPosition(params).then((res: any) => {
moveMotorToPosition(params).then((res) => {
console.log("-----moveMotorToPosition----res---", res);
success(res);
});
};
const onSwitchThreeWayValve = (type: string) => {
const params = <any>{
params: { type },
const params = {
type,
};
switchThreeWayValve(params).then((res: any) => {
switchThreeWayValve(params).then((res) => {
console.log("---onSwitchThreeWayValve---res---", res);
success(res);
});
@ -436,14 +444,14 @@ const onControlValve = (type: ControlNitrogen, open: boolean) => {
isOpen: open,
},
};
controlValve(params).then((res: any) => {
controlValve(params).then((res) => {
console.log("---onControlValve---res---", res);
success(res);
});
};
const onStopDehumidify = () => {
stopDehumidify().then((res: any) => {
stopDehumidify().then((res) => {
success(res);
});
};
@ -459,7 +467,7 @@ function onStartWash(type: WashType) {
}
const onStopWash = () => {
stopWash({}).then((res: any) => {
stopWash({}).then((res) => {
success(res);
});
};
@ -469,7 +477,7 @@ const onTurnOnHighVoltage = () => {
const params = <VoltageType>{
params: { voltage: +voltageValue.value },
};
turnOnHighVoltage(params).then((res: any) => {
turnOnHighVoltage(params).then((res) => {
console.log("---onTurnOnHighVoltage- 电压控制 on --res---", res);
success(res);
});
@ -477,7 +485,7 @@ const onTurnOnHighVoltage = () => {
//
const onTurnOffHighVoltage = () => {
turnOffHighVoltage().then((res: any) => {
turnOffHighVoltage().then((res) => {
console.log("---onTurnOffHighVoltage- 电压控制 off--res---", res);
success(res);
});
@ -493,35 +501,31 @@ const onTurnOnSyringePump = () => {
// time: syringeForm.value.time,
},
};
turnOnSyringePump(params).then((res: any) => {
turnOnSyringePump(params).then((res) => {
console.log("---onTurnOffHighVoltage- 电泵开启--res---", res);
success(res);
});
};
const onTurnOffSyringePump = () => {
turnOffSyringePump().then((res: any) => {
turnOffSyringePump().then((res) => {
success(res);
});
};
const onStartWork = () => {
const params = <any>{
params: {
const params = <WorkType>{
...workForm.value,
position: <any>[axis.value],
},
position: [axis.value],
};
startWork(params).then((res: any) => {
console.log("startWork-----", startWork);
startWork(params).then((res) => {
success(res);
});
};
function onStopWork() {
stopWork().then((res: any) => {
console.log("startWork-----", startWork);
stopWork().then((res) => {
success(res);
});
}
@ -531,51 +535,35 @@ const onRotate = () => {
...rotateForm.value,
};
setMotorSpeed(params).then((res: any) => {
setMotorSpeed(params).then((res) => {
success(res);
});
};
const onStopRotate = (axis: string) => {
const params = {
params: {
axis,
},
};
stopMotor(params).then((res: any) => {
console.log("res--停止电机-");
stopMotor({axis}).then((res) => {
success(res);
});
};
type resData = {
code: number;
msg: string;
};
let brightness = ref()
const onTurnOnLightPanel = () => {
const params = {
params: {
brightness: brightness.value
},
};
turnOnLightPanel(params).then((res: any) => {
turnOnLightPanel({brightness: brightness.value}).then(res => {
success(res);
});
};
function onTurnOffLightPanel() {
const params = {
params: {
brightness: 40,
},
brightness: 40,
};
turnOffLightPanel(params).then((res: any) => {
turnOffLightPanel(params).then((res) => {
success(res);
});
}
function success(data: resData) {
function success(data:BaseResponse) {
if (data && data.msg == "ok") {
ElMessage.success("发送成功");
} else {

21
src/views/matrixCraft/index.vue

@ -51,6 +51,7 @@
</main>
<footer class="footer w-[93vw]">
<el-pagination background layout="prev, pager, next" :total="total" />
</footer>
<el-dialog v-model="sprayVisible">
@ -93,12 +94,14 @@
import { ElMessage, ElMessageBox } from "element-plus";
import route_h from "@/assets/route_horizontal.png";
import route_v from "@/assets/route_vertical.png";
let total = ref()
import type { MatrixItem } from '../matrixManage/type';
let total = ref(0)
const settingStore = useSettingStore()
let sprayVisible = ref(false)
let tableData = ref<any>([])
let tableData = ref<MatrixItem[]>([])
let operType = ref('add')
let loading = ref(false)
const searchForm = ref({
matrixCraftName:undefined,
matrixId:undefined,
@ -126,11 +129,9 @@
}else{
onMatrixChange(null)
}
console.log('defaultSprayData---', defaultSprayData)
})
onMounted(()=>{
let matrixList = settingStore.matrixList
tableData.value = matrixList;
if(matrixList && matrixList.length){
onMatrixChange(matrixList[0].id)
}else{
@ -149,8 +150,10 @@
}
loading.value = true;
getList(params).then((res:any)=>{
tableData.value = res.data.list
getList(params).then((res)=>{
let list = res.data.list
settingStore.setMatrixCraftList(list)
tableData.value = list
total.value = res.data.total
}).finally(()=>{
loading.value = false;
@ -176,12 +179,12 @@
}
const onDel = () => {
const selectRows = craftTableRef.value.getSelectionRows()
const selectRows = craftTableRef.value.getSelectionRows() as CraftItem[]
if(!selectRows.length){
ElMessage.error('请选择要删除的数据')
return;
}
const ids = selectRows.map((item:any) => item.id)
const ids = selectRows.map(item => item.id)
ElMessageBox.confirm('确认删除此条数据吗?','提示',{
confirmButtonText: '确认',
cancelButtonText: '取消',
@ -252,7 +255,7 @@
}
function onMatrixChange(val: any) {
function onMatrixChange(val:number|null) {
defaultSprayData.value.matrixId = val
}

2
src/views/matrixManage/add.vue

@ -24,7 +24,7 @@
})
const addVisible = ref(false)
let addForm = ref({name:''})
const addFormRef:any = ref<any>()
const addFormRef = ref()
let operateType = 'add'
const showDialog = (type:string, craftItem:{name:string}) => {

25
src/views/matrixManage/matrixList.vue

@ -32,18 +32,18 @@
</footer>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import type { MatrixItem } from './type'
import { ref, onMounted } from 'vue'
import type { MatrixItem, resMatrix } from './type'
import { ElMessage, ElMessageBox } from "element-plus";
import {getList, add, updateMatrix, del} from '@/services/matrix/manage'
import { useSettingStore } from "@/stores/setting";
import Add from './add.vue'
const settingStore = useSettingStore();
const addRef:any = ref()
const addRef = ref()
const matrixList = ref<Array<MatrixItem>>([])
const loading = ref(false)
const totalData = ref()
const totalData = ref(0)
const searchForm = ref({
matrixName:'',
})
@ -81,8 +81,8 @@
const matrixTableRef = ref()
const onEdit = () => {
const selectRows = matrixTableRef.value.getSelectionRows()
const selectRows = matrixTableRef.value.getSelectionRows() as MatrixItem[]
console.log('selectRows---', selectRows)
if(selectRows.length !== 1){
ElMessage.error('请选择一条数据进行编辑')
return;
@ -115,30 +115,29 @@
}
const onDel = ()=>{
const selectRows = matrixTableRef.value.getSelectionRows()
const selectRows = matrixTableRef.value.getSelectionRows() as MatrixItem[]
if(selectRows.length !== 1){
ElMessage.error('请选择要删除的数据')
return;
}
const ids = selectRows.map((item:any) => item.id)
const ids = selectRows.map(item => item.id)
ElMessageBox.confirm('确认删除此条数据吗?','提示',{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}).then(()=>{
del(ids.join(',')).then((res:any) => {
del(ids.join(',')).then((res) => {
if(res.success){
ElMessage.success("删除成功")
const { data } = res;
if(data && data.length){
let names = data.map((item:any)=> item.matrixName).join(',')
const { matrixName } = res.data;
if(matrixName && matrixName.length){
let names = matrixName.map(name=> name).join(',')
ElMessage.warning(`${names}有关联的工艺,不可删除操作`)
}
getMatrixList()
}else{
ElMessage.error(res.msg)
}
})
})

7
src/views/matrixManage/type.ts

@ -1,6 +1,11 @@
export type MatrixItem = {
id: number;
name: string;
isSelected?: boolean;
};
export type resMatrix<T> = {
code: string;
data: T;
msg: string;
success: boolean;
}
Loading…
Cancel
Save