DauXJB4s.js
2.02 KB
import{c as i,Z as u}from"./Bd-k_Jez.js";import{a9 as p,aa as d}from"./BtEn9SvP.js";function T(e){return i(u,e)}const y=["robot","controller","vision","chassis","communication","power","sensor","actuator","other"];function c(e){return typeof e=="object"&&e!==null}function f(e){return typeof e=="string"&&y.includes(e)}function g(e){return Array.isArray(e)?e.filter(c).map(r=>{const t=r.category;return{id:Number(r.id??0),name:typeof r.name=="string"?r.name:"",model:typeof r.model=="string"?r.model:"",category:f(t)?t:"other",lengthMm:Number(r.lengthMm??0),widthMm:Number(r.widthMm??0),heightMm:Number(r.heightMm??0),weightKg:Number(r.weightKg??0),hasBattery:!!r.hasBattery,batterySpec:typeof r.batterySpec=="string"?r.batterySpec:void 0,description:typeof r.description=="string"?r.description:void 0,updatedAt:typeof r.updatedAt=="string"?r.updatedAt:""}}).filter(r=>r.id>0&&r.name.length>0):[]}function n(e,r){if(!c(e))return{success:!1,errorCode:"REQUEST_FAILED",message:r};const t=typeof e.message=="string"&&e.message.length>0?e.message:r;return{success:typeof e.success=="boolean"?e.success:!1,errorCode:typeof e.errorCode=="string"?e.errorCode:null,message:t}}const m=()=>{const e=d();return{getDeviceTypes:()=>e.useApiFetch("/api/base-info/device-types",{transform:g,default:()=>[]}),createDeviceType:async s=>{try{const o=await e.request("/api/base-info/device-types",{method:"POST",body:s});return n(o,"创建设备类型失败。")}catch{return{success:!1,errorCode:"REQUEST_FAILED",message:"创建设备类型失败。"}}},updateDeviceType:async(s,o)=>{try{const a=await e.request(`/api/base-info/device-types/${s}`,{method:"PUT",body:o});return n(a,"更新设备类型失败。")}catch{return{success:!1,errorCode:"REQUEST_FAILED",message:"更新设备类型失败。"}}},deleteDeviceType:async s=>{try{const o=await e.request(`/api/base-info/device-types/${s}`,{method:"DELETE"});return n(o,"删除设备类型失败。")}catch{return{success:!1,errorCode:"REQUEST_FAILED",message:"删除设备类型失败。"}}}}},D=p(m);export{y as D,T as n,D as u};