'radio', 'name' => 'group', 'title' => '配置分组', 'extra' => config('config_group'), 'value' => $group, ], [ 'type' => 'select', 'name' => 'type', 'title' => '配置类型', 'tips' => '', 'extra' => config('form_item_type') ], [ 'type' => 'text', 'name' => 'title', 'title' => '配置标题', 'attr' => 'data-rule="required;" data-msg-required="标题不能为空,可以使用中文或者英文"' ], [ 'type' => 'text', 'name' => 'name', 'title' => '配置标识', 'attr' => 'data-rule="required;name;" data-rule-name="[/^[a-zA-Z][a-zA-Z0-9_]*$/, \'请输入正确的配置标识,只能使用英文和下划线,必须以英文字母开头\']" data-msg-required="配置标识不能为空"' ], ['type' => 'textarea', 'name' => 'value', 'title' => '配置值'], ['type' => 'textarea', 'name' => 'extra', 'title' => '配置项', 'tips' => '用于单选、多选、下拉、联动等类型'], ['type' => 'textarea', 'name' => 'tips', 'title' => '配置说明'], ['type' => 'radio', 'name' => 'status', 'title' => '状态', '', 'extra' => ['禁用', '启用'], 'value' => 1] ]; $this->assign('page_title', '新增管理员'); $this->assign('form_items', $fields); return $this->fetch('public/add'); } /** * 编辑表单项 * @param int $id * @author 似水星辰 [ 2630481389@qq.com ] * @return mixed */ public function edit($id = 0) { if ($id === 0) $this->error('参数错误'); // 获取数据 $info = ConfigModel::get($id); $fields = [ ['type' => 'hidden', 'name' => 'id',], ['type' => 'radio', 'name' => 'group', 'title' => '配置分组', 'extra' => config('config_group'), 'value' => $group,], ['type' => 'select', 'name' => 'type', 'title' => '配置类型', 'extra' => config('form_item_type')], [ 'type' => 'text', 'name' => 'title', 'title' => '配置标题', 'attr' => 'data-rule="required;" data-msg-required="标题不能为空,可以使用中文或者英文"'], [ 'type' => 'text', 'name' => 'name', 'title' => '配置标识', 'attr' => 'data-rule="required;name;" data-rule-name="[/^[a-zA-Z][a-zA-Z0-9_]*$/, \'请输入正确的配置标识,只能使用英文和下划线,必须以英文字母开头\']" data-msg-required="配置标识不能为空"' ], ['type' => 'textarea', 'name' => 'value', 'title' => '配置值'], ['type' => 'textarea', 'name' => 'extra', 'title' => '配置项', 'tips' => '用于单选、多选、下拉、联动等类型'], ['type' => 'textarea', 'name' => 'tips', 'title' => '配置说明'], ['type' => 'radio', 'name' => 'status', 'title' => '状态', '', 'extra' => ['禁用', '启用'], 'value' => 1] ]; $this->assign('page_title', '编辑配置'); $this->assign('form_items', $this->setData($fields, $info)); return $this->fetch('public/edit'); } /** * 设置表单数据 * @param array $fields 字段组 * @param array $info 字段值组 * @author 似水星辰 [ 2630481389@qq.com ] * @return mixed */ public function setData($fields = [], $info =[]){ if(is_array($fields)){ foreach($fields as &$v){ if($v['type'] != 'sort'){ if($v['type'] == 'password'){ $v['value'] = ''; }else if($v['type'] == 'attr'){ $v['value'] = htmlspecialchars_decode($info[$v['name']]); }else{ $v['value'] = $info[$v['name']]; } } } } return $fields; } }