power BI 倒计时+插件HTML Content,实现更新倒计时看板!

直接拿去玩吧,花了我两个小时。

搜了b站和百度都没找到像样的,就决定自己干一个了。

先看效果:

起个度量值,然后去power bi 插件那边搜索html Content,把这个放进html content插件的字段values即可。

复制代码
HTML倒计时每周一18点循环版 = 
"
<div style='text-align:center; padding:20px; background: #fff; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.1);'>
  <div style='margin-bottom: 15px; font-family: Arial; color: #444;'>
    <span style='font-size: 18px;'>数据更新倒计时</span>
    <span id='countdown' style='font-size: 24px; margin-left: 10px; color: #d32f2f;'>00天 00时 00分 00秒</span>
  </div>
  <svg width='300' height='30' xmlns='http://www.w3.org/2000/svg' style='overflow: visible;'>
    <rect width='100%' height='20' rx='10' fill='#f0f0f0'></rect>
    <defs>
      <linearGradient id='barGradient' x1='0%' y1='0%' x2='100%' y2='0%' gradientUnits='userSpaceOnUse'>
        <stop id='gradientStart' offset='0%' stop-color='#ff6b6b'/>
        <stop id='gradientEnd' offset='100%' stop-color='#d32f2f'/>
      </linearGradient>
    </defs>
    <path id='progress' d='M10,10 L290,10' stroke='url(#barGradient)' stroke-width='20'
          stroke-linecap='round' fill='none' stroke-dasharray='0 280'/>
  </svg>
</div>

<script>
  // 计算下一个周一 18:00
  function getNextMonday6PM() {
    var now = new Date();
    var day = now.getDay();           
    var offset = (1 - day + 7) % 7;   
    if(offset === 0 && now.getHours() >= 18) {
      offset = 7;
    }
    var target = new Date(now);
    target.setDate(now.getDate() + offset);
    target.setHours(18,0,0,0);
    return target;
  }

  var pathLength = 280;
  var elements = {
    progressBar: document.getElementById('progress'),
    gradientStart: document.getElementById('gradientStart'),
    gradientEnd: document.getElementById('gradientEnd'),
    countdown: document.getElementById('countdown')
  };

  var targetTime = getNextMonday6PM();
  var initialSeconds = Math.round((targetTime - new Date()) / 1000);

  function formatCountdown(sec) {
    var days = Math.floor(sec / 86400),
        hrs  = Math.floor((sec % 86400) / 3600),
        mins = Math.floor((sec % 3600) / 60),
        secs = sec % 60;
    var d = days < 10 ? '0' + days : days;
    var h = hrs   < 10 ? '0' + hrs   : hrs;
    var m = mins  < 10 ? '0' + mins  : mins;
    var s = secs  < 10 ? '0' + secs  : secs;
    return d + '天 ' + h + '时 ' + m + '分 ' + s + '秒';
  }

  function updateProgress() {
    var now = new Date();
    if(now >= targetTime) {
      targetTime = getNextMonday6PM();
      initialSeconds = Math.round((targetTime - now) / 1000);
    }
    var remaining = Math.round((targetTime - now) / 1000);
    var progress  = (initialSeconds - remaining) / initialSeconds * pathLength;

    elements.progressBar.setAttribute('stroke-dasharray', progress + ' ' + pathLength);
    elements.countdown.textContent = formatCountdown(remaining);

    var pct = remaining / initialSeconds;
    elements.gradientStart.setAttribute('stop-color',
      'hsl(0,' + (80 + 20 * (1 - pct)) + '%,60%)');
    elements.gradientEnd.setAttribute('stop-color',
      'hsl(0,' + (60 + 40 * (1 - pct)) + '%,40%)');
  }

  // 立刻执行并开始每秒更新
  updateProgress();
  setInterval(updateProgress, 1000);
</script>

<style>
  /* 1s 线性过渡,同步每秒步进,消除闪烁 */
  #progress {
    transition: stroke-dasharray 1s linear !important;
    will-change: stroke-dasharray;
  }
</style>
"
相关推荐
大家的林语冰3 小时前
ESLint 近期动态大全,新版本正式发布,antfu 大佬推荐的插件也更新了!
前端·javascript·前端工程化
只会cv的前端攻城狮3 小时前
DSL 领域模型架构设计:消灭 CRUD 重复工作
前端·架构
码事漫谈4 小时前
时序数据库2026盘点:国产数据库如何以“融合多模”走出差异化之路?
前端·后端
道友可好4 小时前
让 AI 自己验收,等于让学生自己批卷
前端·人工智能·后端
yingyima4 小时前
Go 语言正则表达式速查手册:30 分钟掌握核心语法与实战技巧
前端
大蝴蝶博努奇a4 小时前
使用ChatGPT 解决各类代码报错
前端
胡志辉4 小时前
深入浅出 call、apply、bind
前端·javascript·后端
iccb10135 小时前
5年,一个程序员是如何把私有化在线客服系统做到第一名的
前端·后端·github
假如让我当三天老蒯5 小时前
回归基本功:Map/Set 与 WeakMap/WeakSet 的区别
前端·面试
IT乐手5 小时前
48队都装不下你|国足第24次让全世界失望
前端