zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
3 lines (2 loc) • 4.35 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ColorScheme-CIG48waE.js","./index-B8xHYEBg.js","./index-j3oOpPBM.css"])))=>i.map(i=>d[i]);
import{_ as c,m as h,ar as w,d as _,e as y,w as i,b as o,F as V,n as b,as as v,H as S,s as u,at as x,k as n,G as C,T as L,o as M,D as m,M as I,au as T,i as U,O as A,t as P,f as k,u as q,C as B,x as d,av as D,L as N,y as O,z}from"./index-B8xHYEBg.js";const F=N.get("Login"),J={components:{ColorScheme:_(()=>O(()=>import("./ColorScheme-CIG48waE.js"),__vite__mapDeps([0,1,2]),import.meta.url)),Logo:w},data(){return{username:"",password:"",rememberMe:!1,error_text:"",error_type:"error",showPsw:!1,error:!1,valid_login:!0,rules:{required(s){return!!s||"This field is required."}}}},watch:{error:function(s){s&&setTimeout(function(){this.error=!1},5e3)}},mounted(){if(this.isLocalStorageSupported()){const s=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):null,e=!!localStorage.getItem("logged");s&&s.rememberMe?(this.username=s.username||this.username,this.password=s.password||this.password,this.rememberMe=s.rememberMe,e&&this.login(!0)):localStorage.removeItem("user"),this.initColorScheme()}else this.error=!0,this.error_type="error",this.error_text="Local storage not supported"},methods:{...h(d,["initColorScheme"]),isLocalStorageSupported(){const s="test",e=window.localStorage;try{return e.setItem(s,"1"),e.removeItem(s),!0}catch{return!1}},async login(s){if(!this.isLocalStorageSupported()){this.error=!0,this.error_type="error",this.error_text="Local storage not supported";return}const e=await this.$refs.form.validate();if(s===!0||e.valid)try{let t={username:this.username,password:this.password};const a=await B.login(t);a.success?(t=Object.assign(t,a.user),t.rememberMe=this.rememberMe,localStorage.setItem("user",JSON.stringify(t)),localStorage.setItem("logged","true"),d().onUserLogged(t),this.$route.params.nextUrl!=null?this.$router.push(this.$route.params.nextUrl):this.$router.push(D.main)):(a.message&&(this.error=!0),this.error_type="error",this.error_text=a.message)}catch(t){F.error(t),this.error=!0,this.error_type="error",this.error_text=t.message}}}},R={class:"d-flex align-center"};function j(s,e,t,a,r,p){const f=u("Logo"),g=u("color-scheme");return z(),y(q,{class:"pa-0 background",fluid:"","fill-height":""},{default:i(()=>[o(k,{elevation:"12",cols:"12",class:"pa-0 fill-height"},{default:i(()=>[o(V,{class:b(["mx-auto",s.$vuetify.display.smAndDown?"":"ml-10"]),width:s.$vuetify.display.smAndDown?"100%":"500",height:"100%",tile:""},{default:i(()=>[o(v,null,{default:i(()=>[S("div",R,[o(f,{size:"50"}),o(x,{style:{"margin-left":"20px"}},{default:i(()=>[...e[6]||(e[6]=[n("Z-Wave JS UI",-1)])]),_:1})])]),_:1}),o(C,null,{default:i(()=>[o(L,{modelValue:r.valid_login,"onUpdate:modelValue":e[4]||(e[4]=l=>r.valid_login=l),id:"login-form",onSubmit:M(p.login,["prevent"]),ref:"form","validate-on":"lazy"},{default:i(()=>[o(m,{required:"",rules:[r.rules.required],modelValue:r.username,"onUpdate:modelValue":e[0]||(e[0]=l=>r.username=l),modelModifiers:{trim:!0},autocomplete:"","prepend-icon":"person",name:"username",label:"Username",type:"text"},null,8,["rules","modelValue"]),o(m,{required:"",rules:[r.rules.required],modelValue:r.password,"onUpdate:modelValue":e[1]||(e[1]=l=>r.password=l),"prepend-icon":"lock",name:"password",label:"Password",autocomplete:"",type:r.showPsw?"text":"password","append-icon":r.showPsw?"visibility":"visibility_off","onClick:append":e[2]||(e[2]=l=>r.showPsw=!r.showPsw)},null,8,["rules","modelValue","type","append-icon"]),o(I,{modelValue:r.rememberMe,"onUpdate:modelValue":e[3]||(e[3]=l=>r.rememberMe=l),"prepend-icon":"null",name:"rememberMe","hide-details":"",label:"Remember Me"},null,8,["modelValue"]),o(g,{"hide-details":""})]),_:1},8,["modelValue","onSubmit"])]),_:1}),o(T,{class:"justify-center"},{default:i(()=>[o(U,{color:"primary",style:{"min-width":"150px",margin:"10px"},rounded:"",variant:"flat",class:"mb-6",type:"submit",form:"login-form"},{default:i(()=>[...e[7]||(e[7]=[n("Login",-1)])]),_:1})]),_:1}),o(A,{closable:"",type:r.error_type,modelValue:r.error,"onUpdate:modelValue":e[5]||(e[5]=l=>r.error=l)},{default:i(()=>[n(P(r.error_text),1)]),_:1},8,["type","modelValue"])]),_:1},8,["class","width"])]),_:1})]),_:1})}const G=c(J,[["render",j],["__scopeId","data-v-3e5554d2"]]);export{G as default};