mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 02:22:48 +08:00
feat: 实现基本的详情生成
This commit is contained in:
@@ -1454,6 +1454,129 @@ class BuildCurdServiceBase
|
||||
);
|
||||
$this->fileList[$viewEditFile] = $viewEditValue;
|
||||
|
||||
// 详情页面
|
||||
$viewReadFile = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}read.html";
|
||||
$mainFields = '';
|
||||
$basicFields = '';
|
||||
|
||||
// 定义基础字段(右侧显示)
|
||||
$basicFieldList = ['id', 'create_time', 'update_time', 'status', 'sort', 'delete_time'];
|
||||
|
||||
foreach ($this->tableColumns as $field => $val) {
|
||||
if (in_array($field, ['id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$templateFile = "view{$this->DS}module{$this->DS}input";
|
||||
$value = '{$row.' . $field . '|default=\'\'}';
|
||||
|
||||
// 根据字段类型选择不同的模板
|
||||
if ($val['formType'] == 'image') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}image";
|
||||
} elseif ($val['formType'] == 'images') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}images";
|
||||
} elseif ($val['formType'] == 'file') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}file";
|
||||
} elseif ($val['formType'] == 'files') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}files";
|
||||
} elseif ($val['formType'] == 'editor' || in_array($field, ['remark']) || $val['formType'] == 'textarea') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}textarea";
|
||||
$value = '{$row.' . $field . '|raw|default=\'\'}';
|
||||
} elseif ($val['formType'] == 'date') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}date";
|
||||
if (isset($val['define']) && !empty($val['define'])) {
|
||||
$define = $val['define'];
|
||||
} else {
|
||||
$define = 'datetime';
|
||||
}
|
||||
if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) {
|
||||
$define = 'datetime';
|
||||
}
|
||||
} elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}radio";
|
||||
if (isset($val['define']) && !empty($val['define'])) {
|
||||
$define = $this->buildRadioView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}');
|
||||
}
|
||||
} elseif ($val['formType'] == 'checkbox') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}checkbox";
|
||||
if (isset($val['define']) && !empty($val['define'])) {
|
||||
$define = $this->buildCheckboxView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}');
|
||||
}
|
||||
} elseif ($val['formType'] == 'select') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}select";
|
||||
if (isset($val['bindRelation'])) {
|
||||
$define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
||||
} elseif (isset($val['define']) && !empty($val['define'])) {
|
||||
$define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
||||
}
|
||||
} elseif ($val['formType'] == 'relation') {
|
||||
$val['define']['type'] = 'radio';
|
||||
$val['define']['valueField'] = 'id';
|
||||
$val['define']['fieldName'] = $val['define']['relationBindSelect'];
|
||||
$templateFile = "view{$this->DS}module{$this->DS}table";
|
||||
$define = $this->buildTableView($field, $val, $value);
|
||||
} elseif ($val['formType'] == 'table') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}table";
|
||||
$define = $this->buildTableView($field, $val, $value);
|
||||
} elseif ($val['formType'] == 'city') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}city";
|
||||
$define = $this->buildCityView($field, $val, $value);
|
||||
} elseif ($val['formType'] == 'tag') {
|
||||
$templateFile = "view{$this->DS}module{$this->DS}tag";
|
||||
}
|
||||
|
||||
// 直接生成详情页面的字段展示HTML,使用简单的div结构
|
||||
$fieldContent = '<div class="detail-field-item">';
|
||||
$fieldContent .= '<div class="detail-field-label">' . $val['comment'] . '</div>';
|
||||
$fieldContent .= '<div class="detail-field-value">';
|
||||
|
||||
// 根据字段类型处理值的显示
|
||||
if ($val['formType'] == 'editor' || in_array($field, ['remark']) || $val['formType'] == 'textarea') {
|
||||
$fieldContent .= '{$row.' . $field . '|raw|default=\'\'}';
|
||||
} elseif ($val['formType'] == 'image') {
|
||||
$fieldContent .= '<img src="{$row.' . $field . '}" class="detail-image" style="max-width: 200px; max-height: 200px;">';
|
||||
} elseif ($val['formType'] == 'switch') {
|
||||
$fieldContent .= '{eq name="row.' . $field . '" value="1"}启用{else/}禁用{/eq}';
|
||||
} else {
|
||||
$fieldContent .= '{$row.' . $field . '|default=\'\'}';
|
||||
}
|
||||
|
||||
$fieldContent .= '</div>';
|
||||
$fieldContent .= '</div>';
|
||||
|
||||
// 注释掉表单模板生成逻辑
|
||||
/*
|
||||
$fieldContent = $this->replaceTemplate(
|
||||
$this->getTemplate($templateFile),
|
||||
[
|
||||
'comment' => $val['comment'],
|
||||
'field' => $field,
|
||||
'required' => '',
|
||||
'required_text' => '',
|
||||
'value' => $value,
|
||||
'define' => $define,
|
||||
]
|
||||
);
|
||||
*/
|
||||
|
||||
// 根据字段类型分配到不同区域
|
||||
if (in_array($field, $basicFieldList)) {
|
||||
$basicFields .= $fieldContent;
|
||||
} else {
|
||||
$mainFields .= $fieldContent;
|
||||
}
|
||||
}
|
||||
|
||||
$viewReadValue = $this->replaceTemplate(
|
||||
$this->getTemplate("view{$this->DS}read"),
|
||||
[
|
||||
|
||||
'mainFields' => $mainFields,
|
||||
'basicFields' => $basicFields,
|
||||
]
|
||||
);
|
||||
$this->fileList[$viewReadFile] = $viewReadValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -1538,7 +1661,8 @@ class BuildCurdServiceBase
|
||||
}
|
||||
}
|
||||
|
||||
$indexCols .= $this->formatColsRow("{width: 250, title: '操作', templet: ua.table.tool , fixed:'right'},\r");
|
||||
$indexCols .= $this->formatColsRow("{width: 250, title: '操作', templet: ua.table.tool, operat: [{class: 'layui-btn layui-btn-primary layui-btn-xs', method: 'tab', field: 'id', text: '详情', title: '查看详情', auth: 'read', url: 'read', icon: ''}, 'edit', 'delete'], fixed:'right'},
|
||||
");
|
||||
|
||||
$js_index = $this->replaceTemplate(
|
||||
$this->getTemplate("js{$this->DS}index"),
|
||||
@@ -1560,12 +1684,16 @@ class BuildCurdServiceBase
|
||||
|
||||
$js_add_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}add.js";
|
||||
$js_edit_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}edit.js";
|
||||
$js_read_file = "{$this->rootDir}app{$this->DS}admin{$this->DS}view{$this->DS}{$this->viewFilename}{$this->DS}read.js";
|
||||
|
||||
$js_add = $this->replaceTemplate($this->getTemplate("js{$this->DS}add"));
|
||||
$this->fileList[$js_add_file] = $js_add;
|
||||
|
||||
$js_edit = $this->replaceTemplate($this->getTemplate("js{$this->DS}edit"));
|
||||
$this->fileList[$js_edit_file] = $js_edit;
|
||||
|
||||
$js_read = $this->replaceTemplate($this->getTemplate("js{$this->DS}read"));
|
||||
$this->fileList[$js_read_file] = $js_read;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
22
extend/base/admin/service/curd/templates/js/read.code
Normal file
22
extend/base/admin/service/curd/templates/js/read.code
Normal file
@@ -0,0 +1,22 @@
|
||||
$(function(){
|
||||
// 删除数据
|
||||
window.deleteData = function(id) {
|
||||
layer.confirm('确定要删除这条数据吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function(index) {
|
||||
$.post('{{:url("delete")}}', {id: id}, function(res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg('删除成功', {icon: 1}, function() {
|
||||
location.href = '{{:url("index")}}';
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2});
|
||||
}
|
||||
}, 'json');
|
||||
layer.close(index);
|
||||
});
|
||||
};
|
||||
|
||||
ua.listen();
|
||||
})
|
||||
40
extend/base/admin/service/curd/templates/view/read.code
Normal file
40
extend/base/admin/service/curd/templates/view/read.code
Normal file
@@ -0,0 +1,40 @@
|
||||
<div class="layuimini-container detail-container">
|
||||
<div class="layuimini-main">
|
||||
<div class="layui-card detail-card">
|
||||
<div class="layui-card-header detail-header">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md9">
|
||||
<h2 class="detail-title">#{$row.id} {$title}</h2>
|
||||
<div class="detail-id">ID: {$row.id}</div>
|
||||
</div>
|
||||
<div class="layui-col-md3 text-right detail-actions">
|
||||
<button class="layui-btn layui-btn-primary" onclick="window.history.back()">返回</button>
|
||||
<button class="layui-btn" onclick="location.href='{{:url("edit", ["id" => $row.id])}}'">编辑</button>
|
||||
<button class="layui-btn layui-btn-danger" onclick="deleteData({{$row.id}})">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-card-body detail-content">
|
||||
<div class="layui-row">
|
||||
<!-- 左侧主体内容 -->
|
||||
<div class="layui-col-md8 detail-main">
|
||||
<div class="detail-field-group">
|
||||
{{mainFields}}
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右侧基础信息 -->
|
||||
<div class="layui-col-md4 detail-side">
|
||||
<h3 class="detail-side-title">基础信息</h3>
|
||||
<div class="detail-field-group">
|
||||
<div class="detail-field-item">
|
||||
<div class="detail-field-label">ID</div>
|
||||
<div class="detail-field-value">{$row.id}</div>
|
||||
</div>
|
||||
{{basicFields}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,6 +130,23 @@ trait CurdTraitBase
|
||||
return download($content, $export_file_name . date('YmdHis') . '.xlsx', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @\app\admin\service\annotation\NodeAnotation(title="详情")
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
|
||||
// 获取模型的标题(表注释)
|
||||
$title = $row->title;
|
||||
|
||||
$this->assign('row', $row);
|
||||
$this->assign('title', $title);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @\app\admin\service\annotation\NodeAnotation(title="属性修改")
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user