cms first commit

This commit is contained in:
JaguarJack
2021-05-22 11:02:45 +08:00
parent 0f24c9c580
commit f81eaf40af
77 changed files with 4990 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
namespace catchAdmin\cms\tables\forms;
use catchAdmin\cms\model\Tags;
use catcher\library\form\Form;
use catchAdmin\cms\model\Articles as Article;
use catchAdmin\cms\model\Category;
class Articles extends Form
{
public function fields(): array
{
// TODO: Implement fields() method.
return [
self::input('title', '标题')->required()->maxlength(100)->col(12),
self::cascader('category_id', '选择分类')
->options(
Category::field(['id', 'name', 'parent_id'])->select()->toTree()
)
->col(12)
->props(self::props('name', 'id', [
'checkStrictly' => true
]))
->filterable(true)
->clearable(true)
->style(['width' => '100%'])
->required()->col(8),
self::input('keywords', '关键字')->col(12),
self::image('封面', 'cover')->col(12),
self::textarea('description', '摘要')->col(12),
self::images('组图', 'images')->col(12),
self::selectMultiple('tags', '标签')
->options(Tags::field(['name as value', 'name as label'])->select()->toArray())
->clearable(true)
->allowCreate(true)
->filterable(true)
->style(['width' => '100%'])
->col(12),
self::input('url', '自定义URL')->col(8),
self::editor('content', '内容')->required(),
self::radio('is_top', '置顶', Article::UN_TOP)->options(
self::options()->add('是', Article::TOP)
->add('否', Article::UN_TOP)->render()
),
self::radio('is_recommend', '推荐', Article::UN_RECOMMEND)->options(
self::options()->add('是', Article::RECOMMEND)
->add('否', Article::UN_RECOMMEND)->render()
),
self::radio('status', '展示', Article::ENABLE)->options(
self::options()->add('是', Article::ENABLE)
->add('否', Article::DISABLE)->render()
),
self::radio('is_can_comment', '允许评论', Article::UN_CAN_COMMENT)->options(
self::options()->add('是', Article::CAN_COMMENT)
->add('否', Article::UN_CAN_COMMENT)->render()
),
];
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace catchAdmin\cms\tables\forms;
use catchAdmin\cms\model\Category as CategoryModel;
use catchAdmin\cms\support\DynamicFormFields;
use catcher\library\form\Form;
abstract class BaseForm extends Form
{
protected $table = null;
public function create(): array
{
$fields = parent::create(); // TODO: Change the autogenerated stub
if ($this->table) {
return array_merge($fields, (new DynamicFormFields())->build($this->table));
}
return $fields;
}
}

View File

@@ -0,0 +1,73 @@
<?php
// +----------------------------------------------------------------------
// | Catch-CMS Design On 2020
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\cms\tables\forms;
use catchAdmin\cms\model\Category as CategoryModel;
use catcher\library\form\Form;
class Category extends BaseForm
{
protected $table = 'cms_category';
/**
* create form
*
* @time 2021年03月02日
* @return array
*/
public function fields(): array
{
// TODO: Implement create() method.
return [
Form::input('name', '分类名称')->required(),
Form::cascader('parent_id', '父级栏目')
->options(CategoryModel::field(['id', 'name', 'parent_id'])->select()->toTree())->props([
'props' => [
'value' => 'id',
'label' => 'name',
'checkStrictly' => true
]
])->showAllLevels(false)->style(['width' => '100%']),
Form::input('title', 'seo标题'),
Form::input('keywords', 'seo关键词'),
Form::textarea('description', 'seo描述'),
Form::input('url', '自定义URL'),
Form::select('type', '页面类型', 1)->options([
['value' => 1, 'label' => '列表模式'],
['value' => 2, 'label' => '单页模式'],
['value' => 3, 'label' => '封面模式'],
]),
Form::radio('status', '状态', 1)->options(
self::options()->add('启用', 1)
->add('禁用', 2)->render()
),
Form::radio('is_can_comment', '评论', 2)->options(
self::options()->add('可以', 1)
->add('不可以', 2)->render()
),
Form::radio('is_can_contribute', '投稿', 2)->options(
self::options()->add('可以', 1)
->add('不可以', 2)->render()
),
Form::number('weight', '权重', 1),
Form::number('limit', '每页数量', 10),
];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace catchAdmin\cms\tables\forms;
use catcher\library\form\FormFactory;
class Factory extends FormFactory
{
public static function from(): string
{
return __NAMESPACE__;
}
}

View File

@@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | Catch-CMS Design On 2020
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\cms\tables\forms;
use catcher\library\form\Form;
class Field extends Form
{
/**
* create form
*
* @time 2021年03月02日
* @return array
*/
public function fields(): array
{
// TODO: Implement create() method.
return [
// 字段名称
Form::input('name', '字段名称')->required()
->appendValidate(
Form::validatePattern('^[a-z]{1,30}_?[a-z]{1,30}?')->message('字段名称只支持小写字母_组合')
)
->placeholder('由英文和下划线组成')
->clearable(true),
// 字段释义
Form::input('title', 'label名称')->required()->placeholder('表单Label')->clearable(true),
// 字段类型
Form::select('type', '类型')
->required()
->options($this->types())
->style(['width' => '100%'])
->appendControl('string', [Form::number('length', '长度', 1)->max(1000)->min(1)])
->appendControl('int', [Form::number('length', '长度', 1)->max(11)->min(1)])
->appendControl('select', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')])
->appendControl('radio', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')])
->appendControl('checkbox', [Form::textarea('options', '选项')->placeholder('格式(value|label),一个选项占用一行')])
->clearable(true),
// 默认值
Form::input('default_value', '默认值'),
// 加索引
Form::radio('is_index', '加索引', 2)->options(
self::options()->add('是', 1)
->add('否', 2)->render()
),
// 值唯一
Form::radio('is_unique', '值唯一', 2)->options(
self::options()->add('是', 1)
->add('否', 2)->render()
),
// 表单验证规则
Form::selectMultiple('rules', '验证规则')
->options($this->rules()),
// 正则验证
Form::input('pattern', '正则验证')->placeholder('格式如下(正则|提示信息)'),
// 排序
Form::number('sort', '排序', 1)->max(10000)->min(1),
// 字段是否在表单中显示
Form::radio('status', '状态', 1)->options(
self::options()->add('正常', 1)
->add('隐藏', 2)->render()
)
];
}
/**
* 表单类型
*
* @time 2021年03月06日
* @return \string[][]
*/
protected function types(): array
{
return [
['value' => 'string', 'label' => '字符串'],
['value' => 'int', 'label' => '整数'],
['value' => 'float', 'label' => '小数'],
['value' => 'textarea', 'label' => 'textarea文本'],
['value' => 'text', 'label' => '编辑器(建议)'],
['value' => 'longtext', 'label' => '编辑器(支持超大文本)'],
['value' => 'date', 'label' => '日期型'],
['value' => 'datetime', 'label' => '日期时间型'],
['value' => 'image', 'label' => '图片上传'],
['value' => 'images', 'label' => '多图上传'],
['value' => 'file', 'label' => '文件上传'],
['value' => 'files', 'label' => '多文件上传'],
['value' => 'select', 'label' => '列表'],
['value' => 'checkbox', 'label' => '复选框'],
['value' => 'password', 'label' => '密码框'],
['value' => 'color', 'label' => '颜色选项'],
['value' => 'radio', 'label' => '单选'],
];
}
protected function rules(): array
{
return [
['value' => 'require', 'label' => '必填'],
['value' => 'number', 'label' => '数字'],
['value' => 'integer', 'label' => '整数'],
['value' => 'float', 'label' => '浮点数'],
['value' => 'email', 'label' => '邮箱'],
['value' => 'date', 'label' => '日期'],
['value' => 'alpha', 'label' => '纯字母'],
['value' => 'alphaNum', 'label' => '纯字母和数字'],
['value' => 'url', 'label' => 'url地址'],
['value' => 'ip', 'label' => 'ip地址'],
['value' => 'mobile', 'label' => '手机号'],
['value' => 'idCard', 'label' => '身份证'],
['value' => 'zip', 'label' => '邮政编码'],
['value' => 'password', 'label' => '密码'],
['value' => 'strong_password', 'label' => '强密码'],
['value' => 'landLine', 'label' => '座机'],
['value' => 'chinese_character', 'label' => '汉字']
];
}
}

View File

@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | Catch-CMS Design On 2020
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\cms\tables\forms;
use catchAdmin\cms\support\Table;
use catchAdmin\cms\support\TableColumn;
use catcher\library\form\Form;
use think\facade\Db;
use think\helper\Str;
class Model extends Form
{
protected $table = 'cms_articles';
/**
* create form
*
* @time 2021年03月02日
* @return array
*/
public function fields(): array
{
// TODO: Implement create() method.
return [
self::input('name', '模型名称')->required()->maxlength(100),
self::input('alias', '模型别名')->required()->appendValidates([
self::validateAlphaDash()
]),
self::select('table_name', '模型关联表')
->options($this->getCMSTables())
->style(['width' => '100%'])
->required(),
self::textarea('description', '模型描述')->maxlength(255),
];
}
/**
* 获取 Cms 表
*
* @time 2021年04月30日
* @return mixed
*/
protected function getCMSTables()
{
$options = self::options();
foreach (Db::getTables() as $table) {
if (Str::contains($table, 'cms') && !Str::contains($table, 'relate')) {
$options->add($table, $table);
}
}
return $options->render();
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace catchAdmin\cms\tables\forms;
use catchAdmin\cms\model\Models;
use catcher\library\form\Form;
use think\facade\Db;
class ModelUsedFields extends Form
{
public function fields(): array
{
$modelId = request()->param('model_id');
$model = Models::where('id', $modelId)->with('fields')->find();
$fields = $this->getModelFields($model->table_name);
$this->primaryKeyValue = $modelId;
// TODO: Implement fields() method.
return [
self::select('used_at_list', '列表使用', $model->used_at_list ? explode(',', $model->used_at_list) : '')
->multiple(true)
->style(['width' => '100%'])
->options($fields),
self::select('used_at_search', '搜索使用' , $model->used_at_search ? explode(',', $model->used_at_search) : '')
->multiple(true)
->style(['width' => '100%'])
->options($fields),
self::select('used_at_detail', '详情使用', $model->used_at_detail ? explode(',', $model->used_at_detail) : '')
->multiple(true)
->style(['width' => '100%'])
->options($fields),
];
}
/**
* 获取模型字段
*
* @time 2021年05月11日
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return int[]|string[]
*/
protected function getModelFields($tableName)
{
$fields = array_keys(Db::name($tableName)->getFields());
foreach ($fields as $k => $field) {
if ($field === app(Models::class)->getDeleteAtField()) {
unset($fields[$k]);
}
}
$options = self::options();
foreach ($fields as $field) {
$options = $options->add($field, $field);
}
return $options->render();
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace catchAdmin\cms\tables\forms;
use catchAdmin\cms\model\BaseModel;
class SiteLink extends BaseForm
{
protected $table = 'cms_site_links';
public function fields(): array
{
// TODO: Implement fields() method.
return [
self::input('title', '网站标题')->required(),
self::input('link_to', '跳转地址')->required()->appendValidates([
self::validateUrl()
]),
self::image('网站图标', 'icon'),
self::radio('is_show', '展示', BaseModel::ENABLE)->options(
self::options()->add('是', BaseModel::ENABLE)
->add('否', BaseModel::DISABLE)->render()
),
self::number('weight', '权重')->min(1)->max(10000)
];
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace catchAdmin\cms\tables\forms;
class Tags extends BaseForm
{
protected $table = 'cms_tags';
public function fields(): array
{
// TODO: Implement fields() method.
return [
self::input('name', '名称')->required(),
self::input('title', 'seo 标题'),
self::input('keywords', 'seo 关键词'),
self::input('description', 'seo 描述'),
];
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace catchAdmin\cms\tables\forms;
use catcher\library\form\Form;
class UsedAt extends Form
{
public function fields(): array
{
// TODO: Implement fields() method.
return [
];
}
}