best-unit 1.2.17 → 1.2.19

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.
Files changed (49) hide show
  1. package/dist/best-unit.cjs +1 -1
  2. package/dist/best-unit.js +1 -1
  3. package/package.json +4 -1
  4. package/BEST_UNIT_USAGE.md +0 -402
  5. package/index.html +0 -13
  6. package/src/api/axiosInstance.ts +0 -111
  7. package/src/api/index.ts +0 -136
  8. package/src/api/proxy.ts +0 -11
  9. package/src/components/business/recharge-sdk/components/offline-transfer-form/index.tsx +0 -158
  10. package/src/components/business/recharge-sdk/components/offline-transfer-form/theme.tsx +0 -238
  11. package/src/components/business/recharge-sdk/components/online-recharge-form/index.tsx +0 -199
  12. package/src/components/business/recharge-sdk/components/online-recharge-form/theme.tsx +0 -151
  13. package/src/components/business/recharge-sdk/components/recharge/index.tsx +0 -152
  14. package/src/components/business/recharge-sdk/components/recharge/theme.tsx +0 -64
  15. package/src/components/business/recharge-sdk/index.tsx +0 -37
  16. package/src/components/business/refresh-button/index.tsx +0 -99
  17. package/src/components/business/refresh-button/theme.tsx +0 -58
  18. package/src/components/business/statistical-balance/index.tsx +0 -190
  19. package/src/components/business/statistical-balance/theme.tsx +0 -110
  20. package/src/components/common/button/index.tsx +0 -17
  21. package/src/components/common/button/theme.tsx +0 -48
  22. package/src/components/common/hover-popover/index.tsx +0 -179
  23. package/src/components/common/hover-popover/theme.tsx +0 -39
  24. package/src/components/common/message/index.tsx +0 -321
  25. package/src/components/common/message/theme.tsx +0 -25
  26. package/src/components/common/modal/index.tsx +0 -99
  27. package/src/components/common/modal/theme.tsx +0 -91
  28. package/src/components/common/select/index.tsx +0 -229
  29. package/src/components/common/select/theme.tsx +0 -104
  30. package/src/components/common/upload/index.tsx +0 -140
  31. package/src/components/common/upload/theme.tsx +0 -89
  32. package/src/demo/App.tsx +0 -685
  33. package/src/demo/index.tsx +0 -4
  34. package/src/demo/testBalanceData.tsx +0 -79
  35. package/src/demo/theme-config-example.tsx +0 -1
  36. package/src/local/en.ts +0 -63
  37. package/src/local/index.ts +0 -36
  38. package/src/local/zh.ts +0 -62
  39. package/src/main.ts +0 -26
  40. package/src/types/global.d.ts +0 -146
  41. package/src/types/index.ts +0 -31
  42. package/src/types/preact-custom-element.d.ts +0 -1
  43. package/src/utils/business/index.ts +0 -132
  44. package/src/utils/common/index.ts +0 -8
  45. package/src/vite-env.d.ts +0 -8
  46. package/tsconfig.app.json +0 -33
  47. package/tsconfig.json +0 -15
  48. package/tsconfig.node.json +0 -24
  49. package/vite.config.ts +0 -24
@@ -42,7 +42,7 @@
42
42
  padding: 4px;
43
43
  color: ${i.closeColor};
44
44
  font-size: 12px;
