import{d as B,k as i,l as T,p as Y,r as Z,o as x,x as h,z as s,b as n,u as o,F as b,t as r,a as m,E as A,X as tt,a0 as et,M as C,G as ot,H as st}from"./vue.1703796278973.js";import{cJ as at,aM as nt,M as k,a9 as it,a5 as lt,a7 as rt,cF as ut,I as ct,aG as pt}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 M}from"./index.vue_vue_type_script_setup_true_name_PermissionButton_lang.1703796278973.js";import{u as dt}from"./instance.17037962789732.js";import{ab as vt,ac as mt,ad as _t,ae as ft,af as yt}from"./instance.1703796278973.js";import{_ as gt}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"./comm.1703796278973.js";import"./system.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";const J=w=>(ot("data-v-d12425b8"),w=w(),st(),w),xt={class:"top"},ht={class:"top-left"},bt={class:"bottom"},Ct={style:{width:"49.5%"}},kt={class:"bottom-title"},wt=J(()=>s("div",{class:"bottom-title-text"},"模拟输入",-1)),It={class:"bottom-title-topic"},St=J(()=>s("div",{style:{"margin-right":"5px"}},"Topic:",-1)),jt=J(()=>s("div",{style:{"margin-right":"5px"}},"URL:",-1)),Vt={style:{width:"49.5%"}},Tt=J(()=>s("div",{class:"bottom-title"},[s("div",{class:"bottom-title-text"},"运行结果")],-1)),Mt={style:{"margin-top":"10px","margin-left":"10px"}},Jt=B({name:"Parsing"}),Ot=B({...Jt,setup(w){const F=`//解码函数\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
`,E=i(null),{toggle:N}=at(E),l=dt(),O=i(""),_=i(!0),f=i(""),y=i(""),L=i([]),p=i(""),d=i({}),g=i(!1),I=i(!1),u=i(""),R=T(()=>({color:_.value?"#415ed1":"#a6a6a6"})),z=T(()=>nt.isBoolean(d.value.success)?{"margin-top":"10px","border-color":d.value.success?"green":"red"}:{"margin-top":"10px"}),G=(e,t)=>t.value.indexOf(e)!==-1,Q=T(()=>p.value===""),P=T(()=>{var e;return d.value.success?JSON.stringify((e=d.value.outputs)==null?void 0:e[0]):d.value.reason}),q=async()=>{(await vt(l.current.productId,l.current.id)).status===200&&(U(),k.success("操作成功"))},H=async()=>{var t;const e=await mt(l.current.protocol,l.current.transport);if(e.status===200){const c=(t=e.result.routes)==null?void 0:t.map(v=>({value:v.topic}));L.value=c}},U=async()=>{var t,c,v,S,j;const e=await _t(l.current.productId,l.current.id);if(e.status===200){const V=(c=(t=e.result)==null?void 0:t.configuration)!=null&&c.script?(S=(v=e.result)==null?void 0:v.configuration)==null?void 0:S.script:F;(j=e.result)!=null&&j.deviceId?(_.value=!1,O.value="rest",u.value=V):(_.value=!0,O.value="edit",u.value=V)}},D=async e=>{g.value=!0;const t=await yt(e);t.status===200?(g.value=!1,d.value=t==null?void 0:t.result):g.value=!1},X=async()=>{const e={provider:"jsr223",configuration:{script:u.value,lang:"javascript"}};(await ft(l.current.productId,l.current.id,e)).status===200&&(k.success("保存成功"),U())},K=()=>{l.current.transport==="MQTT"?y.value!==""?(D({headers:{topic:y.value},configuration:{script:u.value,lang:"javascript"},provider:"jsr223",payload:p.value}),I.value=!0):k.error("请输入topic"):f.value!==""?(D({headers:{url:f.value},provider:"jsr223",configuration:{script:u.value,lang:"javascript"},payload:p.value}),I.value=!0):k.error("请输入url")};return Y(()=>{U(),H()}),(e,t)=>{const c=Z("AIcon"),v=it,S=lt,j=rt,V=ut,W=ct,$=pt;return x(),h(b,null,[s("div",null,[s("div",xt,[s("div",ht,[s("div",null,[n(c,{type:"ExclamationCircleOutlined"}),o(O)==="rest"?(x(),h(b,{key:0},[r(" 当前数据解析内容已脱离产品影响， "),n(M,{type:"link",hasPermission:"device/Instance:update",onClick:t[0]||(t[0]=a=>q())},{default:m(()=>[r(" 重置 ")]),_:1}),r(" 后将继承产品数据解析内容 ")],64)):(x(),h(b,{key:1},[r(" 当前数据解析内容继承自产品, "),n(M,{type:"link",hasPermission:"device/Instance:update",onClick:t[1]||(t[1]=a=>_.value=!1),style:A(o(R))},{default:m(()=>[r(" 修改 ")]),_:1},8,["style"]),r(" 后将脱离产品影响。 ")],64))])]),s("div",null,[r(" 脚本语言: "),n(S,{defaultValue:"JavaScript",style:{width:"200px","margin-left":"5px"}},{default:m(()=>[n(v,{value:"JavaScript"},{default:m(()=>[r("JavaScript(ECMAScript 5)")]),_:1})]),_:1}),n(c,{type:"ExpandOutlined",style:{"margin-left":"20px"},onClick:o(N)},null,8,["onClick"])])]),s("div",{class:"edit",ref_key:"el",ref:E},[tt(s("div",{class:"edit-only",onClick:t[2]||(t[2]=()=>{o(k).warning({key:1,content:()=>"请点击上方修改字样,用以编辑脚本",style:{marginTop:"260px"}})})},null,512),[[et,o(_)]]),n(j,{language:"javascript",style:{height:"100%"},theme:"vs",modelValue:o(u),"onUpdate:modelValue":t[3]||(t[3]=a=>C(u)?u.value=a:null)},null,8,["modelValue"])],512),s("div",bt,[s("div",Ct,[s("div",kt,[wt,s("div",It,[o(l).current.transport==="MQTT"?(x(),h(b,{key:0},[St,n(V,{placeholder:"请输入Topic",style:{width:"300px"},options:o(L),allowClear:!0,filterOption:G,value:o(y),"onUpdate:value":t[4]||(t[4]=a=>C(y)?y.value=a:null)},null,8,["options","value"])],64)):(x(),h(b,{key:1},[jt,n(W,{placeholder:"请输入URL",value:o(f),"onUpdate:value":t[5]||(t[5]=a=>C(f)?f.value=a:null),style:{width:"300px"}},null,8,["value"])],64))])]),n($,{rows:5,placeholder:"// 二进制数据以0x开头的十六进制输入，字符串数据输入原始字符串",style:{"margin-top":"10px"},value:o(p),"onUpdate:value":t[6]||(t[6]=a=>C(p)?p.value=a:null)},null,8,["value"])]),s("div",Vt,[Tt,n($,{autoSize:{minRows:5},style:A(o(z)),value:o(P),"onUpdate:value":t[7]||(t[7]=a=>C(P)?P.value=a:null)},null,8,["style","value"])])])]),s("div",Mt,[n(M,{type:"primary",hasPermission:"device/Instance:update",loading:o(g),disabled:o(Q),onClick:t[8]||(t[8]=a=>K()),tooltip:{title:"需输入脚本和模拟数据后再点击"}},{default:m(()=>[r(" 调试 ")]),_:1},8,["loading","disabled"]),n(M,{hasPermission:"device/Instance:update",loading:o(g),disabled:!o(I),onClick:t[9]||(t[9]=a=>X()),style:{marginLeft:"10px"},tooltip:{title:o(I)?"":"请先调试"}},{default:m(()=>[r(" 保存 ")]),_:1},8,["loading","disabled","tooltip"])])],64)}}});const re=gt(Ot,[["__scopeId","data-v-d12425b8"]]);export{re as default};
