import{cJ as q,aM as H,M as S,a9 as K,a5 as W,a7 as X,cF as Y,I as Z,aG as tt}from"./index.17037962789732.js";import"./index.170379627897314.js";import"./index.170379627897315.js";import"./index.1703796278973320.js";import"./index.170379627897316.js";import"./index.170379627897317.js";import"./index.170379627897338.js";import{_ as U}from"./index.vue_vue_type_script_setup_true_name_PermissionButton_lang.1703796278973.js";import{u as et}from"./product.17037962789738.js";import{ac as ot,aj as st,ak as at,af as nt}from"./instance.1703796278973.js";import{d as A,k as r,l as w,p as rt,r as lt,o as C,x as V,z as e,t as y,b as n,a as x,u as s,M as _,F as k,E as it,G as ut,H as ct}from"./vue.1703796278973.js";import{_ as pt}from"./_plugin-vue_export-helper.1703796278973.js";import"./index.17037962789733.js";import"./dayjs.min.1703796278973.js";import"./isArray.1703796278973.js";import"./editor.api.1703796278973.js";import"./preload-helper.1703796278973.js";import"./monaco.contribution.1703796278973.js";import"./index.170379627897320.js";import"./index.170379627897321.js";import"./permission.1703796278973.js";import"./product.17037962789737.js";import"./system.1703796278973.js";import"./comm.1703796278973.js";import"./index.170379627897332.js";import"./index.170379627897333.js";import"./index.170379627897334.js";import"./default.1703796278973.js";import"./consts.1703796278973.js";import"./404.1703796278973.js";import"./encodeQuery.1703796278973.js";const h=f=>(ut("data-v-d5c5d5a8"),f=f(),ct(),f),dt={class:"top"},mt={class:"bottom"},vt={style:{width:"49.5%"}},_t={class:"bottom-title"},ft=h(()=>e("div",{class:"bottom-title-text"},"模拟输入",-1)),gt={class:"bottom-title-topic"},yt=h(()=>e("div",{style:{"margin-right":"5px"}},"Topic:",-1)),xt=h(()=>e("div",{style:{"margin-right":"5px"}},"URL:",-1)),ht={style:{width:"49.5%"}},bt=h(()=>e("div",{class:"bottom-title"},[e("div",{class:"bottom-title-text"},"运行结果")],-1)),jt={style:{"margin-top":"10px","margin-left":"10px"}},St=A({name:"DataAnalysis"}),wt=A({...St,setup(f){const L=`//解码函数\r
function decode(context) {\r
    //原始报文\r
    var buffer = context.payload();\r
    // 转为json\r
    // var json = context.json();\r
    //mqtt 时通过此方法获取topic\r
    // var topic = context.topic();\r
\r
    // 提取变量\r
    // var topicVars = context.pathVars("/{deviceId}/**",topic)\r
    //温度属性\r
    var temperature = buffer.getShort(3) * 10;\r
    //湿度属性\r
    var humidity = buffer.getShort(6) * 10;\r
    return {\r
        "temperature": temperature,\r
        "humidity": humidity\r
    };\r
}\r
`,I=r(null),{toggle:O}=q(I),i=et(),d=r(""),m=r(""),P=r([]),u=r(""),c=r({}),v=r(!1),g=r(!1),l=r(""),E=w(()=>H.isBoolean(c.value.success)?{"margin-top":"10px","border-color":c.value.success?"green":"red"}:{"margin-top":"10px"}),B=w(()=>u.value===""),b=w(()=>{var o;return c.value.success?JSON.stringify((o=c.value.outputs)==null?void 0:o[0]):c.value.reason}),F=async()=>{var t;const o=await ot(i.current.messageProtocol,i.current.transportProtocol);if(o.status===200){const p=(t=o.result.routes)==null?void 0:t.map(j=>({value:j.topic}));P.value=p}},M=async()=>{var t,p;const o=await st(i.current.id);o.status===200&&(o.result?l.value=(p=(t=o.result)==null?void 0:t.configuration)==null?void 0:p.script:l.value=L)},T=async o=>{v.value=!0;const t=await nt(o);t.status===200?(v.value=!1,c.value=t==null?void 0:t.result):v.value=!1},N=async()=>{const o={provider:"jsr223",configuration:{script:l.value,lang:"javascript"}};(await at(i.current.id,o)).status===200&&(S.success("保存成功"),M())},R=()=>{i.current.transportProtocol==="MQTT"?m.value!==""?(T({headers:{topic:m.value},configuration:{script:l.value,lang:"javascript"},provider:"jsr223",payload:u.value}),g.value=!0):S.error("请输入topic"):d.value!==""?(T({headers:{url:d.value},provider:"jsr223",configuration:{script:l.value,lang:"javascript"},payload:u.value}),g.value=!0):S.error("请输入url")};return rt(()=>{M(),F()}),(o,t)=>{const p=K,j=W,z=lt("AIcon"),D=X,$=Y,G=Z,J=tt;return C(),V(k,null,[e("div",null,[e("div",dt,[e("div",null,[y(" 脚本语言: "),n(j,{defaultValue:"JavaScript",style:{width:"200","margin-left":"5px"}},{default:x(()=>[n(p,{value:"JavaScript"},{default:x(()=>[y("JavaScript(ECMAScript 5)")]),_:1})]),_:1}),n(z,{type:"ExpandOutlined",style:{"margin-left":"20px"},onClick:s(O)},null,8,["onClick"])])]),e("div",{class:"edit",ref_key:"el",ref:I},[n(D,{language:"javascript",style:{height:"100%"},theme:"vs",modelValue:s(l),"onUpdate:modelValue":t[0]||(t[0]=a=>_(l)?l.value=a:null)},null,8,["modelValue"])],512),e("div",mt,[e("div",vt,[e("div",_t,[ft,e("div",gt,[s(i).current.transportProtocol==="MQTT"?(C(),V(k,{key:0},[yt,n($,{placeholder:"请输入Topic",style:{width:"300px"},options:s(P),allowClear:!0,filterOption:(a,Q)=>Q.value.indexOf(a)!==-1,value:s(m),"onUpdate:value":t[1]||(t[1]=a=>_(m)?m.value=a:null)},null,8,["options","filterOption","value"])],64)):(C(),V(k,{key:1},[xt,n(G,{placeholder:"请输入URL",value:s(d),"onUpdate:value":t[2]||(t[2]=a=>_(d)?d.value=a:null),style:{width:"300px"}},null,8,["value"])],64))])]),n(J,{rows:5,placeholder:"// 二进制数据以0x开头的十六进制输入，字符串数据输入原始字符串",style:{"margin-top":"10px"},value:s(u),"onUpdate:value":t[3]||(t[3]=a=>_(u)?u.value=a:null)},null,8,["value"])]),e("div",ht,[bt,n(J,{autoSize:{minRows:5},style:it(s(E)),value:s(b),"onUpdate:value":t[4]||(t[4]=a=>_(b)?b.value=a:null)},null,8,["style","value"])])])]),e("div",jt,[n(U,{type:"primary",hasPermission:"device/Instance:update",loading:s(v),disabled:s(B),onClick:t[5]||(t[5]=a=>R()),tooltip:{title:"需输入脚本和模拟数据后再点击"}},{default:x(()=>[y(" 调试 ")]),_:1},8,["loading","disabled"]),n(U,{hasPermission:"device/Instance:update",loading:s(v),disabled:!s(g),onClick:t[6]||(t[6]=a=>N()),style:{marginLeft:"10px"},tooltip:{title:s(g)?"":"请先调试"}},{default:x(()=>[y(" 保存 ")]),_:1},8,["loading","disabled","tooltip"])])],64)}}});const oe=pt(wt,[["__scopeId","data-v-d5c5d5a8"]]);export{oe as default};
