2025-06-25 17:41:48 +08:00

311 lines
8.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="breadcrumb"}
<span class="layui-breadcrumb">
<a href="http://www.meteteme.com/" target="_blank">江苏美天科技</a>
<a href="/applications/nav/index">
<cite>应用</cite>
</a>
<a>
<cite>软件管理</cite>
</a>
</span>
{/block}
{block name="body"}
<div class="table-content p-3">
<div class="layui-form-bar border-t border-x">
<button class="layui-btn layui-btn-sm layui-bg-blue add-new">+ 上传软件</button>
<button class="layui-btn layui-btn-sm" id="refresh-btn">刷新</button>
</div>
<div class="layui-form-bar border-t border-x">
<form id="taskForm" class="layui-form">
<div class="layui-col-md4" style="width: 200px;margin-right: 10px;">
<div class="layui-input-wrap">
<div class="layui-input-prefix">
<!-- <i class="layui-icon layui-icon-username"></i>-->
</div>
<input id="gys" type="text" name="name" value="" placeholder="请输入软件名称" class="layui-input"
lay-affix="clear">
</div>
</div>
<div class="layui-col-md4" style="width: 200px; margin-right: 10px;">
<div class="layui-input-wrap">
<select id="lxr" name="cid" lay-search="" lay-filter="cid">
<option value="">请选择软件分类</option>
</select>
</div>
</div>
<div class="layui-col-md4" style="width: 200px;margin-right: 10px;">
<div class="layui-input-wrap">
<input id="lxdh" type="text" name="uid" value="" placeholder="请输入上传者" class="layui-input"
lay-affix="clear">
</div>
</div>
<button class="layui-btn" lay-submit lay-filter="webform">搜索</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</form>
</div>
<table class="layui-hide" id="download" lay-filter="download"></table>
</div>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool', 'gouguEdit', 'gouguComment'];
function gouguInit() {
var table = layui.table,
form = layui.form,
layer = layui.layer,
tool = layui.tool;
//存储表格原始数据
var originalData = [];
// 添加按钮
$('.add-new').on('click', function () {
tool.open('/download/index/add');
});
// 刷新按钮
$("#refresh-btn").on("click", function () {
location.reload();
});
// 动态加载软件分类
fetch("/download/index/catelist")
.then((response) => response.json())
.then((result) => {
if (result.code === 0 && Array.isArray(result.data)) {
var select = document.querySelector('select[name="cid"]');
select.innerHTML = '<option value="">请选择软件分类</option>'; // 清空并添加默认选项
result.data.forEach((item) => {
var option = document.createElement("option");
option.value = item.name; // 使用分类名称作为 value
option.innerText = item.name; // 显示分类名称
select.appendChild(option);
});
// 重新渲染 select
form.render("select");
} else {
console.error("分类加载失败:", result.msg || "未知错误");
}
})
.catch((error) => {
console.error("分类加载接口异常:", error);
});
// 搜索按钮
form.on('submit(webform)', function (data) {
var field = data.field; // 获取表单字段
// 重新加载表格数据,传递筛选条件
layui.pageTable.reload({
where: {
name: field.name || '', // 软件名称
cid: field.cid || '', // 分类名称(通过分类名称筛选)
uid: field.uid || '' // 上传用户
},
page: {
curr: 1 // 重新从第 1 页开始
}
});
return false; // 阻止默认 form 提交
});
// 表格渲染
layui.pageTable = table.render({
elem: '#download',
title: '下载列表',
cellMinWidth: 80,
url: "/download/index/index", // 数据接口method: 'POST', // 使用 POST 方法传递筛选条件
where: {}, // 初始筛选条件为空
page: true, // 开启分页
limit: 50,
height: 'full-130',
cols: [[
// {
// field: 'id',
// title: '下载编号',
// width: 100,
// align: 'center',
// rowspan: 2,
// templet: function (d) {
// return 'S' + d.id;
// }
// },
{
field: 'name',
title: '软件名称',
align: 'center',
width: 300,
rowspan: 2,
templet: function (d) {
var html = '<span>' + (d.name || '-') + '</span>';
return html;
}
},
{
field: 'cid',
title: '软件分类',
align: 'center',
width: 160,
rowspan: 2,
templet: function (d) {
var html = '<span>' + (d.cid || '-') + '</span>';
return html;
}
},
{
field: 'version',
title: '软件版本',
align: 'center',
width: 120,
rowspan: 2,
templet: function (d) {
var html = '<span>' + (d.version || '-') + '</span>';
return html;
}
},
{
field: 'size',
title: '软件大小',
align: 'center',
width: 120,
rowspan: 2,
templet: function (d) {
var html = '<span>' + (d.size || '-') + '</span>';
return html;
}
},
{
field: 'type',
title: '软件类型',
align: 'center',
width: 120,
rowspan: 2,
templet: function (d) {
var html = '<span>' + (d.type || '-') + '</span>';
return html;
}
},
{
field: 'download_url',
title: '下载链接',
align: 'center',
// width: 500,
rowspan: 2,
templet: function (d) {
var html = '';
if (d.path && d.path !== 'https://project.meteteme.com/') {
// 如果有 path 且 path 不等于指定值,则显示 path
html += '<span>' + d.path + '</span>';
}
if (d.download_url) {
// 如果有 download_url则显示 download_url 并拼接 download_code
var downloadCode = d.download_code || '-';
html += '<span>' + d.download_url + '&nbsp;&nbsp;&nbsp;&nbsp;分享码:' + downloadCode + '</span>';
}
return html || '<span>-</span>'; // 如果都没有值,显示占位符
}
},
// {
// field: 'description',
// title: '软件描述',
// align: 'center',
// rowspan: 2,
// templet: function (d) {
// var html = '<span>' + (d.description || '-') + '</span>';
// return html;
// }
// },
// {
// field: 'uid',
// title: '上传用户',
// align: 'center',
// width: 200,
// rowspan: 2,
// templet: function (d) {
// var html = '<span>' + (d.uid || '-') + '</span>';
// return html;
// }
// },
{
title: "操作",
align: "center",
width: 240,
minWidth: 125,
toolbar: "#barDemo",
},
]],
done: function (res, curr, count) {
// 仅在首次加载表格时保存原始数据
if (originalData.length === 0) {
originalData = res.data;
}
}
});
// 搜索重置按钮
$("#taskForm").on("click", '[lay-filter="clear"]', function () {
location.reload();
});
table.on('tool(download)', function (obj) {
var data = obj.data; // 获取当前行的数据
if (obj.event === 'edit') {
var id = data.id; // 获取当前行数据的id
var url = '/download/index/edit?id=' + id;
tool.open(url);
} else if (obj.event === 'delete') {
layui.layer.confirm(
"确定删除该软件吗?",
{ icon: 3, title: "提示" },
function (index) {
$.post(
"/download/index/delete",
{ id: data.id },
function (res) {
if (res.code === 0) {
layui.layer.msg(res.msg);
obj.del(); // 删除表格中的对应行数据
} else {
layui.layer.msg(res.msg);
}
}
);
layui.layer.close(index);
}
);
} else if (obj.event === 'view') {
var id = data.id; // 获取当前行数据的id
console.log('查看详情', id);
// 查看详情
layui.layer.open({
type: 2, // iframe层
title: '供应商详情',
shadeClose: true,
shade: 0.8,
area: ['70%', '90%'], // 宽高
content: '/download/index/view?id=' + id,
});
}
});
}
</script>
<script type="text/html" id="barDemo">
<!-- <a class="layui-btn layui-btn-xs " lay-event="view">详情</a> -->
<a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delete">删除</a>
</script>
{/block}
<!-- /脚本 -->