编辑器兼容curd自动生成

This commit is contained in:
wolfcode
2023-11-20 12:43:05 +08:00
parent 646ccde5fa
commit 0bd1ec9d04
3 changed files with 8 additions and 6 deletions

View File

@@ -872,7 +872,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;
}
@@ -940,7 +940,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;
}
@@ -1146,7 +1146,8 @@ class BuildCurd
$templateFile = "view{$this->DS}module{$this->DS}files";
$define = isset($val['define']) ? $val['define'] : '|';
} elseif ($val['formType'] == 'editor') {
$templateFile = "view{$this->DS}module{$this->DS}editor";
$templateFile = "view{$this->DS}module{$this->DS}editor";
$val['default'] = '""';
} elseif ($val['formType'] == 'date') {
$templateFile = "view{$this->DS}module{$this->DS}date";
if (isset($val['define']) && !empty($val['define'])) {
@@ -1221,7 +1222,7 @@ class BuildCurd
$templateFile = "view{$this->DS}module{$this->DS}files";
} elseif ($val['formType'] == 'editor') {
$templateFile = "view{$this->DS}module{$this->DS}editor";
$value = '{$row.' . $field . '|raw|default=\'\'}';
$value = '$row["' . $field . '"]';
} elseif ($val['formType'] == 'date') {
$templateFile = "view{$this->DS}module{$this->DS}date";
if (isset($val['define']) && !empty($val['define'])) {

View File

@@ -2,6 +2,7 @@
<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>

View File

@@ -130,7 +130,7 @@ if (!function_exists('auth')) {
function editor_textarea($row, string $name = 'desc', string $placeholder = '请输入'): string
{
$editor_type = sysconfig('site', 'editor_type');
$detail = $row[$name] ?? '';
$detail = is_array($row) ? ($row[$name] ?? '') : $row;
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>",