内容模型功能完成

This commit is contained in:
2020-04-01 22:20:11 +08:00
parent 85d33da0d4
commit 9dafceb2eb
32 changed files with 415 additions and 339 deletions

View File

@@ -24,25 +24,6 @@ class Attribute extends Base {
public function initialize() {
parent::initialize();
$this->getContentMenu();
// $this->model = model('Attribute');
// //遍历属性列表
// foreach (get_attribute_type() as $key => $value) {
// $this->attr[$key] = $value[0];
// }
// $this->validate_rule = array(
// 0 => '请选择',
// 'regex' => '正则验证',
// 'function' => '函数验证',
// 'unique' => '唯一验证',
// 'length' => '长度验证',
// 'in' => '验证在范围内',
// 'notin' => '验证不在范围内',
// 'between' => '区间验证',
// 'notbetween' => '不在区间验证',
// );
// $this->auto_type = array(0 => '请选择', 'function' => '函数', 'field' => '字段', 'string' => '字符串');
// $this->the_time = array(0 => '请选择', '3' => '始 终', '1' => '新 增', '2' => '编 辑');
// $this->field = $this->getField();
}
/**
@@ -67,22 +48,25 @@ class Attribute extends Base {
* @title 创建字段
* @author colin <colin@tensent.cn>
*/
public function add($model_id = '') {
public function add(AttributeModel $attribute) {
if ($this->request->isPost()) {
$result = $this->model->validate('attribute.add')->save($this->request->param());
$data = $this->request->post();
$result = $attribute->save($data);
if (false !== $result) {
return $this->success("创建成功!", url('Attribute/index', array('model_id' => $model_id)));
return $this->success("创建成功!", url('/admin/attribute/index', ['model_id' => $data['model_id']]));
} else {
return $this->error($this->model->getError());
return $this->error('创建失败!');
}
} else {
$data = array(
$model_id = $this->request->param('model_id', 0);
if (!$model_id) {
return $this->error('非法操作!');
}
$this->data = array(
'info' => array('model_id' => $model_id),
'fieldGroup' => $this->field,
'fieldGroup' => AttributeModel::getfieldList(),
);
$this->assign($data);
$this->setMeta('添加字段');
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -90,23 +74,22 @@ class Attribute extends Base {
* @title 编辑字段
* @author colin <colin@tensent.cn>
*/
public function edit($id = '', $model_id = '') {
public function edit(AttributeModel $attribute, $id = '', $model_id = '') {
if ($this->request->isPost()) {
$result = $this->model->validate('attribute.edit')->save($this->request->param(), array('id' => $id));
$data = $this->request->post();
$result = $attribute->exists(true)->save($data);
if ($result) {
return $this->success("修改成功!", url('Attribute/index', array('model_id' => $model_id)));
return $this->success("修改成功!", url('/admin/attribute/index', ['model_id' => $model_id]));
} else {
return $this->error($this->model->getError());
return $this->error('修改失败!');
}
} else {
$info = db('Attribute')->find($id);
$data = array(
$info = AttributeModel::find($id);
$this->data = array(
'info' => $info,
'fieldGroup' => $this->field,
'fieldGroup' => AttributeModel::getfieldList(),
);
$this->assign($data);
$this->setMeta('编辑字段');
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -115,47 +98,19 @@ class Attribute extends Base {
* @var delattr 是否删除字段表里的字段
* @author colin <colin@tensent.cn>
*/
public function del(\think\Request $request) {
$id = $request->param('id');
$model_id = $request->param('model_id');
public function del() {
$id = $this->request->param('id');
$model_id = $this->request->param('model_id');
if (!$id) {
return $this->error("非法操作!");
}
$result = $this->model->del($id, $model_id);
$result = AttributeModel::find($id)->delete();
if ($result) {
return $this->success("删除成功!");
} else {
return $this->error($this->model->getError());
}
}
//字段编辑所需字段
protected function getField() {
return array(
'基础' => array(
array('name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'),
array('name' => 'model_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'),
array('name' => 'name', 'title' => '字段名', 'help' => '英文字母开头长度不超过30', 'type' => 'text'),
array('name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'type' => 'text'),
array('name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $this->attr, 'help' => ''),
array('name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'),
array('name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'),
array('name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'),
array('name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'),
array('name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => array('1' => '始终显示', '2' => '新增显示', '3' => '编辑显示', '0' => '不显示'), 'value' => 1),
array('name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => array('0' => '否', '1' => '是')),
),
'高级' => array(
array('name' => 'validate_type', 'title' => '验证方式', 'type' => 'select', 'option' => $this->validate_rule, 'help' => ''),
array('name' => 'validate_rule', 'title' => '验证规则', 'help' => '根据验证方式定义相关验证规则', 'type' => 'text'),
array('name' => 'error_info', 'title' => '出错提示', 'type' => 'text', 'help' => ''),
array('name' => 'validate_time', 'title' => '验证时间', 'help' => '英文字母开头长度不超过30', 'type' => 'select', 'option' => $this->the_time, 'help' => ''),
array('name' => 'auto_type', 'title' => '自动完成方式', 'help' => '英文字母开头长度不超过30', 'type' => 'select', 'option' => $this->auto_type, 'help' => ''),
array('name' => 'auto_rule', 'title' => '自动完成规则', 'help' => '根据完成方式订阅相关规则', 'type' => 'text'),
array('name' => 'auto_time', 'title' => '自动完成时间', 'help' => '英文字母开头长度不超过30', 'type' => 'select', 'option' => $this->the_time),
),
);
}
}