workload-gantt-preview.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>工作量负载概览 - 方案预览</title>
  7. <!-- 替换为国内稳定的 BootCDN 源 -->
  8. <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
  9. <style>
  10. :root {
  11. --primary-color: #3b82f6;
  12. --bg-color: #f8fafc;
  13. --card-bg: #ffffff;
  14. --text-main: #1e293b;
  15. --text-sub: #64748b;
  16. }
  17. body {
  18. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  19. background-color: var(--bg-color);
  20. margin: 0;
  21. padding: 40px;
  22. color: var(--text-main);
  23. }
  24. .container {
  25. max-width: 1000px;
  26. margin: 0 auto;
  27. }
  28. .card {
  29. background: var(--card-bg);
  30. border-radius: 16px;
  31. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  32. padding: 24px;
  33. margin-bottom: 30px;
  34. }
  35. .header {
  36. display: flex;
  37. justify-content: space-between;
  38. align-items: center;
  39. margin-bottom: 24px;
  40. }
  41. .title-group h3 {
  42. margin: 0 0 4px 0;
  43. font-size: 18px;
  44. font-weight: 600;
  45. }
  46. .title-group p {
  47. margin: 0;
  48. font-size: 13px;
  49. color: var(--text-sub);
  50. }
  51. .controls {
  52. display: flex;
  53. gap: 16px;
  54. align-items: center;
  55. }
  56. .switch-group {
  57. background: #f1f5f9;
  58. padding: 4px;
  59. border-radius: 8px;
  60. display: flex;
  61. }
  62. .switch-btn {
  63. border: none;
  64. background: transparent;
  65. padding: 6px 12px;
  66. border-radius: 6px;
  67. font-size: 13px;
  68. cursor: pointer;
  69. color: var(--text-sub);
  70. transition: all 0.2s;
  71. }
  72. .switch-btn.active {
  73. background: white;
  74. color: var(--primary-color);
  75. box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  76. font-weight: 500;
  77. }
  78. .legend {
  79. display: flex;
  80. gap: 12px;
  81. font-size: 12px;
  82. color: var(--text-sub);
  83. }
  84. .legend-item {
  85. display: flex;
  86. align-items: center;
  87. gap: 6px;
  88. }
  89. .dot {
  90. width: 8px;
  91. height: 8px;
  92. border-radius: 2px;
  93. }
  94. .chart-container {
  95. width: 100%;
  96. height: 400px;
  97. }
  98. /* 方案说明样式 */
  99. .scheme-tag {
  100. display: inline-block;
  101. padding: 4px 8px;
  102. border-radius: 4px;
  103. font-size: 12px;
  104. font-weight: 600;
  105. margin-bottom: 8px;
  106. }
  107. .tag-1 { background: #e0f2fe; color: #0369a1; }
  108. .tag-2 { background: #f3e8ff; color: #7e22ce; }
  109. </style>
  110. </head>
  111. <body>
  112. <div class="container">
  113. <!-- 方案一:极简热力方块 -->
  114. <div class="scheme-tag tag-1">方案一:极简热力方块 (推荐)</div>
  115. <div class="card">
  116. <div class="header">
  117. <div class="title-group">
  118. <h3>工作量负载概览</h3>
  119. <p>极简风格,通过色块直观展示忙闲分布</p>
  120. </div>
  121. <div class="controls">
  122. <div class="legend">
  123. <span class="legend-item"><span class="dot" style="background:#f1f5f9"></span>空闲</span>
  124. <span class="legend-item"><span class="dot" style="background:#eff6ff; border:1px solid #bfdbfe"></span>适中</span>
  125. <span class="legend-item"><span class="dot" style="background:#fee2e2; border:1px solid #fecaca"></span>超负荷</span>
  126. </div>
  127. <div class="switch-group">
  128. <button class="switch-btn active" onclick="updateChart1('week')">周视图</button>
  129. <button class="switch-btn" onclick="updateChart1('month')">月视图</button>
  130. </div>
  131. </div>
  132. </div>
  133. <div id="chart1" class="chart-container"></div>
  134. </div>
  135. <!-- 方案二:数字化日历 -->
  136. <div class="scheme-tag tag-2">方案二:数字化日历</div>
  137. <div class="card">
  138. <div class="header">
  139. <div class="title-group">
  140. <h3>工作量负载概览</h3>
  141. <p>数据风格,直接显示每日项目数量</p>
  142. </div>
  143. <div class="controls">
  144. <div class="legend">
  145. <span class="legend-item">数字代表项目数</span>
  146. </div>
  147. </div>
  148. </div>
  149. <div id="chart2" class="chart-container"></div>
  150. </div>
  151. </div>
  152. <script>
  153. // ================== 模拟数据生成 ==================
  154. const designers = ['王刚', '李婷', '张伟', '陈思', '赵敏', '刘强'];
  155. const today = new Date();
  156. // 生成未来30天的数据
  157. function generateData(days) {
  158. const data = [];
  159. designers.forEach((designer, yIndex) => {
  160. for (let i = 0; i < days; i++) {
  161. const date = new Date(today);
  162. date.setDate(today.getDate() + i);
  163. const ts = date.getTime();
  164. // 随机生成负载 (0-4)
  165. // 让某些人更忙,模拟真实情况
  166. const baseLoad = (yIndex % 2 === 0) ? 2 : 0;
  167. const randomLoad = Math.floor(Math.random() * 3);
  168. const count = Math.max(0, Math.min(4, baseLoad + randomLoad - 1));
  169. let status = 'idle';
  170. if (count === 0) status = 'idle';
  171. else if (count >= 3) status = 'overload';
  172. else status = 'busy';
  173. // 模拟项目详情
  174. const projects = [];
  175. for(let p=0; p<count; p++) {
  176. projects.push({
  177. name: ['锦江上院', '天鹅湖', '龙湖天街', '万科城市', '保利国际'][Math.floor(Math.random()*5)] + '-' + (p+1) + '期',
  178. stage: ['建模', '渲染', '后期', '修改'][Math.floor(Math.random()*4)]
  179. });
  180. }
  181. data.push({
  182. value: [yIndex, ts, ts + 24*3600*1000, designer, status, count, projects],
  183. itemStyle: getItemStyle(status)
  184. });
  185. }
  186. });
  187. return data;
  188. }
  189. function getItemStyle(status) {
  190. if (status === 'overload') return { color: '#fee2e2', borderColor: '#fca5a5', borderWidth: 1 };
  191. if (status === 'busy') return { color: '#eff6ff', borderColor: '#bfdbfe', borderWidth: 1 };
  192. return { color: '#f8fafc', borderColor: '#f1f5f9', borderWidth: 1 }; // idle
  193. }
  194. // 声明图表实例变量
  195. let chart1, chart2;
  196. // ================== 方案一:极简热力方块 ==================
  197. function renderChart1(scale) {
  198. // 确保 chart1 已初始化
  199. if (!chart1) {
  200. const dom = document.getElementById('chart1');
  201. if (dom) {
  202. chart1 = echarts.init(dom);
  203. } else {
  204. console.error('Chart1 DOM not found');
  205. return;
  206. }
  207. }
  208. const days = scale === 'week' ? 7 : 30;
  209. const data = generateData(days);
  210. const xMin = today.getTime();
  211. const xMax = xMin + days * 24 * 3600 * 1000;
  212. const option = {
  213. tooltip: {
  214. padding: 0,
  215. backgroundColor: '#fff',
  216. borderColor: '#e2e8f0',
  217. textStyle: { color: '#334155' },
  218. formatter: function (params) {
  219. const val = params.value;
  220. const [yIndex, start, end, name, status, count, projects] = val;
  221. const date = new Date(start);
  222. const dateStr = `${date.getMonth()+1}/${date.getDate()}`;
  223. // 精简的 Tooltip
  224. let listHtml = projects.map(p =>
  225. `<div style="display:flex;justify-content:space-between;font-size:12px;margin-top:4px;color:#64748b;">
  226. <span>${p.name}</span><span style="font-size:10px;background:#f1f5f9;padding:1px 4px;border-radius:2px;">${p.stage}</span>
  227. </div>`
  228. ).join('');
  229. let statusColor = count >= 3 ? '#ef4444' : (count > 0 ? '#3b82f6' : '#94a3b8');
  230. return `
  231. <div style="width:200px; padding:10px;">
  232. <div style="display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid #f1f5f9; padding-bottom:6px; margin-bottom:6px;">
  233. <span style="font-weight:600;">${name}</span>
  234. <span style="font-size:12px; color:${statusColor}; font-weight:500;">${count}个项目</span>
  235. </div>
  236. ${count > 0 ? listHtml : '<div style="font-size:12px;color:#cbd5e1;text-align:center;">无安排</div>'}
  237. </div>
  238. `;
  239. }
  240. },
  241. grid: { top: 30, left: 80, right: 20, bottom: 20 },
  242. xAxis: {
  243. type: 'time',
  244. min: xMin,
  245. max: xMax,
  246. position: 'top',
  247. axisLine: { show: false },
  248. axisTick: { show: false },
  249. splitLine: { show: false }, // 去掉竖线,更干净
  250. axisLabel: {
  251. formatter: (val) => {
  252. const d = new Date(val);
  253. return `${d.getMonth()+1}/${d.getDate()}`;
  254. },
  255. color: '#94a3b8',
  256. fontSize: 11,
  257. margin: 10
  258. }
  259. },
  260. yAxis: {
  261. type: 'category',
  262. data: designers,
  263. inverse: true,
  264. axisLine: { show: false },
  265. axisTick: { show: false },
  266. axisLabel: {
  267. color: '#475569',
  268. fontSize: 13,
  269. fontWeight: 500,
  270. margin: 20
  271. }
  272. },
  273. series: [{
  274. type: 'custom',
  275. renderItem: function (params, api) {
  276. const y = api.value(0);
  277. const start = api.coord([api.value(1), y]);
  278. const end = api.coord([api.value(2), y]);
  279. const height = api.size([0, 1])[1] * 0.7; // 高度占比
  280. const width = (end[0] - start[0]) * 0.85; // 宽度占比,留出间隙
  281. // 绘制圆角矩形
  282. return {
  283. type: 'rect',
  284. shape: {
  285. x: start[0] + (end[0] - start[0] - width) / 2, // 居中
  286. y: start[1] - height / 2,
  287. width: width,
  288. height: height,
  289. r: 4 // 圆角
  290. },
  291. style: api.style()
  292. };
  293. },
  294. data: data
  295. }]
  296. };
  297. chart1.setOption(option);
  298. }
  299. function updateChart1(scale) {
  300. // 更新按钮状态
  301. const btns = document.querySelectorAll('.switch-btn');
  302. btns.forEach(b => b.classList.remove('active'));
  303. if(event && event.target) {
  304. event.target.classList.add('active');
  305. }
  306. renderChart1(scale);
  307. }
  308. // ================== 方案二:数字化日历 ==================
  309. function renderChart2() {
  310. // 确保 chart2 已初始化
  311. if (!chart2) {
  312. const dom = document.getElementById('chart2');
  313. if (dom) {
  314. chart2 = echarts.init(dom);
  315. } else {
  316. console.error('Chart2 DOM not found');
  317. return;
  318. }
  319. }
  320. const days = 14; // 展示两周
  321. const data = generateData(days);
  322. const xMin = today.getTime();
  323. const xMax = xMin + days * 24 * 3600 * 1000;
  324. const option = {
  325. tooltip: { show: false }, // 直接显示数字,不需要Tooltip
  326. grid: { top: 30, left: 80, right: 20, bottom: 20 },
  327. xAxis: {
  328. type: 'time',
  329. min: xMin,
  330. max: xMax,
  331. position: 'top',
  332. axisLine: { show: false },
  333. axisTick: { show: false },
  334. splitLine: { show: true, lineStyle: { color: '#f1f5f9' } },
  335. axisLabel: {
  336. formatter: (val) => {
  337. const d = new Date(val);
  338. return `${d.getMonth()+1}/${d.getDate()}`;
  339. },
  340. color: '#94a3b8'
  341. }
  342. },
  343. yAxis: {
  344. type: 'category',
  345. data: designers,
  346. inverse: true,
  347. axisLine: { show: false },
  348. axisTick: { show: false },
  349. axisLabel: {
  350. color: '#475569',
  351. fontSize: 13,
  352. margin: 20
  353. }
  354. },
  355. series: [{
  356. type: 'custom',
  357. renderItem: function (params, api) {
  358. const y = api.value(0);
  359. const start = api.coord([api.value(1), y]);
  360. const end = api.coord([api.value(2), y]);
  361. const height = api.size([0, 1])[1];
  362. const width = end[0] - start[0];
  363. const count = api.value(5);
  364. // 根据数量决定背景色深浅
  365. let bgColor = '#fff';
  366. let textColor = '#cbd5e1'; // 0 - 浅灰
  367. if (count === 1) { bgColor = '#eff6ff'; textColor = '#3b82f6'; }
  368. if (count === 2) { bgColor = '#dbeafe'; textColor = '#2563eb'; }
  369. if (count >= 3) { bgColor = '#fee2e2'; textColor = '#dc2626'; }
  370. return {
  371. type: 'group',
  372. children: [
  373. {
  374. type: 'rect',
  375. shape: {
  376. x: start[0],
  377. y: start[1] - height / 2,
  378. width: width - 2, // 留微小缝隙
  379. height: height - 2
  380. },
  381. style: { fill: bgColor }
  382. },
  383. {
  384. type: 'text',
  385. style: {
  386. text: count > 0 ? count : '-',
  387. x: start[0] + width / 2,
  388. y: start[1],
  389. textAlign: 'center',
  390. textVerticalAlign: 'middle',
  391. fill: textColor,
  392. fontSize: 14,
  393. fontWeight: 'bold'
  394. }
  395. }
  396. ]
  397. };
  398. },
  399. data: data
  400. }]
  401. };
  402. chart2.setOption(option);
  403. }
  404. // 页面加载完成后初始化图表
  405. window.addEventListener('load', () => {
  406. renderChart1('week');
  407. renderChart2();
  408. });
  409. // 响应窗口大小
  410. window.addEventListener('resize', () => {
  411. if(chart1) chart1.resize();
  412. if(chart2) chart2.resize();
  413. });
  414. </script>
  415. </body>
  416. </html>