45
- `,l.onclick=()=>{document.body.removeChild(a)},a.appendChild(l)}document.body.appendChild(a),o!==0&&setTimeout(()=>{document.body.contains(a)&&document.body.removeChild(a)},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 it=new Oo;function Po(e={}){const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");console.log("fundUnitParams",t);const{env:n}=t;let r;switch(n){case ne.DEV:case ne.DEVELOPMENT:r="/api";break;case ne.TEST:r="https://fund.bestfulfill.tech/api/sdk";break;case ne.PROD:case ne.PRODUCTION:default:r="https://fund.bestfulfill.com/api/sdk";break}const{baseURL:o=r,timeout:s=1e4,onError:i}=e,a=M.create({baseURL:o,timeout:s});return a.interceptors.request.use(u=>{const{token:l,locale:d}=t;return u.headers={...u.headers,Authorization:l,"x-locale":d===We.ZH?"zh-CN":"en-US"},u}),a.interceptors.response.use(u=>{if(u.data&&u.data.code===0)return u.data;const l=u.data?.msg||u.data?.message||"未知错误";return it.error(l),i&&i(l,u),Promise.reject(u.data||{message:"未知错误"})},u=>{const l=u.response?.data?.msg||u.response?.data?.message||u.message||"网络请求失败";return it.error(l),i&&i(l,u),Promise.reject(u)}),a}let Ce=null;function ae(){return Ce||(Ce=Po()),Ce}function Io(){Ce=null}function Un(){const e=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");return ae().get("/balance",{params:{merchant_id:e.merchantId,biz_type:e.bizType,fund_balance_id:e.fundBalanceId}}).then(t=>{const n=t.data,r={fundBalanceId:n.fund_balance_id,merchantId:n.merchant_id,bizType:n.biz_type,currency:n.currency,totalAmount:n.total_amount,frozenAmount:n.frozen_amount,creditLimit:n.credit_config?.credit_limit,creditUsed:n.credit_used,isCredit:!!n.credit_config,availableAmount:n.available_amount,pendingAmount:n.pending_amount,status:n.status,createdAt:n.created_at};return sessionStorage.setItem("balanceData",JSON.stringify(r)),r})}const No=async()=>ae().get("/all-dicts",{}).then(e=>(sessionStorage.setItem("all_dicts",JSON.stringify(e.data)),e.data||{})),Do=async(e,t)=>ae().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||""),zo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),n={merchant_id:Number(t.merchantId),biz_type:t.bizType,fund_balance_id:t.fundBalanceId,source_operator:t.userId?String(t.userId):void 0,transfer_no:e.transferNo,transfer_channel:e.transferChannel,voucher_urls:e.voucherUrls};return ae().post("/offline/recharge/create",n,{})},Uo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),n={merchant_id:Number(t.merchantId),biz_type:t.bizType,fund_balance_id:t.fundBalanceId,source_operator:t.userId?String(t.userId):void 0,amount:e.amount,currency:e.currency,recharge_channel:e.rechargeChannel,return_url:window.location.href};return ae().post("/online/recharge/create",n,{}).then(r=>r.data.redirect_url)},Ho=async e=>ae().get("/calc-payment-amount",{params:e}).then(t=>t.data.payment_amount);async function $o(){let e=JSON.parse(sessionStorage.getItem("balanceData")||"{}");return e&&Object.keys(e).length>0||(e=await Un()),e}function jo(e){const{merchant_id:t,biz_type:n,fund_balance_id:r,user_id:o,theme:s=$.WHITE,locale:i=We.ZH,env:a,size:u,themeConfig:l}=e;console.log(e,"InitParams");const d="Bearer "+e.token;return sessionStorage.setItem("fund_unit_params",JSON.stringify({merchantId:t,bizType:n,fundBalanceId:r,userId:o,token:d,theme:s,locale:i,env:a,size:u,themeConfig:l})),Io(),No(),{token:d,merchantId:t,bizType:n,fundBalanceId:r,userId:o,theme:s,locale:i,env:a,size:u}}function v(e){const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");if(!e)return t;if(Array.isArray(e)){const n={};return e.forEach(r=>{n[r]=t[r]}),n}return t[e]}function Hn(){const e=new CustomEvent("refresh-balance",{detail:{},bubbles:!0,composed:!0});document.dispatchEvent(e)}const Wo={"/api":{target:"https://fund.bestfulfill.tech/api/sdk",changeOrigin:!0,rewrite:e=>e.replace(/^\/api/,""),secure:!1}},ye=v("size"),xe={white:{background:"#1890ff",color:"#fff",border:"none",borderRadius:6,padding:ye===f.SMALL?"6px 10px":"8px 16px",cursor:"pointer",fontSize:ye===f.SMALL?12:16,fontWeight:600},dark:{background:"#00E8C6",color:"#fff",border:"none",borderRadius:6,padding:ye===f.SMALL?"6px 10px":"8px 16px",cursor:"pointer",fontSize:ye===f.SMALL?12:16,fontWeight:600}};function qo(e){const t=v("theme"),n=v("themeConfig"),r=t===$.WHITE;let o=e;return!o&&n&&(o=(r?n.white:n.dark)?.color),r?{...xe.white,background:o||xe.white.background}:{...xe.dark,background:o||xe.dark.background}}function $n({onClick:e,color:t,children:n}){const r=qo(t);return m("button",{style:r,onClick:e,type:"button",children:n})}const Jo={余额详情:"余额详情",真实金额:"真实金额",冻结金额:"冻结金额",信用额度:"信用额度",已用额度:"已用额度",可用余额:"可用余额",暂无数据:"暂无数据","金额需在1到999999.99之间":"金额需在1到999999.99之间","充值 / 转账":"充值 / 转账",在线充值:"在线充值",线下转账:"线下转账",充值币种:"充值币种",充值金额:"充值金额",支付平台:"支付平台",请选择充值币种:"请选择充值币种",请输入充值金额:"请输入充值金额",请选择支付平台:"请选择支付平台","需要收取手续费,实际支付金额约为:":"需要收取手续费,实际支付金额约为:","提交失败,请重试":"提交失败,请重试","提交中...":"提交中...",去支付:"去支付",取消:"取消",关闭:"关闭",第三方支付平台:"第三方支付平台",交易ID:"交易ID",请输入转账交易ID:"请输入转账交易ID",上传文件:"上传文件",请上传转账凭证:"请上传转账凭证",离线充值创建成功:"离线充值创建成功","加载中...":"加载中...",错误:"错误",成功:"成功",必填:"必填","充值/转账":"充值/转账",切换为暗黑主题:"切换为暗黑主题",切换为白色主题:"切换为白色主题",点击或拖拽文件到此处上传:"点击或拖拽文件到此处上传","支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":"支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传",个文件:"个文件","正在上传...":"正在上传...",已上传:"已上传",移除:"移除"};function Vo(e){return Jo[e]||e}const Go={余额详情:"Balance Details",真实金额:"Real Balance",冻结金额:"Frozen Amount",信用额度:"Credit Limit",已用额度:"Credit Used",可用余额:"Available Balance",暂无数据:"No Data","金额需在1到999999.99之间":"Amount must be between 1 and 999999.99","充值 / 转账":"Recharge / Transfer",在线充值:"Online Recharge",线下转账:"Offline Transfer",充值币种:"Recharge Currency",充值金额:"Recharge Amount",支付平台:"Payment Platform",请选择充值币种:"Please select recharge currency",请输入充值金额:"Please enter recharge amount",请选择支付平台:"Please select payment platform","需要收取手续费,实际支付金额约为:":"requires a handling fee, the actual payment amount is approximately: ","提交失败,请重试":"Submit failed, please try again","提交中...":"Submitting...",去支付:"Go to Pay",取消:"Cancel",关闭:"Close",第三方支付平台:"Third-party Payment Platform",交易ID:"Transaction ID",请输入转账交易ID:"Please enter transfer transaction ID",上传文件:"Upload Files",请上传转账凭证:"Please upload transfer voucher",离线充值创建成功:"Offline recharge created successfully","加载中...":"Loading...",错误:"Error",成功:"Success",必填:"Required","充值/转账":"Recharge/Transfer",切换为暗黑主题:"Switch to Dark Theme",切换为白色主题:"Switch to Light Theme",点击或拖拽文件到此处上传:"Click or drag files here to upload","支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":"Supports JPG, PNG, PDF formats, single file not exceeding 20MB, maximum",个文件:"files can be uploaded","正在上传...":"Uploading...",已上传:"Uploaded",移除:"Remove"};function Ko(e){return Go[e]||e}function Xo(){return JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}").locale||We.ZH}function A(e){return Xo()==="zh"?Vo(e):Ko(e)}const jt={white:{trigger:{background:"#fff",color:"#222",border:"1px solid #d9d9d9"},triggerDisabled:{background:"#f5f5f5",color:"#bfbfbf",border:"1px solid #f0f0f0"},triggerError:{background:"#fff",color:"#222",border:"1px solid #ff4d4f"},dropdown:{background:"#fff",border:"1px solid #d9d9d9",color:"#222"},option:(e,t,n)=>({color:t?"#bfbfbf":e?"#1890ff":"#222",background:e?"#e6f7ff":n&&!t||t?"#f5f5f5":"#fff"}),placeholder:{color:"#bfbfbf"},scrollbarThumb:"#e5e5e5",scrollbarTrack:"#f5f5f5",boxShadow:"0 2px 8px rgba(0,0,0,0.08)"},dark:{trigger:{background:"#23262F",color:"#fff",border:"1px solid #374151"},triggerDisabled:{background:"#23262F",color:"#666",border:"1px solid #374151"},triggerError:{background:"#23262F",color:"#fff",border:"1px solid #ff4d4f"},dropdown:{background:"#23262F",border:"1px solid #374151",color:"#fff"},option:(e,t,n)=>({color:t?"#666":e?"#00E8C6":"#fff",background:e?"#23262F":n&&!t?"#333843":"#23262F"}),placeholder:{color:"#666"},scrollbarThumb:"#444C5C",scrollbarTrack:"#23262F",boxShadow:"0 2px 8px rgba(0,0,0,0.32)"}};function Zo(){const e=v("theme"),t=v("themeConfig"),n=e===$.WHITE,r=n?jt.white:jt.dark;if(t){const o=n?t.white:t.dark;if(o?.color)return{...r,option:(s,i,a)=>({...r.option(s,i,a),color:i?r.option(s,i,a).color:s?o.color:r.option(s,i,a).color})}}return r}const z=v("size"),st=({value:e,onChange:t,options:n,placeholder:r,style:o,error:s,disabled:i,dropdownStyle:a,className:u,dropdownClassName:l,children:d})=>{const[c,_]=N(!1),h=Oe(null),[g,y]=N(null),b=Zo();he(()=>{if(!c)return;const w=k=>{h.current&&!h.current.contains(k.target)&&_(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[c]);const x=n.find(w=>w.value===e),S=()=>s?b.triggerError:i?b.triggerDisabled:b.trigger;return m("div",{ref:h,className:u,style:{position:"relative",...o},children:[m("style",{children:`
45
+ `,l.onclick=()=>{document.body.removeChild(a)},a.appendChild(l)}document.body.appendChild(a),o!==0&&setTimeout(()=>{document.body.contains(a)&&document.body.removeChild(a)},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 it=new Oo;function Po(e={}){const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");console.log("fundUnitParams",t);const{env:n}=t;let r;switch(n){case ne.DEV:case ne.DEVELOPMENT:r="/api";break;case ne.TEST:r="https://fund.bestfulfill.tech/api/sdk";break;case ne.PROD:case ne.PRODUCTION:default:r="https://fund.bestfulfill.com/api/sdk";break}const{baseURL:o=r,timeout:s=1e4,onError:i}=e,a=M.create({baseURL:o,timeout:s});return a.interceptors.request.use(u=>{const{token:l,locale:d}=t;return u.headers={...u.headers,Authorization:l,"x-locale":d===We.ZH?"zh-CN":"en-US"},u}),a.interceptors.response.use(u=>{if(u.data&&u.data.code===0)return u.data;const l=u.data?.msg||u.data?.message||"未知错误";return it.error(l),i&&i(l,u),Promise.reject(u.data||{message:"未知错误"})},u=>{const l=u.response?.data?.msg||u.response?.data?.message||u.message||"网络请求失败";return it.error(l),i&&i(l,u),Promise.reject(u)}),a}let Ce=null;function ae(){return Ce||(Ce=Po()),Ce}function Io(){Ce=null}function Un(){const e=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");return ae().get("/balance",{params:{merchant_id:e.merchantId,biz_type:e.bizType,fund_balance_id:e.fundBalanceId}}).then(t=>{const n=t.data,r={fundBalanceId:n.fund_balance_id,merchantId:n.merchant_id,bizType:n.biz_type,currency:n.currency,totalAmount:n.total_amount,frozenAmount:n.frozen_amount,creditLimit:n.credit_config?.credit_limit,creditUsed:n.credit_used,isCredit:!!n.credit_config,availableAmount:n.available_amount,pendingAmount:n.pending_amount,status:n.status,createdAt:n.created_at};return sessionStorage.setItem("balanceData",JSON.stringify(r)),r})}const No=async()=>ae().get("/all-dicts",{}).then(e=>(sessionStorage.setItem("all_dicts",JSON.stringify(e.data)),e.data||{})),Do=async(e,t)=>ae().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||""),zo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),n={merchant_id:Number(t.merchantId),biz_type:t.bizType,fund_balance_id:t.fundBalanceId,source_operator:t.userId?String(t.userId):void 0,transfer_no:e.transferNo,transfer_channel:e.transferChannel,voucher_urls:e.voucherUrls};return ae().post("/offline/recharge/create",n,{})},Uo=async e=>{const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}"),n={merchant_id:Number(t.merchantId),biz_type:t.bizType,fund_balance_id:t.fundBalanceId,source_operator:t.userId?String(t.userId):void 0,amount:e.amount,currency:e.currency,recharge_channel:e.rechargeChannel,return_url:window.location.href};return ae().post("/online/recharge/create",n,{}).then(r=>r.data.redirect_url)},Ho=async e=>ae().get("/calc-payment-amount",{params:e}).then(t=>t.data.payment_amount);async function $o(){let e=JSON.parse(sessionStorage.getItem("balanceData")||"{}");return e&&Object.keys(e).length>0||(e=await Un()),e}function jo(e){const{merchant_id:t,biz_type:n,fund_balance_id:r,user_id:o,theme:s=$.WHITE,locale:i=We.ZH,env:a,size:u,themeConfig:l}=e;console.log(e,"InitParams1111");const d="Bearer "+e.token;return sessionStorage.setItem("fund_unit_params",JSON.stringify({merchantId:t,bizType:n,fundBalanceId:r,userId:o,token:d,theme:s,locale:i,env:a,size:u,themeConfig:l})),Io(),No(),{token:d,merchantId:t,bizType:n,fundBalanceId:r,userId:o,theme:s,locale:i,env:a,size:u}}function v(e){const t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");if(!e)return t;if(Array.isArray(e)){const n={};return e.forEach(r=>{n[r]=t[r]}),n}return t[e]}function Hn(){const e=new CustomEvent("refresh-balance",{detail:{},bubbles:!0,composed:!0});document.dispatchEvent(e)}const Wo={"/api":{target:"https://fund.bestfulfill.tech/api/sdk",changeOrigin:!0,rewrite:e=>e.replace(/^\/api/,""),secure:!1}},ye=v("size"),xe={white:{background:"#1890ff",color:"#fff",border:"none",borderRadius:6,padding:ye===f.SMALL?"6px 10px":"8px 16px",cursor:"pointer",fontSize:ye===f.SMALL?12:16,fontWeight:600},dark:{background:"#00E8C6",color:"#fff",border:"none",borderRadius:6,padding:ye===f.SMALL?"6px 10px":"8px 16px",cursor:"pointer",fontSize:ye===f.SMALL?12:16,fontWeight:600}};function qo(e){const t=v("theme"),n=v("themeConfig"),r=t===$.WHITE;let o=e;return!o&&n&&(o=(r?n.white:n.dark)?.color),r?{...xe.white,background:o||xe.white.background}:{...xe.dark,background:o||xe.dark.background}}function $n({onClick:e,color:t,children:n}){const r=qo(t);return m("button",{style:r,onClick:e,type:"button",children:n})}const Jo={余额详情:"余额详情",真实金额:"真实金额",冻结金额:"冻结金额",信用额度:"信用额度",已用额度:"已用额度",可用余额:"可用余额",暂无数据:"暂无数据","金额需在1到999999.99之间":"金额需在1到999999.99之间","充值 / 转账":"充值 / 转账",在线充值:"在线充值",线下转账:"线下转账",充值币种:"充值币种",充值金额:"充值金额",支付平台:"支付平台",请选择充值币种:"请选择充值币种",请输入充值金额:"请输入充值金额",请选择支付平台:"请选择支付平台","需要收取手续费,实际支付金额约为:":"需要收取手续费,实际支付金额约为:","提交失败,请重试":"提交失败,请重试","提交中...":"提交中...",去支付:"去支付",取消:"取消",关闭:"关闭",第三方支付平台:"第三方支付平台",交易ID:"交易ID",请输入转账交易ID:"请输入转账交易ID",上传文件:"上传文件",请上传转账凭证:"请上传转账凭证",离线充值创建成功:"离线充值创建成功","加载中...":"加载中...",错误:"错误",成功:"成功",必填:"必填","充值/转账":"充值/转账",切换为暗黑主题:"切换为暗黑主题",切换为白色主题:"切换为白色主题",点击或拖拽文件到此处上传:"点击或拖拽文件到此处上传","支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":"支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传",个文件:"个文件","正在上传...":"正在上传...",已上传:"已上传",移除:"移除"};function Vo(e){return Jo[e]||e}const Go={余额详情:"Balance Details",真实金额:"Real Balance",冻结金额:"Frozen Amount",信用额度:"Credit Limit",已用额度:"Credit Used",可用余额:"Available Balance",暂无数据:"No Data","金额需在1到999999.99之间":"Amount must be between 1 and 999999.99","充值 / 转账":"Recharge / Transfer",在线充值:"Online Recharge",线下转账:"Offline Transfer",充值币种:"Recharge Currency",充值金额:"Recharge Amount",支付平台:"Payment Platform",请选择充值币种:"Please select recharge currency",请输入充值金额:"Please enter recharge amount",请选择支付平台:"Please select payment platform","需要收取手续费,实际支付金额约为:":"requires a handling fee, the actual payment amount is approximately: ","提交失败,请重试":"Submit failed, please try again","提交中...":"Submitting...",去支付:"Go to Pay",取消:"Cancel",关闭:"Close",第三方支付平台:"Third-party Payment Platform",交易ID:"Transaction ID",请输入转账交易ID:"Please enter transfer transaction ID",上传文件:"Upload Files",请上传转账凭证:"Please upload transfer voucher",离线充值创建成功:"Offline recharge created successfully","加载中...":"Loading...",错误:"Error",成功:"Success",必填:"Required","充值/转账":"Recharge/Transfer",切换为暗黑主题:"Switch to Dark Theme",切换为白色主题:"Switch to Light Theme",点击或拖拽文件到此处上传:"Click or drag files here to upload","支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":"Supports JPG, PNG, PDF formats, single file not exceeding 20MB, maximum",个文件:"files can be uploaded","正在上传...":"Uploading...",已上传:"Uploaded",移除:"Remove"};function Ko(e){return Go[e]||e}function Xo(){return JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}").locale||We.ZH}function A(e){return Xo()==="zh"?Vo(e):Ko(e)}const jt={white:{trigger:{background:"#fff",color:"#222",border:"1px solid #d9d9d9"},triggerDisabled:{background:"#f5f5f5",color:"#bfbfbf",border:"1px solid #f0f0f0"},triggerError:{background:"#fff",color:"#222",border:"1px solid #ff4d4f"},dropdown:{background:"#fff",border:"1px solid #d9d9d9",color:"#222"},option:(e,t,n)=>({color:t?"#bfbfbf":e?"#1890ff":"#222",background:e?"#e6f7ff":n&&!t||t?"#f5f5f5":"#fff"}),placeholder:{color:"#bfbfbf"},scrollbarThumb:"#e5e5e5",scrollbarTrack:"#f5f5f5",boxShadow:"0 2px 8px rgba(0,0,0,0.08)"},dark:{trigger:{background:"#23262F",color:"#fff",border:"1px solid #374151"},triggerDisabled:{background:"#23262F",color:"#666",border:"1px solid #374151"},triggerError:{background:"#23262F",color:"#fff",border:"1px solid #ff4d4f"},dropdown:{background:"#23262F",border:"1px solid #374151",color:"#fff"},option:(e,t,n)=>({color:t?"#666":e?"#00E8C6":"#fff",background:e?"#23262F":n&&!t?"#333843":"#23262F"}),placeholder:{color:"#666"},scrollbarThumb:"#444C5C",scrollbarTrack:"#23262F",boxShadow:"0 2px 8px rgba(0,0,0,0.32)"}};function Zo(){const e=v("theme"),t=v("themeConfig"),n=e===$.WHITE,r=n?jt.white:jt.dark;if(t){const o=n?t.white:t.dark;if(o?.color)return{...r,option:(s,i,a)=>({...r.option(s,i,a),color:i?r.option(s,i,a).color:s?o.color:r.option(s,i,a).color})}}return r}const z=v("size"),st=({value:e,onChange:t,options:n,placeholder:r,style:o,error:s,disabled:i,dropdownStyle:a,className:u,dropdownClassName:l,children:d})=>{const[c,_]=N(!1),h=Oe(null),[g,y]=N(null),b=Zo();he(()=>{if(!c)return;const w=k=>{h.current&&!h.current.contains(k.target)&&_(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[c]);const x=n.find(w=>w.value===e),S=()=>s?b.triggerError:i?b.triggerDisabled:b.trigger;return m("div",{ref:h,className:u,style:{position:"relative",...o},children:[m("style",{children:`
46
46
  .custom-select-dropdown {
47
47
  scrollbar-width: thin;
48
48
  scrollbar-color: ${b.scrollbarThumb} ${b.scrollbarTrack};
package/dist/best-unit.js CHANGED
@@ -2341,7 +2341,7 @@ function Hi(e) {
2341
2341
  size: u,
2342
2342
  themeConfig: l
2343
2343
  } = e;
2344
- console.log(e, "InitParams");
2344
+ console.log(e, "InitParams1111");
2345
2345
  const d = "Bearer " + e.token;
2346
2346
  return sessionStorage.setItem(
2347
2347
  "fund_unit_params",
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "1.2.17",
4
+ "version": "1.2.19",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
8
8
  "types": "dist/types/global.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
9
12
  "scripts": {
10
13
  "dev": "vite",
11
14
  "build": "tsc --noEmit && vite build && cp -r src/types dist/types",
@@ -1,402 +0,0 @@
1
- # BestUnit 组件库使用文档
2
-
3
- ## 概述
4
-
5
- BestUnit 是一个功能完整的组件库,提供了余额管理、充值功能和刷新按钮等核心功能。本文档详细说明了所有导出的函数、组件及其使用方法。
6
-
7
- ## 快速开始
8
-
9
- ### 1. 安装和引入
10
-
11
- ```javascript
12
- import {
13
- initFundUnit,
14
- getBalanceData,
15
- refreshBalance,
16
- npmTest,
17
- printCurrentTime,
18
- viteProxy,
19
- } from "best-unit";
20
-
21
- // 引入组件
22
- import "best-unit";
23
- ```
24
-
25
- ### 2. 初始化
26
-
27
- ```javascript
28
- // 初始化组件库
29
- initFundUnit({
30
- token: "your-jwt-token",
31
- user_id: "user-uuid",
32
- env: "dev",
33
- });
34
- ```
35
-
36
- ## 核心函数
37
-
38
- ### initFundUnit(params: InitParams)
39
-
40
- 初始化组件库的核心函数,必须在其他功能使用前调用。
41
-
42
- #### 参数说明
43
-
44
- | 参数名 | 类型 | 必填 | 默认值 | 说明 |
45
- | ----------------- | -------- | ---- | ------------- | ------------ |
46
- | `token` | `string` | ✅ | - | JWT 认证令牌 |
47
- | `user_id` | `string` | ✅ | - | 用户唯一标识 |
48
- | `env` | `Env` | ✅ | - | 环境配置 |
49
- | `merchant_id` | `string` | ❌ | - | 商户 ID |
50
- | `biz_type` | `string` | ❌ | - | 业务类型 |
51
- | `fund_balance_id` | `string` | ❌ | - | 余额账户 ID |
52
- | `theme` | `Theme` | ❌ | `Theme.WHITE` | 主题设置 |
53
- | `locale` | `Locale` | ❌ | `Locale.ZH` | 语言设置 |
54
-
55
- #### 使用示例
56
-
57
- ```javascript
58
- import { initFundUnit } from "best-unit";
59
- import { Theme, Locale, Env } from "best-unit";
60
-
61
- // 基本初始化
62
- initFundUnit({
63
- token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
64
- user_id: "19b8a77c-d3fc-45da-9520-4a07463123df",
65
- env: Env.DEV,
66
- });
67
-
68
- // 完整初始化
69
- initFundUnit({
70
- token: "your-jwt-token",
71
- user_id: "user-uuid",
72
- merchant_id: "merchant-123",
73
- biz_type: "payment",
74
- fund_balance_id: "FB1FNZ5Q55M7QP2C",
75
- theme: Theme.DARK,
76
- locale: Locale.EN,
77
- env: Env.PROD,
78
- });
79
- ```
80
-
81
- ### getBalanceData()
82
-
83
- 获取当前余额数据。如果缓存中没有有效数据,会自动调用接口获取最新值。
84
-
85
- #### 返回值
86
-
87
- ```typescript
88
- interface BalanceData {
89
- fundBalanceId: string; // 余额账户ID
90
- merchantId: number; // 商户ID
91
- bizType: string; // 业务类型
92
- currency: string; // 币种
93
- totalAmount: string; // 真实金额
94
- availableAmount: string; // 可用余额
95
- frozenAmount: string; // 冻结金额
96
- pendingAmount: string; // 待处理金额
97
- status: string; // 状态
98
- createdAt: string; // 创建时间
99
- }
100
- ```
101
-
102
- #### 使用示例
103
-
104
- ```javascript
105
- import { getBalanceData } from "best-unit";
106
-
107
- // 异步获取余额数据
108
- const balanceData = await getBalanceData();
109
- console.log("当前余额:", balanceData);
110
-
111
- // 使用 async/await
112
- async function getBalance() {
113
- try {
114
- const data = await getBalanceData();
115
- console.log("余额数据:", data);
116
- } catch (error) {
117
- console.error("获取余额失败:", error);
118
- }
119
- }
120
-
121
- // 使用 Promise
122
- getBalanceData()
123
- .then((data) => {
124
- console.log("余额数据:", data);
125
- })
126
- .catch((error) => {
127
- console.error("获取余额失败:", error);
128
- });
129
- ```
130
-
131
- ### refreshBalance()
132
-
133
- 触发余额刷新事件,所有余额相关组件会自动更新。
134
-
135
- #### 使用示例
136
-
137
- ```javascript
138
- import { refreshBalance } from "best-unit";
139
-
140
- // 手动刷新余额
141
- refreshBalance();
142
- ```
143
-
144
- ## 工具函数
145
-
146
- ### npmTest()
147
-
148
- 测试函数,用于验证包是否正确安装。
149
-
150
- ```javascript
151
- import { npmTest } from "best-unit";
152
-
153
- npmTest(); // 输出: "npm package test!!!"
154
- ```
155
-
156
- ### printCurrentTime()
157
-
158
- 打印当前时间。
159
-
160
- ```javascript
161
- import { printCurrentTime } from "best-unit";
162
-
163
- printCurrentTime(); // 输出: "Current time: 2024-01-01T00:00:00.000Z"
164
- ```
165
-
166
- ### viteProxy
167
-
168
- Vite 代理配置,用于开发环境。
169
-
170
- ```javascript
171
- import { viteProxy } from "best-unit";
172
-
173
- // 在 vite.config.js 中使用
174
- export default {
175
- server: {
176
- proxy: viteProxy,
177
- },
178
- };
179
- ```
180
-
181
- ## 组件使用
182
-
183
- ### 1. best-statistical-balance (余额统计组件)
184
-
185
- 显示用户余额信息的组件,支持悬停查看详情。
186
-
187
- #### 基本用法
188
-
189
- ```html
190
- <!-- 基本使用 -->
191
- <best-statistical-balance></best-statistical-balance>
192
-
193
- <!-- 自定义弹窗位置 -->
194
- <best-statistical-balance popover-position="top"></best-statistical-balance>
195
- ```
196
-
197
- #### 属性说明
198
-
199
- | 属性名 | 类型 | 必填 | 默认值 | 说明 |
200
- | ------------------ | -------- | ---- | ---------- | -------------------------------------------------- |
201
- | `popover-position` | `string` | ❌ | `"bottom"` | 弹窗位置:`"top"`, `"bottom"`, `"left"`, `"right"` |
202
-
203
- #### 功能特性
204
-
205
- - 自动获取并显示余额数据
206
- - 悬停显示详细余额信息
207
- - 响应式设计,支持主题切换
208
- - 自动监听刷新事件
209
-
210
- ### 2. best-refresh-button (刷新按钮组件)
211
-
212
- 可自定义的刷新按钮,支持动画效果。
213
-
214
- #### 基本用法
215
-
216
- ```html
217
- <!-- 显示默认文案 -->
218
- <best-refresh-button>刷新</best-refresh-button>
219
-
220
- <!-- 只显示图标 -->
221
- <best-refresh-button></best-refresh-button>
222
-
223
- <!-- 自定义文案 -->
224
- <best-refresh-button>重新加载</best-refresh-button>
225
- ```
226
-
227
- #### 属性说明
228
-
229
- | 属性名 | 类型 | 必填 | 默认值 | 说明 |
230
- | ------- | -------- | ---- | ---------- | ------------------------------------------ |
231
- | `color` | `string` | ❌ | - | 按钮颜色 |
232
- | `size` | `string` | ❌ | `"medium"` | 按钮尺寸:`"small"`, `"medium"`, `"large"` |
233
-
234
- #### 功能特性
235
-
236
- - 点击时图标旋转动画
237
- - 自动触发余额刷新
238
- - 支持自定义文案和颜色
239
- - 响应式设计
240
-
241
- ### 3. best-recharge (充值组件)
242
-
243
- 提供充值功能的组件。
244
-
245
- #### 基本用法
246
-
247
- ```html
248
- <!-- 基本使用 -->
249
- <best-recharge></best-recharge>
250
-
251
- <!-- 自定义主题 -->
252
- <best-recharge theme="dark"></best-recharge>
253
- ```
254
-
255
- #### 属性说明
256
-
257
- | 属性名 | 类型 | 必填 | 默认值 | 说明 |
258
- | ------- | -------- | ---- | --------- | ------------------------- |
259
- | `theme` | `string` | ❌ | `"white"` | 主题:`"white"`, `"dark"` |
260
-
261
- #### 功能特性
262
-
263
- - 在线充值功能
264
- - 支持多种支付方式
265
- - 自动跳转支付页面
266
- - 响应式设计
267
-
268
- ## 类型定义
269
-
270
- ### Env (环境枚举)
271
-
272
- ```typescript
273
- enum Env {
274
- DEV = "dev",
275
- DEVELOPMENT = "development",
276
- TEST = "test",
277
- PROD = "prod",
278
- PRODUCTION = "production",
279
- }
280
- ```
281
-
282
- ### Theme (主题枚举)
283
-
284
- ```typescript
285
- enum Theme {
286
- WHITE = "white",
287
- DARK = "dark",
288
- }
289
- ```
290
-
291
- ### Locale (语言枚举)
292
-
293
- ```typescript
294
- enum Locale {
295
- ZH = "zh",
296
- EN = "en",
297
- }
298
- ```
299
-
300
- ## 完整示例
301
-
302
- ### HTML 页面集成
303
-
304
- ```html
305
- <!DOCTYPE html>
306
- <html lang="zh-CN">
307
- <head>
308
- <meta charset="UTF-8" />
309
- <title>BestUnit 示例</title>
310
- </head>
311
- <body>
312
- <!-- 余额显示 -->
313
- <best-statistical-balance></best-statistical-balance>
314
-
315
- <!-- 刷新按钮 -->
316
- <best-refresh-button>刷新余额</best-refresh-button>
317
-
318
- <!-- 充值按钮 -->
319
- <best-recharge></best-recharge>
320
-
321
- <script type="module">
322
- import { initFundUnit } from "best-unit";
323
- import { Env, Theme, Locale } from "best-unit";
324
-
325
- // 初始化
326
- initFundUnit({
327
- token: "your-jwt-token",
328
- user_id: "user-uuid",
329
- theme: Theme.WHITE,
330
- locale: Locale.ZH,
331
- env: Env.DEV,
332
- });
333
- </script>
334
- </body>
335
- </html>
336
- ```
337
-
338
- ### React/Vue 集成
339
-
340
- ```javascript
341
- // React 示例
342
- import React, { useEffect } from "react";
343
- import { initFundUnit } from "best-unit";
344
-
345
- function App() {
346
- useEffect(() => {
347
- initFundUnit({
348
- token: "your-jwt-token",
349
- user_id: "user-uuid",
350
- env: "dev",
351
- });
352
- }, []);
353
-
354
- return (
355
- <div>
356
- <best-statistical-balance></best-statistical-balance>
357
- <best-refresh-button>刷新</best-refresh-button>
358
- <best-recharge></best-recharge>
359
- </div>
360
- );
361
- }
362
- ```
363
-
364
- ## 注意事项
365
-
366
- 1. **初始化顺序**:必须先调用 `initFundUnit()` 再使用其他功能
367
- 2. **Token 安全**:确保 JWT token 的安全性,不要在客户端存储敏感信息
368
- 3. **环境配置**:根据实际环境选择合适的 `env` 参数
369
- 4. **组件依赖**:所有组件都依赖于初始化配置,确保配置正确
370
- 5. **浏览器兼容性**:需要支持 Custom Elements 和 Shadow DOM 的现代浏览器
371
-
372
- ## 错误处理
373
-
374
- ```javascript
375
- try {
376
- initFundUnit({
377
- token: "invalid-token",
378
- user_id: "user-uuid",
379
- env: "dev",
380
- });
381
- } catch (error) {
382
- console.error("初始化失败:", error);
383
- }
384
-
385
- // 检查余额数据(异步)
386
- async function checkBalanceData() {
387
- try {
388
- const balanceData = await getBalanceData();
389
- if (!balanceData.fundBalanceId) {
390
- console.warn("余额数据未初始化");
391
- }
392
- } catch (error) {
393
- console.error("获取余额数据失败:", error);
394
- }
395
- }
396
- ```
397
-
398
- ## 更新日志
399
-
400
- - **v1.0.0**: 初始版本,包含基础功能
401
- - **v1.1.0**: 添加动画效果和主题支持
402
- - **v1.2.0**: 优化缓存机制和错误处理
package/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Best Unit</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/demo/index.tsx"></script>
12
- </body>
13
- </html>
@@ -1,111 +0,0 @@
1
- import axios from "axios";
2
- import type {
3
- AxiosInstance,
4
- AxiosResponse,
5
- InternalAxiosRequestConfig,
6
- } from "axios";
7
- import { message } from "@/components/common/message";
8
- import { Env, Locale } from "@/types";
9
-
10
- export interface CreateAxiosOptions {
11
- baseURL?: string;
12
- timeout?: number;
13
- onError?: (msg: string, error: any) => void;
14
- }
15
-
16
- export function createAxiosInstance(options: CreateAxiosOptions = {}) {
17
- // 根据 fund_unit_params 中的 env 参数选择 API URL
18
- const fundUnitParams = JSON.parse(
19
- sessionStorage.getItem("fund_unit_params") || "{}"
20
- );
21
-
22
- console.log("fundUnitParams", fundUnitParams);
23
- const { env } = fundUnitParams;
24
-
25
- let apiUrl: string;
26
- switch (env) {
27
- case Env.DEV:
28
- case Env.DEVELOPMENT:
29
- apiUrl = "/api";
30
- break;
31
- case Env.TEST:
32
- apiUrl = "https://fund.bestfulfill.tech/api/sdk";
33
- break;
34
- case Env.PROD:
35
- case Env.PRODUCTION:
36
- default:
37
- apiUrl = "https://fund.bestfulfill.com/api/sdk";
38
- break;
39
- }
40
-
41
- const { baseURL = apiUrl, timeout = 10000, onError } = options;
42
-
43
- const instance: AxiosInstance = axios.create({ baseURL, timeout });
44
-
45
- // 请求拦截:加 token、国际化
46
- instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
47
- const { token, locale } = fundUnitParams;
48
- config.headers = {
49
- ...config.headers,
50
- Authorization: token,
51
- "x-locale": locale === Locale.ZH ? "zh-CN" : "en-US",
52
- } as any;
53
-
54
- return config;
55
- });
56
-
57
- // 响应拦截:code=0判定成功,其他走 onError
58
- instance.interceptors.response.use(
59
- (response: AxiosResponse) => {
60
- if (response.data && response.data.code === 0) {
61
- return response.data;
62
- }
63
- const errorMsg =
64
- response.data?.msg || response.data?.message || "未知错误";
65
-
66
- // 显示错误消息
67
- message.error(errorMsg);
68
-
69
- if (onError) {
70
- onError(errorMsg, response);
71
- }
72
- return Promise.reject(response.data || { message: "未知错误" });
73
- },
74
- (error) => {
75
- const errorMsg =
76
- error.response?.data?.msg ||
77
- error.response?.data?.message ||
78
- error.message ||
79
- "网络请求失败";
80
-
81
- // 显示错误消息
82
- message.error(errorMsg);
83
-
84
- if (onError) {
85
- onError(errorMsg, error);
86
- }
87
- return Promise.reject(error);
88
- }
89
- );
90
-
91
- return instance;
92
- }
93
-
94
- // 缓存 axios 实例
95
- let httpInstance: AxiosInstance | null = null;
96
-
97
- // 获取 axios 实例的函数
98
- export function http(): AxiosInstance {
99
- if (!httpInstance) {
100
- httpInstance = createAxiosInstance();
101
- }
102
- return httpInstance;
103
- }
104
-
105
- // 重置 axios 实例(当 fund_unit_params 更新时调用)
106
- export function resetHttpInstance(): void {
107
- httpInstance = null;
108
- }
109
-
110
- // 默认导出获取实例的函数
111
- export default http;