提交 35064f72 编写于 作者: W wolfcode

编辑器兼容curd自动生成

上级 00ccd891
......@@ -62,7 +62,7 @@
<div class="layui-form-item">
<label class="layui-form-label">商品描述</label>
<div class="layui-input-block">
{!!editor_textarea([],'describe') !!}
{!!editor_textarea('','describe') !!}
</div>
</div>
......
......@@ -63,7 +63,7 @@
<div class="layui-form-item">
<label class="layui-form-label">商品描述</label>
<div class="layui-input-block">
{!!editor_textarea($row,'describe') !!}
{!!editor_textarea($row["describe"],'describe') !!}
</div>
</div>
......
......@@ -871,7 +871,7 @@ class BuildCurd
}
// 判断富文本
if (in_array($field, $this->editorFields)) {
if (in_array($field, $this->editorFields) || in_array($val['type'], ['text', 'tinytext', 'mediumtext', 'longtext'])) {
$this->tableColumns[$field]['formType'] = 'editor';
continue;
}
......@@ -939,7 +939,7 @@ class BuildCurd
}
// 判断富文本
if (in_array($field, $this->editorFields)) {
if (in_array($field, $this->editorFields) || in_array($val['type'], ['text', 'tinytext', 'mediumtext', 'longtext'])) {
$this->relationArray[$table]['tableColumns'][$field]['formType'] = 'editor';
continue;
}
......@@ -1134,6 +1134,12 @@ class BuildCurd
$templateFile = "view{$this->DS}module{$this->DS}input";
$define = '';
// 根据formType去获取具体模板
if ($val['formType'] == 'editor') {
$templateFile = "view{$this->DS}module{$this->DS}editor";
$val['default'] = '""';
}
$addFormList .= CommonTool::replaceTemplate(
$this->getTemplate($templateFile),
[
......@@ -1166,6 +1172,12 @@ class BuildCurd
$define = '';
$value = '{{$row[\'' . $field . '\']}}';
// 根据formType去获取具体模板
if ($val['formType'] == 'editor') {
$templateFile = "view{$this->DS}module{$this->DS}editor";
$value = '$row["' . $field . '"]';
}
$editFormList .= CommonTool::replaceTemplate(
$this->getTemplate($templateFile),
[
......
......@@ -2,6 +2,6 @@
<div class="layui-form-item">
<label class="layui-form-label">{{comment}}</label>
<div class="layui-input-block">
<textarea name="{{field}}" rows="20" class="layui-textarea editor" {{comment}} placeholder="请输入{{comment}}">{{value}}</textarea>
{!! editor_textarea({{value}},"{{field}}","{{comment}}") !!}
</div>
</div>
\ No newline at end of file
......@@ -154,15 +154,14 @@ if (!function_exists('updateFields')) {
}
/**
* @param $row
* @param string $detail
* @param string $name
* @param string $placeholder
* @return string
*/
function editor_textarea($row, string $name = 'desc', string $placeholder = '请输入'): string
function editor_textarea(string $detail, string $name = 'desc', string $placeholder = '请输入'): string
{
$editor_type = sysconfig('site', 'editor_type');
$detail = $row[$name] ?? '';
return match ($editor_type) {
'ckeditor' => "<textarea name='{$name}' rows='20' class='layui-textarea editor' placeholder='{$placeholder}'>{$detail}</textarea>",
default => "<script type='text/plain' id='{$name}' name='{$name}' class='editor' data-content='{$detail}'></script>",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册