best-unit 1.2.8 → 1.2.9
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.
- package/dist/best-unit.cjs +1 -1
- package/dist/best-unit.js +13 -1
- package/package.json +1 -1
- package/src/api/axiosInstance.ts +19 -1
package/dist/best-unit.cjs
CHANGED
|
@@ -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 Ke=new ko;function To(e={}){
|
|
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 Ke=new ko;function To(e={}){let t=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");if(!t||Object.keys(t).length===0){const u=Date.now(),l=3e3;for(;Date.now()-u<l;)try{const d=sessionStorage.getItem("fund_unit_params")||"{}",c=JSON.parse(d);if(c&&Object.keys(c).length>0){t=c;break}}catch{}}console.log("fundUnitParams",t);const{env:n}=t;let r;switch(n){case K.DEV:case K.DEVELOPMENT:r="/api";break;case K.TEST:r="https://fund.bestfulfill.tech/api/sdk";break;case K.PROD:case K.PRODUCTION:default:r="https://fund.bestfulfill.com/api/sdk";break}const{baseURL:o=r,timeout:s=1e4,onError:i}=e,a=C.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===Ne.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 Ke.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 Ke.error(l),i&&i(l,u),Promise.reject(u)}),a}let ye=null;function ee(){return ye||(ye=To()),ye}function Co(){ye=null}function Bn(){const e=JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}");return ee().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 Ro=async()=>ee().get("/all-dicts",{}).then(e=>(sessionStorage.setItem("all_dicts",JSON.stringify(e.data)),e.data||{})),Ao=async(e,t)=>ee().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||""),Fo=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 ee().post("/offline/recharge/create",n,{})},Bo=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 ee().post("/online/recharge/create",n,{}).then(r=>r.data.redirect_url)},Oo=async e=>ee().get("/calc-payment-amount",{params:e}).then(t=>t.data.payment_amount);async function Po(){let e=JSON.parse(sessionStorage.getItem("balanceData")||"{}");return e&&Object.keys(e).length>0||(e=await Bn()),e}function No(e){const{merchant_id:t,biz_type:n,fund_balance_id:r,user_id:o,theme:s=D.WHITE,locale:i=Ne.ZH,env:a,themeConfig:u}=e,l="Bearer "+e.token;return sessionStorage.setItem("fund_unit_params",JSON.stringify({merchantId:t,bizType:n,fundBalanceId:r,userId:o,token:l,theme:s,locale:i,env:a,themeConfig:u})),Co(),Ro(),{token:l,merchantId:t,bizType:n,fundBalanceId:r,userId:o,theme:s,locale:i,env:a}}function B(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 On(){const e=new CustomEvent("refresh-balance",{detail:{},bubbles:!0,composed:!0});document.dispatchEvent(e)}const Io={"/api":{target:"https://fund.bestfulfill.tech/api/sdk",changeOrigin:!0,rewrite:e=>e.replace(/^\/api/,""),secure:!1}},fe={white:{background:"#1890ff",color:"#fff",border:"none",borderRadius:6,padding:"8px 16px",cursor:"pointer",fontSize:16,fontWeight:600},dark:{background:"#00E8C6",color:"#fff",border:"none",borderRadius:6,padding:"8px 16px",cursor:"pointer",fontSize:16,fontWeight:600}};function Do(e){const t=B("theme"),n=B("themeConfig"),r=t===D.WHITE;let o=e;return!o&&n&&(o=(r?n.white:n.dark)?.color),r?{...fe.white,background:o||fe.white.background}:{...fe.dark,background:o||fe.dark.background}}function Pn({onClick:e,color:t,children:n}){const r=Do(t);return h("button",{style:r,onClick:e,type:"button",children:n})}const Lo={余额详情:"余额详情",真实金额:"真实金额",冻结金额:"冻结金额",信用额度:"信用额度",已用额度:"已用额度",可用余额:"可用余额",暂无数据:"暂无数据","金额需在1到999999.99之间":"金额需在1到999999.99之间","充值 / 转账":"充值 / 转账",在线充值:"在线充值",线下转账:"线下转账",充值币种:"充值币种",充值金额:"充值金额",支付平台:"支付平台",请选择充值币种:"请选择充值币种",请输入充值金额:"请输入充值金额",请选择支付平台:"请选择支付平台","需要收取手续费,实际支付金额约为:":"需要收取手续费,实际支付金额约为:","提交失败,请重试":"提交失败,请重试","提交中...":"提交中...",去支付:"去支付",取消:"取消",关闭:"关闭",第三方支付平台:"第三方支付平台",交易ID:"交易ID",请输入转账交易ID:"请输入转账交易ID",上传文件:"上传文件",请上传转账凭证:"请上传转账凭证",离线充值创建成功:"离线充值创建成功","加载中...":"加载中...",错误:"错误",成功:"成功",必填:"必填","充值/转账":"充值/转账",切换为暗黑主题:"切换为暗黑主题",切换为白色主题:"切换为白色主题",点击或拖拽文件到此处上传:"点击或拖拽文件到此处上传","支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传":"支持 JPG、PNG、PDF 格式,单个文件不超过 20MB,最多上传",个文件:"个文件","正在上传...":"正在上传...",已上传:"已上传",移除:"移除"};function Uo(e){return Lo[e]||e}const zo={余额详情:"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 Ho(e){return zo[e]||e}function Mo(){return JSON.parse(sessionStorage.getItem("fund_unit_params")||"{}").locale||Ne.ZH}function E(e){return Mo()==="zh"?Uo(e):Ho(e)}const Pt={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 jo(){const e=B("theme"),t=B("themeConfig"),n=e===D.WHITE,r=n?Pt.white:Pt.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 Xe=({value:e,onChange:t,options:n,placeholder:r,style:o,error:s,disabled:i,dropdownStyle:a,className:u,dropdownClassName:l,children:d})=>{const[c,m]=O(!1),p=ve(null),[b,g]=O(null),_=jo();ae(()=>{if(!c)return;const x=k=>{p.current&&!p.current.contains(k.target)&&m(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[c]);const y=n.find(x=>x.value===e),w=()=>s?_.triggerError:i?_.triggerDisabled:_.trigger;return h("div",{ref:p,className:u,style:{position:"relative",...o},children:[h("style",{children:`
|
|
46
46
|
.custom-select-dropdown {
|
|
47
47
|
scrollbar-width: thin;
|
|
48
48
|
scrollbar-color: ${_.scrollbarThumb} ${_.scrollbarTrack};
|
package/dist/best-unit.js
CHANGED
|
@@ -2206,9 +2206,21 @@ class Eo {
|
|
|
2206
2206
|
}
|
|
2207
2207
|
const Ke = new Eo();
|
|
2208
2208
|
function So(e = {}) {
|
|
2209
|
-
|
|
2209
|
+
let t = JSON.parse(
|
|
2210
2210
|
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
2211
2211
|
);
|
|
2212
|
+
if (!t || Object.keys(t).length === 0) {
|
|
2213
|
+
const u = Date.now(), l = 3e3;
|
|
2214
|
+
for (; Date.now() - u < l; )
|
|
2215
|
+
try {
|
|
2216
|
+
const d = sessionStorage.getItem("fund_unit_params") || "{}", c = JSON.parse(d);
|
|
2217
|
+
if (c && Object.keys(c).length > 0) {
|
|
2218
|
+
t = c;
|
|
2219
|
+
break;
|
|
2220
|
+
}
|
|
2221
|
+
} catch {
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2212
2224
|
console.log("fundUnitParams", t);
|
|
2213
2225
|
const { env: n } = t;
|
|
2214
2226
|
let r;
|
package/package.json
CHANGED
package/src/api/axiosInstance.ts
CHANGED
|
@@ -15,10 +15,28 @@ export interface CreateAxiosOptions {
|
|
|
15
15
|
|
|
16
16
|
export function createAxiosInstance(options: CreateAxiosOptions = {}) {
|
|
17
17
|
// 根据 fund_unit_params 中的 env 参数选择 API URL
|
|
18
|
-
|
|
18
|
+
let fundUnitParams = JSON.parse(
|
|
19
19
|
sessionStorage.getItem("fund_unit_params") || "{}"
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
+
// 简单同步轮询,尽量在不改动对外调用方式的情况下等待参数就绪
|
|
23
|
+
if (!fundUnitParams || Object.keys(fundUnitParams).length === 0) {
|
|
24
|
+
const start = Date.now();
|
|
25
|
+
const maxWaitMs = 3000; // 最多等待 3 秒
|
|
26
|
+
while (Date.now() - start < maxWaitMs) {
|
|
27
|
+
try {
|
|
28
|
+
const raw = sessionStorage.getItem("fund_unit_params") || "{}";
|
|
29
|
+
const obj = JSON.parse(raw);
|
|
30
|
+
if (obj && Object.keys(obj).length > 0) {
|
|
31
|
+
fundUnitParams = obj;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
} catch (_) {
|
|
35
|
+
// 略过解析错误,继续等待
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
console.log("fundUnitParams", fundUnitParams);
|
|
23
41
|
const { env } = fundUnitParams;
|
|
24
42
|
|