var e=Object.defineProperty,t=Object.defineProperties,a=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,s=(t,a,o)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[a]=o,r=(e,t)=>{for(var a in t||(t={}))l.call(t,a)&&s(e,a,t[a]);if(o)for(var a of o(t))n.call(t,a)&&s(e,a,t[a]);return e},c=(e,o)=>t(e,a(o)),i=(e,t,a)=>new Promise(((o,l)=>{var n=e=>{try{r(a.next(e))}catch(t){l(t)}},s=e=>{try{r(a.throw(e))}catch(t){l(t)}},r=e=>e.done?o(e.value):Promise.resolve(e.value).then(n,s);r((a=a.apply(e,t)).next())}));import{r as u,s as d,d as v,g as y,a as p,b as _,c as m,e as f,u as g,n as b,f as $,o as w,h as O,i as h,j,k,w as x,l as P,m as I,p as q,q as D,t as T,v as E,x as S,_ as L}from"./index-DvtSxfxs.js";const C=e=>new Promise(((t,a)=>{u(c(r({},e),{dataType:"json",header:{"content-type":"application/json"},responseType:"json",success(e){var o,l,n;(null==(o=e.data)?void 0:o.code)>=200&&(null==(l=e.data)?void 0:l.code)<300?t(e.data):401===(null==(n=e.data)?void 0:n.code)?(window.parent.postMessage({data:{type:"logout"}},"*"),a(e)):t(e.data)},fail(e){d({icon:"none",title:"网络错误,换个网络试试"}),a(e)}}))}));C.get=(e,t)=>C({url:e,query:t,method:"GET"}),C.post=(e,t,a,o=!1)=>C({url:e,query:a,data:t,method:"POST",hideErrorToast:o});const U=e=>C.get("/v1/content",e),J=L(v(c(r({},{name:"Home"}),{__name:"index",setup(e){const{safeAreaInsets:t}=y(),a=p({}),o=_(""),l=_("");let n="activity",s=null;const r={Interface:"api_code",lottery:"lottery_code",activity:"activity_code"},c=p({url:"",title:""}),{MODE:u}=T();console.log("----mode",u);const v="production"===u?m():f();console.log(".....urlPath",v),o.value=v.activity_code,n=v.codeS;const L=g(o.value),C=e=>Object.entries(e).reduce(((e,t)=>e?e+`&${t[0]}=${t[1]}`:e+`${t[0]}=${t[1]}`),"");function J(){return i(this,null,(function*(){const e={};e[r[n]]=o.value||"",L.reset();M(yield U(e))}))}function M(e){if(200===e.code){const{login_content_template:t,login_content_templates:n,content_templates:s,token:r}=e.data;o.value=e.data.activity_code,Object.assign(a,e.data),1===t.validate_login?(c.url=N(n.source+`?activity_code=${o.value}`),c.title=n.moduledesc):2===t.validate_login&&(c.url=N(s.source+`?activity_code=${o.value}&token=${r}&lottery_code=${l.value}`),c.title=s.moduledesc),$({title:c.title}),L.setUserInfo({srcList:c,contentData:a,activityCode:o.value,token:r,lottery:l.value})}else d({title:e.message,icon:"none"})}function N(e){const t=(new Date).getTime();return e+(e.includes("?")?"×tamp=":"?timestamp=")+t}window.addEventListener("message",(function(e){switch(e.data.data.type){case"login":case"couponBack":c.url=a.content_templates.source+`?activity_code=${o.value}`,c.title=a.content_templates.moduledesc;break;case"coupon":const t=e.data.data.url?`#${e.data.data.url}`:"",n=e.data.data.query?C(e.data.data.query)+"&":"";c.url=a.user_content_templates.source+`${t}?${n}activity_code=${o.value}&lottery_code=${l.value}`,c.title=a.user_content_templates.moduledesc;break;case"location":window.location.replace(e.data.data.url);break;case"orderDetail":const s=e.data.data.query?C(e.data.data.query)+"&":"";c.url=a.order_detail_templates.source+`?${s}activity_code=${o.value}&lottery_code=${l.value}`,c.title=a.order_detail_templates.moduledesc;break;case"product":const r=e.data.data.url?`${e.data.data.url}`:"",i=e.data.data.query?C(e.data.data.query)+"&":"";console.log("----\x3e_newUrl",r),console.log("----\x3e_newParams",i),c.url=r+`?${i}activity_code=${o.value}&lottery_code=${l.value}`,c.title=e.data.data.extraData.moduledesc;break;case"logout":return J()}b((()=>{c.url=N(c.url),$({title:c.title}),L.setUserInfo({srcList:c,contentData:a,activityCode:o.value,token:a.token,lottery:l.value})}))}));const A=()=>{s=setInterval((()=>i(this,null,(function*(){const e={};e[r[n]]=l.value||"";const t=yield U(e);JSON.stringify(t.data)!==JSON.stringify(L.userInfo.contentData)&&(d({title:"活动发生变更",icon:"none"}),M(t))}))),6e4)};return w((()=>{const{srcList:e,lottery:t,activityCode:n,contentData:s}=L.userInfo;l.value=o.value,!e.url||t!==l.value&&n!==o.value?J():(o.value=n,c.url=s.content_templates.source+`?activity_code=${o.value}&lottery_code=${l.value}`,c.title=s.content_templates.moduledesc,Object.assign(c,{url:N(c.url)}),Object.assign(a,s),$({title:c.title})),A()})),O((()=>{clearInterval(s),s=null})),(e,a)=>{const o=E,l=S,n=h("layout-default-uni");return j(),k(n,null,{default:x((()=>{var e;return[P(l,{class:"bg-white overflow-hidden pt-2 px-4",style:D({marginTop:(null==(e=I(t))?void 0:e.top)+"px"})},{default:x((()=>[I(c).url?(j(),k(o,{key:0,src:I(c).url},null,8,["src"])):q("",!0)])),_:1},8,["style"])]})),_:1})}}})),[["__scopeId","data-v-57b9c012"]]);export{J as default};