hifun-tools 1.3.30 → 1.3.32

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.
@@ -144,18 +144,17 @@ class InitCls {
144
144
  throw new Error("无法获取有效的租户信息");
145
145
  }
146
146
  refreshHttp() {
147
- rewardMsg({
148
- title: "提示",
149
- text: "网络环境异常,刷新页面以重置",
150
- onSubmit() {
151
- location.reload();
152
- },
153
- });
154
147
  try {
155
148
  getOptimalDecodedString([this.getBaseUrl()]);
156
149
  }
157
150
  catch (error) {
158
- console.log(error);
151
+ rewardMsg({
152
+ title: "提示",
153
+ text: "网络环境异常,刷新页面以重置",
154
+ onSubmit() {
155
+ location.reload();
156
+ },
157
+ });
159
158
  }
160
159
  }
161
160
  /** 获取 lineDict.txt 内容 */
@@ -187,10 +186,12 @@ class InitCls {
187
186
  // 备用策略
188
187
  let allBaseUrl = filterSmartLines(dictList, OriginBaseUrl);
189
188
  try {
190
- this.domainBaseUrl = toStandardUrl(await getOptimalDecodedString(difArr(allBaseUrl, baseUrl)));
189
+ this.domainBaseUrl = toStandardUrl(await getOptimalDecodedString(difArr(allBaseUrl, baseUrl), {
190
+ filterIp: false,
191
+ }));
191
192
  console.info("✅ 备用配置成功:", this.domainBaseUrl);
192
193
  }
193
- catch {
194
+ catch (err) {
194
195
  this.domainBaseUrl = toStandardUrl(allBaseUrl[0]);
195
196
  console.warn("⚠️ 备选测速失败,使用备用配置:", allBaseUrl);
196
197
  }
@@ -136,8 +136,6 @@ export async function getOptimalDecodedString(arr, options) {
136
136
  ? targetArr.filter(isIPv4)
137
137
  : targetArr.filter((v) => !isIPv4(v));
138
138
  }
139
- if (!targetArr.length)
140
- throw new Error("无可用地址");
141
139
  const failedUrls = [];
142
140
  const controllerMap = {};
143
141
  return new Promise((resolve, reject) => {
package/dist/msg/index.js CHANGED
@@ -1,7 +1,9 @@
1
+ let isRewardShowing = false;
1
2
  // --------------------------- 普通消息 ---------------------------
2
3
  let messageStackContainer = null;
3
4
  // --------------------------- reward 弹窗 ---------------------------
4
5
  let rewardMask = null;
6
+ const rewardQueue = [];
5
7
  let rewardStackContainer = null;
6
8
  function getMessageStackContainer() {
7
9
  if (!messageStackContainer) {
@@ -55,7 +57,7 @@ function getRewardMask() {
55
57
  left: "0",
56
58
  width: "100vw",
57
59
  height: "100vh",
58
- background: "rgba(0,0,0,0.5)", // 使用 rgba,蒙层透明不影响弹窗
60
+ background: "rgba(0,0,0,0.5)",
59
61
  zIndex: "100000",
60
62
  pointerEvents: "auto",
61
63
  display: "flex",
@@ -82,71 +84,21 @@ function getRewardStackContainer() {
82
84
  }
83
85
  return rewardStackContainer;
84
86
  }
85
- export function msg(message, options = {}) {
86
- const { type = "info", duration = 3000, closable = false, onClose } = options;
87
- const container = document.createElement("div");
88
- Object.assign(container.style, {
89
- backgroundColor: getColorByType(type),
90
- color: "#fff",
91
- borderRadius: "12px",
92
- fontSize: "12px",
93
- fontWeight: "500",
94
- padding: "10px 16px",
95
- maxWidth: "400px",
96
- minWidth: "120px",
97
- textAlign: "center",
98
- display: "-webkit-box",
99
- WebkitLineClamp: "2",
100
- WebkitBoxOrient: "vertical",
101
- overflow: "hidden",
102
- textOverflow: "ellipsis",
103
- wordWrap: "break-word",
104
- boxShadow: "0 6px 18px rgba(0,0,0,0.12)",
105
- opacity: "0",
106
- transform: "translateY(20px)",
107
- transition: "all 0.3s cubic-bezier(0.4,0,0.2,1)",
108
- pointerEvents: "auto",
109
- position: "relative",
110
- });
111
- container.textContent = message;
112
- if (closable) {
113
- const closeBtn = document.createElement("span");
114
- closeBtn.innerHTML = "×";
115
- Object.assign(closeBtn.style, {
116
- position: "absolute",
117
- top: "50%",
118
- right: "10px",
119
- transform: "translateY(-50%)",
120
- cursor: "pointer",
121
- fontSize: "14px",
122
- fontWeight: "bold",
123
- });
124
- closeBtn.onclick = () => hideMsg(container, onClose);
125
- container.appendChild(closeBtn);
126
- container.style.paddingRight = "30px";
127
- }
128
- const stack = getMessageStackContainer();
129
- stack.appendChild(container);
130
- requestAnimationFrame(() => {
131
- container.style.opacity = "1";
132
- container.style.transform = "translateY(0)";
133
- });
134
- if (duration > 0) {
135
- setTimeout(() => hideMsg(container, onClose), duration);
136
- }
137
- }
138
- export function rewardMsg(options) {
139
- const { title, text, topImg, submitText, cancelText, onSubmit, onCancel, onClose, } = options;
87
+ function showNextReward() {
88
+ if (isRewardShowing || rewardQueue.length === 0)
89
+ return;
90
+ const options = rewardQueue.shift();
91
+ isRewardShowing = true;
140
92
  const mask = getRewardMask();
141
93
  const originalOverflow = document.body.style.overflow;
142
- document.body.style.overflow = "hidden"; // 禁止下方滚动
94
+ document.body.style.overflow = "hidden";
143
95
  const container = document.createElement("div");
144
96
  container.className = "rewardWindow";
145
97
  Object.assign(container.style, {
146
98
  position: "relative",
147
99
  width: "calc(100% - 60px)",
148
100
  maxWidth: "370px",
149
- paddingTop: topImg ? "88px" : "23px",
101
+ paddingTop: options.topImg ? "88px" : "23px",
150
102
  backgroundColor: "#fff",
151
103
  borderRadius: "12px",
152
104
  boxSizing: "border-box",
@@ -155,15 +107,14 @@ export function rewardMsg(options) {
155
107
  alignItems: "center",
156
108
  textAlign: "center",
157
109
  opacity: "0",
158
- transform: "translateY(-20px) scale(0.9)",
110
+ transform: "scale(0.9)",
159
111
  transition: "all 0.3s cubic-bezier(0.4,0,0.2,1)",
160
112
  overflow: "hidden",
161
113
  zIndex: "100001",
162
114
  });
163
- // 标题
164
- if (title) {
115
+ if (options.title) {
165
116
  const titleEl = document.createElement("div");
166
- titleEl.textContent = title;
117
+ titleEl.textContent = options.title;
167
118
  Object.assign(titleEl.style, {
168
119
  fontSize: "16px",
169
120
  fontWeight: "600",
@@ -171,10 +122,9 @@ export function rewardMsg(options) {
171
122
  });
172
123
  container.appendChild(titleEl);
173
124
  }
174
- // 顶部图片
175
- if (topImg) {
125
+ if (options.topImg) {
176
126
  const imgEl = document.createElement("img");
177
- imgEl.src = topImg;
127
+ imgEl.src = options.topImg;
178
128
  Object.assign(imgEl.style, {
179
129
  position: "absolute",
180
130
  top: "-68px",
@@ -183,10 +133,9 @@ export function rewardMsg(options) {
183
133
  });
184
134
  container.appendChild(imgEl);
185
135
  }
186
- // 文本内容
187
- if (text) {
136
+ if (options.text) {
188
137
  const textEl = document.createElement("div");
189
- textEl.innerHTML = text;
138
+ textEl.innerHTML = options.text;
190
139
  Object.assign(textEl.style, {
191
140
  padding: "14px 22px 12px",
192
141
  fontSize: "12px",
@@ -200,7 +149,6 @@ export function rewardMsg(options) {
200
149
  });
201
150
  container.appendChild(textEl);
202
151
  }
203
- // 按钮容器
204
152
  const btnContainer = document.createElement("div");
205
153
  Object.assign(btnContainer.style, {
206
154
  display: "flex",
@@ -217,39 +165,26 @@ export function rewardMsg(options) {
217
165
  fontSize: "14px",
218
166
  fontWeight: "500",
219
167
  };
220
- // 仅当传入 cancelText 才显示取消按钮
221
- if (cancelText) {
168
+ if (options.cancelText) {
222
169
  const cancelBtn = document.createElement("button");
223
- cancelBtn.textContent = cancelText;
170
+ cancelBtn.textContent = options.cancelText;
224
171
  Object.assign(cancelBtn.style, {
225
172
  ...btnStyle,
226
173
  borderRight: "1px solid #f2f2f6",
227
174
  color: "#303442",
228
175
  });
229
- cancelBtn.onclick = () => {
230
- hideMsg(container, onCancel ?? onClose);
231
- // 如果这是最后一个弹窗,隐藏蒙层并恢复滚动
232
- if (rewardStackContainer?.childElementCount === 1) {
233
- hideMsg(mask);
234
- document.body.style.overflow = originalOverflow;
235
- }
236
- };
176
+ cancelBtn.onclick = () => closeReward(container, options.onCancel ?? options.onClose, originalOverflow);
237
177
  btnContainer.appendChild(cancelBtn);
238
178
  }
239
- // 确认按钮始终显示
240
179
  const confirmBtn = document.createElement("button");
241
- confirmBtn.textContent = submitText || "确认";
180
+ confirmBtn.textContent = options.submitText || "确认";
242
181
  Object.assign(confirmBtn.style, {
243
182
  ...btnStyle,
244
183
  color: "#179CFF",
245
184
  });
246
185
  confirmBtn.onclick = () => {
247
- onSubmit?.();
248
- hideMsg(container, onClose);
249
- if (rewardStackContainer?.childElementCount === 1) {
250
- hideMsg(mask);
251
- document.body.style.overflow = originalOverflow;
252
- }
186
+ options.onSubmit?.();
187
+ closeReward(container, options.onClose, originalOverflow);
253
188
  };
254
189
  btnContainer.appendChild(confirmBtn);
255
190
  container.appendChild(btnContainer);
@@ -257,6 +192,79 @@ export function rewardMsg(options) {
257
192
  stack.appendChild(container);
258
193
  requestAnimationFrame(() => {
259
194
  container.style.opacity = "1";
260
- container.style.transform = "translateY(0) scale(1)";
195
+ container.style.transform = "scale(1)";
261
196
  });
262
197
  }
198
+ function closeReward(container, callback, originalOverflow) {
199
+ container.style.opacity = "0";
200
+ container.style.transform = "scale(0.9)";
201
+ setTimeout(() => {
202
+ container.parentNode?.removeChild(container);
203
+ callback?.();
204
+ if (rewardStackContainer?.childElementCount === 0) {
205
+ rewardMask?.remove();
206
+ rewardMask = null;
207
+ rewardStackContainer = null;
208
+ document.body.style.overflow = originalOverflow ?? "";
209
+ }
210
+ isRewardShowing = false;
211
+ showNextReward(); // 显示下一个弹窗
212
+ }, 300);
213
+ }
214
+ export function msg(message, options = {}) {
215
+ const { type = "info", duration = 3000, closable = false, onClose } = options;
216
+ const container = document.createElement("div");
217
+ Object.assign(container.style, {
218
+ backgroundColor: getColorByType(type),
219
+ color: "#fff",
220
+ borderRadius: "12px",
221
+ fontSize: "12px",
222
+ fontWeight: "500",
223
+ padding: "10px 16px",
224
+ maxWidth: "400px",
225
+ minWidth: "120px",
226
+ textAlign: "center",
227
+ display: "-webkit-box",
228
+ WebkitLineClamp: "2",
229
+ WebkitBoxOrient: "vertical",
230
+ overflow: "hidden",
231
+ textOverflow: "ellipsis",
232
+ wordWrap: "break-word",
233
+ boxShadow: "0 6px 18px rgba(0,0,0,0.12)",
234
+ opacity: "0",
235
+ transform: "translateY(20px)",
236
+ transition: "all 0.3s cubic-bezier(0.4,0,0.2,1)",
237
+ pointerEvents: "auto",
238
+ position: "relative",
239
+ });
240
+ container.textContent = message;
241
+ if (closable) {
242
+ const closeBtn = document.createElement("span");
243
+ closeBtn.innerHTML = "×";
244
+ Object.assign(closeBtn.style, {
245
+ position: "absolute",
246
+ top: "50%",
247
+ right: "10px",
248
+ transform: "translateY(-50%)",
249
+ cursor: "pointer",
250
+ fontSize: "14px",
251
+ fontWeight: "bold",
252
+ });
253
+ closeBtn.onclick = () => hideMsg(container, onClose);
254
+ container.appendChild(closeBtn);
255
+ container.style.paddingRight = "30px";
256
+ }
257
+ const stack = getMessageStackContainer();
258
+ stack.appendChild(container);
259
+ requestAnimationFrame(() => {
260
+ container.style.opacity = "1";
261
+ container.style.transform = "translateY(0)";
262
+ });
263
+ if (duration > 0) {
264
+ setTimeout(() => hideMsg(container, onClose), duration);
265
+ }
266
+ }
267
+ export function rewardMsg(options) {
268
+ rewardQueue.push(options);
269
+ showNextReward();
270
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hifun-tools",
3
- "version": "1.3.30",
3
+ "version": "1.3.32",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",