import { ref, reactive, onMounted } from "vue";
|
import axios from "@/assets/js/axios";
|
|
/**
|
* 查询所有在用电池信息
|
*/
|
function getBatts() {
|
return axios({
|
method: "GET",
|
url: "binf/getAllSinfBinf1",
|
});
|
}
|
|
/**
|
* 查询所有在用电源信息
|
*/
|
function getPowers() {
|
return axios({
|
method: "GET",
|
url: "binf/getAllSinfBinf2",
|
});
|
}
|
|
/**
|
* type: 0 电池 ; 1 电源
|
*/
|
export default (type = 0) => {
|
const batts = reactive([]);
|
const powers = reactive([]);
|
|
async function getBattList() {
|
let res = await getBatts();
|
batts.length = 0;
|
let { code, data, data2 } = res.data;
|
if (code && data) {
|
batts.push(...data2);
|
}
|
}
|
|
async function getPowerList() {
|
let res = await getPowers();
|
powers.length = 0;
|
let { code, data, data2 } = res.data;
|
if (code && data) {
|
powers.push(...data2);
|
}
|
}
|
|
onMounted(() => {
|
switch (type) {
|
case 0:
|
getBattList();
|
break;
|
case 1:
|
getPowerList();
|
break;
|
default:
|
console.error("type参数不正确 ", type);
|
break;
|
}
|
});
|
|
return { batts, powers, getBattList, getPowerList };
|
};
|