import{M as _,a0 as le,av as ce,aw as pe,ax as ue}from"./index.17037962789732.js";import"./index.1703796278973300.js";import"./index.170379627897315.js";import"./index.170379627897317.js";import"./index.1703796278973301.js";import"./index.1703796278973302.js";import"./index.170379627897332.js";import"./index.1703796278973303.js";import"./index.170379627897339.js";import"./index.170379627897316.js";import"./index.170379627897314.js";import"./index.1703796278973304.js";import"./index.1703796278973305.js";import"./index.1703796278973306.js";import{_ as de}from"./index.170379627897313.js";import"./index.170379627897319.js";import"./index.170379627897327.js";import"./index.170379627897336.js";import{_ as me}from"./index.vue_vue_type_script_setup_true_name_PermissionButton_lang.1703796278973.js";import{k as ve,_ as ye,x as fe,y as _e,ah as he,ai as ke}from"./instance.1703796278973.js";import{a as Ce,B as K,L as U,T as H}from"./comm.1703796278973.js";import{_ as xe}from"./modal.vue_vue_type_script_setup_true_name_DeviceImport_lang.17037962789732.js";import{_ as Ie}from"./index.vue_vue_type_script_setup_true_lang.170379627897330.js";import{_ as be}from"./index.vue_vue_type_script_setup_true_lang.170379627897332.js";import{_ as ge}from"./index.vue_vue_type_script_setup_true_lang.170379627897325.js";import{b as we,g as Te,q as $e,k as Se}from"./product.17037962789737.js";import{q as Ae}from"./category.1703796278973.js";import{h as De}from"./system.1703796278973.js";import{a as Oe}from"./dayjs.min.1703796278973.js";import{_ as Pe}from"./index.vue_vue_type_script_setup_true_lang.17037962789733.js";import{_ as Ee}from"./index.vue_vue_type_script_setup_true_lang.170379627897333.js";import{u as Ne}from"./useParams.1703796278973.js";import{a as qe}from"./setting.1703796278973.js";import{d as Be,k as m,p as je,r as w,o as y,x as q,b as o,a as i,u as l,t as z,M as Re,z as k,A as T,c as x,F as B,h as Ve,B as A}from"./vue.1703796278973.js";import"./index.17037962789733.js";import"./isArray.1703796278973.js";import"./editor.api.1703796278973.js";import"./preload-helper.1703796278973.js";import"./monaco.contribution.1703796278973.js";import"./index.170379627897335.js";import"./_plugin-vue_export-helper.1703796278973.js";import"./index.170379627897320.js";import"./index.170379627897321.js";import"./permission.1703796278973.js";import"./index.170379627897337.js";import"./index.170379627897318.js";import"./index.1703796278973311.js";import"./product.17037962789734.js";import"./index.170379627897322.js";import"./index.170379627897323.js";import"./index.170379627897324.js";import"./index.170379627897325.js";import"./index.170379627897326.js";import"./index.170379627897328.js";import"./Item.1703796278973.js";import"./index.170379627897333.js";import"./index.170379627897334.js";import"./default.1703796278973.js";import"./consts.1703796278973.js";import"./404.1703796278973.js";import"./file.17037962789732.js";import"./index.170379627897329.js";import"./index.170379627897330.js";import"./index.17037962789736.js";import"./utils.1703796278973.js";import"./moment.1703796278973.js";import"./eventsource.1703796278973.js";import"./plugin.17037962789732.js";import"./index.1703796278973157.js";import"./accessConfig.1703796278973.js";import"./encodeQuery.1703796278973.js";const Me=["src"],Fe={style:{"font-size":"16px","font-weight":"600"}},Je=k("div",{class:"card-item-content-text"}," 设备类型 ",-1),Le=k("div",{class:"card-item-content-text"}," 产品名称 ",-1),da=Be({__name:"index",setup(Ye){const h=m({}),C=m({}),c=m([]),$=m(!1),D=m(!1),I=m(!1),O=m({}),S=m(!1),P=m(""),E=m(""),b=m(!1),j=Ne(),G=De(),R=e=>Array.isArray(e)&&e.length?(e||[]).map(t=>({...t,id:`classifiedId is ${t.id}`,children:R(t.children)})):[],V=[{title:"ID",dataIndex:"id",key:"id",ellipsis:!0,search:{type:"string",defaultTermType:"eq"}},{title:"设备名称",dataIndex:"name",key:"name",ellipsis:!0,search:{type:"string",first:!0}},{title:"产品名称",dataIndex:"productName",key:"productName",ellipsis:!0,search:{type:"select",rename:"productId",options:()=>new Promise(e=>{we({paging:!1}).then(t=>{e(t.result.map(a=>({label:a.name,value:a.id})))})})}},{title:"创建时间",dataIndex:"createTime",key:"createTime",scopedSlots:!0,width:200,search:{type:"date"}},{title:"状态",dataIndex:"state",key:"state",scopedSlots:!0,search:{type:"select",options:[{label:"禁用",value:"notActive"},{label:"离线",value:"offline"},{label:"在线",value:"online"}]}},{key:"classifiedId",dataIndex:"classifiedId",title:"产品分类",hideInTable:!0,search:{type:"treeSelect",options:()=>new Promise(e=>{Ae({paging:!1}).then(t=>{e(R(t.result))})})}},{key:"accessProvider",title:"网关类型",dataIndex:"accessProvider",valueType:"select",hideInTable:!0,search:{type:"select",options:()=>new Promise(e=>{Te().then(t=>{const a=t.result||[];e(qe(a).map(s=>({...s,value:`accessProvider is ${s.id}`})))})})}},{key:"accessId",dataIndex:"accessId",title:"接入方式",hideInTable:!0,search:{type:"select",options:()=>new Promise(e=>{$e({}).then(t=>{e(t.result.map(a=>({label:a.name,value:`accessId is ${a.id}`})))})})}},{dataIndex:"deviceType",title:"设备类型",valueType:"select",hideInTable:!0,search:{type:"select",options:[{label:"直连设备",value:"device"},{label:"网关子设备",value:"childrenDevice"},{label:"网关设备",value:"gateway"}]}},{dataIndex:"id$dim-assets",title:"所属组织",hideInTable:!0,search:{type:"treeSelect",options:()=>new Promise(e=>{Se({}).then(t=>{const a=s=>{const r=[];return s.forEach(d=>{d.children&&(d.children=a(d.children)),r.push({...d,id:JSON.stringify({assetType:"device",targets:[{type:"org",id:d.id}]})})}),r};e(a(t.result))})})}},{title:"说明",dataIndex:"describe",key:"describe",ellipsis:!0,search:{type:"string"}},{title:"操作",key:"action",fixed:"right",width:200,scopedSlots:!0}],M=(e,t,a)=>{e!=null&&e.terms&&Array.isArray(e.terms)&&(e==null?void 0:e.terms.length)>0?((e==null?void 0:e.terms)||[]).map((s,r)=>{s!=null&&s.type&&(t[`${a?`${a}.`:""}terms[${r}].type`]=s.type),M(s,t,`${a?`${a}.`:""}terms[${r}]`)}):!(e!=null&&e.terms)&&Object.keys(e).length>0&&Object.keys(e).forEach(s=>{e[s]&&(t[`${a?`${a}.`:""}${s}`]=e[s])})};je(()=>{j.params.value.type==="add"&&J(),j.params.value.type==="import"&&($.value=!0)});const F=e=>{const t={};if(M(e,t),Object.keys(t).length){const a=new URLSearchParams;return Object.keys(t).forEach(s=>{console.log(t[s]),a.append(s,t[s])}),a.toString()}else return""},J=()=>{I.value=!0,O.value={}},L=e=>{G.jumpPage("device/Instance/Detail",{id:e})},Y=(e,t)=>{var s,r,d;if(!e)return[];const a=[{key:"view",text:"查看",tooltip:{title:"查看"},icon:"EyeOutlined",onClick:()=>{L(e.id)}},{key:"update",text:"编辑",tooltip:{title:"编辑"},icon:"EditOutlined",onClick:()=>{I.value=!0,O.value=e}},{key:"action",text:((s=e.state)==null?void 0:s.value)!=="notActive"?"禁用":"启用",tooltip:{title:((r=e.state)==null?void 0:r.value)!=="notActive"?"禁用":"启用"},icon:e.state.value!=="notActive"?"StopOutlined":"CheckCircleOutlined",popConfirm:{title:`确认${e.state.value!=="notActive"?"禁用":"启用"}?`,onConfirm:async()=>{var f;let v;e.state.value!=="notActive"?v=await ye(e.id):v=await fe(e.id),v&&v.status===200?(_.success("操作成功!"),(f=h.value)==null||f.reload()):_.error("操作失败!")}}},{key:"delete",text:"删除",disabled:((d=e.state)==null?void 0:d.value)!=="notActive",tooltip:{title:e.state.value!=="notActive"?"已启用的设备不能删除":"删除"},popConfirm:{title:"确认删除?",onConfirm:async()=>{var f;(await _e(e.id)).status===200?(_.success("操作成功!"),(f=h.value)==null||f.reload()):_.error("操作失败!")}},icon:"DeleteOutlined"}];return t==="card"?a.filter(v=>v.key!=="view"):a},X=e=>{c.value=[...e]},Q=e=>{if(b.value)if(c.value.includes(e.id)){const t=c.value.findIndex(a=>a===e.id);c.value.splice(t,1)}else c.value=[...c.value,e.id];else L(e.id)},W=()=>{c.value=[]},Z=e=>(e==null||e.terms.map(t=>t.terms.map(a=>(a.column.includes("$product-info")&&(a.column="productId",a.termType="product-info"),a))),e),ee=[{key:"export",text:"批量导出设备",permission:"device/Instance:export",icon:"ExportOutlined",onClick:()=>{D.value=!0}},{key:"import",text:"批量导入设备",permission:"device/Instance:import",icon:"ImportOutlined",onClick:()=>{$.value=!0}},{key:"activeAll",text:"启用全部设备",ghost:!0,type:"primary",permission:"device/Instance:action",icon:"CheckCircleOutlined",popConfirm:{title:"确认启用全部设备?",onConfirm:()=>{E.value="active";const e=`${K}/device-instance/deploy?:X_Access_Token=${U.get(H)}&${F(Z(C.value))}`;P.value=e,S.value=!0}}},{key:"sync",text:"同步设备状态",type:"primary",ghost:!0,icon:"SyncOutlined",onClick:()=>{E.value="sync";const e=`${K}/device-instance/state/_sync?:X_Access_Token=${U.get(H)}&${F(C.value)}`;P.value=e,S.value=!0}},{key:"delete",text:"批量删除设备",danger:!0,permission:"device/Instance:delete",icon:"DeleteOutlined",selected:{popConfirm:{title:"已启用的设备无法删除,确认删除选中的禁用状态设备?",onConfirm:async()=>{var t;if(!c.value.length){_.error("请选择设备");return}(await he(c.value)).status===200&&(_.success("操作成功!"),c.value=[],(t=h.value)==null||t.reload())}}}},{key:"disable",text:"批量禁用设备",danger:!0,icon:"StopOutlined",permission:"device/Instance:action",selected:{popConfirm:{title:"确认禁用选中设备?",onConfirm:async()=>{var t;if(!c.value.length){_.error("请选择设备");return}(await ke(c.value)).status===200&&(_.success("操作成功!"),c.value=[],(t=h.value)==null||t.reload())}}}}],te=()=>{var e;I.value=!1,(e=h.value)==null||e.reload()},ae=e=>{var a;const t=(a=e==null?void 0:e.terms)==null?void 0:a.map(s=>(s.terms=s.terms.map(r=>r.column&&["classifiedId","accessId","accessProvider"].includes(r.column)?{...r,column:"productId$product-info"}:r),s));C.value={terms:t||[]}},N=()=>{var e;(e=h.value)==null||e.reload()};return(e,t)=>{const a=w("pro-search"),s=w("AIcon"),r=me,d=le,v=w("Ellipsis"),f=ce,se=pe,ne=de,ie=ue,oe=w("FullPage"),re=w("page-container");return y(),q(B,null,[o(re,null,{default:i(()=>[o(a,{columns:V,target:"device-instance",onSearch:ae}),o(oe,null,{default:i(()=>[o(ie,{ref_key:"instanceRef",ref:h,columns:V,request:l(ve),defaultParams:{sorts:[{name:"createTime",order:"desc"}]},rowSelection:l(b)?{selectedRowKeys:l(c),onChange:X}:!1,params:l(C)},{headerTitle:i(()=>[o(d,null,{default:i(()=>[o(r,{type:"primary",onClick:J,hasPermission:"device/Instance:add"},{icon:i(()=>[o(s,{type:"PlusOutlined"})]),default:i(()=>[z(" 新增 ")]),_:1}),o(Ee,{isCheck:l(b),"onUpdate:isCheck":t[0]||(t[0]=n=>Re(b)?b.value=n:null),actions:ee,onChange:W},null,8,["isCheck"])]),_:1})]),card:i(n=>{var p,g;return[o(ne,{value:n,onClick:Q,actions:Y(n,"card"),active:l(c).includes(n.id),status:(p=n.state)==null?void 0:p.value,statusText:(g=n.state)==null?void 0:g.text,statusNames:{online:"processing",offline:"error",notActive:"warning"}},{img:i(()=>[k("img",{width:80,height:80,src:(n==null?void 0:n.photoUrl)||l(Ce)("/device/instance/device-card.png")},null,8,Me)]),content:i(()=>[o(v,{style:{width:"calc(100% - 100px)","margin-bottom":"18px"}},{default:i(()=>[k("span",Fe,T(n.name),1)]),_:2},1024),o(se,null,{default:i(()=>[o(f,{span:12},{default:i(()=>{var u;return[Je,k("div",null,T((u=n.deviceType)==null?void 0:u.text),1)]}),_:2},1024),o(f,{span:12},{default:i(()=>[Le,o(v,{style:{width:"100%"}},{default:i(()=>[z(T(n.productName),1)]),_:2},1024)]),_:2},1024)]),_:2},1024)]),actions:i(u=>[o(r,{disabled:u.disabled,popConfirm:u.popConfirm,tooltip:{...u.tooltip},onClick:u.onClick,hasPermission:"device/Instance:"+u.key},{default:i(()=>[u.key==="delete"?(y(),x(s,{key:0,type:"DeleteOutlined"})):(y(),q(B,{key:1},[o(s,{type:u.icon},null,8,["type"]),k("span",null,T(u==null?void 0:u.text),1)],64))]),_:2},1032,["disabled","popConfirm","tooltip","onClick","hasPermission"])]),_:2},1032,["value","actions","active","status","statusText"])]}),state:i(n=>{var p,g;return[o(Pe,{status:(p=n.state)==null?void 0:p.value,text:(g=n.state)==null?void 0:g.text,statusNames:{online:"processing",offline:"error",notActive:"warning"}},null,8,["status","text"])]}),createTime:i(n=>[k("span",null,T(n!=null&&n.createTime?l(Oe)(n.createTime).format("YYYY-MM-DD HH:mm:ss"):""),1)]),action:i(n=>[o(d,null,{default:i(()=>[(y(!0),q(B,null,Ve(Y(n,"table"),p=>(y(),x(r,{key:p.key,disabled:p.disabled,popConfirm:p.popConfirm,tooltip:{...p.tooltip},onClick:p.onClick,type:"link",style:{padding:"0 5px"},danger:p.key==="delete",hasPermission:p.key==="view"?!0:"device/Instance:"+p.key},{icon:i(()=>[o(s,{type:p.icon},null,8,["type"])]),_:2},1032,["disabled","popConfirm","tooltip","onClick","danger","hasPermission"]))),128))]),_:2},1024)]),_:1},8,["request","rowSelection","params"])]),_:1})]),_:1}),l($)?(y(),x(xe,{key:0,onCancel:t[1]||(t[1]=n=>$.value=!1),onSave:N})):A("",!0),l(D)?(y(),x(Ie,{key:1,onClose:t[2]||(t[2]=n=>D.value=!1),data:l(C),onSave:N},null,8,["data"])):A("",!0),l(S)?(y(),x(be,{key:2,onClose:t[3]||(t[3]=n=>S.value=!1),api:l(P),type:l(E),data:l(C),onSave:N},null,8,["api","type","data"])):A("",!0),l(I)?(y(),x(ge,{key:3,data:l(O),onClose:t[4]||(t[4]=n=>I.value=!1),onSave:te},null,8,["data"])):A("",!0)],64)}}});export{da as default};