This commit is contained in:
walkor 2022-12-06 14:30:26 +08:00
parent 50a4d4577c
commit 3a522c5999
3 changed files with 10 additions and 8 deletions

View File

@ -106,15 +106,15 @@ class AdminRuleController extends Crud
*/ */
public function permission(Request $request): Response public function permission(Request $request): Response
{ {
$controller = $request->get('controller');
if (!$controller) {
return $this->json(0, 'ok', []);
}
$rules = $this->getRules(admin('roles')); $rules = $this->getRules(admin('roles'));
// 超级管理员 // 超级管理员
if (in_array('*', $rules)) { if (in_array('*', $rules)) {
return $this->json(0, 'ok', ['*']); return $this->json(0, 'ok', ['*']);
} }
$controller = $request->get('controller');
if (!$controller) {
return $this->json(0, 'ok', []);
}
// 获取详细权限 // 获取详细权限
$controller_search = str_replace('\\', '\\\\', $controller); $controller_search = str_replace('\\', '\\\\', $controller);
$keys = AdminRule::where('key', 'like', "$controller_search%") $keys = AdminRule::where('key', 'like', "$controller_search%")

View File

@ -485,7 +485,7 @@ class TableController extends Base
$template_file_path = "$controller_path_base/app/view/$template_path"; $template_file_path = "$controller_path_base/app/view/$template_path";
$model_class_with_namespace = "$model_namespace\\$model_class"; $model_class_with_namespace = "$model_namespace\\$model_class";
$primary_key = (new $model_class_with_namespace)->getKeyName(); $primary_key = (new $model_class_with_namespace)->getKeyName();
$this->createTemplate($template_file_path, $table_name, $template_path, $url_path_base, $primary_key); $this->createTemplate($template_file_path, $table_name, $template_path, $url_path_base, $primary_key, "$controller_namespace\\$controller_class");
$reflection = new \ReflectionClass("$controller_namespace\\$controller_class"); $reflection = new \ReflectionClass("$controller_namespace\\$controller_class");
$controller_class_with_nsp = $reflection->getName(); $controller_class_with_nsp = $reflection->getName();
@ -696,9 +696,10 @@ EOF;
* @param $template_path * @param $template_path
* @param $url_path_base * @param $url_path_base
* @param $primary_key * @param $primary_key
* @param $controller_class_with_namespace
* @return void * @return void
*/ */
protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key) protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key, $controller_class_with_namespace)
{ {
$this->mkdir($template_file_path . '/index.html'); $this->mkdir($template_file_path . '/index.html');
$form = LayuiForm::buildForm($table, 'search'); $form = LayuiForm::buildForm($table, 'search');
@ -772,8 +773,9 @@ EOF
<script src="/app/admin/admin/js/common.js"></script> <script src="/app/admin/admin/js/common.js"></script>
<script> <script>
// 相关接口 // 相关常量
const PRIMARY_KEY = '$primary_key'; const PRIMARY_KEY = '$primary_key';
const CONTROLLER = '$controller_class_with_namespace';
const SELECT_API = "$url_path_base/$template_path/select"; const SELECT_API = "$url_path_base/$template_path/select";
const UPDATE_API = "$url_path_base/$template_path/update"; const UPDATE_API = "$url_path_base/$template_path/update";
const DELETE_API = "$url_path_base/$template_path/delete"; const DELETE_API = "$url_path_base/$template_path/delete";

View File

@ -40,7 +40,7 @@ layui.$(function () {
$.ajax({ $.ajax({
url: "/app/admin/admin-rule/permission", url: "/app/admin/admin-rule/permission",
dataType: "json", dataType: "json",
data: {controller: CONTROLLER}, data: {controller: window.CONTROLLER || ''},
success: function (res) { success: function (res) {
let style = ''; let style = '';
layui.each(res.data || [], function (k, action) { layui.each(res.data || [], function (k, action) {