import{a8 as e,a9 as t,aa as a,o as s,e as n,w as i,j as c,p as o,r,A as l,t as u,ab as h,ac as d,d as m,y as p,l as g,m as f,Z as v,f as y,C as x,D as _,g as T,E as C,_ as S,F as b,S as w}from"./index-e204f8a0.js";import{_ as k}from"./_plugin-vue_export-helper.1b428a4d.js";import{_ as N}from"./u-input.32fa069b.js";import{_ as E}from"./u-modal.610fde20.js";const G=k({name:"u-code",mixins:[t,a,{props:{seconds:{type:[String,Number],default:()=>e.code.seconds},startText:{type:String,default:()=>e.code.startText},changeText:{type:String,default:()=>e.code.changeText},endText:{type:String,default:()=>e.code.endText},keepRunning:{type:Boolean,default:()=>e.code.keepRunning},uniqueKey:{type:String,default:()=>e.code.uniqueKey}}}],data(){return{secNum:this.seconds,timer:null,canGetCode:!0}},mounted(){this.checkKeepRunning()},watch:{seconds:{immediate:!0,handler(e){this.secNum=e}}},emits:["start","end","change"],methods:{checkKeepRunning(){let e=Number(uni.getStorageSync(this.uniqueKey+"_$uCountDownTimestamp"));if(!e)return this.changeEvent(this.startText);let t=Math.floor(+new Date/1e3);this.keepRunning&&e&&e>t?(this.secNum=e-t,uni.removeStorageSync(this.uniqueKey+"_$uCountDownTimestamp"),this.start()):this.changeEvent(this.startText)},start(){this.timer&&(clearInterval(this.timer),this.timer=null),this.$emit("start"),this.canGetCode=!1,this.changeEvent(this.changeText.replace(/x|X/,this.secNum)),this.timer=setInterval(()=>{--this.secNum?this.changeEvent(this.changeText.replace(/x|X/,this.secNum)):(clearInterval(this.timer),this.timer=null,this.changeEvent(this.endText),this.secNum=this.seconds,this.$emit("end"),this.canGetCode=!0)},1e3),this.setTimeToStorage()},reset(){this.canGetCode=!0,clearInterval(this.timer),this.secNum=this.seconds,this.changeEvent(this.endText)},changeEvent(e){this.$emit("change",e)},setTimeToStorage(){if(this.keepRunning&&this.timer&&this.secNum>0&&this.secNum[c(" 此组件功能由js完成,无需写html逻辑 ")]),_:1})}],["__scopeId","data-v-75751f8d"]]);function $(e){const t=r("");return{image:t,refresh:async()=>{try{const a=await d();e.captcha_key=a.data.captcha_key,e.captcha_code="",t.value=a.data.img.replace(/\r\n/g,"")}catch(a){}}}}const K=k(m({__name:"sms-code",props:{mobile:String,type:String,isAgree:{type:Boolean,default:!0},modelValue:{type:String,default:""}},emits:["update:modelValue"],setup(e,{emit:t}){const a=e,n=u({get:()=>a.modelValue,set(e){t("update:modelValue",e)}}),c=r(null),d=function(e){const t=r(l("getSmsCode")),a="X"+l("smsCodeChangeText"),s=u(()=>!e.value||e.value.canGetCode);return{tips:t,seconds:60,canGetCode:s,send:async t=>{if(!s.value)return;e.value.start();let a=!1;return await h(t).then(t=>{1==t.code?a=t.data.key:(e.value.reset(),a=!1)}).catch(t=>{a=!1,e.value.reset()}),a},codeChange:e=>{t.value=e},changeText:a}}(c),m=r(!1),k=p({mobile:"",captcha_code:"",captcha_key:"",type:a.type}),K=$(k),R=async()=>{if(c.value.canGetCode){if(k.mobile=a.mobile,!a.isAgree)return void b({title:l("isAgreeTips"),icon:"none"});if(uni.$u.test.isEmpty(k.mobile))return void b({title:l("mobilePlaceholder"),icon:"none"});if(!uni.$u.test.mobile(k.mobile))return void b({title:l("mobileError"),icon:"none"});await K.refresh(),m.value=!0}},V=async()=>{if(uni.$u.test.isEmpty(k.captcha_code))return void b({title:l("captchaPlaceholder"),icon:"none"});const e=await d.send(k);e?(n.value=e,m.value=!1):!1===e&&K.refresh()};return(e,t)=>{const a=o,n=g(f("u-code"),G),r=g(f("u-input"),N),u=w,h=g(f("u-modal"),E);return s(),v(S,null,[y(a,{class:C(["fs-26",{"text-primary":T(d).canGetCode.value,"text-gray-300":!T(d).canGetCode.value}]),onClick:R},{default:i(()=>[x(_(T(d).tips.value),1)]),_:1},8,["class"]),y(n,{seconds:T(d).seconds,"change-text":T(d).changeText,ref_key:"smsRef",ref:c,onChange:T(d).codeChange},null,8,["seconds","change-text","onChange"]),y(h,{show:m.value,title:T(l)("captchaTitle"),"confirm-text":T(l)("confirm"),"cancel-text":T(l)("cancel"),"show-cancel-button":!0,onCancel:t[2]||(t[2]=e=>m.value=!1),onConfirm:V,confirmColor:"var(--primary-color)"},{default:i(()=>[y(a,{class:"flex mt-[20rpx]"},{default:i(()=>[y(r,{placeholder:T(l)("captchaPlaceholder"),border:"surround",modelValue:k.captcha_code,"onUpdate:modelValue":t[0]||(t[0]=e=>k.captcha_code=e)},null,8,["placeholder","modelValue"]),y(u,{src:T(K).image.value,class:"h-[76rpx] w-[auto] ml-[20rpx]",mode:"heightFix",onClick:t[1]||(t[1]=e=>T(K).refresh())},null,8,["src"])]),_:1})]),_:1},8,["show","title","confirm-text","cancel-text"])],64)}}}),[["__scopeId","data-v-6efc3df3"]]);export{K as _,$ as u};