Browse Source

状态和报警监听 移到全局

feature/layout_0214
zhangjiming 5 months ago
parent
commit
e1c966ffd6
  1. 18
      src/App.vue
  2. 24
      src/stores/status.ts
  3. 12
      src/views/debug/debug.vue
  4. 7
      src/views/graphite/index.vue

18
src/App.vue

@ -6,8 +6,24 @@ import { onMounted } from "vue";
import { getConfig, getContainerList } from "./services/sysConfig/sysConfig";
import { useSettingStore } from "./stores/setting";
import { getLiquidList } from "./services/liquid/liquidManage";
import { useStatusStore } from "./stores/status";
import { ElMessage } from "element-plus";
const router = useRouter();
const settingStore = useSettingStore();
const statusStore = useStatusStore();
const wsClient = createWebSocket(sharedWsUrl);
wsClient.dataOb.subscribe(data => {
if (data.type === "status") {
statusStore.setStatus(data.data);
} else if (data.type === "warn") {
ElMessage({
message: data.data.message,
type: "warning",
});
}
});
wsClient.connect();
exceptionOb.subscribe(exp => {
if (exp === "invalidToken") {
@ -23,7 +39,7 @@ onMounted(() => {
});
getLiquidList({ pageNum: 1, pageSize: 9999 }).then(res => {
if (res.success) {
settingStore.setLiquidList(res.data.list)
settingStore.setLiquidList(res.data.list);
}
});
getContainerList().then(res => {

24
src/stores/status.ts

@ -1,12 +1,16 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import type { StatusDatagram } from '@/services/socket'
import { ref, computed } from "vue";
import { defineStore } from "pinia";
import * as R from "ramda";
import type { StatusDatagram } from "@/services/socket";
export const useStatusStore = defineStore('status', () => {
const status = ref<StatusDatagram['data']|undefined>()
const setStatus = (data: StatusDatagram['data']) => {
status.value = data
}
export const useStatusStore = defineStore("status", () => {
const status = ref<StatusDatagram["data"] | undefined>();
const setStatus = (data: StatusDatagram["data"]) => {
if (!R.equals(status.value, data)) {
console.log("status: ", data);
status.value = data;
}
};
return { status, setStatus }
})
return { status, setStatus };
});

12
src/views/debug/debug.vue

@ -29,12 +29,12 @@
v-model="y"
class="rounded-sm px-1 w-16" />
Z:<input type="number" v-model="z" class="rounded-sm px-1 w-16" />
<label for="">当前位置</label>
<!-- <label for="">当前位置</label>
<span class="text-warn">{{
`${statusStore.status?.railArm.x || 0},${statusStore.status?.railArm.y || 0},${
statusStore.status?.railArm.z || 0
}`
}}</span>
}}</span> -->
</div>
<button class="btn-light px-2 py-1 min-w-20" @click="onCmdClick('moveMachineArm')">移动机械臂</button>
</div>
@ -212,7 +212,6 @@ const shakeUpSpeed = ref(5);
onMounted(() => {
const wsClient = createWebSocket(sharedWsUrl);
const subscription = wsClient.dataOb.subscribe(data => {
console.log(data);
if (data.type === "cmd") {
const cmdInfo = getTxnRecord(data.data.commandId, "debug");
if (cmdInfo) {
@ -224,13 +223,6 @@ onMounted(() => {
type: data.data.success ? "success" : "error",
});
}
} else if (data.type === "status") {
statusStore.setStatus(data.data);
} else if (data.type === "warn") {
ElMessage({
message: data.data.message,
type: "warning",
});
}
});
wsClient.connect();

7
src/views/graphite/index.vue

@ -147,13 +147,6 @@ onMounted(() => {
type: data.data.success ? "success" : "error",
});
}
} else if (data.type === "status") {
statusStore.setStatus(data.data);
} else if (data.type === "warn") {
ElMessage({
message: data.data.message,
type: "warning",
});
}
});
wsClient.connect();

Loading…
Cancel
Save