diff --git a/admin/src/components/ds-select/index.vue b/admin/src/components/ds-select/index.vue
new file mode 100644
index 0000000000000000000000000000000000000000..a389d02f259f0c4cd5f1e2418d2478237badb1ee
--- /dev/null
+++ b/admin/src/components/ds-select/index.vue
@@ -0,0 +1,102 @@
+
+
+
+
+ {{current}} / {{Math.ceil(total/props.pageSize)}}
+
+
+
+
+
diff --git a/admin/src/views/dev_tools/code/edit.vue b/admin/src/views/dev_tools/code/edit.vue
index 6764088637c93b1b1ddb6fd4e3ffc0bee99de8c0..d05aa3f875afd23b3162e6d2b8e4038c627e91a3 100644
--- a/admin/src/views/dev_tools/code/edit.vue
+++ b/admin/src/views/dev_tools/code/edit.vue
@@ -129,12 +129,17 @@
+
+
getAuthorContent(),
+ $this->getNoteDateContent(),
+ trim($relations),
+ ];
+ $tpl .= $this->replaceFileData($needReplace, $waitReplace, $templatePath) . PHP_EOL;
+ }
+ }
+
return $tpl;
}
diff --git a/server/app/common/service/generator/core/VueEditGenerator.php b/server/app/common/service/generator/core/VueEditGenerator.php
index 9a1fcea173b72dd2268e0273f9f80db80b481794..151218610668adbaec075ef13bb8251902b6584d 100644
--- a/server/app/common/service/generator/core/VueEditGenerator.php
+++ b/server/app/common/service/generator/core/VueEditGenerator.php
@@ -258,6 +258,12 @@ class VueEditGenerator extends BaseGenerator implements GenerateInterface
array_push($waitReplace, $stubItemValue);
}
+ // 关联表字段处理
+ if ($column['view_type'] == 'relationData') {
+ array_push($needReplace, '{UPPER_CAMEL_NAME}');
+ array_push($waitReplace, $this->getUpperCamelName());
+ }
+
$content .= $this->replaceFileData($needReplace, $waitReplace, $templatePath) . PHP_EOL;
}
diff --git a/server/app/common/service/generator/core/VueIndexGenerator.php b/server/app/common/service/generator/core/VueIndexGenerator.php
index a3c5b4fbe4351da83862d5549149eea63be6c92f..eb1ac92ebb8a2f5fff99a287404cc2c8660b87dc 100644
--- a/server/app/common/service/generator/core/VueIndexGenerator.php
+++ b/server/app/common/service/generator/core/VueIndexGenerator.php
@@ -48,7 +48,9 @@ class VueIndexGenerator extends BaseGenerator implements GenerateInterface
'{PERMS_ADD}',
'{PERMS_EDIT}',
'{PERMS_DELETE}',
- '{SETUP_NAME}'
+ '{SETUP_NAME}',
+ '{RELATION_DATA_REF}',
+ '{FETCH_FUN}',
];
// 等待替换的内容
@@ -63,7 +65,9 @@ class VueIndexGenerator extends BaseGenerator implements GenerateInterface
$this->getPermsContent(),
$this->getPermsContent('edit'),
$this->getPermsContent('delete'),
- $this->getLowerCamelName()
+ $this->getLowerCamelName(),
+ $this->getRealtionDataRef(),
+ $this->getFetchFun(),
];
$templatePath = $this->getTemplatePath('vue/index');
@@ -116,6 +120,13 @@ class VueIndexGenerator extends BaseGenerator implements GenerateInterface
if (!file_exists($templatePath)) {
continue;
}
+
+ // 关联表字段处理
+ if ($column['view_type'] == 'relationData') {
+ array_push($needReplace, '{UPPER_CAMEL_NAME}');
+ array_push($waitReplace, $this->getUpperCamelName());
+ }
+
$content .= $this->replaceFileData($needReplace, $waitReplace, $templatePath) . PHP_EOL;
}
@@ -163,6 +174,9 @@ class VueIndexGenerator extends BaseGenerator implements GenerateInterface
if ($column['column_type'] == 'int' && $column['view_type'] == 'datetime') {
$templatePath = $this->getTemplatePath('vue/table_item/datetime');
}
+ if ($column['view_type'] == 'relationData') {
+ $templatePath = $this->getTemplatePath('vue/table_item/relationData');
+ }
if (!file_exists($templatePath)) {
continue;
}
@@ -215,6 +229,9 @@ class VueIndexGenerator extends BaseGenerator implements GenerateInterface
$content = '';
$isExist = [];
foreach ($this->tableColumn as $column) {
+ if ($column['view_type'] == 'relationData') {
+ continue;
+ }
if (empty($column['dict_type']) || $column['is_pk']) {
continue;
}
@@ -230,6 +247,75 @@ class VueIndexGenerator extends BaseGenerator implements GenerateInterface
return $this->setBlankSpace($content, '');
}
+ /**
+ * @notes 获取关联表数据
+ * @return string
+ * @author 心衍
+ * @date 2022/6/23 11:58
+ */
+ public function getRealtionDataRef(){
+ $columns = array_filter($this->tableColumn,fn($column)=>
+ $column['view_type'] == 'relationData'
+ );
+ if ($columns){
+ $content = '// 数据源数据'.PHP_EOL;
+ $content.= 'const relationData = ref({'.PHP_EOL;
+ foreach ($columns as $column) {
+ $content.= " {$column['column_name']}: [],".PHP_EOL;
+ }
+ $content.= '});'.PHP_EOL;
+ return $this->setBlankSpace($content, '');
+ }
+ return '';
+ }
+
+ /**
+ * @notes 获取加载数据的Api接口
+ * @return string
+ * @author 心衍
+ * @date 2022/6/23 11:58
+ */
+ public function getFetchFun(){
+ $content = 'api'.$this->getUpperCamelName().'Lists';
+ $columns = array_filter($this->tableColumn,fn($column)=>
+ $column['view_type'] == 'relationData'
+ );
+ if ($columns){
+ $templatePath = $this->getTemplatePath('vue/other_item/fetchFunItem');
+ if (!file_exists($templatePath)) {
+ return $content;
+ }
+ $fetchFunItem = '';
+ foreach ($columns as $column) {
+ $needReplace = [
+ '{UPPER_CAMEL_NAME}',
+ '{COLUMN_NAME}',
+ '{DICT_TYPE}',
+ ];
+ $waitReplace = [
+ $this->getUpperCamelName(),
+ $column['column_name'],
+ $column['dict_type'],
+ ];
+ $fetchFunItem.= ' '.$this->replaceFileData($needReplace, $waitReplace, $templatePath) . PHP_EOL;
+ }
+ $templatePath = $this->getTemplatePath('vue/other_item/fetchFun');
+ if (!file_exists($templatePath)) {
+ return $content;
+ }
+ $needReplace = [
+ '{UPPER_CAMEL_NAME}',
+ '{RELATION_DATAS}',
+ ];
+ $waitReplace = [
+ $this->getUpperCamelName(),
+ trim($fetchFunItem),
+ ];
+ $content = $this->replaceFileData($needReplace, $waitReplace, $templatePath) . PHP_EOL;
+ }
+ return $content;
+ }
+
/**
* @notes 权限规则
diff --git a/server/app/common/service/generator/stub/php/controller.stub b/server/app/common/service/generator/stub/php/controller.stub
index 44622d25a52e995d182bfddffb7ba12d36e909dd..c84c47723de0558157b27fa2074ada75b12248b3 100644
--- a/server/app/common/service/generator/stub/php/controller.stub
+++ b/server/app/common/service/generator/stub/php/controller.stub
@@ -101,5 +101,24 @@ class {UPPER_CAMEL_NAME}Controller extends {EXTENDS_CONTROLLER}
return $this->data($result);
}
+ /**
+ * @notes 获取关联表数据列表
+ * @return \think\response\Json
+ * @author {AUTHOR}
+ * @date {DATE}
+ **/
+ public function relationDatas()
+ {
+ $field = input('field/s','');//关联字段名
+ $show_field = input('show_field/s','');//显示字段名
+ $title = input('title/s','');//模糊搜索
+ $ids = input('ids/s','');//指定ID列表
+ $page = input('page/i',1);
+ $pageSize = input('pageSize/i',10);
+ $ids = $ids?explode(',',$ids):null;
+ list($total,$rows) = {UPPER_CAMEL_NAME}Logic::relationDatas($field,$show_field,$ids,$title,$page,$pageSize);
+ return $this->success('',['total'=>$total,'rows'=>$rows]);
+ }
+
}
\ No newline at end of file
diff --git a/server/app/common/service/generator/stub/php/logic.stub b/server/app/common/service/generator/stub/php/logic.stub
index 4d4b7a6a3aad863ed3efd0c73cc633dbf077addb..08023fc750629d915c815116e4636b2507db0ace 100644
--- a/server/app/common/service/generator/stub/php/logic.stub
+++ b/server/app/common/service/generator/stub/php/logic.stub
@@ -103,4 +103,16 @@ class {UPPER_CAMEL_NAME}Logic extends BaseLogic
{
return {UPPER_CAMEL_NAME}::findOrEmpty($params['{PK}'])->toArray();
}
+
+ /**
+ * @notes 获取关联表数据列表
+ * @param $params
+ * @return array
+ * @author {AUTHOR}
+ * @date {DATE}
+ **/
+ public static function relationDatas($field,$show_field,$ids=null,$title='',$page=1,$pageSize=10): array
+ {
+ return {UPPER_CAMEL_NAME}::relationDatas($field,$show_field,$ids,$title,$page,$pageSize);
+ }
}
\ No newline at end of file
diff --git a/server/app/common/service/generator/stub/php/model/relation_data.stub b/server/app/common/service/generator/stub/php/model/relation_data.stub
new file mode 100644
index 0000000000000000000000000000000000000000..453d82361f8ad5f5a43a2f3b3cbeda06cc963a94
--- /dev/null
+++ b/server/app/common/service/generator/stub/php/model/relation_data.stub
@@ -0,0 +1,25 @@
+
+ /**
+ * @notes 获取关联表数据列表
+ * @return array
+ * @author {AUTHOR}
+ * @date {DATE}
+ **/
+ public static function relationDatas(string $field,string $show_field,int|array|null $ids,string $title,int $page=1,int $pageSize=10): array
+ {
+ switch($field){
+ {RELATIONS}
+ default:
+ return [0,[]];
+ }
+ $model = $model->field([
+ $model->getPk().' as id',
+ $show_field.' as title'
+ ]);
+ $ids && $model = $model->where([$model->getPk()=>$ids]);
+ $title && $model = $model->where($show_field,'like','%'.$title.'%');
+ $total = $model->count();
+ $ids || $model = $model->limit(($page-1)*$pageSize,$pageSize);
+ $rows = array_map(fn($x)=>['id'=>$x['id'],'title'=>$x['title']],$model->select()->toArray());
+ return [$total,$rows];
+ }
\ No newline at end of file
diff --git a/server/app/common/service/generator/stub/vue/api.stub b/server/app/common/service/generator/stub/vue/api.stub
index 1858e9a1298be240868a128a216ee6d6e9bc02d8..40016fd99bc7f9f57cb63b355e8474d69b815d77 100644
--- a/server/app/common/service/generator/stub/vue/api.stub
+++ b/server/app/common/service/generator/stub/vue/api.stub
@@ -23,4 +23,9 @@ export function api{UPPER_CAMEL_NAME}Delete(params: any) {
// {COMMENT}详情
export function api{UPPER_CAMEL_NAME}Detail(params: any) {
return request.get({ url: '/{ROUTE}/detail', params })
+}
+
+// {COMMENT}关联数据
+export function api{UPPER_CAMEL_NAME}RelationDatas(params: any){
+ return request.get({ url: '/{ROUTE}/relationDatas', params });
}
\ No newline at end of file
diff --git a/server/app/common/service/generator/stub/vue/edit.stub b/server/app/common/service/generator/stub/vue/edit.stub
index 3928bf8f4daff2411d90cd7b5cb147fc7d980d0a..80ef9b0fc8f8b52676e567c94c02c1b251c05b8b 100644
--- a/server/app/common/service/generator/stub/vue/edit.stub
+++ b/server/app/common/service/generator/stub/vue/edit.stub
@@ -18,7 +18,7 @@