best-unit 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,4 +42,4 @@
42
42
  padding: 4px;
43
43
  color: #999;
44
44
  font-size: 12px;
45
- `,c.onclick=()=>{document.body.removeChild(s)},s.appendChild(c)}document.body.appendChild(s),o!==0&&setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},o||3e3)}success(t){this.show("success",t)}error(t){this.show("error",t)}warning(t){this.show("warning",t)}info(t){this.show("info",t)}}const ze=new io;function so(e={}){const{baseURL:t="/api",timeout:n=1e4,getLocale:r,onError:o}=e,i=R.create({baseURL:t,timeout:n});return i.interceptors.request.use(s=>{const a=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),{token:c}=a;if(s.headers={...s.headers,Authorization:c},r){const u=r();u&&(s.headers={...s.headers,"Accept-Language":u})}return s}),i.interceptors.response.use(s=>{if(s.data&&s.data.code===0)return s.data;const a=s.data?.msg||s.data?.message||"未知错误";return ze.error(a),o&&o(a,s),Promise.reject(s.data||{message:"未知错误"})},s=>{const a=s.response?.data?.msg||s.response?.data?.message||s.message||"网络请求失败";return ze.error(a),o&&o(a,s),Promise.reject(s)}),i}const ie=so();function ao(){const e=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");return console.log(e,"fundUnitParams"),ie.get("/balance",{params:{merchant_id:e.merchantId,biz_type:e.bizType}}).then(t=>{const n=t.data;return{totalAmount:n.total_amount||0,availableAmount:n.available_amount||0,frozenAmount:n.frozen_amount||0}})}const lo=async()=>ie.get("/all-dicts",{}).then(e=>(sessionStorage.setItem("all_dicts",JSON.stringify(e.data)),e.data||{})),co=async(e,t)=>ie.post("/oss/upload",e,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:n=>{if(n.total){const r=Math.round(n.loaded*100/n.total);t&&t(r)}}}).then(n=>n.data?.url||""),uo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),n={merchant_id:Number(t.merchantId),biz_type:t.bizType,source_operator:String(t.userId),transfer_no:e.transferNo,transfer_channel:e.transferChannel,voucher_urls:e.voucherUrls};return ie.post("/offline/recharge/create",n,{})},fo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");console.log(t,"fundUnitParams");const n={merchant_id:Number(t.merchantId),biz_type:t.bizType,source_operator:String(t.userId),amount:e.amount,currency:e.currency,recharge_channel:e.rechargeChannel,return_url:window.location.href};return ie.post("/online/recharge/create",n,{}).then(r=>r.data.redirect_url)},po=({value:e=[],onChange:t,maxCount:n=10,accept:r=".jpg,.jpeg,.png,.pdf",multiple:o=!0,disabled:i=!1})=>{const s=Lt(null),[a,c]=I(!1),[u,f]=I(0),l=async h=>{const p=Array.from(h.target.files).slice(0,n);if(!p.length)return;c(!0);const g=[];for(let _=0;_<p.length;_++){f(0);const y=new FormData;y.append("file",p[_]);try{const w=await co(y,S=>f(S));w&&g.push(w)}catch{}}c(!1),f(0),t?.([...e,...g]),s.current&&(s.current.value="")},b=h=>{const p=e.filter((g,_)=>_!==h);t?.(p)};return m("div",{children:[m("div",{style:{border:"1px dashed #E5E6EB",borderRadius:8,background:"#FCFCFD",padding:24,textAlign:"center",cursor:i?"not-allowed":"pointer",minHeight:120,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#999",fontSize:15,opacity:i?.6:1},onClick:()=>!i&&s.current?.click(),children:[m("div",{style:{fontSize:48,marginBottom:12},children:"📁"}),m("div",{style:{color:"#222",fontSize:15,marginBottom:4},children:"点击或拖拽文件到此处上传"}),m("div",{style:{color:"#999",fontSize:13},children:["支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传 ",n," ","个文件"]}),m("input",{ref:s,type:"file",multiple:o,accept:r,style:{display:"none"},onChange:l,disabled:i}),a&&m("div",{style:{marginTop:12,color:"#1677ff"},children:["正在上传... ",u,"%"]})]}),e&&e.length>0&&m("div",{style:{marginTop:12},children:e.map((h,p)=>m("div",{style:{display:"flex",alignItems:"center",background:"#F7F8FA",borderRadius:8,padding:"12px 16px",marginBottom:8,fontSize:15,color:"#222",justifyContent:"space-between"},children:[m("div",{style:{display:"flex",alignItems:"center",flex:1},children:[m("span",{style:{fontWeight:500,wordBreak:"break-all"},children:h.split("/").pop()}),m("span",{style:{color:"#8C8F93",fontSize:13,marginLeft:8},children:"[已上传]"})]}),m("button",{type:"button",onClick:g=>{g.stopPropagation(),b(p)},style:{background:"#FF4D4F",color:"#fff",border:"none",borderRadius:6,padding:"4px 14px",fontSize:15,marginLeft:16,cursor:"pointer"},disabled:i,children:"移除"})]},h))})]})},ho=({formState:e,setFormState:t,onClose:n,loading:r,whiteTheme:o=!1})=>{const i=JSON.parse(sessionStorage.getItem("all_dicts")||"{}");console.log(i,"allDicts");const s=i?.channel||[],a=o?{label:{marginBottom:8,fontSize:14,color:"#222",textAlign:"left",display:"block"},input:{width:"100%",padding:"10px 12px",borderRadius:6,boxSizing:"border-box",border:"1px solid #E5E6EB",background:"#fff",color:"#222",fontSize:15,outline:"none",marginBottom:0},inputError:{border:"1px solid #ff4d4f"},select:{width:"100%",padding:"10px 12px",borderRadius:6,border:"1px solid #E5E6EB",background:"#fff",color:"#222",fontSize:15,outline:"none"},selectError:{border:"1px solid #ff4d4f"},buttonCancel:{background:"#fff",color:"#222",border:"1px solid #E5E6EB",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer"},buttonSubmit:{background:"#155EEF",color:"#fff",border:"none",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer",fontWeight:600},error:{color:"#ff4d4f",fontSize:13,marginTop:4,textAlign:"left"}}:{label:{marginBottom:8,fontSize:14,color:"#fff",textAlign:"left",display:"block"},input:{width:"100%",padding:"10px 12px",borderRadius:6,boxSizing:"border-box",border:"1px solid #23262F",background:"#23262F",color:"#fff",fontSize:15,outline:"none",marginBottom:0},inputError:{border:"1px solid #ff4d4f"},select:{width:"100%",padding:"10px 12px",borderRadius:6,border:"1px solid #23262F",background:"#23262F",color:"#fff",fontSize:15,outline:"none"},selectError:{border:"1px solid #ff4d4f"},buttonCancel:{background:"#23262F",color:"#fff",border:"none",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer"},buttonSubmit:{background:"#00E8C6",color:"#fff",border:"none",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer",fontWeight:600},error:{color:"#ff4d4f",fontSize:13,marginTop:4,textAlign:"left"}};return m("form",{onSubmit:async u=>{u.preventDefault();let f=!0;t(l=>({...l,platformError:"",transactionIdError:"",filesError:""})),e.platform||(t(l=>({...l,platformError:"请选择支付平台"})),f=!1),e.transactionId.trim()||(t(l=>({...l,transactionIdError:"请输入转账交易ID"})),f=!1),(!e.files||e.files.length===0)&&(t(l=>({...l,filesError:"请上传转账凭证"})),f=!1),f&&(await uo({transferChannel:e.platform,transferNo:e.transactionId,voucherUrls:e.files}),n(),ze.success("离线充值创建成功"))},children:[m("div",{style:{marginBottom:18},children:[m("div",{style:a.label,children:[m("span",{style:{color:"#F53F3F"},children:"*"})," 第三方支付平台"]}),m("select",{style:{...a.select,...e.platformError?a.selectError:{}},value:e.platform,onInput:u=>{const f=u.target.value;t(l=>({...l,platform:f,platformError:f?"":l.platformError}))},children:[m("option",{value:"",disabled:!0,hidden:!0,children:"请选择支付平台"}),s?.map(u=>m("option",{value:u.value,children:u.label}))]}),e.platformError&&m("div",{style:a.error,children:e.platformError})]}),m("div",{style:{marginBottom:18},children:[m("div",{style:a.label,children:[m("span",{style:{color:"#F53F3F"},children:"*"})," 交易ID"]}),m("input",{type:"text",placeholder:"请输入转账交易ID",value:e.transactionId,onInput:u=>{const f=u.target.value;t(l=>({...l,transactionId:f,transactionIdError:f?"":l.transactionIdError}))},style:{...a.input,...e.transactionIdError?a.inputError:{}}}),e.transactionIdError&&m("div",{style:a.error,children:e.transactionIdError})]}),m("div",{style:{marginBottom:24},children:[m("div",{style:a.label,children:[m("span",{style:{color:"#F53F3F"},children:"*"})," 上传文件"]}),m(po,{value:e.files,onChange:u=>t(f=>({...f,files:u,filesError:""})),maxCount:10,accept:".jpg,.jpeg,.png,.pdf",multiple:!0}),e.filesError&&m("div",{style:a.error,children:e.filesError})]}),m("div",{style:{display:"flex",justifyContent:"flex-end",gap:12},children:[m("button",{type:"button",onClick:n,style:a.buttonCancel,children:"取消"}),m("button",{type:"submit",disabled:r,style:a.buttonSubmit,children:"去支付"})]})]})};function _o({visible:e,onClose:t,onSubmit:n,color:r,whiteTheme:o=!0}){const[i,s]=I({amount:"",rechargeChannel:"",currency:"USD",loading:!1,error:"",amountError:"",rechargeChannelError:"",currencyError:""}),[a,c]=I("online"),[u,f]=I({platform:"",transactionId:"",files:[],platformError:"",transactionIdError:"",filesError:"",loading:!1});if(Dt(()=>{e||(c("online"),s({amount:"",rechargeChannel:"",currency:"USD",loading:!1,error:"",amountError:"",rechargeChannelError:"",currencyError:""}),f({platform:"",transactionId:"",files:[],platformError:"",transactionIdError:"",filesError:"",loading:!1}))},[e]),!e)return null;const l=async p=>{p.preventDefault();let g=!0;if(s(_=>({..._,amountError:"",rechargeChannelError:""})),i.amount.trim()||(s(_=>({..._,amountError:"请输入充值金额"})),g=!1),i.rechargeChannel||(s(_=>({..._,rechargeChannelError:"请选择支付平台"})),g=!1),!!g){s(_=>({..._,loading:!0,error:""}));try{await n({amount:i.amount,rechargeChannel:i.rechargeChannel,currency:i.currency}),t()}catch{s(_=>({..._,error:"提交失败,请重试"}))}finally{s(_=>({..._,loading:!1}))}}},b=p=>{p.target===p.currentTarget&&t()},h=o?{modalBg:"#fff",modalColor:"#222",modalBoxShadow:"0 4px 24px rgba(0,0,0,0.08)",mask:"rgba(0,0,0,0.3)",title:{fontWeight:600,fontSize:20,marginBottom:24,textAlign:"left",color:"#222"},closeBtn:{position:"absolute",right:16,top:16,background:"none",border:"none",color:"#222",fontSize:22,cursor:"pointer",lineHeight:1},tabBtn:(p,g)=>({flex:1,background:p?"#fff":"#F7F8FA",color:p?"#155EEF":"#222",border:"none",borderRadius:g?"8px 0 0 8px":"0 8px 8px 0",fontWeight:p?600:400,fontSize:16,height:48,boxShadow:p?"0 2px 8px 0 rgba(20,20,20,0.04)":"none",outline:"none",cursor:"pointer",borderRight:g?"1px solid #F0F1F3":void 0,borderLeft:g?void 0:"1px solid #F0F1F3",transition:"all 0.2s"})}:{modalBg:"#181A20",modalColor:"#fff",modalBoxShadow:"0 4px 24px rgba(0,0,0,0.5)",mask:"rgba(0,0,0,0.7)",title:{fontWeight:600,fontSize:20,marginBottom:24,textAlign:"left",color:"#fff"},closeBtn:{position:"absolute",right:16,top:16,background:"none",border:"none",color:"#fff",fontSize:22,cursor:"pointer",lineHeight:1},tabBtn:(p,g)=>({flex:1,background:p?"#23262F":"#181A20",color:p?"#00E8C6":"#fff",border:"none",borderRadius:g?"8px 0 0 8px":"0 8px 8px 0",fontWeight:p?600:400,fontSize:16,height:48,boxShadow:p?"0 2px 8px 0 rgba(20,20,20,0.10)":"none",outline:"none",cursor:"pointer",borderRight:g?"1px solid #23262F":void 0,borderLeft:g?void 0:"1px solid #23262F",transition:"all 0.2s"})};return m("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:h.mask,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},onClick:b,children:m("form",{onSubmit:l,style:{background:h.modalBg,padding:32,borderRadius:12,minWidth:400,maxWidth:400,color:r||h.modalColor,boxShadow:h.modalBoxShadow,position:"relative"},onClick:p=>p.stopPropagation(),children:[m("button",{type:"button",onClick:t,style:h.closeBtn,"aria-label":"关闭",children:"×"}),m("div",{style:h.title,children:"充值 / 转账"}),m("div",{style:{display:"flex",marginBottom:28},children:[m("button",{type:"button",onClick:()=>c("online"),style:h.tabBtn(a==="online",!0),children:"在线充值"}),m("button",{type:"button",onClick:()=>c("offline"),style:h.tabBtn(a==="offline",!1),children:"线下转账"})]}),a==="online"?m(An,{formState:i,setFormState:s,onClose:t,loading:i.loading,whiteTheme:o}):m(ho,{formState:u,setFormState:f,onClose:t,loading:u.loading,whiteTheme:o})]})})}function Ke(){return(Ke=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var mo=["context","children"];function bo(e){this.getChildContext=function(){return e.context};var t=e.children,n=function(r,o){if(r==null)return{};var i,s,a={},c=Object.keys(r);for(s=0;s<c.length;s++)o.indexOf(i=c[s])>=0||(a[i]=r[i]);return a}(e,mo);return Pt(t,n)}function go(){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=W(bo,Ke({},this._props,{context:e.detail.context}),function t(n,r){if(n.nodeType===3)return n.data;if(n.nodeType!==1)return null;var o=[],i={},s=0,a=n.attributes,c=n.childNodes;for(s=a.length;s--;)a[s].name!=="slot"&&(i[a[s].name]=a[s].value,i[dn(a[s].name)]=a[s].value);for(s=c.length;s--;){var u=t(c[s],null),f=c[s].slot;f?i[f]=W(wt,{name:f},u):o[s]=u}var l=r?W(wt,null,o):o;return W(r||n.nodeName.toLowerCase(),i,l)}(this,this._vdomComponent)),(this.hasAttribute("hydrate")?Nt:be)(this._vdom,this._root)}function dn(e){return e.replace(/-(\w)/g,function(t,n){return n?n.toUpperCase():""})}function yo(e,t,n){if(this._vdom){var r={};r[e]=n=n??void 0,r[dn(e)]=n,this._vdom=Pt(this._vdom,r),be(this._vdom,this._root)}}function wo(){be(this._vdom=null,this._root)}function wt(e,t){var n=this;return W("slot",Ke({},e,{ref:function(r){r?(n.ref=r,n._listener||(n._listener=function(o){o.stopPropagation(),o.detail.context=t},r.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function pn(e,t,n,r){function o(){var i=Reflect.construct(HTMLElement,[],o);return i._vdomComponent=e,i._root=r&&r.shadow?i.attachShadow({mode:r.mode||"open"}):i,i}return(o.prototype=Object.create(HTMLElement.prototype)).constructor=o,o.prototype.connectedCallback=go,o.prototype.attributeChangedCallback=yo,o.prototype.disconnectedCallback=wo,n=n||e.observedAttributes||Object.keys(e.propTypes||{}),o.observedAttributes=n,n.forEach(function(i){Object.defineProperty(o.prototype,i,{get:function(){return this._vdom.props[i]},set:function(s){this._vdom?this.attributeChangedCallback(i,null,s):(this._props||(this._props={}),this._props[i]=s,this.connectedCallback());var a=typeof s;s!=null&&a!=="string"&&a!=="boolean"&&a!=="number"||this.setAttribute(i,s)}})}),customElements.define(t||e.tagName||e.displayName||e.name,o)}lo();function xo(e){const[t,n]=I(!1),[r,o]=I(!0),i=e.theme?.primaryColor;return m("div",{children:[m(kn,{color:i,onClick:()=>n(!0),children:"打开表单"}),m("button",{style:{marginLeft:16,padding:"8px 16px",borderRadius:6,border:"1px solid #eee",cursor:"pointer"},onClick:()=>o(a=>!a),children:r?"切换为暗黑主题":"切换为白色主题"}),m(_o,{visible:t,onClose:()=>n(!1),onSubmit:async a=>{const c=await fo({amount:a.amount,currency:a.currency,rechargeChannel:a.rechargeChannel});window.open(c,"_blank")},color:i,whiteTheme:r})]})}pn(xo,"x-best-modal-form",["theme"],{shadow:!1});const Eo=({popover:e,children:t,popoverWidth:n=300,popoverMinWidth:r=200,offsetY:o=16,offsetX:i=16,popoverPosition:s="top"})=>{const[a,c]=I(!1),[u,f]=I(s),l=Lt(null),b=()=>{if(s==="top"||s==="bottom")if(l.current){const g=l.current.getBoundingClientRect();s==="top"&&g.top<100?f("bottom"):s==="bottom"&&window.innerHeight-g.bottom<100?f("top"):f(s)}else f(s);else f(s);c(!0)};let h={position:"absolute",zIndex:10,background:"#fff",color:"#222",borderRadius:6,fontSize:15,minWidth:r,width:n,padding:"8px 14px",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",pointerEvents:"auto",textAlign:"center",border:"none",animation:"fadeInUp 0.3s"},p={position:"absolute",zIndex:11,width:0,height:0};return u==="top"?(h={...h,left:"50%",top:-48,transform:"translateX(-50%)"},p={...p,left:"50%",bottom:-8,transform:"translateX(-50%)",borderLeft:"8px solid transparent",borderRight:"8px solid transparent",borderTop:"8px solid #fff"}):u==="bottom"?(h={...h,left:"50%",top:"100%",marginTop:o,transform:"translateX(-50%)"},p={...p,left:"50%",top:-8,transform:"translateX(-50%)",borderLeft:"8px solid transparent",borderRight:"8px solid transparent",borderBottom:"8px solid #fff"}):u==="leftTop"?(h={...h,right:"100%",top:0,marginRight:i,transform:"none"},p={...p,right:-8,top:12,borderTop:"8px solid transparent",borderBottom:"8px solid transparent",borderLeft:"8px solid #fff"}):u==="rightTop"&&(h={...h,left:"100%",top:0,marginLeft:i,transform:"translateY(0)"},p={...p,left:-8,top:12,borderTop:"8px solid transparent",borderBottom:"8px solid transparent",borderRight:"8px solid #fff"}),m("div",{ref:l,style:{position:"relative",display:"inline-block"},onMouseEnter:b,onMouseLeave:()=>c(!1),children:[t,a&&m("div",{style:h,children:[e,m("div",{style:p})]})]})},So={available:0,currency:"USD",symbol:"$",details:[{label:"真实金额",value:0,color:"#15b36b",dot:"#15b36b"},{label:"冻结金额",value:0,color:"#f59e0b",dot:"#f59e0b"},{label:"总可用",value:0,color:"#155EEF",dot:"#15b36b"}]};function xt(e){return e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}function vo(){const[e,t]=I(So);return Dt(()=>{(async()=>{try{const r=await ao(),o={available:r.availableAmount,currency:"USD",symbol:"$",details:[{label:"真实金额",value:r.totalAmount,color:"#15b36b",dot:"#15b36b"},{label:"冻结金额",value:r.frozenAmount,color:"#f59e0b",dot:"#f59e0b"},{label:"总可用",value:r.availableAmount,color:"#155EEF",dot:"#15b36b"}]};t(o)}catch(r){console.error("获取余额失败:",r)}})()},[]),m(Eo,{popover:m(V,{children:[m("div",{style:{fontSize:16,fontWeight:600,color:"#222",marginBottom:16,textAlign:"center"},children:"余额详情"}),e.details.map(n=>m("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 0",borderBottom:"1px solid #e5e7eb",fontSize:15},children:[m("span",{style:{display:"flex",alignItems:"center",color:"#6b7280",fontWeight:500},children:[m("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:n.dot,marginRight:8}}),n.label]}),m("span",{style:{color:n.color,fontWeight:600,fontSize:15},children:[e.symbol,xt(n.value)]})]},n.label))]}),popoverPosition:"rightTop",children:m("div",{style:{fontSize:24,fontWeight:800,color:"#111827",display:"inline-block"},children:[e.symbol,xt(e.available),m("span",{style:{fontSize:18,color:"#6b7280",marginLeft:8,fontWeight:600},children:e.currency})]})})}pn(vo,"best-statistical-balance");const Ro=["x-greeting","x-best-modal-form","best-statistical-balance"];exports.components=Ro;exports.initFundUnit=mn;exports.npmTest=hn;exports.printCurrentTime=_n;
45
+ `,c.onclick=()=>{document.body.removeChild(s)},s.appendChild(c)}document.body.appendChild(s),o!==0&&setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},o||3e3)}success(t){this.show("success",t)}error(t){this.show("error",t)}warning(t){this.show("warning",t)}info(t){this.show("info",t)}}const ze=new io;function so(e={}){const{baseURL:t="/api",timeout:n=1e4,getLocale:r,onError:o}=e,i=R.create({baseURL:t,timeout:n});return i.interceptors.request.use(s=>{const a=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),{token:c}=a;if(s.headers={...s.headers,Authorization:c},r){const u=r();u&&(s.headers={...s.headers,"Accept-Language":u})}return s}),i.interceptors.response.use(s=>{if(s.data&&s.data.code===0)return s.data;const a=s.data?.msg||s.data?.message||"未知错误";return ze.error(a),o&&o(a,s),Promise.reject(s.data||{message:"未知错误"})},s=>{const a=s.response?.data?.msg||s.response?.data?.message||s.message||"网络请求失败";return ze.error(a),o&&o(a,s),Promise.reject(s)}),i}const ie=so();function ao(){const e=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");return ie.get("/balance",{params:{merchant_id:e.merchantId,biz_type:e.bizType}}).then(t=>{const n=t.data;return{totalAmount:n.total_amount||0,availableAmount:n.available_amount||0,frozenAmount:n.frozen_amount||0}})}const lo=async()=>ie.get("/all-dicts",{}).then(e=>(sessionStorage.setItem("all_dicts",JSON.stringify(e.data)),e.data||{})),co=async(e,t)=>ie.post("/oss/upload",e,{headers:{"Content-Type":"multipart/form-data"},onUploadProgress:n=>{if(n.total){const r=Math.round(n.loaded*100/n.total);t&&t(r)}}}).then(n=>n.data?.url||""),uo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),n={merchant_id:Number(t.merchantId),biz_type:t.bizType,source_operator:String(t.userId),transfer_no:e.transferNo,transfer_channel:e.transferChannel,voucher_urls:e.voucherUrls};return ie.post("/offline/recharge/create",n,{})},fo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");console.log(t,"fundUnitParams");const n={merchant_id:Number(t.merchantId),biz_type:t.bizType,source_operator:String(t.userId),amount:e.amount,currency:e.currency,recharge_channel:e.rechargeChannel,return_url:window.location.href};return ie.post("/online/recharge/create",n,{}).then(r=>r.data.redirect_url)},po=({value:e=[],onChange:t,maxCount:n=10,accept:r=".jpg,.jpeg,.png,.pdf",multiple:o=!0,disabled:i=!1})=>{const s=Lt(null),[a,c]=I(!1),[u,f]=I(0),l=async h=>{const p=Array.from(h.target.files).slice(0,n);if(!p.length)return;c(!0);const g=[];for(let _=0;_<p.length;_++){f(0);const y=new FormData;y.append("file",p[_]);try{const w=await co(y,S=>f(S));w&&g.push(w)}catch{}}c(!1),f(0),t?.([...e,...g]),s.current&&(s.current.value="")},b=h=>{const p=e.filter((g,_)=>_!==h);t?.(p)};return m("div",{children:[m("div",{style:{border:"1px dashed #E5E6EB",borderRadius:8,background:"#FCFCFD",padding:24,textAlign:"center",cursor:i?"not-allowed":"pointer",minHeight:120,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#999",fontSize:15,opacity:i?.6:1},onClick:()=>!i&&s.current?.click(),children:[m("div",{style:{fontSize:48,marginBottom:12},children:"📁"}),m("div",{style:{color:"#222",fontSize:15,marginBottom:4},children:"点击或拖拽文件到此处上传"}),m("div",{style:{color:"#999",fontSize:13},children:["支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传 ",n," ","个文件"]}),m("input",{ref:s,type:"file",multiple:o,accept:r,style:{display:"none"},onChange:l,disabled:i}),a&&m("div",{style:{marginTop:12,color:"#1677ff"},children:["正在上传... ",u,"%"]})]}),e&&e.length>0&&m("div",{style:{marginTop:12},children:e.map((h,p)=>m("div",{style:{display:"flex",alignItems:"center",background:"#F7F8FA",borderRadius:8,padding:"12px 16px",marginBottom:8,fontSize:15,color:"#222",justifyContent:"space-between"},children:[m("div",{style:{display:"flex",alignItems:"center",flex:1},children:[m("span",{style:{fontWeight:500,wordBreak:"break-all"},children:h.split("/").pop()}),m("span",{style:{color:"#8C8F93",fontSize:13,marginLeft:8},children:"[已上传]"})]}),m("button",{type:"button",onClick:g=>{g.stopPropagation(),b(p)},style:{background:"#FF4D4F",color:"#fff",border:"none",borderRadius:6,padding:"4px 14px",fontSize:15,marginLeft:16,cursor:"pointer"},disabled:i,children:"移除"})]},h))})]})},ho=({formState:e,setFormState:t,onClose:n,loading:r,whiteTheme:o=!1})=>{const i=JSON.parse(sessionStorage.getItem("all_dicts")||"{}");console.log(i,"allDicts");const s=i?.channel||[],a=o?{label:{marginBottom:8,fontSize:14,color:"#222",textAlign:"left",display:"block"},input:{width:"100%",padding:"10px 12px",borderRadius:6,boxSizing:"border-box",border:"1px solid #E5E6EB",background:"#fff",color:"#222",fontSize:15,outline:"none",marginBottom:0},inputError:{border:"1px solid #ff4d4f"},select:{width:"100%",padding:"10px 12px",borderRadius:6,border:"1px solid #E5E6EB",background:"#fff",color:"#222",fontSize:15,outline:"none"},selectError:{border:"1px solid #ff4d4f"},buttonCancel:{background:"#fff",color:"#222",border:"1px solid #E5E6EB",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer"},buttonSubmit:{background:"#155EEF",color:"#fff",border:"none",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer",fontWeight:600},error:{color:"#ff4d4f",fontSize:13,marginTop:4,textAlign:"left"}}:{label:{marginBottom:8,fontSize:14,color:"#fff",textAlign:"left",display:"block"},input:{width:"100%",padding:"10px 12px",borderRadius:6,boxSizing:"border-box",border:"1px solid #23262F",background:"#23262F",color:"#fff",fontSize:15,outline:"none",marginBottom:0},inputError:{border:"1px solid #ff4d4f"},select:{width:"100%",padding:"10px 12px",borderRadius:6,border:"1px solid #23262F",background:"#23262F",color:"#fff",fontSize:15,outline:"none"},selectError:{border:"1px solid #ff4d4f"},buttonCancel:{background:"#23262F",color:"#fff",border:"none",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer"},buttonSubmit:{background:"#00E8C6",color:"#fff",border:"none",borderRadius:6,padding:"8px 24px",fontSize:15,cursor:"pointer",fontWeight:600},error:{color:"#ff4d4f",fontSize:13,marginTop:4,textAlign:"left"}};return m("form",{onSubmit:async u=>{u.preventDefault();let f=!0;t(l=>({...l,platformError:"",transactionIdError:"",filesError:""})),e.platform||(t(l=>({...l,platformError:"请选择支付平台"})),f=!1),e.transactionId.trim()||(t(l=>({...l,transactionIdError:"请输入转账交易ID"})),f=!1),(!e.files||e.files.length===0)&&(t(l=>({...l,filesError:"请上传转账凭证"})),f=!1),f&&(await uo({transferChannel:e.platform,transferNo:e.transactionId,voucherUrls:e.files}),n(),ze.success("离线充值创建成功"))},children:[m("div",{style:{marginBottom:18},children:[m("div",{style:a.label,children:[m("span",{style:{color:"#F53F3F"},children:"*"})," 第三方支付平台"]}),m("select",{style:{...a.select,...e.platformError?a.selectError:{}},value:e.platform,onInput:u=>{const f=u.target.value;t(l=>({...l,platform:f,platformError:f?"":l.platformError}))},children:[m("option",{value:"",disabled:!0,hidden:!0,children:"请选择支付平台"}),s?.map(u=>m("option",{value:u.value,children:u.label}))]}),e.platformError&&m("div",{style:a.error,children:e.platformError})]}),m("div",{style:{marginBottom:18},children:[m("div",{style:a.label,children:[m("span",{style:{color:"#F53F3F"},children:"*"})," 交易ID"]}),m("input",{type:"text",placeholder:"请输入转账交易ID",value:e.transactionId,onInput:u=>{const f=u.target.value;t(l=>({...l,transactionId:f,transactionIdError:f?"":l.transactionIdError}))},style:{...a.input,...e.transactionIdError?a.inputError:{}}}),e.transactionIdError&&m("div",{style:a.error,children:e.transactionIdError})]}),m("div",{style:{marginBottom:24},children:[m("div",{style:a.label,children:[m("span",{style:{color:"#F53F3F"},children:"*"})," 上传文件"]}),m(po,{value:e.files,onChange:u=>t(f=>({...f,files:u,filesError:""})),maxCount:10,accept:".jpg,.jpeg,.png,.pdf",multiple:!0}),e.filesError&&m("div",{style:a.error,children:e.filesError})]}),m("div",{style:{display:"flex",justifyContent:"flex-end",gap:12},children:[m("button",{type:"button",onClick:n,style:a.buttonCancel,children:"取消"}),m("button",{type:"submit",disabled:r,style:a.buttonSubmit,children:"去支付"})]})]})};function _o({visible:e,onClose:t,onSubmit:n,color:r,whiteTheme:o=!0}){const[i,s]=I({amount:"",rechargeChannel:"",currency:"USD",loading:!1,error:"",amountError:"",rechargeChannelError:"",currencyError:""}),[a,c]=I("online"),[u,f]=I({platform:"",transactionId:"",files:[],platformError:"",transactionIdError:"",filesError:"",loading:!1});if(Dt(()=>{e||(c("online"),s({amount:"",rechargeChannel:"",currency:"USD",loading:!1,error:"",amountError:"",rechargeChannelError:"",currencyError:""}),f({platform:"",transactionId:"",files:[],platformError:"",transactionIdError:"",filesError:"",loading:!1}))},[e]),!e)return null;const l=async p=>{p.preventDefault();let g=!0;if(s(_=>({..._,amountError:"",rechargeChannelError:""})),i.amount.trim()||(s(_=>({..._,amountError:"请输入充值金额"})),g=!1),i.rechargeChannel||(s(_=>({..._,rechargeChannelError:"请选择支付平台"})),g=!1),!!g){s(_=>({..._,loading:!0,error:""}));try{await n({amount:i.amount,rechargeChannel:i.rechargeChannel,currency:i.currency}),t()}catch{s(_=>({..._,error:"提交失败,请重试"}))}finally{s(_=>({..._,loading:!1}))}}},b=p=>{p.target===p.currentTarget&&t()},h=o?{modalBg:"#fff",modalColor:"#222",modalBoxShadow:"0 4px 24px rgba(0,0,0,0.08)",mask:"rgba(0,0,0,0.3)",title:{fontWeight:600,fontSize:20,marginBottom:24,textAlign:"left",color:"#222"},closeBtn:{position:"absolute",right:16,top:16,background:"none",border:"none",color:"#222",fontSize:22,cursor:"pointer",lineHeight:1},tabBtn:(p,g)=>({flex:1,background:p?"#fff":"#F7F8FA",color:p?"#155EEF":"#222",border:"none",borderRadius:g?"8px 0 0 8px":"0 8px 8px 0",fontWeight:p?600:400,fontSize:16,height:48,boxShadow:p?"0 2px 8px 0 rgba(20,20,20,0.04)":"none",outline:"none",cursor:"pointer",borderRight:g?"1px solid #F0F1F3":void 0,borderLeft:g?void 0:"1px solid #F0F1F3",transition:"all 0.2s"})}:{modalBg:"#181A20",modalColor:"#fff",modalBoxShadow:"0 4px 24px rgba(0,0,0,0.5)",mask:"rgba(0,0,0,0.7)",title:{fontWeight:600,fontSize:20,marginBottom:24,textAlign:"left",color:"#fff"},closeBtn:{position:"absolute",right:16,top:16,background:"none",border:"none",color:"#fff",fontSize:22,cursor:"pointer",lineHeight:1},tabBtn:(p,g)=>({flex:1,background:p?"#23262F":"#181A20",color:p?"#00E8C6":"#fff",border:"none",borderRadius:g?"8px 0 0 8px":"0 8px 8px 0",fontWeight:p?600:400,fontSize:16,height:48,boxShadow:p?"0 2px 8px 0 rgba(20,20,20,0.10)":"none",outline:"none",cursor:"pointer",borderRight:g?"1px solid #23262F":void 0,borderLeft:g?void 0:"1px solid #23262F",transition:"all 0.2s"})};return m("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:h.mask,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999},onClick:b,children:m("form",{onSubmit:l,style:{background:h.modalBg,padding:32,borderRadius:12,minWidth:400,maxWidth:400,color:r||h.modalColor,boxShadow:h.modalBoxShadow,position:"relative"},onClick:p=>p.stopPropagation(),children:[m("button",{type:"button",onClick:t,style:h.closeBtn,"aria-label":"关闭",children:"×"}),m("div",{style:h.title,children:"充值 / 转账"}),m("div",{style:{display:"flex",marginBottom:28},children:[m("button",{type:"button",onClick:()=>c("online"),style:h.tabBtn(a==="online",!0),children:"在线充值"}),m("button",{type:"button",onClick:()=>c("offline"),style:h.tabBtn(a==="offline",!1),children:"线下转账"})]}),a==="online"?m(An,{formState:i,setFormState:s,onClose:t,loading:i.loading,whiteTheme:o}):m(ho,{formState:u,setFormState:f,onClose:t,loading:u.loading,whiteTheme:o})]})})}function Ke(){return(Ke=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var mo=["context","children"];function bo(e){this.getChildContext=function(){return e.context};var t=e.children,n=function(r,o){if(r==null)return{};var i,s,a={},c=Object.keys(r);for(s=0;s<c.length;s++)o.indexOf(i=c[s])>=0||(a[i]=r[i]);return a}(e,mo);return Pt(t,n)}function go(){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=W(bo,Ke({},this._props,{context:e.detail.context}),function t(n,r){if(n.nodeType===3)return n.data;if(n.nodeType!==1)return null;var o=[],i={},s=0,a=n.attributes,c=n.childNodes;for(s=a.length;s--;)a[s].name!=="slot"&&(i[a[s].name]=a[s].value,i[dn(a[s].name)]=a[s].value);for(s=c.length;s--;){var u=t(c[s],null),f=c[s].slot;f?i[f]=W(wt,{name:f},u):o[s]=u}var l=r?W(wt,null,o):o;return W(r||n.nodeName.toLowerCase(),i,l)}(this,this._vdomComponent)),(this.hasAttribute("hydrate")?Nt:be)(this._vdom,this._root)}function dn(e){return e.replace(/-(\w)/g,function(t,n){return n?n.toUpperCase():""})}function yo(e,t,n){if(this._vdom){var r={};r[e]=n=n??void 0,r[dn(e)]=n,this._vdom=Pt(this._vdom,r),be(this._vdom,this._root)}}function wo(){be(this._vdom=null,this._root)}function wt(e,t){var n=this;return W("slot",Ke({},e,{ref:function(r){r?(n.ref=r,n._listener||(n._listener=function(o){o.stopPropagation(),o.detail.context=t},r.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function pn(e,t,n,r){function o(){var i=Reflect.construct(HTMLElement,[],o);return i._vdomComponent=e,i._root=r&&r.shadow?i.attachShadow({mode:r.mode||"open"}):i,i}return(o.prototype=Object.create(HTMLElement.prototype)).constructor=o,o.prototype.connectedCallback=go,o.prototype.attributeChangedCallback=yo,o.prototype.disconnectedCallback=wo,n=n||e.observedAttributes||Object.keys(e.propTypes||{}),o.observedAttributes=n,n.forEach(function(i){Object.defineProperty(o.prototype,i,{get:function(){return this._vdom.props[i]},set:function(s){this._vdom?this.attributeChangedCallback(i,null,s):(this._props||(this._props={}),this._props[i]=s,this.connectedCallback());var a=typeof s;s!=null&&a!=="string"&&a!=="boolean"&&a!=="number"||this.setAttribute(i,s)}})}),customElements.define(t||e.tagName||e.displayName||e.name,o)}lo();function xo(e){const[t,n]=I(!1),[r,o]=I(!0),i=e.theme?.primaryColor;return m("div",{children:[m(kn,{color:i,onClick:()=>n(!0),children:"打开表单"}),m("button",{style:{marginLeft:16,padding:"8px 16px",borderRadius:6,border:"1px solid #eee",cursor:"pointer"},onClick:()=>o(a=>!a),children:r?"切换为暗黑主题":"切换为白色主题"}),m(_o,{visible:t,onClose:()=>n(!1),onSubmit:async a=>{const c=await fo({amount:a.amount,currency:a.currency,rechargeChannel:a.rechargeChannel});window.open(c,"_blank")},color:i,whiteTheme:r})]})}pn(xo,"x-best-modal-form",["theme"],{shadow:!1});const Eo=({popover:e,children:t,popoverWidth:n=300,popoverMinWidth:r=200,offsetY:o=16,offsetX:i=16,popoverPosition:s="top"})=>{const[a,c]=I(!1),[u,f]=I(s),l=Lt(null),b=()=>{if(s==="top"||s==="bottom")if(l.current){const g=l.current.getBoundingClientRect();s==="top"&&g.top<100?f("bottom"):s==="bottom"&&window.innerHeight-g.bottom<100?f("top"):f(s)}else f(s);else f(s);c(!0)};let h={position:"absolute",zIndex:10,background:"#fff",color:"#222",borderRadius:6,fontSize:15,minWidth:r,width:n,padding:"8px 14px",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",pointerEvents:"auto",textAlign:"center",border:"none",animation:"fadeInUp 0.3s"},p={position:"absolute",zIndex:11,width:0,height:0};return u==="top"?(h={...h,left:"50%",top:-48,transform:"translateX(-50%)"},p={...p,left:"50%",bottom:-8,transform:"translateX(-50%)",borderLeft:"8px solid transparent",borderRight:"8px solid transparent",borderTop:"8px solid #fff"}):u==="bottom"?(h={...h,left:"50%",top:"100%",marginTop:o,transform:"translateX(-50%)"},p={...p,left:"50%",top:-8,transform:"translateX(-50%)",borderLeft:"8px solid transparent",borderRight:"8px solid transparent",borderBottom:"8px solid #fff"}):u==="leftTop"?(h={...h,right:"100%",top:0,marginRight:i,transform:"none"},p={...p,right:-8,top:12,borderTop:"8px solid transparent",borderBottom:"8px solid transparent",borderLeft:"8px solid #fff"}):u==="rightTop"&&(h={...h,left:"100%",top:0,marginLeft:i,transform:"translateY(0)"},p={...p,left:-8,top:12,borderTop:"8px solid transparent",borderBottom:"8px solid transparent",borderRight:"8px solid #fff"}),m("div",{ref:l,style:{position:"relative",display:"inline-block"},onMouseEnter:b,onMouseLeave:()=>c(!1),children:[t,a&&m("div",{style:h,children:[e,m("div",{style:p})]})]})},So={available:0,currency:"USD",symbol:"$",details:[{label:"真实金额",value:0,color:"#15b36b",dot:"#15b36b"},{label:"冻结金额",value:0,color:"#f59e0b",dot:"#f59e0b"},{label:"总可用",value:0,color:"#155EEF",dot:"#15b36b"}]};function xt(e){return e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}function vo(){const[e,t]=I(So);return Dt(()=>{(async()=>{try{const r=await ao(),o={available:r.availableAmount,currency:"USD",symbol:"$",details:[{label:"真实金额",value:r.totalAmount,color:"#15b36b",dot:"#15b36b"},{label:"冻结金额",value:r.frozenAmount,color:"#f59e0b",dot:"#f59e0b"},{label:"总可用",value:r.availableAmount,color:"#155EEF",dot:"#15b36b"}]};t(o)}catch(r){console.error("获取余额失败:",r)}})()},[]),m(Eo,{popover:m(V,{children:[m("div",{style:{fontSize:16,fontWeight:600,color:"#222",marginBottom:16,textAlign:"center"},children:"余额详情"}),e.details.map(n=>m("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 0",borderBottom:"1px solid #e5e7eb",fontSize:15},children:[m("span",{style:{display:"flex",alignItems:"center",color:"#6b7280",fontWeight:500},children:[m("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:n.dot,marginRight:8}}),n.label]}),m("span",{style:{color:n.color,fontWeight:600,fontSize:15},children:[e.symbol,xt(n.value)]})]},n.label))]}),popoverPosition:"rightTop",children:m("div",{style:{fontSize:24,fontWeight:800,color:"#111827",display:"inline-block"},children:[e.symbol,xt(e.available),m("span",{style:{fontSize:18,color:"#6b7280",marginLeft:8,fontWeight:600},children:e.currency})]})})}pn(vo,"best-statistical-balance");const Ro=["x-greeting","x-best-modal-form","best-statistical-balance"];exports.components=Ro;exports.initFundUnit=mn;exports.npmTest=hn;exports.printCurrentTime=_n;
package/dist/best-unit.js CHANGED
@@ -2465,7 +2465,7 @@ function oo() {
2465
2465
  const e = JSON.parse(
2466
2466
  sessionStorage.getItem("fund_unit_params") || "{}"
2467
2467
  );
2468
- return console.log(e, "fundUnitParams"), ie.get("/balance", {
2468
+ return ie.get("/balance", {
2469
2469
  params: {
2470
2470
  merchant_id: e.merchantId,
2471
2471
  biz_type: e.bizType
@@ -16,6 +16,16 @@ export declare function initFundUnit(params: {
16
16
  userId: string;
17
17
  };
18
18
  declare global {
19
+ interface Window {
20
+ bestUnit: {
21
+ initFundUnit: (params: {
22
+ token: string;
23
+ merchant_id: string;
24
+ biz_type: string;
25
+ }) => void;
26
+ };
27
+ }
28
+
19
29
  namespace JSX {
20
30
  interface IntrinsicElements {
21
31
  "x-greeting": any;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "0.0.26",
4
+ "version": "0.0.28",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
8
- "types": "dist/types/index.d.ts",
8
+ "types": "dist/types/global.d.ts",
9
9
  "scripts": {
10
10
  "dev": "vite",
11
11
  "build": "tsc -b && vite build && cp -r src/types dist/types",
package/src/api/index.ts CHANGED
@@ -5,7 +5,6 @@ export function getBalance() {
5
5
  const fundUnitParams = JSON.parse(
6
6
  sessionStorage.getItem("fund_unit_params") || "{}"
7
7
  );
8
- console.log(fundUnitParams, "fundUnitParams");
9
8
  return http
10
9
  .get("/balance", {
11
10
  params: {
@@ -16,6 +16,16 @@ export declare function initFundUnit(params: {
16
16
  userId: string;
17
17
  };
18
18
  declare global {
19
+ interface Window {
20
+ bestUnit: {
21
+ initFundUnit: (params: {
22
+ token: string;
23
+ merchant_id: string;
24
+ biz_type: string;
25
+ }) => void;
26
+ };
27
+ }
28
+
19
29
  namespace JSX {
20
30
  interface IntrinsicElements {
21
31
  "x-greeting": any;