仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 天前
1<?php
2/** 本地镜像 */
3$active = 'image';
4include __DIR__ . '/head.php';
5?>
6<div class="dk-card">
7 <div class="dk-card-head"><h3>本地镜像</h3><button class="dk-btn dk-btn-ghost dk-btn-sm" onclick="loadImages()">刷新</button></div>
8 <div class="dk-card-body flush">
9 <div class="dk-spinner-overlay" id="dkImgLoading"><span class="dk-spin"></span> 加载中…</div>
10 <table class="dk-table" id="dkImgTable" style="display:none">
11 <thead><tr><th>镜像</th><th>标签</th><th>大小</th><th>创建时间</th><th>ID</th></tr></thead>
12 <tbody></tbody>
13 </table>
14 </div>
15</div>
16<script>
17function esc(s){ return $('<div>').text(s==null?'':String(s)).html(); }
18function fmtSize(s){
19 var n = parseInt(s,10)||0;
20 if (n < 1048576) return (n/1024).toFixed(1)+' KB';
21 if (n < 1073741824) return (n/1048576).toFixed(1)+' MB';
22 return (n/1073741824).toFixed(2)+' GB';
23}
24function loadImages(){
25 $('#dkImgLoading').show(); $('#dkImgTable').hide();
26 dkAjax('image_list', {}, {silent:true, timeout:60000}).then(function(r){
27 var list = r.data && r.data.data ? r.data.data : (r.data || []);
28 list = Array.isArray(list) ? list : [];
29 var rows = '';
30 if (!list.length) rows = '<tr><td colspan="5" class="dk-empty">暂无本地镜像</td></tr>';
31 list.forEach(function(img){
32 var tags = img.RepoTags || img.repo_tags || img.tags || [];
33 if (Array.isArray(tags)) tags = tags.join(', ');
34 var size = img.Size || img.size || 0;
35 var created = img.Created || img.created || '';
36 if (created) { try { created = new Date(created*1000).toLocaleString(); } catch(e){} }
37 var id = (img.Id || img.id || '').toString().slice(0,19);
38 rows += '<tr><td class="dk-mono">'+ esc((tags||'').split(':')[0] || '-') +'</td><td class="dk-mono">'+ esc((tags||'').split(':')[1] || '-') +'</td><td>'+ esc(fmtSize(size)) +'</td><td class="dk-mono">'+ esc(created || '-') +'</td><td class="dk-mono">'+ esc(id) +'</td></tr>';
39 });
40 $('#dkImgTable tbody').html(rows);
41 $('#dkImgLoading').hide(); $('#dkImgTable').show();
42 }).fail(function(){ $('#dkImgLoading').html('<div class="dk-empty"><p>加载失败,请确认节点 Docker 可用</p></div>'); });
43}
44loadImages();
45</script>
46<?php include __DIR__ . '/foot.php'; ?>