diff --git a/app/BaseController.php b/app/BaseController.php index ecc9d349..d8c15cf3 100644 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -58,10 +58,10 @@ abstract class BaseController /** * 验证数据 * @access protected - * @param array $data 数据 + * @param array $data 数据 * @param string|array $validate 验证器名或者验证规则数组 - * @param array $message 提示信息 - * @param bool $batch 是否批量验证 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 * @return array|string|true * @throws ValidateException */ diff --git a/app/admin/controller/Dashboard.php b/app/admin/controller/Dashboard.php index 74b6ee89..3965360e 100644 --- a/app/admin/controller/Dashboard.php +++ b/app/admin/controller/Dashboard.php @@ -9,7 +9,7 @@ class Dashboard extends Backend { public function dashboard() { - $this->success('ok', [ + $this->success('', [ 'adminName' => $this->auth->nickname, 'remark' => get_route_remark() ]); diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index acc9dc58..3acf51c5 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -17,7 +17,7 @@ class Index extends Backend { $adminInfo = $this->auth->getInfo(); unset($adminInfo['token']); - $this->success('ok', [ + $this->success('', [ 'adminInfo' => $adminInfo, 'menus' => $this->auth->getMenus() ]); @@ -84,7 +84,7 @@ class Index extends Backend } } - $this->success('ok', [ + $this->success('', [ 'captcha' => $captchaSwitch ]); } diff --git a/app/admin/controller/auth/Menu.php b/app/admin/controller/auth/Menu.php index 7594e9e2..de79efbc 100644 --- a/app/admin/controller/auth/Menu.php +++ b/app/admin/controller/auth/Menu.php @@ -20,9 +20,9 @@ class Menu extends Backend protected $keyword = false; - public function _initialize() + public function initialize() { - parent::_initialize(); + parent::initialize(); $this->model = new MenuRule(); } @@ -32,7 +32,7 @@ class Menu extends Backend $this->select(); } - $this->success('ok', [ + $this->success('', [ 'menu' => $this->getMenus() ]); } @@ -41,7 +41,7 @@ class Menu extends Backend { $row = $this->model->find($id); if (!$row) { - $this->error(__('No Results were found')); + $this->error(__('Record not found')); } if ($this->request->isPost()) { @@ -66,7 +66,7 @@ class Menu extends Backend if ($isTree) { $data = Tree::assembleTree(Tree::getTreeArray($data, 'title')); } - $this->success('select', [ + $this->success('', [ 'options' => $data ]); } diff --git a/app/admin/lang/en.php b/app/admin/lang/en.php index f12fd053..b14094ff 100644 --- a/app/admin/lang/en.php +++ b/app/admin/lang/en.php @@ -6,6 +6,7 @@ return [ 'CaptchaId' => 'Captcha Id', 'Please enter the correct verification code' => 'Please enter the correct verification code!', 'Parameter %s can not be empty' => 'Parameter %s can not be empty', + 'Record not found' => 'Record not found', 'No rows were added' => 'No rows were added', 'No rows were deleted' => 'No rows were deleted', 'No rows updated' => 'No rows updated', diff --git a/app/admin/lang/zh-cn.php b/app/admin/lang/zh-cn.php index adbd631f..98276371 100644 --- a/app/admin/lang/zh-cn.php +++ b/app/admin/lang/zh-cn.php @@ -6,6 +6,7 @@ return [ 'CaptchaId' => '验证码ID', 'Please enter the correct verification code' => '请输入正确的验证码!', 'Parameter %s can not be empty' => '参数%s不能为空', + 'Record not found' => '记录未找到', 'No rows were added' => '未添加任何行', 'No rows were deleted' => '未删除任何行', 'No rows updated' => '未更新任何行', diff --git a/app/admin/lang/zh-cn/auth/menu.php b/app/admin/lang/zh-cn/auth/menu.php new file mode 100644 index 00000000..957e64d3 --- /dev/null +++ b/app/admin/lang/zh-cn/auth/menu.php @@ -0,0 +1,4 @@ +model->find($id); if (!$row) { - $this->error(__('No Results were found')); + $this->error(__('Record not found')); } if ($this->request->isPost()) { @@ -65,7 +65,7 @@ trait Backend } - $this->success('edit', [ + $this->success('', [ 'row' => $row ]); } diff --git a/app/common/controller/Api.php b/app/common/controller/Api.php index eadb121f..f9a6e546 100644 --- a/app/common/controller/Api.php +++ b/app/common/controller/Api.php @@ -19,28 +19,40 @@ class Api extends BaseController */ protected $responseType = 'json'; + /** + * 控制器目录路径 + */ + protected $controllerPath; + public function __construct(App $app) { parent::__construct($app); - $this->_initialize(); } /** * 控制器初始化方法 */ - protected function _initialize() + protected function initialize() { + parent::initialize(); $this->request->filter('trim,strip_tags,htmlspecialchars'); + + // 加载控制器语言包 + $langset = $this->app->lang->getLangSet(); + $this->controllerPath = str_replace('.', DIRECTORY_SEPARATOR, $this->request->controller(true)); + $this->app->lang->load([ + app_path() . 'lang' . DIRECTORY_SEPARATOR . $langset . DIRECTORY_SEPARATOR . $this->controllerPath . '.php' + ]); } /** * 操作成功 - * @param string $msg 提示消息 - * @param null $data 返回数据 - * @param int $code 错误码 - * @param null $type 输出类型 - * @param array $header 发送的 header 信息 - * @param array $options Response 输出参数 + * @param string $msg 提示消息 + * @param null $data 返回数据 + * @param int $code 错误码 + * @param null $type 输出类型 + * @param array $header 发送的 header 信息 + * @param array $options Response 输出参数 */ protected function success($msg = '', $data = null, $code = 1, $type = null, $header = [], $options = []) { @@ -49,12 +61,12 @@ class Api extends BaseController /** * 操作失败 - * @param string $msg 提示消息 - * @param null $data 返回数据 - * @param int $code 错误码 - * @param null $type 输出类型 - * @param array $header 发送的 header 信息 - * @param array $options Response 输出参数 + * @param string $msg 提示消息 + * @param null $data 返回数据 + * @param int $code 错误码 + * @param null $type 输出类型 + * @param array $header 发送的 header 信息 + * @param array $options Response 输出参数 */ protected function error($msg = '', $data = null, $code = 0, $type = null, array $header = [], $options = []) { @@ -63,12 +75,12 @@ class Api extends BaseController /** * 返回 API 数据 - * @param string $msg 提示消息 - * @param null $data 返回数据 - * @param int $code 错误码 - * @param null $type 输出类型 - * @param array $header 发送的 header 信息 - * @param array $options Response 输出参数 + * @param string $msg 提示消息 + * @param null $data 返回数据 + * @param int $code 错误码 + * @param null $type 输出类型 + * @param array $header 发送的 header 信息 + * @param array $options Response 输出参数 */ public function result($msg, $data = null, $code = 0, $type = null, $header = [], $options = []) { diff --git a/app/common/controller/Backend.php b/app/common/controller/Backend.php index 3fdcf00b..ce7dfda1 100644 --- a/app/common/controller/Backend.php +++ b/app/common/controller/Backend.php @@ -2,7 +2,6 @@ namespace app\common\controller; -use app\common\controller\Api; use app\admin\library\Auth; use think\facade\Cookie; @@ -20,6 +19,9 @@ class Backend extends Api protected $model = null; + /** + * 快速搜索字段 + */ protected $quickSearchField = 'id'; /** @@ -28,15 +30,11 @@ class Backend extends Api */ use \app\admin\library\traits\Backend; - public function _initialize() + public function initialize() { - $modulename = app('http')->getName(); - $controllername = $this->request->controller(true); - $actionname = $this->request->action(true); - - $path = str_replace('.', '/', $controllername) . '/' . $actionname; - + parent::initialize(); $this->auth = Auth::instance(); + $routePath = $this->controllerPath . '/' . $this->request->action(true); $token = $this->request->server('HTTP_BATOKEN', $this->request->request('batoken', Cookie::get('batoken') ?: false)); if (!$this->auth->actionInArr($this->noNeedLogin)) { $this->auth->init($token); @@ -46,7 +44,7 @@ class Backend extends Api ], 302); } if (!$this->auth->actionInArr($this->noNeedPermission)) { - if (!$this->auth->check($path)) { + if (!$this->auth->check($routePath)) { $this->error(__('You have no permission'), [ 'routeName' => 'admin' ], 302); @@ -57,10 +55,6 @@ class Backend extends Api $this->auth->init($token); } } - - // 语言检测 - // 加载语言包? - // 初始化需要用到的配置 } public function select() diff --git a/app/installapi/controller/Index.php b/app/installapi/controller/Index.php index e637448c..4658a412 100644 --- a/app/installapi/controller/Index.php +++ b/app/installapi/controller/Index.php @@ -156,7 +156,7 @@ class Index extends Api ]; } - $this->success('ok', [ + $this->success('', [ 'php_version' => [ 'describe' => $phpVersion, 'state' => $phpVersionCompare ? self::$ok : self::$fail, @@ -272,7 +272,7 @@ class Index extends Api ]; } - $this->success('ok', [ + $this->success('', [ 'npm_version' => [ 'describe' => $npmVersion ? $npmVersion : __('Acquisition failed'), 'state' => $npmVersionCompare ? self::$ok : self::$warn, @@ -338,7 +338,7 @@ class Index extends Api if ($conn['code'] == 0) { $this->error($conn['msg']); } else { - $this->success('ok', [ + $this->success('', [ 'databases' => $conn['databases'] ]); } @@ -352,7 +352,7 @@ class Index extends Api $envOk = $this->commandExecutionCheck(); if ($this->request->isGet()) { - $this->success('ok', ['envOk' => $envOk]); + $this->success('', ['envOk' => $envOk]); } $param = $this->request->only(['hostname', 'username', 'password', 'hostport', 'database', 'prefix', 'adminname', 'adminpassword', 'sitename']); @@ -389,7 +389,7 @@ class Index extends Api $this->error(__('File has no write permission:%s', ['public/' . self::$lockFileName]), [], 102); } - $this->success('ok', [ + $this->success('', [ 'execution' => $envOk ]); } @@ -411,7 +411,7 @@ class Index extends Api if (rename($indexHtmlPath, $toIndexHtmlPath) && rename($assetsPath, $toAssetsPath)) { deldir($distPath); - $this->success('ok'); + $this->success(''); } else { $this->error(__('Failed to move the front-end file, please move it manually!'), [], 104); } @@ -438,7 +438,7 @@ class Index extends Api public function manualInstall() { // 取得 web 目录完整路径 - $this->success('ok', [ + $this->success('', [ 'webPath' => root_path() . 'web' ]); } diff --git a/web/src/views/backend/auth/menu.vue b/web/src/views/backend/auth/menu.vue index d077be15..26fd1ce2 100644 --- a/web/src/views/backend/auth/menu.vue +++ b/web/src/views/backend/auth/menu.vue @@ -32,7 +32,7 @@
- + { if (form.items.pid == form.items.pidebak) { delete form.items.pid } + if (!form.items.extend) { + delete form.items.extend + } postEdit(form.items) .then((res) => { + onAction('refresh', {}) form.submitLoading = false form.operateIds.shift() if (form.operateIds.length > 0) {