* +---------------------------------------------------------------------- */ /** * 分享列表 * @author crud自动生成代码 * @date 2025/03/17 16:22:48 */ namespace app\services\crud; use app\services\BaseServices; use think\exception\ValidateException; use app\dao\crud\ShareListDao; use crmeb\services\FormBuilder; /** * Class CrudService * @date 2025/03/17 * @package app\services\crud */ class ShareListServices extends BaseServices { /** * ShareListServices constructor. * @param ShareListDao $dao */ public function __construct(ShareListDao $dao) { $this->dao = $dao; } /** * 主页数据接口 * @param array $where * @return array * @date 2025/03/17 */ public function getCrudListIndex(array $where = []) { [$page, $limit] = $this->getPageValue(); $model = $this->dao->searchCrudModel($where, 'name,link,img,img_two,sort,id', 'id desc', []); return ['count' => $model->count(), 'list' => $model->page($page ?: 1, $limit ?: 10)->select()->toArray()]; } /** * 编辑和获取表单 * @date 2025/03/17 * @param int $id * @return array */ public function getCrudForm(int $id = 0) { $url = '/crud/share_list'; $info = []; if ($id) { $info = $this->dao->get($id); if (!$info) { throw new ValidateException(100026); } $url .= '/' . $id; } $rule = []; $rule[] = FormBuilder::input("name", "名称", $info["name"] ?? ''); $rule[] = FormBuilder::input("link", "分享链接", $info["link"] ?? ''); $rule[] = FormBuilder::frameImage('img', '图标', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => 'img']), $info['img'] ?? '')->icon('el-icon-picture-outline')->width('950px')->height('560px')->Props(['footer' => false]); $rule[] = FormBuilder::frameImage('img_two', '蓝色图标', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => 'img_two']), $info['img_two'] ?? '')->icon('el-icon-picture-outline')->width('950px')->height('560px')->Props(['footer' => false]); $rule[] = FormBuilder::number("sort", "排序", $info["sort"] ?? ''); return create_form('分享列表', $rule, $url, $id ? 'PUT' : 'POST'); } /** * 新增 * @date 2025/03/17 * @param array $data * @return mixed */ public function crudSave(array $data) { return $this->dao->save($data); } /** * 修改 * @date 2025/03/17 * @param int $id * @param array $data * @return \crmeb\basic\BaseModel */ public function crudUpdate(int $id, array $data) { return $this->dao->update($id, $data); } }