master
吴普建 12 months ago
parent 6550d40efd
commit 3bd002c96f

@ -39,9 +39,20 @@
<n-grid-item v-for="item in deviceDataList" :key="item.code"> <n-grid-item v-for="item in deviceDataList" :key="item.code">
<div class="device-card" :class="getStatus(item.status).className"> <div class="device-card" :class="getStatus(item.status).className">
<div>设备编码 : {{ item.code }}</div> <div>设备编码 : {{ item.code }}</div>
<div>状态 : {{ getStatus(item.status).text }}</div> <div>设备类型 : 开料机</div>
<div>开始时间 : {{ item.startTime }}</div> <div>运行状态 : {{ getStatus(item.status).text }}</div>
<div>加工数量 : {{ item.count }}</div> <div>产品型号 : {{ item.productModel }}</div>
<div>生产产量 :
<count-to
:start-value="1"
:end-value="item.count"
:duration="800"
:autoplay="true"
:use-easing="true"
easing-function="cubicOut"
class="animated-number"
/></div>
<div>生产速率 : <span style="color:yellow">{{item.rate}}</span> /</div>
<div>结束日期 : {{ item.endTime }}</div> <div>结束日期 : {{ item.endTime }}</div>
</div> </div>
</n-grid-item> </n-grid-item>
@ -59,10 +70,12 @@ import { useResetSearch } from '~/src/utils/common/searchReset';
import {useSearchBtn} from '~/src/hooks/common/useBtn'; import {useSearchBtn} from '~/src/hooks/common/useBtn';
import {formatDate} from '~/src/utils/form/rule'; import {formatDate} from '~/src/utils/form/rule';
import {GradientBg} from './components'; import {GradientBg} from './components';
const {searchForm, reset} = useResetSearch({ const {searchForm, reset} = useResetSearch({
location: '全部' location: '全部'
}); });
const productModels = ['LX25-Y39-002金', 'LX30-Y40-005浅蓝', 'LX35-Z25-006蓝灰', 'LX40-B02-002黑', 'LX30-Y40-005蓝', 'LX35-Z5-004白', 'LX25-A08-007黑'
, 'LX-Y39-030黑', 'LX20-Y30-010灰', 'LX35-Z5-006蓝', 'LX40-B01-003黑', 'LX30-Y42-002蓝', 'LX35-Z15-004单蓝', 'LX25-A08-006灰']; //
interface CardData { interface CardData {
id: string; id: string;
title: string; title: string;
@ -79,6 +92,12 @@ type device = {
count: number; count: number;
endTime: string; endTime: string;
process: string; process: string;
productModel: string;
timerId?: number;
interval: number;
originalCode: string; //
currentModelIndex: number; //
rate?: String;
}; };
const deviceAllList = ref<Array<device>>([]); const deviceAllList = ref<Array<device>>([]);
@ -96,7 +115,7 @@ const cardData = reactive<CardData[]>([
{ {
id: 'visit', id: 'visit',
title: '设备总数', title: '设备总数',
value: 72, value: 0,
unit: '', unit: '',
colors: ['#ec4786', '#b955a4'], colors: ['#ec4786', '#b955a4'],
icon: 'ant-design:bar-chart-outlined' icon: 'ant-design:bar-chart-outlined'
@ -104,7 +123,7 @@ const cardData = reactive<CardData[]>([
{ {
id: 'amount', id: 'amount',
title: '运行中', title: '运行中',
value: 60, value: 40,
unit: '$', unit: '$',
colors: ['#865ec0', '#5144b4'], colors: ['#865ec0', '#5144b4'],
icon: 'ant-design:money-collect-outlined' icon: 'ant-design:money-collect-outlined'
@ -112,7 +131,7 @@ const cardData = reactive<CardData[]>([
{ {
id: 'download', id: 'download',
title: '待机', title: '待机',
value: 10, value: 9,
unit: '', unit: '',
colors: ['#56cdf3', '#719de3'], colors: ['#56cdf3', '#719de3'],
icon: 'carbon:document-download' icon: 'carbon:document-download'
@ -216,7 +235,7 @@ async function getList() {
}); });
} }
}); });
// cardData[0].value = deviceAllList.value.length; cardData[0].value = deviceAllList.value.length;
init(); init();
} }
@ -227,9 +246,11 @@ function deviceEach(item: any) {
value: item.process value: item.process
}); });
} }
deviceAllList.value.push({ let interval = Math.floor((16 + Math.random() * 10)) * 1000;
const newDevice = reactive({
code: item.equipmentCode, code: item.equipmentCode,
status: 0, status: 0,
productModel: productModels[getRandom(1, 4)],
startTime: formatDate( startTime: formatDate(
new Date(getRandom(new Date().getTime() - 1000 * 60 * 60 * 48, new Date().getTime())), new Date(getRandom(new Date().getTime() - 1000 * 60 * 60 * 48, new Date().getTime())),
'yyyy-MM-dd hh:mm:ss' 'yyyy-MM-dd hh:mm:ss'
@ -239,10 +260,40 @@ function deviceEach(item: any) {
new Date(getRandom(new Date().getTime(), new Date().getTime() + 1000 * 60 * 60 * 48)), new Date(getRandom(new Date().getTime(), new Date().getTime() + 1000 * 60 * 60 * 48)),
'yyyy-MM-dd' 'yyyy-MM-dd'
), ),
process: item.process process: item.process,
originalCode: item.equipmentCode,
currentModelIndex: 0,
interval: interval, // 16-24
// count: 0,
timerId: undefined,
rate: (60 * 1000 / interval).toFixed(1)
}); });
startDeviceTimer(newDevice); //
deviceAllList.value.push(newDevice);
}
//
function startDeviceTimer(device: device) {
device.timerId = window.setInterval(() => {
device.count++;
if (device.count >= 200) {
resetDeviceProduction(device);
}
}, device.interval); // 20
}
//
function resetDeviceProduction(device: device) {
device.count = 0;
device.currentModelIndex = (device.currentModelIndex + 1) % productModels.length;
device.productModel = productModels[device.currentModelIndex];
clearInterval(device.timerId);
device.interval = Math.floor((15 + Math.random() * 10)) * 1000; //
device.rate = (60 * 1000 / device.interval).toFixed(1);
startDeviceTimer(device);
} }
function getRandom(min: number, max: number) { function getRandom(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1) + min); return Math.floor(Math.random() * (max - min + 1) + min);
} }
@ -268,15 +319,21 @@ function init() {
deviceDataList.value = deviceAllList.value.filter(item => item.process === searchForm.value.location); deviceDataList.value = deviceAllList.value.filter(item => item.process === searchForm.value.location);
} }
//
let intervalId: number;
// MQTT // MQTT
onMounted(() => { onMounted(() => {
connectToMQTT(); connectToMQTT();
init(); init();
getList(); getList();
}); });
// MQTT // MQTT
onUnmounted(() => { onUnmounted(() => {
deviceAllList.value.forEach(device => {
if (device.timerId) clearInterval(device.timerId);
});
if (client) { if (client) {
client.end(); client.end();
} }
@ -284,8 +341,6 @@ onUnmounted(() => {
</script> </script>
<style scoped> <style scoped>
/* 你的样式 */
.device-card { .device-card {
color: #fff; color: #fff;
border-radius: 8px; border-radius: 8px;
@ -305,4 +360,19 @@ onUnmounted(() => {
.trade-color { .trade-color {
background: linear-gradient(45deg, #fcbc25, #f68057); background: linear-gradient(45deg, #fcbc25, #f68057);
} }
/* 添加数字变化动画 */
.flip-animation {
transition: transform 0.5s;
}
.flip-animation-up {
transform: translateY(-20px);
opacity: 0;
}
.flip-animation-down {
transform: translateY(20px);
opacity: 0;
}
</style> </style>

Loading…
Cancel
Save