tableName); // 获取列表数据 $columns = MakeBuilder::getListColumns($this->tableName); // 获取搜索数据 $search = MakeBuilder::getListSearch($this->tableName); // 获取当前模块信息 $model = '\app\common\model\\' . $this->modelName; $module = \app\common\model\Module::where('table_name', $this->tableName)->find(); // 检测单页模式 $isSingle = MakeBuilder::checkSingle($this->modelName); if ($isSingle) { return redirect($isSingle); } // 搜索 if (Request::param('getList') == 1) { return $model::getList(); } // 构建页面 return TableBuilder::getInstance() ->setUniqueId($pk) // 设置主键 ->addColumns($columns) // 添加列表字段数据 ->setSearch($search) // 添加头部搜索 ->addColumn('right_button', '操作', 'btn') // 启用右侧操作列 ->addRightButton('info', [ // 添加额外按钮 'title' => '添加', 'icon' => 'fa fa-plus', 'class' => 'btn btn-success btn-xs', 'href' => url('add', ['parentId' => '__id__']) ]) ->addRightButtons($module->right_button) // 设置右侧操作列 ->addTopButtons($module->top_button) // 设置顶部按钮组 ->addTopButton('default', [ 'title' => '展开/折叠', 'icon' => 'fas fa-exchange-alt', 'class' => 'btn btn-info treeStatus', 'href' => '', 'onclick' => '$.operate.treeStatus()' ]) // 自定义按钮 ->addTopButton('default', [ 'title' => '批量新增', 'icon' => 'fa fa-plus', 'class' => 'btn btn-success', 'href' => '', 'onclick' => '$.operate.batchAdd(\'' . url('batchAdd') . '\')' ]) // 自定义按钮 ->setPagination('false') // 关闭分页显示 ->setParentIdField('parent_id') // 设置列表树父id ->fetch(); } // 添加 public function add(string $parentId = '') { // 获取字段信息 $columns = MakeBuilder::getAddColumns($this->tableName); // 重置`所属模块`和`上级栏目`的选项 foreach ($columns as $k => $coloumn) { if ($coloumn[1] == 'module_id') { $columns[$k][4] = $this->getModuleIds(); } if ($coloumn[1] == 'parent_id') { $model = '\app\common\model\\' . $this->modelName; $pidOptions = $model::getPidOptions(); $columns[$k][4] = $pidOptions; // 设置父ID默认值 if ($parentId) { $columns[$k][5] = $parentId; } } } // 获取分组后的字段信息 $groups = MakeBuilder::getAddGroups($this->modelName, $this->tableName, $columns); // 构建页面 $builder = FormBuilder::getInstance(); $groups ? $builder->addGroup($groups) : $builder->addFormItems($columns); return $builder->fetch(); } // 添加保存 public function addPost() { if (Request::isPost()) { $data = MakeBuilder::changeFormData(Request::except(['file'], 'post'), $this->tableName); $result = $this->validate($data, $this->validate); if (true !== $result) { // 验证失败 输出错误信息 $this->error($result); } else { $model = '\app\common\model\\' . $this->modelName; $result = $model::addPost($data); if ($result['error']) { $this->error($result['msg']); } else { $this->singleCateInit($data); $this->success($result['msg'], 'index'); } } } } // 修改 public function edit(string $id) { $model = '\app\common\model\\' . $this->modelName; $info = $model::edit($id)->toArray(); // 获取字段信息 $columns = MakeBuilder::getAddColumns($this->tableName, $info); // 重置`所属模块`和`上级栏目`的选项 foreach ($columns as $k => $coloumn) { if ($coloumn[1] == 'module_id') { $columns[$k][4] = $this->getModuleIds(); } if ($coloumn[1] == 'parent_id') { $model = '\app\common\model\\' . $this->modelName; $pidOptions = $model::getPidOptions(); $columns[$k][4] = $pidOptions; // 设置父ID默认值 if ($info['parent_id']) { $columns[$k][5] = $info['parent_id']; } } } // 获取分组后的字段信息 $groups = MakeBuilder::getAddGroups($this->modelName, $this->tableName, $columns); // 构建页面 $builder = FormBuilder::getInstance(); $groups ? $builder->addGroup($groups) : $builder->addFormItems($columns); return $builder->fetch(); } // 修改保存 public function editPost() { if (Request::isPost()) { $data = MakeBuilder::changeFormData(Request::except(['file'], 'post'), $this->tableName); if ($data['id'] == $data['parent_id']) { $this->error('上级栏目不可以为当前栏目'); } $result = $this->validate($data, $this->validate); if (true !== $result) { // 验证失败 输出错误信息 $this->error($result); } else { $model = '\app\common\model\\' . $this->modelName; $result = $model::editPost($data); if ($result['error']) { $this->error($result['msg']); } else { $this->success($result['msg'], 'index'); } } } } // 删除 public function del(string $id) { if (Request::isPost()) { // 删除子分类 $this->delChildsCate($id); if (strpos($id, ',') !== false) { return $this->selectDel($id); } $model = '\app\common\model\\' . $this->modelName; return $model::del($id); } } // 批量添加 public function batchAdd() { // 额外CSS $css = ''; // 额外js $js = ''; // 添加按钮 $html = '
'; // 所属模块 $modules = $this->getModuleIds(); $modulesStr = ''; foreach ($modules as $k => $v) { $modulesStr .= ''; } $html .= '