2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{_ as L}from"./button.vue_vue_type_style_index_0_lang-379723a2.js";import{_ as J}from"./BasicInput.vue_vue_type_style_index_0_lang-1513fc09.js";import{H as X,a2 as V,f as Y,g as w,d as D,u as M,z as E,r as R,o as p,c as I,a as d,b as c,w as f,i as $,j as o,x as Z,p as z,a4 as N,a5 as ee,C as F,a6 as U,Q as T,v as ne,a7 as te,a8 as se,k as W,l as ae,F as oe,n as le,e as ue}from"./index-5870e6d3.js";import{n as ie}from"./phone-6ff17ec0.js";import{u as re,I as de}from"./Icon-61906fca.js";import{F as P,_ as B}from"./index-c8d614fc.js";import{S as A}from"./index-ccb2a61b.js";import{a as K,T as ce}from"./index-3e5e4620.js";import"./_plugin-vue_export-helper-5e3c08f4.js";import"./usePrice-7afab779.js";import"./index-f48a08af.js";import"./FormItemContext-817438bc.js";import"./vnode-22dd7580.js";import"./isPlainObject-9db900ef.js";import"./shallowequal-2bdf6cc7.js";import"./Col-619d881f.js";import"./toArray-f3da0fcb.js";import"./useState-9f642396.js";import"./useRefs-f4db4963.js";const pe="/assets/logo-dd2a3541.png",me=async e=>{const a=ie(e.username),{data:l,error:n}=await X.auth.signInWithPassword({email:`${a}@example.com`,password:e.password});if(n)throw n;return l},fe=async e=>await V.post("/auth/login",e),ve=async e=>await V.post("/auth/verify",e),H=Y("login",()=>{const e=w(""),a=w(null);return{mobile:e,id:a,setMobile:s=>{e.value=s},setId:s=>{a.value=s}}}),ye={class:"grid grid-cols-1 md:grid-cols-12 h-full bg-gradient"},he={class:"md:col-span-3 flex justify-center items-center"},ge={class:"min-h-[300px]"},_e={key:1},we={key:1},Oe=d("div",{class:"md:col-span-9 md:flex md:justify-center md:items-center hidden"},[d("img",{src:pe,alt:"machartaa logo",class:"w-40vw"})],-1),be=D({__name:"Panel",emits:["verify"],setup(e,{emit:a}){const l=w(0),n=w(!1),s=M(),y=E(),{prefixCls:g}=re("login"),O=H(),u=R({username:"",password:""}),b=async i=>{var t,m,_,v;try{if(n.value=!0,i.username&&i.password){const h={...i,provider:"user"};console.log("Login payload:",h);const S=await me(h);if(console.log("Login response:",S),(t=S==null?void 0:S.session)!=null&&t.access_token){await N(S.session.access_token);try{await y.getMyInfo()}catch{ee(),F.error("شما دسترسی ادمین ندارید");return}U(y.routePermissionKeys,s,y.isSuperAdmin),await s.push({name:"dashboard"})}else F.error("توکن دریافتی نامعتبر است")}else F.error("وارد کردن تمامی فیلدها الزامی است")}catch(h){console.log("Login error:",h),console.log("Error response:",(m=h==null?void 0:h.response)==null?void 0:m.data),F.error(((v=(_=h==null?void 0:h.response)==null?void 0:_.data)==null?void 0:v.message)||"خطا در ورود به پنل کاربری")}finally{n.value=!1}},k=async i=>{try{if(n.value=!0,i.username!==""){O.setMobile(i.username);let t=await fe({...i,provider:"user"});O.setId(t.id),a("verify",!0)}else F.error("وارد کردن تمامی فیلدها الزامی است")}catch(t){console.log(t),F.error("خطا در ورود به پنل کاربری")}finally{n.value=!1}};return(i,t)=>{const m=J,_=L;return p(),I("div",{class:z(["h-screen bg-image overflow-hidden",[`${o(g)}`]])},[d("div",ye,[d("div",he,[d("div",ge,[c(o(ce),{activeKey:o(l),"onUpdate:activeKey":t[3]||(t[3]=v=>Z(l)?l.value=v:null)},{default:f(()=>[(p(),$(o(K),{tab:"ورود با شماره تلفن",key:0,"force-render":""},{default:f(()=>[c(o(P),{model:o(u),onFinish:b},{default:f(()=>[c(o(B),{label:"شماره تلفن",name:"username"},{default:f(()=>[c(m,{"place-holder":"مثال: 09123456789",value:o(u).username,"onUpdate:value":t[0]||(t[0]=v=>o(u).username=v)},null,8,["value"])]),_:1}),c(o(B),{label:"کلمه عبور",name:"password"},{default:f(()=>[c(m,{"is-password":"","place-holder":"کلمه عبور",value:o(u).password,"onUpdate:value":t[1]||(t[1]=v=>o(u).password=v)},null,8,["value"])]),_:1}),c(o(B),null,{default:f(()=>[c(_,{class:"mt-5 w-full",disabled:o(n),type:"primary","html-type":"submit"},{default:f(()=>[d("div",null,[o(n)?(p(),$(o(A),{key:0,size:"small"})):(p(),I("div",_e,"ورود"))])]),_:1},8,["disabled"])]),_:1})]),_:1},8,["model"
|