@@ -21,6 +21,8 @@ class Md2c extends Command
2121 protected $ entity_map = [];
2222 // 字典映射
2323 protected $ dict_map = [];
24+ // UI建议映射
25+ protected $ uihint_map = [];
2426
2527 // 忽略实体
2628 public const IGNORE_ENTITY = ['dict ' , 'dict_item ' , 'admin ' , 'config ' , 'menu ' , 'table ' , 'col ' ];
@@ -40,6 +42,7 @@ protected function execute(Input $input, Output $output)
4042 $ this ->models = json_decode (file_get_contents (self ::MODEL_PATH ), true );
4143 $ this ->entity_map = array_column ($ this ->models ['entities ' ], 'id ' );
4244 $ this ->dict_map = array_column ($ this ->models ['dicts ' ], 'id ' );
45+ $ this ->uihint_map = array_column ($ this ->models ['profile ' ]['uiHint ' ], 'id ' );
4346
4447 array_walk ($ this ->models ['entities ' ], [$ this , 'entity2class ' ]);
4548 array_walk ($ this ->models ['entities ' ], [$ this , 'entity2table ' ]);
@@ -93,7 +96,7 @@ protected function entity2class($entity)
9396 }
9497 $ path = $ this ->app ->getBasePath () . 'model ' . DIRECTORY_SEPARATOR . name_class ($ entity ['defKey ' ]) . '.php ' ;
9598 if (file_exists ($ path )) {
96- $ this ->output ->writeln ('<warning> ' . $ path . ' Already Exists!</warning> ' );
99+ // $this->output->writeln('<warning>' . $path . ' Already Exists!</warning>');
97100 } else {
98101 file_put_contents ($ path , (new PsrPrinter ())->printFile ($ file ));
99102 $ this ->output ->writeln ('<info> ' . $ path . ' Created!</info> ' );
@@ -109,7 +112,7 @@ protected function entity2class($entity)
109112 $ class ->addProperty ('rule ' , [])->setProtected ()->addComment ('验证规则 ' );
110113 $ path = $ this ->app ->getBasePath () . 'validate ' . DIRECTORY_SEPARATOR . name_class ($ entity ['defKey ' ]) . '.php ' ;
111114 if (file_exists ($ path )) {
112- $ this ->output ->writeln ('<warning> ' . $ path . ' Already Exists!</warning> ' );
115+ // $this->output->writeln('<warning>' . $path . ' Already Exists!</warning>');
113116 } else {
114117 file_put_contents ($ path , (new PsrPrinter ())->printFile ($ file ));
115118 $ this ->output ->writeln ('<info> ' . $ path . ' Created!</info> ' );
@@ -124,7 +127,7 @@ protected function entity2class($entity)
124127 $ class ->addMethod ('initialize ' )->setProtected ()->setBody ('$this->model = new \app\model \\' . name_class ($ entity ['defKey ' ]) . '(); ' );
125128 $ path = $ this ->app ->getBasePath () . 'controller ' . DIRECTORY_SEPARATOR . 'admin ' . DIRECTORY_SEPARATOR . name_class ($ entity ['defKey ' ]) . '.php ' ;
126129 if (file_exists ($ path )) {
127- $ this ->output ->writeln ('<warning> ' . $ path . ' Already Exists!</warning> ' );
130+ // $this->output->writeln('<warning>' . $path . ' Already Exists!</warning>');
128131 } else {
129132 file_put_contents ($ path , (new PsrPrinter ())->printFile ($ file ));
130133 $ this ->output ->writeln ('<info> ' . $ path . ' Created!</info> ' );
@@ -167,20 +170,33 @@ protected function entity2table($entity)
167170 // 属性转列
168171 protected function field2col ($ field , $ index , $ entity )
169172 {
170- if (in_array (strtolower ($ field ['defKey ' ]), ['update_time ' , ' delete_time ' , 'revision ' ])) {
173+ if (in_array (strtolower ($ field ['defKey ' ]), ['delete_time ' , 'revision ' ])) {
171174 return ;
172175 }
173176
174177 $ data = [
175178 'table_code ' => strtolower ($ entity ['defKey ' ]),
176179 'data_index ' => strtolower ($ field ['defKey ' ]),
180+ 'value_type ' => 'text ' ,
177181 'title ' => $ field ['defName ' ],
178182 'tip ' => $ field ['comment ' ],
183+ 'hide_in_table ' => $ field ['hideInGraph ' ] ? 1 : 0 ,
184+ 'hide_in_form ' => ($ field ['hideInGraph ' ] || $ field ['primaryKey ' ]) ? 1 : 0 ,
179185 'sort ' => $ index
180186 ];
181187 if (!empty ($ field ['refDict ' ])) {
182188 $ dict = map_array_value ($ this ->dict_map , $ this ->models ['dicts ' ], $ field ['refDict ' ]);
183- $ data ['value_enum_dict_key ' ] = $ dict ? $ dict ['defKey ' ] : '' ;
189+ if ($ dict ) {
190+ $ data ['value_enum_dict_key ' ] = $ dict ['defKey ' ];
191+ $ data ['value_type ' ] = 'select ' ;
192+ $ data ['filters ' ] = 1 ;
193+ }
194+ }
195+ if (!empty ($ field ['uiHint ' ])) {
196+ $ uihint = map_array_value ($ this ->uihint_map , $ this ->models ['profile ' ]['uiHint ' ], $ field ['uiHint ' ]);
197+ if ($ uihint ) {
198+ $ data ['value_type ' ] = $ uihint ['defKey ' ];
199+ }
184200 }
185201
186202 Col::create ($ data );
0 commit comments