mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-08 02:52:49 +08:00
关联模型使用table选择器代替;
This commit is contained in:
@@ -708,26 +708,6 @@ class BuildCurdService
|
|||||||
);
|
);
|
||||||
return $selectCode;
|
return $selectCode;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 构建关联下拉控制器
|
|
||||||
* @param $field
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function buildRelationSelectController($field)
|
|
||||||
{
|
|
||||||
|
|
||||||
$name = $this->getFieldMethodName($field);
|
|
||||||
$var_name = $this->getFieldVarName($field);
|
|
||||||
|
|
||||||
$selectCode = $this->replaceTemplate(
|
|
||||||
$this->getTemplate("controller{$this->DS}relationSelect"),
|
|
||||||
[
|
|
||||||
'name' => $name,
|
|
||||||
'var_name' => $var_name,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
return $selectCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构架下拉模型
|
* 构架下拉模型
|
||||||
@@ -755,28 +735,6 @@ class BuildCurdService
|
|||||||
return $selectCode;
|
return $selectCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构架关联下拉模型
|
|
||||||
* @param $relation
|
|
||||||
* @param $filed
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function buildRelationSelectModel($relation, $filed)
|
|
||||||
{
|
|
||||||
$relationArray = explode('\\', $relation);
|
|
||||||
$name = end($relationArray);
|
|
||||||
$name = "getList{$name}";
|
|
||||||
$selectCode = $this->replaceTemplate(
|
|
||||||
$this->getTemplate("model{$this->DS}relationSelect"),
|
|
||||||
[
|
|
||||||
'name' => $name,
|
|
||||||
'relation' => $relation,
|
|
||||||
'values' => $filed,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
return $selectCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建下拉框视图
|
* 构建下拉框视图
|
||||||
* @param $field
|
* @param $field
|
||||||
@@ -804,8 +762,10 @@ class BuildCurdService
|
|||||||
protected function buildTableView($field, $options, $value)
|
protected function buildTableView($field, $options, $value)
|
||||||
{
|
{
|
||||||
$default_define = [
|
$default_define = [
|
||||||
|
'table' => '', // 必填
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'value_filed' => 'id',
|
'valueField' => 'id',
|
||||||
|
'fieldName' => 'title', // 必填
|
||||||
'comment' => $options['comment'],
|
'comment' => $options['comment'],
|
||||||
'field' => $field,
|
'field' => $field,
|
||||||
'required' => $options['required'],
|
'required' => $options['required'],
|
||||||
@@ -816,7 +776,6 @@ class BuildCurdService
|
|||||||
|
|
||||||
$table_controller_name = $this->getTableControllerName($define['table']);
|
$table_controller_name = $this->getTableControllerName($define['table']);
|
||||||
|
|
||||||
|
|
||||||
$nodeArray = explode($this->DS, $table_controller_name);
|
$nodeArray = explode($this->DS, $table_controller_name);
|
||||||
$formatArray = [];
|
$formatArray = [];
|
||||||
foreach ($nodeArray as $vo) {
|
foreach ($nodeArray as $vo) {
|
||||||
@@ -826,7 +785,6 @@ class BuildCurdService
|
|||||||
|
|
||||||
$define['controller_url'] = $controller_url;
|
$define['controller_url'] = $controller_url;
|
||||||
|
|
||||||
|
|
||||||
$table_main_code = $this->replaceTemplate(
|
$table_main_code = $this->replaceTemplate(
|
||||||
$this->getTemplate("view{$this->DS}module{$this->DS}tableMain"),
|
$this->getTemplate("view{$this->DS}module{$this->DS}tableMain"),
|
||||||
$define
|
$define
|
||||||
@@ -1069,12 +1027,7 @@ class BuildCurdService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
$selectList = '';
|
$selectList = '';
|
||||||
foreach ($this->relationArray as $relation) {
|
|
||||||
if (!empty($relation['bindSelectField'])) {
|
|
||||||
$relationArray = explode('\\', $relation['modelFilename']);
|
|
||||||
$selectList .= $this->buildRelationSelectController(end($relationArray));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($this->tableColumns as $field => $val) {
|
foreach ($this->tableColumns as $field => $val) {
|
||||||
if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) {
|
if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) {
|
||||||
$selectList .= $this->buildSelectController($field);
|
$selectList .= $this->buildSelectController($field);
|
||||||
@@ -1126,11 +1079,7 @@ class BuildCurdService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$selectList = '';
|
$selectList = '';
|
||||||
foreach ($this->relationArray as $relation) {
|
|
||||||
if (!empty($relation['bindSelectField'])) {
|
|
||||||
$selectList .= $this->buildRelationSelectModel($relation['modelFilename'], $relation['bindSelectField']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($this->tableColumns as $field => $val) {
|
foreach ($this->tableColumns as $field => $val) {
|
||||||
if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) {
|
if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) {
|
||||||
$selectList .= $this->buildSelectModel($field, $val['define']);
|
$selectList .= $this->buildSelectModel($field, $val['define']);
|
||||||
@@ -1257,6 +1206,7 @@ class BuildCurdService
|
|||||||
} elseif ($val['formType'] == 'select') {
|
} elseif ($val['formType'] == 'select') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}select";
|
$templateFile = "view{$this->DS}module{$this->DS}select";
|
||||||
if (isset($val['bindRelation'])) {
|
if (isset($val['bindRelation'])) {
|
||||||
|
// TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理
|
||||||
$define = $this->buildOptionView($val['bindRelation']);
|
$define = $this->buildOptionView($val['bindRelation']);
|
||||||
} elseif (isset($val['define']) && !empty($val['define'])) {
|
} elseif (isset($val['define']) && !empty($val['define'])) {
|
||||||
$define = $this->buildOptionView($field);
|
$define = $this->buildOptionView($field);
|
||||||
@@ -1266,13 +1216,13 @@ class BuildCurdService
|
|||||||
} elseif ($val['formType'] == 'relation') {
|
} elseif ($val['formType'] == 'relation') {
|
||||||
|
|
||||||
|
|
||||||
// 使用select生成
|
$val['define']['type'] = 'radio';
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}select";
|
$val['define']['valueField'] = 'id';
|
||||||
if (isset($val['bindRelation'])) {
|
$val['define']['fieldName'] = $val['define']['relationBindSelect'];
|
||||||
$define = $this->buildOptionView($val['bindRelation']);
|
|
||||||
} elseif (isset($val['define']) && !empty($val['define'])) {
|
$templateFile = "view{$this->DS}module{$this->DS}table";
|
||||||
$define = $this->buildOptionView($field);
|
|
||||||
}
|
$define = $this->buildTableView($field, $val, $val['default']);
|
||||||
} elseif ($val['formType'] == 'table') {
|
} elseif ($val['formType'] == 'table') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}table";
|
$templateFile = "view{$this->DS}module{$this->DS}table";
|
||||||
$define = $this->buildTableView($field, $val, $val['default']);
|
$define = $this->buildTableView($field, $val, $val['default']);
|
||||||
@@ -1348,6 +1298,7 @@ class BuildCurdService
|
|||||||
} elseif ($val['formType'] == 'select') {
|
} elseif ($val['formType'] == 'select') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}select";
|
$templateFile = "view{$this->DS}module{$this->DS}select";
|
||||||
if (isset($val['bindRelation'])) {
|
if (isset($val['bindRelation'])) {
|
||||||
|
// TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理
|
||||||
$define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
$define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
||||||
} elseif (isset($val['define']) && !empty($val['define'])) {
|
} elseif (isset($val['define']) && !empty($val['define'])) {
|
||||||
$define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
$define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
||||||
@@ -1358,13 +1309,13 @@ class BuildCurdService
|
|||||||
} elseif ($val['formType'] == 'relation') {
|
} elseif ($val['formType'] == 'relation') {
|
||||||
|
|
||||||
|
|
||||||
// 使用select生成
|
$val['define']['type'] = 'radio';
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}select";
|
$val['define']['valueField'] = 'id';
|
||||||
if (isset($val['bindRelation'])) {
|
$val['define']['fieldName'] = $val['define']['relationBindSelect'];
|
||||||
$define = $this->buildOptionView($val['bindRelation'], '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
|
||||||
} elseif (isset($val['define']) && !empty($val['define'])) {
|
$templateFile = "view{$this->DS}module{$this->DS}table";
|
||||||
$define = $this->buildOptionView($field, '{in name="k" value="$row.' . $field . '"}selected=""{/in}');
|
|
||||||
}
|
$define = $this->buildTableView($field, $val, $value);
|
||||||
} elseif ($val['formType'] == 'table') {
|
} elseif ($val['formType'] == 'table') {
|
||||||
$templateFile = "view{$this->DS}module{$this->DS}table";
|
$templateFile = "view{$this->DS}module{$this->DS}table";
|
||||||
$define = $this->buildTableView($field, $val, $value);
|
$define = $this->buildTableView($field, $val, $value);
|
||||||
@@ -1417,6 +1368,8 @@ class BuildCurdService
|
|||||||
continue;
|
continue;
|
||||||
} elseif ($val['formType'] == 'editor') {
|
} elseif ($val['formType'] == 'editor') {
|
||||||
continue;
|
continue;
|
||||||
|
} elseif ($val['formType'] == 'table') {
|
||||||
|
continue;
|
||||||
} elseif (in_array($field, $this->switchFields)) {
|
} elseif (in_array($field, $this->switchFields)) {
|
||||||
if (isset($val['define']) && !empty($val['define'])) {
|
if (isset($val['define']) && !empty($val['define'])) {
|
||||||
$templateValue = "{field: '{$field}', search: 'select', selectList: ea.getDataBrage('{$var_name}'), title: '{$val['comment']}', templet: ea.table.switch}";
|
$templateValue = "{field: '{$field}', search: 'select', selectList: ea.getDataBrage('{$var_name}'), title: '{$val['comment']}', templet: ea.table.switch}";
|
||||||
@@ -1454,6 +1407,8 @@ class BuildCurdService
|
|||||||
continue;
|
continue;
|
||||||
} elseif ($val['formType'] == 'editor') {
|
} elseif ($val['formType'] == 'editor') {
|
||||||
continue;
|
continue;
|
||||||
|
} elseif ($val['formType'] == 'table') {
|
||||||
|
continue;
|
||||||
} elseif ($val['formType'] == 'select') {
|
} elseif ($val['formType'] == 'select') {
|
||||||
$templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}";
|
$templateValue = "{field: '{$table}.{$field}', title: '{$val['comment']}'}";
|
||||||
} elseif (in_array($field, ['remark'])) {
|
} elseif (in_array($field, ['remark'])) {
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
|
|
||||||
$this->assign('{{var_name}}', $this->model::{{name}}(), true);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
public static function {{name}}()
|
|
||||||
{
|
|
||||||
return \app\admin\model\{{relation}}::column('{{values}}', 'id');
|
|
||||||
}
|
|
||||||
@@ -76,24 +76,24 @@ define(['jquery', 'vue'], function ($, Vue) {
|
|||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.value = options.selectValue;
|
this.value = options.selectValue;
|
||||||
if(typeof this.value != 'string') {
|
if (typeof this.value != 'string') {
|
||||||
this.value = this.value.toString();
|
this.value = this.value.toString();
|
||||||
}
|
}
|
||||||
var valueLength = this.value.split(',').length;
|
var valueLength = this.value.split(',').length;
|
||||||
loading.show();
|
loading.show();
|
||||||
$.get(options.index,{
|
$.get(options.index, {
|
||||||
page:1,
|
page: 1,
|
||||||
limit:valueLength,
|
limit: valueLength,
|
||||||
filter:JSON.stringify({id:this.value}),
|
filter: JSON.stringify({ id: this.value }),
|
||||||
op: JSON.stringify({id:'in'})
|
op: JSON.stringify({ id: 'in' })
|
||||||
},(result)=>{
|
}, (result) => {
|
||||||
loading.hide()
|
loading.hide()
|
||||||
this.listSelected = result.data;
|
this.listSelected = result.data;
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if(options.required == 1){
|
if (options.required == 1) {
|
||||||
$(this.$refs['tableData']).closest('.layui-form-item').children('.layui-form-label').addClass('required');
|
$(this.$refs['tableData']).closest('.layui-form-item').children('.layui-form-label').addClass('required');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -108,7 +108,7 @@ define(['jquery', 'vue'], function ($, Vue) {
|
|||||||
title: '选择数据',
|
title: '选择数据',
|
||||||
type: 2,
|
type: 2,
|
||||||
area: [options.width, options.height],
|
area: [options.width, options.height],
|
||||||
content: options.index+'&selectedIds='+selectedIds.join(','),
|
content: options.index + '&selectedIds=' + selectedIds.join(','),
|
||||||
maxmin: true,
|
maxmin: true,
|
||||||
moveOut: true,
|
moveOut: true,
|
||||||
shadeClose: true,
|
shadeClose: true,
|
||||||
@@ -116,6 +116,10 @@ define(['jquery', 'vue'], function ($, Vue) {
|
|||||||
window[options.selectConfirmCallback] = (data) => {
|
window[options.selectConfirmCallback] = (data) => {
|
||||||
data.forEach(dataItem => {
|
data.forEach(dataItem => {
|
||||||
|
|
||||||
|
if (options.selectType == 'radio') {
|
||||||
|
this.listSelected = [];
|
||||||
|
}
|
||||||
|
|
||||||
var itemFind = this.listSelected.find(itemSelect => itemSelect[valueField] == dataItem[valueField])
|
var itemFind = this.listSelected.find(itemSelect => itemSelect[valueField] == dataItem[valueField])
|
||||||
|
|
||||||
if (itemFind == undefined) {
|
if (itemFind == undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user