Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crud upweight一键菜单配置中增加拖拽排序 #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/plugin/admin/app/common/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class Util
{
static public $curdIsSort = false;// 控制是否启用排序(只有在一键生成菜单时才启用排序)

/**
* 密码哈希
* @param $password
Expand Down Expand Up @@ -436,12 +438,32 @@ public static function getSchema($table, $section = null)
foreach ($data['forms'] as $field => $item) {
if (isset($form_schema_map[$field])) {
$data['forms'][$field] = $form_schema_map[$field];
if(self::$curdIsSort)
$data['columns'][$field]['_weight_'] = $form_schema_map[$field]['_weight_']?:0;
}
}

if(self::$curdIsSort){
// 按照我们内置的字段 进行排序
$data['forms'] = self::arraySort(array_values($data['forms']),'_weight_',SORT_ASC);
$data['columns'] = self::arraySort(array_values($data['columns']),'_weight_',SORT_ASC);
}
return $section ? $data[$section] : $data;
}

/**
* 二维数组根据某个字段排序
* @param array $array 要排序的数组
* @param string $keys 要排序的键字段
* @param string $sort 排序类型 SORT_ASC SORT_DESC
* @return array 排序后的数组
*/
protected static function arraySort($array, $keys, $sort = SORT_DESC) {
$keysValue = [];
foreach ($array as $k => $v) {
$keysValue[$k] = $v[$keys];
}
array_multisort($keysValue, $sort, $array);
return $array;
}
/**
* 获取字段长度或默认值
* @param $schema
Expand Down
12 changes: 11 additions & 1 deletion src/plugin/admin/app/controller/TableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ public function crud(Request $request): Response
$controller_file = '/' . trim($request->post('controller', ''), '/');
$model_file = '/' . trim($request->post('model', ''), '/');
$overwrite = $request->post('overwrite');
$ismodel = $request->post('ismodel');

if ($controller_file === '/' || $model_file === '/') {
return $this->json(1, '控制器和model不能为空');
}
Expand All @@ -441,7 +443,7 @@ public function crud(Request $request): Response
}

if (!$overwrite) {
if (is_file(base_path($controller_file))) {
if (!$ismodel && is_file(base_path($controller_file))) {
return $this->json(1, "$controller_file 已经存在");
}
if (is_file(base_path($model_file))) {
Expand Down Expand Up @@ -480,6 +482,11 @@ public function crud(Request $request): Response

// 创建model
$this->createModel($model_class, $model_namespace, base_path($model_file), $table_name);
// 仅生成模型
if($ismodel){
Util::resumeFileMonitor();
return $this->json(0);
}

$controller_suffix = $plugin ? config("plugin.$plugin.app.controller_suffix") : config('app.controller_suffix');
$controller_class = $controller_file_name;
Expand Down Expand Up @@ -512,7 +519,10 @@ public function crud(Request $request): Response
$model_class_with_namespace = "$model_namespace\\$model_class";
$primary_key = (new $model_class_with_namespace)->getKeyName();
$url_path_base = ($plugin ? "/app/$plugin/" : '/') . ($app ? "$app/" : '') . $template_path;
Util::$curdIsSort = true;// 后续查询均使用排序
$this->createTemplate(base_path($template_file_path), $table_name, $url_path_base, $primary_key, "$controller_namespace\\$controller_class");
Util::$curdIsSort = false;// 关闭 防止静态类不会销毁产生的错误

} finally {
Util::resumeFileMonitor();
}
Expand Down
1,470 changes: 768 additions & 702 deletions src/plugin/admin/app/view/table/create.html

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/plugin/admin/app/view/table/crud.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@
</div>
<div class="layui-form-item">
<label class="layui-form-label">强制覆盖</label>
<div class="layui-input-block">
<div class="layui-input-inline" style="width: 20px">
<input type="checkbox" name="overwrite" lay-skin="primary">
</div>

<label class="layui-form-label">仅生成模型</label>
<div class="layui-input-inline" style="width: 20px">
<input type="checkbox" name="ismodel" lay-skin="primary">
</div>
</div>
</div>
</div>
Expand Down
1,375 changes: 726 additions & 649 deletions src/plugin/admin/app/view/table/modify.html

Large diffs are not rendered by default.

Loading