import { ref } from 'vue';
|
import { defineStore } from 'pinia';
|
import deviceApi from '@/api/deviceApi';
|
import { useFetchData } from '@/composables/fetchData';
|
|
// 走航设备
|
export const useDeviceStore = defineStore('device', () => {
|
const deviceList = ref([]);
|
const { loading, fetchData } = useFetchData();
|
|
function getDevice(deviceType) {
|
if (deviceType) {
|
return deviceList.value.filter((v) => v.deviceType == deviceType);
|
} else {
|
return deviceList.value;
|
}
|
}
|
|
function fetchDevice(type) {
|
return fetchData((page, pageSize) => {
|
return deviceApi
|
.fethchDevice({ type: type, page, pageSize })
|
.then((res) => {
|
deviceList.value = res.data;
|
return res;
|
});
|
});
|
}
|
|
function deleteDevice(deviceCode) {
|
return fetchData(() => {
|
return deviceApi.deleteDevice(deviceCode).then((res) => {
|
let index = -1;
|
for (let i = 0; i < deviceList.value.length; i++) {
|
const e = deviceList.value[i];
|
if (e.deviceCode == deviceCode) {
|
index = i;
|
break;
|
}
|
}
|
if (index != -1) {
|
deviceList.value.splice(index, 1);
|
}
|
return res;
|
});
|
});
|
}
|
|
return { deviceList, loading, getDevice, fetchDevice, deleteDevice };
|
});
|