MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / createTip

Function createTip

tech-study.js:4338–4438  ·  view source on GitHub ↗

* @description 创建学习提示

(text, delay = 2, countShow = false, callback)

Source from the content-addressed store, hash-verified

4336 * @description 创建学习提示
4337 */
4338function createTip(text, delay = 2, countShow = false, callback) {
4339 const tipWrap = $$('.egg_tip_wrap')[0];
4340 // 提前去除
4341 const tips = $$('.egg_tip');
4342 if (tips.length) {
4343 tips.forEach((t) => t.delay());
4344 }
4345 // 延迟
4346 const delayCount = ref(delay);
4347 // 文字
4348 const textContent = ref(text);
4349 //显示
4350 const show = ref(false);
4351 // 延迟显示
4352 const delayShow = ref(false);
4353 // 销毁
4354 let destroyed = false;
4355 // 倒计时结束
4356 let done = false;
4357 // 提示
4358 const tip = Tip({
4359 text: textContent,
4360 count: delayCount,
4361 show,
4362 delayShow,
4363 countShow: ref(countShow),
4364 callback: async (count) => {
4365 callback && (await callback(count));
4366 // 恢复显示
4367 if (delayShow.value && count === delay) {
4368 delayShow.value = false;
4369 }
4370 // 倒计时结束
4371 if (count <= 0) {
4372 done = true;
4373 operate.destroy();
4374 }
4375 },
4376 });
4377 // 操作
4378 const operate = {
4379 destroy() {
4380 if (!destroyed) {
4381 // 隐藏
4382 operate.hide();
4383 // 销毁
4384 destroyed = true;
4385 return new Promise((resolve) => {
4386 setTimeout(() => {
4387 tip.ele.remove();
4388 resolve(undefined);
4389 }, 300);
4390 });
4391 }
4392 },
4393 hide() {
4394 if (!destroyed) {
4395 show.value = false;

Callers 15

handleSlideVerifyFunction · 0.70
examPauseLockFunction · 0.70
doingExamFunction · 0.70
doExamPracticeFunction · 0.70
doExamPaperFunction · 0.70
findExamPaperFunction · 0.70
handleLoginFunction · 0.70
handleNewsFunction · 0.70
handleVideoFunction · 0.70
readingFunction · 0.70
readNewsFunction · 0.70
watchVideoFunction · 0.70

Calls 4

$$Function · 0.70
refFunction · 0.70
TipFunction · 0.70
mountElementFunction · 0.70

Tested by

no test coverage detected