marketingSaaS-front_ui/dist/build/h5/assets/pages-index-index.CuDBSK9d.js

2 lines
4.7 KiB
JavaScript

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