4 Commits

Author SHA1 Message Date
wolfcode
9a0ff912b5 feat(mall):新增表单中多选案例 add simulated multi-select feature
- Add simulated multi-select functionality to goods add and edit pages
- Integrate xm-select library for multi-select implementation
- Add random color theme to the multi-select dropdown
- Include predefined options for demonstration purposes
2025-04-18 15:16:06 +08:00
wolfcode
517fd191d3 refactor(curd): improve relation handling and query methods
- Replace with() with withJoin() for more efficient left joins
- Fix foreign key and primary key assignments in relations
- Update index page queries to use relation index method-Modify relation method generation in model to use belongsTo instead of hasOne- Adjust table column definitions for relation fields
2025-04-17 17:25:06 +08:00
wolfcode
d1dfa8b49b Update app.php 2025-04-16 18:40:37 +08:00
wolfcode
c819751a66 chore: update .gitignore files
- Extend and runtime .gitignore: add space after '!' in .gitignore
- Root .gitignore: remove .project file
2025-04-16 18:38:53 +08:00
10 changed files with 64 additions and 17 deletions

View File

@@ -1041,7 +1041,7 @@ class BuildCurd
$relationCode = ''; $relationCode = '';
foreach ($this->relationArray as $key => $val) { foreach ($this->relationArray as $key => $val) {
$relation = CommonTool::lineToHump($key); $relation = CommonTool::lineToHump($key);
$relationCode = "with(['{$relation}'])"; $relationCode = "withJoin('{$relation}', 'LEFT')";
if (!empty($val['bindSelectField']) && !empty($val['primaryKey'])) { if (!empty($val['bindSelectField']) && !empty($val['primaryKey'])) {
$constructRelation = '$notes["' . lcfirst($val['foreignKey']) . '"] = \app\admin\model\\' . $val['modelFilename'] . '::column("' . $val['bindSelectField'] . '", "' . $val['primaryKey'] . '");'; $constructRelation = '$notes["' . lcfirst($val['foreignKey']) . '"] = \app\admin\model\\' . $val['modelFilename'] . '::column("' . $val['bindSelectField'] . '", "' . $val['primaryKey'] . '");';
} }
@@ -1101,8 +1101,8 @@ class BuildCurd
[ [
'relationMethod' => $relation, 'relationMethod' => $relation,
'relationModel' => "{$val['modelFilename']}::class", 'relationModel' => "{$val['modelFilename']}::class",
'foreignKey' => $val['primaryKey'], 'foreignKey' => $val['foreignKey'],
'primaryKey' => $val['foreignKey'], 'primaryKey' => $val['primaryKey'],
'relationFields' => empty($val['onlyFields']) ? "" : "->field('{$val['primaryKey']}," . implode(',', $val['onlyFields']) . "')", 'relationFields' => empty($val['onlyFields']) ? "" : "->field('{$val['primaryKey']}," . implode(',', $val['onlyFields']) . "')",
]); ]);
$relationList .= $relationCode; $relationList .= $relationCode;
@@ -1403,13 +1403,12 @@ class BuildCurd
} else { } else {
$templateValue = "{field: '{$field}', title: '{$val['comment']}'}"; $templateValue = "{field: '{$field}', title: '{$val['comment']}'}";
} }
$indexCols .= $this->formatColsRow("{$templateValue},\r"); $indexCols .= $this->formatColsRow("{$templateValue},\r");
} }
// 关联表 // 关联表
foreach ($this->relationArray as $table => $tableVal) { foreach ($this->relationArray as $table => $tableVal) {
$table = CommonTool::lineToHump($table); $table = CommonTool::humpToLine($table);
foreach ($tableVal['tableColumns'] as $field => $val) { foreach ($tableVal['tableColumns'] as $field => $val) {
if ($val['formType'] == 'image') { if ($val['formType'] == 'image') {
$templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ea.table.image}"; $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', templet: ea.table.image}";
@@ -1430,7 +1429,7 @@ class BuildCurd
} elseif (in_array($field, $this->sortFields)) { } elseif (in_array($field, $this->sortFields)) {
$templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', edit: 'text'}"; $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}', edit: 'text'}";
} else { } else {
$templateValue = ""; $templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}";
} }
if ($templateValue) $indexCols .= $this->formatColsRow("{$templateValue},\r"); if ($templateValue) $indexCols .= $this->formatColsRow("{$templateValue},\r");

View File

@@ -7,7 +7,7 @@
return $this->selectList(); return $this->selectList();
} }
list($page, $limit, $where) = $this->buildTableParams(); list($page, $limit, $where) = $this->buildTableParams();
$count = self::$model::where($where)->count(); $count = self::$model::where($where)->{{relationIndexMethod}}->count();
$list = self::$model::where($where)->{{relationIndexMethod}}->page($page, $limit)->order($this->sort)->select()->toArray(); $list = self::$model::where($where)->{{relationIndexMethod}}->page($page, $limit)->order($this->sort)->select()->toArray();
$data = [ $data = [
'code' => 0, 'code' => 0,

View File

@@ -1,5 +1,5 @@
public function {{relationMethod}}() public function {{relationMethod}}()
{ {
return $this->hasOne({{relationModel}}, '{{foreignKey}}', '{{primaryKey}}'){{relationFields}}; return $this->belongsTo({{relationModel}}, '{{foreignKey}}', '{{primaryKey}}'){{relationFields}};
} }

View File

@@ -91,6 +91,14 @@
</div> </div>
</div> </div>
<!-- 文档https://xm-select.com/file/xm-select/v1.2.4/#/basic/use -->
<div class="layui-form-item">
<label class="layui-form-label">模拟多选</label>
<div class="layui-input-block">
<div id="demo1" class="xm-select-demo"></div>
</div>
</div>
<div class="layui-form-item layui-form-text"> <div class="layui-form-item layui-form-text">
<label class="layui-form-label">备注信息</label> <label class="layui-form-label">备注信息</label>
<div class="layui-input-block"> <div class="layui-input-block">

View File

@@ -92,6 +92,14 @@
</div> </div>
</div> </div>
<!-- 文档https://xm-select.com/file/xm-select/v1.2.4/#/basic/use -->
<div class="layui-form-item">
<label class="layui-form-label">模拟多选</label>
<div class="layui-input-block">
<div id="demo1" class="xm-select-demo"></div>
</div>
</div>
<div class="layui-form-item layui-form-text"> <div class="layui-form-item layui-form-text">
<label class="layui-form-label">备注信息</label> <label class="layui-form-label">备注信息</label>
<div class="layui-input-block"> <div class="layui-input-block">

View File

@@ -93,6 +93,25 @@ define(["jquery", "easy-admin"], function ($, ea) {
aiOptimization(data) aiOptimization(data)
}, },
}) })
let colors = [
'#f10f0f', // 红色
'#ffaf00', // 橙色
'#FF69B4', // 猛男粉
'#0087ff', // 蓝色
'#00ff00', // 青青草原
];
var demo1 = xmSelect.render({
el: '#demo1',
name: 'xxx', // form表单提交的name
theme: {color: colors[Math.floor(Math.random() * colors.length)]},
data: [
{name: 'Make', value: 1},
{name: 'PHP', value: 2},
{name: 'Great Again', value: 3},
]
})
ea.listen(); ea.listen();
}, },
edit: function () { edit: function () {
@@ -103,6 +122,25 @@ define(["jquery", "easy-admin"], function ($, ea) {
aiOptimization(data) aiOptimization(data)
}, },
}) })
let colors = [
'#f10f0f', // 红色
'#ffaf00', // 橙色
'#FF69B4', // 猛男粉
'#0087ff', // 蓝色
'#00ff00', // 青青草原
];
var demo1 = xmSelect.render({
el: '#demo1',
name: 'xxx', // form表单提交的name
theme: {color: colors[Math.floor(Math.random() * colors.length)]},
data: [
{name: 'Make', value: 1},
{name: 'PHP', value: 2, selected: true,},
{name: 'Great Again', value: 3, selected: true,},
]
})
ea.listen(); ea.listen();
}, },
stock: function () { stock: function () {

View File

@@ -10,10 +10,4 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
use think\facade\Route; use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'index/hello');
Route::any('install', '\app\index\controller\Install@index'); Route::any('install', '\app\index\controller\Install@index');