Files
database_render/web/templates/builtin/list.html
2025-08-07 20:03:53 +08:00

128 lines
4.5 KiB
HTML

{{define "content"}}
<div class="bg-white rounded-lg shadow overflow-hidden">
{{if .Data}}
{{if eq .TemplateType "table"}}
{{template "table-view" .}}
{{else if eq .TemplateType "card"}}
{{template "card-view" .}}
{{else}}
{{template "table-view" .}}
{{end}}
{{else}}
<div class="text-center py-8 text-gray-500">
暂无数据
</div>
{{end}}
</div>
<!-- 分页 -->
<div class="mt-4 flex justify-between items-center">
<div class="text-sm text-gray-700">
共 {{.Total}} 条记录,第 {{.Page}} / {{.Pages}} 页
</div>
<div class="flex space-x-2">
{{if gt .Page 1}}
<a href="?table={{.Table}}&page={{sub .Page 1}}&per_page={{.PerPage}}"
class="px-3 py-1 border rounded text-sm hover:bg-gray-50">
上一页
</a>
{{end}}
{{range until .Pages}}
{{$page := add . 1}}
{{if eq $page $.Page}}
<span class="px-3 py-1 bg-blue-500 text-white rounded text-sm">{{$page}}</span>
{{else}}
<a href="?table={{$.Table}}&page={{$page}}&per_page={{$.PerPage}}"
class="px-3 py-1 border rounded text-sm hover:bg-gray-50">
{{$page}}
</a>
{{end}}
{{end}}
{{if lt .Page .Pages}}
<a href="?table={{$.Table}}&page={{add $.Page 1}}&per_page={{$.PerPage}}"
class="px-3 py-1 border rounded text-sm hover:bg-gray-50">
下一页
</a>
{{end}}
</div>
</div>
{{end}}
{{define "table-view"}}
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
{{range .Columns}}
{{if .ShowInList}}
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{{.Alias}}
{{if .Sortable}}
<button onclick="sortBy('{{.Name}}')" class="ml-1 text-gray-400 hover:text-gray-600">
</button>
{{end}}
</th>
{{end}}
{{end}}
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
操作
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
{{range $row := .Data}}
<tr class="hover:bg-gray-50">
{{range $col := $.Columns}}
{{if $col.ShowInList}}
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
{{template "field" dict "Value" (index $row $col.Name) "Type" $col.RenderType "Column" $col}}
</td>
{{end}}
{{end}}
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<button onclick="showDetail('{{index $row "id"}}')"
class="text-blue-600 hover:text-blue-900">
查看详情
</button>
</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
{{define "card-view"}}
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 p-4">
{{range $row := .Data}}
<div class="bg-white border rounded-lg p-4 hover:shadow-md transition-shadow">
{{range $col := $.Columns}}
{{if $col.ShowInList}}
<div class="mb-2">
<label class="block text-sm font-medium text-gray-700">{{$col.Alias}}</label>
<div class="mt-1 text-sm text-gray-900">
{{template "field" dict "Value" (index $row $col.Name) "Type" $col.RenderType "Column" $col}}
</div>
</div>
{{end}}
{{end}}
<div class="mt-4">
<button onclick="showDetail('{{index $row "id"}}')"
class="text-blue-600 hover:text-blue-900 text-sm">
查看详情
</button>
</div>
</div>
{{end}}
</div>
{{end}}
{{define "scripts"}}
<!-- 列表页面特定脚本 -->
<script>
// 列表页面特定功能可以在这里添加
console.log('List template loaded for:', '{{.Table}}');
</script>
{{end}}