diff --git a/niucloud/addon/hello_world/info.json b/niucloud/addon/hello_world/info.json index 666ef504e..7bd3c5b8b 100644 --- a/niucloud/addon/hello_world/info.json +++ b/niucloud/addon/hello_world/info.json @@ -5,5 +5,5 @@ "version": "1.0.1", "author": "niucloud", "type": "addon", - "support_app": "niucloud" -} \ No newline at end of file + "support_app": "" +} diff --git a/niucloud/app/adminapi/controller/addon/Addon.php b/niucloud/app/adminapi/controller/addon/Addon.php index 0b6cd2905..b40eeb57e 100644 --- a/niucloud/app/adminapi/controller/addon/Addon.php +++ b/niucloud/app/adminapi/controller/addon/Addon.php @@ -15,6 +15,7 @@ use app\dict\addon\AddonDict; use app\service\admin\addon\AddonService; use app\service\core\addon\CoreAddonService; use core\base\BaseAdminController; +use think\facade\Cache; use think\Response; @@ -34,17 +35,34 @@ class Addon extends BaseAdminController */ public function install($addon) { - return (new AddonService())->install($addon); + return success((new AddonService())->install($addon)); } /** - * 执行安装 + * 云安装插件 * @param $addon * @return Response */ - public function execute($addon) + public function cloudInstall($addon) { - return (new AddonService())->executeInstall($addon); + return success(data:(new AddonService())->cloudInstall($addon)); + } + + /** + * 获取安装任务 + * @return Response + */ + public function getInstallTask() { + return success(data:(new AddonService())->getInstallTask()); + } + + /** + * 获取云安装日志 + * @param $addon + * @return mixed + */ + public function cloudInstallLog($addon) { + return success(data:(new AddonService())->cloudInstallLog($addon)); } /** @@ -57,17 +75,6 @@ class Addon extends BaseAdminController return (new AddonService())->installCheck($addon); } - /** - * 查询插件安装状态 - * @param $addon - * @param $key - * @return Response - */ - public function getInstallState($addon, $key) - { - return success((new AddonService())->getInstallState($addon, $key)); - } - /** * 卸载插件 * @param string $addon @@ -118,7 +125,10 @@ class Addon extends BaseAdminController * @return Response */ public function download($addon){ - (new AddonService())->download($addon); + $data = $this->request->params([ + ['version', ''] + ]); + (new AddonService())->download($addon, $data['version']); return success('DOWNLOAD_SUCCESS'); } diff --git a/niucloud/app/adminapi/controller/dict/Dict.php b/niucloud/app/adminapi/controller/dict/Dict.php new file mode 100644 index 000000000..801300a53 --- /dev/null +++ b/niucloud/app/adminapi/controller/dict/Dict.php @@ -0,0 +1,121 @@ +request->params([ + ["name",""], + ["key",""] + ]); + return success((new DictService())->getPage($data)); + } + + /** + * 数据字典详情 + * @param int $id + * @return \think\Response + */ + public function info(int $id){ + return success((new DictService())->getInfo($id)); + } + + /** + * 添加数据字典 + * @return \think\Response + */ + public function add(){ + $data = $this->request->params([ + ["name",""], + ["key",""], + ["memo",""], + + ]); +// $this->validate($data, 'app\validate\dict\Dict.add'); + $id = (new DictService())->add($data); + return success('ADD_SUCCESS', ['id' => $id]); + } + + /** + * 数据字典编辑 + * @param $id 数据字典id + * @return \think\Response + */ + public function edit($id){ + $data = $this->request->params([ + ["name",""], + ["key",""], + ["data",""], + ["memo",""], + + ]); +// $this->validate($data, 'app\validate\dict\Dict.edit'); + (new DictService())->edit($id, $data); + return success('EDIT_SUCCESS'); + } + + /** + * 数据字典删除 + * @param $id 数据字典id + * @return \think\Response + */ + public function del(int $id){ + (new DictService())->del($id); + return success('DELETE_SUCCESS'); + } + + /** + * 添加数据字典内容 + */ + public function addDictData($id) + { + $data = $this->request->params([ + ["dictionary",'[]'], + ]); +// $this->validate($data, 'app\validate\dict\Dict.add'); + $data['dictionary'] = json_encode($data['dictionary'], true); + (new DictService())->edit($id,$data); + return success('ADD_SUCCESS'); + } + + /** + * 获取全部数据字典 + * @return \think\Response + */ + public function getAll(){ + return success((new DictService())->getAll()); + } + + /** + * 数据字典详情 + * @param key 数据字典关键字 + * @return \think\Response + */ + public function getKeyInfo(string $type){ + $res = (new DictService())->getKeyInfo($type); + return success($res); + } +} diff --git a/niucloud/app/adminapi/controller/generator/Generator.php b/niucloud/app/adminapi/controller/generator/Generator.php index d0dec460a..861a6f846 100644 --- a/niucloud/app/adminapi/controller/generator/Generator.php +++ b/niucloud/app/adminapi/controller/generator/Generator.php @@ -36,6 +36,7 @@ class Generator extends BaseController $data = $this->request->params([ ['table_name', ''], ['table_content', ''], + ['addon_name',''] ]); return success((new GenerateService())->getPage($data)); } @@ -61,6 +62,7 @@ class Generator extends BaseController public function preview(int $id) { $data = (new GenerateService())->preview(['id' => $id]); +// dd($data); return success('ADD_SUCCESS', $data); } @@ -101,6 +103,7 @@ class Generator extends BaseController ['parent_menu',''], ['relations',[]] ], false); + $this->validate($data, 'app\validate\generator\Generator.edit'); (new GenerateService())->edit($id, $data); return success('MODIFY_SUCCESS'); @@ -125,7 +128,7 @@ class Generator extends BaseController { $data = $this->request->params([ ['id', ''], - ['generate_type', '3'] + ['generate_type', '2'] ]); $data = (new GenerateService())->generate($data); diff --git a/niucloud/app/adminapi/controller/sys/Menu.php b/niucloud/app/adminapi/controller/sys/Menu.php index 7bfd944c6..57d2ffd8c 100644 --- a/niucloud/app/adminapi/controller/sys/Menu.php +++ b/niucloud/app/adminapi/controller/sys/Menu.php @@ -56,13 +56,10 @@ class Menu extends BaseAdminController ['api_url', ''], ['view_path', ''], ['router_path', ''], - ['methods', ''], ['sort', 0], - ['status', MenuDict::ON], ['is_show', 0], - ['addon', ''], ]); $this->validate($data, 'app\validate\sys\Menu.add'); @@ -94,6 +91,7 @@ class Menu extends BaseAdminController ['addon', ''], ]); $this->validate($data, 'app\validate\sys\Menu.edit'); + (new MenuService())->edit($menu_key, $data); return success('EDIT_SUCCESS'); } diff --git a/niucloud/app/adminapi/route/addon.php b/niucloud/app/adminapi/route/addon.php index 5752f771f..632cac092 100644 --- a/niucloud/app/adminapi/route/addon.php +++ b/niucloud/app/adminapi/route/addon.php @@ -30,12 +30,14 @@ Route::group(function () { Route::put('addon/status/:id/:status', 'addon.Addon/setStatus'); //安装插件 Route::post('addon/install/:addon', 'addon.Addon/install'); + //云安装插件 + Route::post('addon/cloudinstall/:addon', 'addon.Addon/cloudInstall'); + // 云编译进度 + Route::get('addon/cloudinstall/:addon', 'addon.Addon/cloudInstallLog'); //插件安装检测安装环境 Route::get('addon/install/check/:addon', 'addon.Addon/installCheck'); - // 执行安装 - Route::post('addon/install/execute/:addon', 'addon.Addon/execute'); - //插件安装状态 - Route::get('addon/install/:addon/status/:key', 'addon.Addon/getInstallState'); + // 获取安装任务 + Route::get('addon/installtask', 'addon.Addon/getInstallTask'); //下载插件 Route::post('addon/download/:addon', 'addon.Addon/download'); //插件类型 @@ -58,8 +60,6 @@ Route::group(function () { //编辑插件 Route::put('addon_develop/:key', 'addon.AddonDevelop/edit'); //删除插件 - Route::delete('addon_develop/:key', 'addon.AddonDevelop/del'); - Route::delete('addon_develop/:key', 'addon.AddonDevelop/del'); //校验是否存在 Route::get('addon_develop/check/:key', 'addon.AddonDevelop/checkKey'); diff --git a/niucloud/app/adminapi/route/dict.php b/niucloud/app/adminapi/route/dict.php new file mode 100644 index 000000000..40ce6401a --- /dev/null +++ b/niucloud/app/adminapi/route/dict.php @@ -0,0 +1,43 @@ +middleware([ + AdminCheckToken::class, + AdminCheckRole::class, + AdminLog::class +]); +// USER_CODE_END -- sys_dict diff --git a/niucloud/app/common.php b/niucloud/app/common.php index 6ae05b1b0..53989e371 100644 --- a/niucloud/app/common.php +++ b/niucloud/app/common.php @@ -50,9 +50,9 @@ function fail($msg = 'FAIL', ?array $data = [], int $code = 0, int $http_code = * @param string $str * @return lang() */ -function get_lang($str) +function get_lang($str,$vars = []) { - return Lang::get($str); + return Lang::get($str,$vars); } @@ -174,8 +174,9 @@ function del_target_dir($path, $delDir) } closedir($handle); if ($delDir) { - return rmdir($path); + @rmdir($path); } + return true; } else { if (file_exists($path)) { return unlink($path); diff --git a/niucloud/app/dict/diy/LinkDict.php b/niucloud/app/dict/diy/LinkDict.php index 68feeab70..72a04ac4f 100644 --- a/niucloud/app/dict/diy/LinkDict.php +++ b/niucloud/app/dict/diy/LinkDict.php @@ -25,7 +25,7 @@ class LinkDict $system_links = [ 'SYSTEM_LINK' => [ 'key' => '', - 'addon_title' => '', + 'addon_title' => get_lang('dict_diy.system_title'), 'title' => get_lang('dict_diy.system_link'), 'child_list' => [ [ @@ -39,7 +39,7 @@ class LinkDict ], 'MEMBER_LINK' => [ 'key' => '', - 'addon_title' => '', + 'addon_title' => get_lang('dict_diy.system_title'), 'title' => get_lang('dict_diy.member_link'), 'child_list' => [ [ diff --git a/niucloud/app/dict/diy/PagesDict.php b/niucloud/app/dict/diy/PagesDict.php index bb6d9d0c2..44b57c3de 100644 --- a/niucloud/app/dict/diy/PagesDict.php +++ b/niucloud/app/dict/diy/PagesDict.php @@ -82,14 +82,7 @@ class PagesDict "componentName" => "AddonList", "componentTitle" => "应用", "ignore" => [], - "list" => [ - [ - "key" => "", - "title" => "", - "url" => "", - "icon" => "", - ] - ], + "list" => [], "textColor" => "#303133", "pageBgColor" => "", "componentBgColor" => "", diff --git a/niucloud/app/dict/menu/admin.php b/niucloud/app/dict/menu/admin.php index cd99c5e09..cdd1db70e 100644 --- a/niucloud/app/dict/menu/admin.php +++ b/niucloud/app/dict/menu/admin.php @@ -2,17 +2,18 @@ return [ [ - 'menu_name' => '首页', + 'menu_name' => '应用中心', 'menu_key' => 'overview', 'menu_type' => 0, 'icon' => 'iconfont-icona-shouyediannao', 'api_url' => '', - 'router_path' => 'index', + 'router_path' => 'apply', 'view_path' => '', 'methods' => '', - 'sort' => 100, + 'sort' => 60, 'status' => 1, 'is_show' => 1, + 'menu_attr' => 'system', 'children' => [ [ 'menu_name' => '应用管理', @@ -29,7 +30,7 @@ return ], [ 'menu_name' => '我的星标', - 'menu_key' => 'app_index', + 'menu_key' => 'app_star', 'menu_type' => 1, 'icon' => 'iconfont-iconwodexingbiao', 'api_url' => '', @@ -38,11 +39,11 @@ return 'methods' => '', 'sort' => 100, 'status' => 1, - 'is_show' => 1, + 'is_show' => 0, ], [ 'menu_name' => '历史查看', - 'menu_key' => 'app_index', + 'menu_key' => 'app_record', 'menu_type' => 1, 'icon' => 'iconfont-iconchakanlishi', 'api_url' => '', @@ -51,13 +52,13 @@ return 'methods' => '', 'sort' => 100, 'status' => 1, - 'is_show' => 1, + 'is_show' => 0, ] ] ], [ - 'menu_name' => '网站', + 'menu_name' => '网站装修', 'menu_key' => 'website', 'menu_type' => 0, 'icon' => 'iconfont-iconwangzhan1', @@ -68,6 +69,7 @@ return 'sort' => 90, 'status' => 1, 'is_show' => 1, + 'menu_attr' => 'common', 'children' => [ [ 'menu_name' => '装修管理', @@ -390,7 +392,7 @@ return ] ], [ - 'menu_name' => '会员', + 'menu_name' => '会员管理', 'menu_key' => 'member', 'menu_type' => 0, 'icon' => 'iconfont-iconhuiyuan2', @@ -401,6 +403,7 @@ return 'sort' => 70, 'status' => 1, 'is_show' => 1, + 'menu_attr' => 'system', 'children' => [ [ 'menu_name' => '会员列表', @@ -623,7 +626,7 @@ return ], ], [ - 'menu_name' => '设置', + 'menu_name' => '系统设置', 'menu_key' => 'setting', 'menu_type' => 0, 'icon' => 'iconfont-iconshezhi1', @@ -634,6 +637,7 @@ return 'sort' => 40, 'status' => 1, 'is_show' => 1, + 'menu_attr' => 'common', 'children' => [ [ 'menu_name' => '基础设置', @@ -1210,7 +1214,7 @@ return ] ], [ - 'menu_name' => '云市场', + 'menu_name' => '应用市场', 'menu_key' => 'app', 'menu_type' => 0, 'icon' => 'iconfont-iconyunshichang', @@ -1221,6 +1225,7 @@ return 'sort' => 10, 'status' => 1, 'is_show' => 1, + 'menu_attr' => 'common', 'children' => [ [ 'menu_name' => '应用插件', @@ -1275,6 +1280,7 @@ return 'sort' => 10, 'status' => 1, 'is_show' => 1, + 'menu_attr' => 'common', 'children' => [ [ 'menu_name' => '插件开发', diff --git a/niucloud/app/install/source/database.sql b/niucloud/app/install/source/database.sql index 399837b1d..c91e14b98 100644 --- a/niucloud/app/install/source/database.sql +++ b/niucloud/app/install/source/database.sql @@ -96,7 +96,7 @@ CREATE TABLE `generate_column` ( `query_type` varchar(100) DEFAULT '=' COMMENT '查询类型', `view_type` varchar(100) DEFAULT 'input' COMMENT '显示类型', `dict_type` varchar(255) DEFAULT '' COMMENT '字典类型', - `validate_type` VARCHAR(255) DEFAULT '' COMMENT '验证类型', + `validate_type` varchar(255) DEFAULT '' COMMENT '验证类型', `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`id`) @@ -115,8 +115,8 @@ CREATE TABLE `generate_table` ( `edit_type` int(11) NOT NULL DEFAULT '1' COMMENT '编辑方式 1-弹框 2-新页面', `order_type` int NOT NULL DEFAULT 0 COMMENT '排序方式 0-无排序 1-正序 2-倒序', `parent_menu` varchar(255) NOT NULL DEFAULT '' COMMENT '上级菜单', - `relations` text NOT NULL COMMENT '关联配置', - `synchronous_number` INT(11) NOT NULL DEFAULT 0 COMMENT '同步次数', + `relations` text DEFAULT NULL COMMENT '关联配置', + `synchronous_number` int NOT NULL DEFAULT 0 COMMENT '同步次数', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='代码生成表'; @@ -4160,6 +4160,7 @@ CREATE TABLE `sys_config` ( KEY `config_key` (`config_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统配置表'; + DROP TABLE IF EXISTS `sys_dict`; CREATE TABLE `sys_dict` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', @@ -4172,6 +4173,7 @@ CREATE TABLE `sys_dict` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数据字典表'; + DROP TABLE IF EXISTS `sys_menu`; CREATE TABLE `sys_menu` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '菜单ID', diff --git a/niucloud/app/install/view/index/step-4.html b/niucloud/app/install/view/index/step-4.html index 094f05a1b..970429366 100644 --- a/niucloud/app/install/view/index/step-4.html +++ b/niucloud/app/install/view/index/step-4.html @@ -38,12 +38,6 @@ 网站后台 -
-
diff --git a/niucloud/app/lang/zh-cn/api.php b/niucloud/app/lang/zh-cn/api.php
index d29b7a0ec..a8aabb4ee 100644
--- a/niucloud/app/lang/zh-cn/api.php
+++ b/niucloud/app/lang/zh-cn/api.php
@@ -38,6 +38,7 @@ return [
'ADDON_INSTALL_NOT_EXIST' => '未找到插件安装任务',
'ADDON_INSTALL_EXECUTED' => '插件安装任务已执行',
'INSTALL_CHECK_NOT_PASS' => '安装校验未通过',
+ 'ADDON_INSTALLING' => '插件正在安装中',
'SITE_INDEX_VIEW_PATH_NOT_EXIST' => '当前首页路径不存在',
'ADMIN_INDEX_VIEW_PATH_NOT_EXIST' => '当前首页路径不存在',
'ADDON_SQL_FAIL' => '插件sql执行失败',
@@ -45,6 +46,7 @@ return [
'LAYOUT_NOT_EXIST' => '该布局不存在',
'ZIP_FILE_NOT_FOUND' => '找不到可用的压缩文件',
'DOWNLOAD_SUCCESS' => '下载成功',
+ 'ADDON_INFO_FILE_NOT_EXIST' => '未找到插件info.json配置文件',
//登录注册重置账号....
'LOGIN_SUCCESS' => '登录成功',
diff --git a/niucloud/app/lang/zh-cn/dict.php b/niucloud/app/lang/zh-cn/dict.php
index f8fd1f3b2..24e2e2e27 100644
--- a/niucloud/app/lang/zh-cn/dict.php
+++ b/niucloud/app/lang/zh-cn/dict.php
@@ -201,6 +201,7 @@ return [
'page_diy' => '自定义页面',
'component_type_basic' => '基础组件',
+ 'system_title' => '系统',
'system_link' => '系统页面',
'system_link_index' => '首页',
diff --git a/niucloud/app/lang/zh-cn/validate.php b/niucloud/app/lang/zh-cn/validate.php
index aeffb72b8..41961addf 100644
--- a/niucloud/app/lang/zh-cn/validate.php
+++ b/niucloud/app/lang/zh-cn/validate.php
@@ -10,6 +10,17 @@
// +----------------------------------------------------------------------
return [
+ //公共
+ 'common_validate' => [
+ 'require' => '%s必须填写',
+ 'number' => '%s必须是正整数',
+ 'mobile' => '%s手机号格式错误',
+ 'id_card' => '%s身份证号格式错误',
+ 'email' => '%s邮箱格式错误',
+ 'max' => '%s最大值不能超过%d',
+ 'min' => '%s最小值不能超过%d',
+ 'between' => '%s必须是%d到%d之间'
+ ],
//菜单
'validate_menu' => [
'menu_name_require' => '菜单名称必须填写',
diff --git a/niucloud/app/model/dict/Dict.php b/niucloud/app/model/dict/Dict.php
new file mode 100644
index 000000000..3e7e46e7f
--- /dev/null
+++ b/niucloud/app/model/dict/Dict.php
@@ -0,0 +1,77 @@
+ 'json'
+ ];
+
+ // 设置json类型字段
+ protected $json = ['dictionary'];
+ // 设置JSON数据返回数组
+ protected $jsonAssoc = true;
+
+ /**
+ * 搜索器:数据字典字典名称
+ * @param $value
+ * @param $data
+ */
+ public function searchNameAttr($query, $value, $data)
+ {
+ if ($value) {
+ $query->where("name", $value);
+ }
+ }
+
+ /**
+ * 搜索器:数据字典字典关键词
+ * @param $value
+ * @param $data
+ */
+ public function searchKeyAttr($query, $value, $data)
+ {
+ if ($value) {
+ $query->where("key", $value);
+ }
+ }
+
+
+
+
+}
diff --git a/niucloud/app/model/generator/GenerateTable.php b/niucloud/app/model/generator/GenerateTable.php
index 1b5647225..96dced52e 100644
--- a/niucloud/app/model/generator/GenerateTable.php
+++ b/niucloud/app/model/generator/GenerateTable.php
@@ -11,6 +11,7 @@
namespace app\model\generator;
+use app\model\addon\Addon;
use app\model\applet\AppletVersion;
use core\base\BaseModel;
@@ -62,5 +63,27 @@ class GenerateTable extends BaseModel
}
}
+ /**
+ * 插件搜索器
+ * @param $query
+ * @param $value
+ * @param $data
+ */
+ public function searchAddonNameAttr($query, $value, $data)
+ {
+ if ($value) {
+ if($value == 2)
+ {
+ $query->where('addon_name','=','');
+ }else{
+ $query->where('addon_name', 'like', '%' . $value . '%');
+ }
+ }
+ }
+
+ public function addon()
+ {
+ return $this->hasOne(Addon::class, 'key', 'addon_name')->joinType('left')->withField('key, title')->bind(['title' => 'title']);
+ }
}
diff --git a/niucloud/app/service/admin/addon/AddonService.php b/niucloud/app/service/admin/addon/AddonService.php
index 6b0eba110..9c5ab8858 100644
--- a/niucloud/app/service/admin/addon/AddonService.php
+++ b/niucloud/app/service/admin/addon/AddonService.php
@@ -14,6 +14,7 @@ namespace app\service\admin\addon;
use app\dict\addon\AddonDict;
use app\model\addon\Addon;
+use app\service\core\addon\CoreAddonCloudService;
use app\service\core\addon\CoreAddonDownloadService;
use app\service\core\addon\CoreAddonInstallService;
use app\service\core\addon\CoreAddonService;
@@ -54,26 +55,33 @@ class AddonService extends BaseAdminService
*/
public function install(string $addon)
{
- try {
- $data = (new CoreAddonInstallService($addon))->install();
- return success('SUCCESS', $data);
- } catch ( Exception $e) {
- return fail($e->getMessage());
- }
+ return (new CoreAddonInstallService($addon))->install();
}
/**
- * 执行安装
+ * 云安装插件
* @param string $addon
* @return Response
*/
- public function executeInstall(string $addon) {
- try {
- $data = (new CoreAddonInstallService($addon))->executeInstall();
- return success('SUCCESS', $data);
- } catch ( Exception $e) {
- return fail($e->getMessage());
- }
+ public function cloudInstall(string $addon) {
+ return (new CoreAddonInstallService($addon))->install('cloud');
+ }
+
+ /**
+ * 云安装日志
+ * @param string $addon
+ * @return null
+ */
+ public function cloudInstallLog(string $addon) {
+ return (new CoreAddonCloudService())->getBuildLog($addon);
+ }
+
+ /**
+ * 获取安装任务
+ * @return mixed
+ */
+ public function getInstallTask() {
+ return (new CoreAddonInstallService(''))->getInstallTask();
}
/**
@@ -86,17 +94,6 @@ class AddonService extends BaseAdminService
return success('SUCCESS', $data);
}
- /**
- * 获取插件安装状态
- * @param string $addon
- * @param string $key
- * @return mixed
- */
- public function getInstallState(string $addon, string $key)
- {
- return CoreAddonInstallService::instance($addon)->getInstallState($key);
- }
-
/**
* 卸载插件
* @param string $addon
@@ -142,8 +139,8 @@ class AddonService extends BaseAdminService
* @param string $app_key
* @return true
*/
- public function download(string $app_key){
- return (new CoreAddonDownloadService())->download($app_key);
+ public function download(string $app_key, string $version){
+ return (new CoreAddonDownloadService())->download($app_key, $version);
}
/**
@@ -161,7 +158,7 @@ class AddonService extends BaseAdminService
* @return array
*/
public function getInstallAddonList($where){
- $field = 'title, icon, key, desc, status, is_star';
+ $field = 'title, icon, key, desc, status, is_star, type, support_app';
return $this->model->where([['status', '=', AddonDict::ON]])->withSearch([ 'title' ], $where)->field($field)->append(['status_name'])->order('create_time desc')->select()->toArray();
}
@@ -170,7 +167,7 @@ class AddonService extends BaseAdminService
* @return array
*/
public function getInstallStarAddonList($where){
- $field = 'title, icon, key, desc, status, is_star';
+ $field = 'title, icon, key, desc, status, is_star, type, support_app';
return $this->model->where([['status', '=', AddonDict::ON],['is_star', '=', 2]])->withSearch([ 'title' ], $where)->field($field)->append(['status_name'])->order('create_time desc')->select()->toArray();
}
@@ -201,7 +198,7 @@ class AddonService extends BaseAdminService
['key', 'in', $keys],
['status', '=', AddonDict::ON]
];
- return $this->model->where($data)->withSearch([ 'title' ], $where)->field('title, icon, key, desc, status, cover, is_star')->select()->toArray();
+ return $this->model->where($data)->withSearch([ 'title' ], $where)->field('title, icon, key, desc, status, cover, is_star, type, support_app')->select()->toArray();
}
@@ -232,7 +229,7 @@ class AddonService extends BaseAdminService
['status', '=', AddonDict::ON],
['is_star', '=', 2]
];
- return $this->model->where($data)->withSearch([ 'title' ], $where)->field('title, icon, key, desc, status, cover')->select()->toArray();
+ return $this->model->where($data)->withSearch([ 'title' ], $where)->field('title, icon, key, desc, status, cover, type, support_app')->select()->toArray();
}
/**
diff --git a/niucloud/app/service/admin/dict/DictService.php b/niucloud/app/service/admin/dict/DictService.php
new file mode 100644
index 000000000..9660c3f0e
--- /dev/null
+++ b/niucloud/app/service/admin/dict/DictService.php
@@ -0,0 +1,125 @@
+model = new Dict();
+ }
+
+ /**
+ * 获取数据字典列表
+ * @param array $where
+ * @return array
+ */
+ public function getPage(array $where = [])
+ {
+ $field = 'id,name,key,memo,create_time,update_time';
+ $order = 'id desc';
+
+ $search_model = $this->model->withSearch(["name","key"], $where)->field($field)->order($order);
+ $list = $this->pageQuery($search_model);
+ return $list;
+ }
+
+ /**
+ * 获取数据字典信息
+ * @param int $id
+ * @return array
+ */
+ public function getInfo(int $id)
+ {
+ $field = 'id,name,key,dictionary,memo,create_time,update_time';
+
+ $info = $this->model->field($field)->where([['id', '=', $id]])->findOrEmpty()->toArray();
+ if($info['dictionary'] == null)
+ {
+ $info['dictionary'] = [];
+ }
+ return $info;
+ }
+
+ /**
+ * 添加数据字典
+ * @param array $data
+ * @return mixed
+ */
+ public function add(array $data)
+ {
+
+ $res = $this->model->create($data);
+ return $res->id;
+
+ }
+
+ /**
+ * 数据字典编辑
+ * @param int $id
+ * @param array $data
+ * @return bool
+ */
+ public function edit(int $id, array $data)
+ {
+ $data['update_time'] = time();
+ $this->model->where([['id', '=', $id]])->update($data);
+ return true;
+ }
+
+ /**
+ * 删除数据字典
+ * @param int $id
+ * @return bool
+ */
+ public function del(int $id)
+ {
+ $res = $this->model->where([['id', '=', $id]])->delete();
+ return $res;
+ }
+
+ /**
+ * 获取全部数据字典
+ * @param array $where
+ * @return array
+ */
+ public function getAll()
+ {
+ $field = 'id,name,key,dictionary,memo,create_time,update_time';
+ $list = $this->model->field($field)->select()->toArray();
+ return $list;
+ }
+
+ public function getKeyInfo($key)
+ {
+ $field = 'id,name,key,dictionary,memo,create_time,update_time';
+
+ $info = $this->model->field($field)->where([['key', '=', $key]])->findOrEmpty()->toArray();
+ if($info['dictionary'] == null)
+ {
+ $info['dictionary'] = [];
+ }
+ return $info;
+ }
+
+
+}
diff --git a/niucloud/app/service/admin/diy/DiyService.php b/niucloud/app/service/admin/diy/DiyService.php
index ac194cb55..ba42f36a1 100644
--- a/niucloud/app/service/admin/diy/DiyService.php
+++ b/niucloud/app/service/admin/diy/DiyService.php
@@ -186,8 +186,8 @@ class DiyService extends BaseAdminService
} elseif (!empty($params[ 'url' ])) {
foreach ($template as $k => $v) {
if ($params[ 'url' ] == '/' . $v[ 'page' ]) {
- $params[ 'name' ]=$k;
- $params[ 'type' ]=$k;
+ $params[ 'name' ] = $k;
+ $params[ 'type' ] = $k;
}
}
}
@@ -383,14 +383,19 @@ class DiyService extends BaseAdminService
/**
* 获取默认页面数据
* @param $type
+ * @param array $template
* @return array|mixed
*/
- public function getFirstPageData($type)
+ public function getFirstPageData($type, $template = [])
{
$pages = PagesDict::getPages([ 'type' => $type ]);
if (!empty($pages)) {
- $template = array_key_first($pages);
- $page = array_shift($pages);
+ if (empty($template)) {
+ $template = array_key_first($pages);
+ $page = array_shift($pages);
+ } else {
+ $page = $pages[ $template ];
+ }
$page[ 'template' ] = $template;
$page[ 'type' ] = $type;
return $page;
@@ -505,6 +510,11 @@ class DiyService extends BaseAdminService
}
}
+ // 如果没有预览图,并且没有地址,则赋值
+ if (empty($use_template[ 'cover' ]) && empty($use_template[ 'url' ])) {
+ $use_template[ 'url' ] = '/' . $v[ 'page' ];
+ }
+
$template[ $k ][ 'use_template' ] = $use_template;
}
@@ -649,6 +659,10 @@ class DiyService extends BaseAdminService
} else {
$res[ 'page' ] .= '?id=' . $info[ 'id' ];
}
+ } elseif ($params[ 'name' ]) {
+ // 表里没有数据,查询默认页面数据
+ $template = $this->getTemplate([ 'type' => [ $params[ 'name' ] ] ])[ $params[ 'name' ] ];
+ $res[ 'page' ] = $template[ 'page' ];
}
return $res;
diff --git a/niucloud/app/service/admin/generator/Generate.php b/niucloud/app/service/admin/generator/Generate.php
index 86d04a938..ca766e5bc 100644
--- a/niucloud/app/service/admin/generator/Generate.php
+++ b/niucloud/app/service/admin/generator/Generate.php
@@ -192,11 +192,15 @@ class Generate
public function preview(array $table)
{
$data = [];
-// $data = [];
foreach ($this->getGenerator() as $item) {
$generator = app()->make($item);
$generator->init($table);
- $data[] = $generator->fileInfo();
+ $file_info = $generator->fileInfo();
+ if(!empty($file_info))
+ {
+ $data[] = $file_info;
+ }
+
}
return $data;
@@ -217,8 +221,8 @@ class Generate
WebLangGenerator::class,
WebEditGenerator::class,
WebIndexGenerator::class,
-// WebEditPageGenerator::class,
-// WebEditLangGenerator::class
+ WebEditPageGenerator::class,
+ WebEditLangGenerator::class
];
}
diff --git a/niucloud/app/service/admin/generator/GenerateService.php b/niucloud/app/service/admin/generator/GenerateService.php
index 5f2dd883e..c7a92a1c1 100644
--- a/niucloud/app/service/admin/generator/GenerateService.php
+++ b/niucloud/app/service/admin/generator/GenerateService.php
@@ -41,9 +41,9 @@ class GenerateService extends BaseAdminService
*/
public function getPage(array $where = [])
{
- $field = 'id,table_name,table_content,class_name,edit_type,create_time';
+ $field = 'id,table_name,table_content,class_name,edit_type,create_time,addon_name';
$order = 'create_time desc';
- $search_model = (new GenerateTable())->withSearch(['table_name', 'table_content'], $where)->field($field)->order($order);
+ $search_model = (new GenerateTable())->withSearch(['table_name', 'table_content','addon_name'], $where)->with('addon')->field($field)->order($order);
return $this->pageQuery($search_model);
}
@@ -57,11 +57,12 @@ class GenerateService extends BaseAdminService
*/
public function getInfo(int $id)
{
- $field = 'id,table_name,table_content,class_name,module_name,edit_type,addon_name,order_type,parent_menu,relations';
+ $field = 'id,table_name,table_content,class_name,module_name,edit_type,addon_name,order_type,parent_menu,relations,synchronous_number';
$info = (new GenerateTable())->field($field)->where([['id', '=', $id]])->findOrEmpty()->toArray();
$info['table_column'] = (new GenerateColumn())->where([['table_id', '=', $id]])->select()->toArray();
+
$column = (new GenerateColumn())->where([['table_id', '=', $id],['is_delete','=',1]])->find();
if($info && $info['order_type'] != 0)
{
@@ -88,7 +89,77 @@ class GenerateService extends BaseAdminService
{
$info['relations'] = [];
}else{
- $info['relations'] = json_decode($info['relations'],true);
+ if(!empty($info['relations']))
+ {
+ $info['relations'] = json_decode($info['relations'],true);
+ }else{
+ $info['relations'] = [];
+ }
+
+ }
+ if($info && !empty($info['table_column']))
+ {
+ foreach ($info['table_column'] as &$value)
+ {
+ if($value['view_type'] === 'number')
+ {
+
+ if(!empty($value['validate_type']))
+ {
+
+ $num_validate = json_decode($value['validate_type'],true);
+ if($num_validate[0] == 'between')
+ {
+ $value['view_max'] = $num_validate[1][1];
+ $value['view_min'] = $num_validate[1][0];
+ } else if($num_validate[0] == 'max')
+ {
+ $value['view_max'] = $num_validate[1][0];
+
+ } else if($num_validate[0] == 'min')
+ {
+ $value['view_min'] = $num_validate[1][0];
+ }else{
+ $value['view_max'] = 100;
+ $value['view_min'] = 0;
+ }
+ }else{
+ $value['view_min'] = 0;
+ $value['view_max'] = 100;
+ }
+
+ }else{
+ $value['view_min'] = 0;
+ $value['view_max'] = 100;
+ }
+
+ if(!empty($value['validate_type']))
+ {
+ $validate = json_decode($value['validate_type'],true);
+
+ if($validate[0] == 'between')
+ {
+ $value['max_number'] = $validate[1][1];
+ $value['min_number'] = $validate[1][0];
+ } else if($validate[0] == 'max')
+ {
+ $value['max_number'] = $validate[1][0];
+
+ } else if($validate[0] == 'min')
+ {
+ $value['min_number'] = $validate[1][0];
+ }else{
+ $value['max_number'] = 120;
+ $value['min_number'] = 1;
+ }
+ $value['validate_type'] = $validate[0];
+ }else{
+ $value['max_number'] = 120;
+ $value['min_number'] = 1;
+ }
+
+
+ }
}
return $info;
}
@@ -119,7 +190,7 @@ class GenerateService extends BaseAdminService
$add_table_data = [
'table_name' => $table_name,
'table_content' => $table_info['Comment'],
- 'class_name' => '',
+ 'class_name' => $table_name,
'create_time' => time(),
'module_name' => $table_name
];
@@ -218,6 +289,26 @@ class GenerateService extends BaseAdminService
}else{
$item['is_order'] = 0;
}
+ if(!empty($item['validate_type']) && $item['view_type'] != 'number')
+ {
+ if($item['validate_type'] == 'between')
+ {
+ $validate_type = [$item['validate_type'],[$item['min_number'],$item['max_number']]];
+ }else if($item['validate_type'] == 'max'){
+ $validate_type = [$item['validate_type'],[$item['max_number']]];
+ }else if($item['validate_type'] == 'min'){
+ $validate_type = [$item['validate_type'],[$item['min_number']]];
+ }else{
+ $validate_type = [$item['validate_type'],[]];
+ }
+ $item['validate_type'] = json_encode($validate_type,JSON_UNESCAPED_UNICODE);
+ }
+ if($item['view_type'] === 'number')
+ {
+ $validate_type = ['between',[$item['view_min'],$item['view_max']]];
+ $item['validate_type'] = $validate_type;
+ $item['validate_type'] = json_encode($validate_type,JSON_UNESCAPED_UNICODE);
+ }
$add_column_data[] = [
'table_id' => $id,
@@ -238,6 +329,8 @@ class GenerateService extends BaseAdminService
'update_time' => time(),
'create_time' => time(),
'column_type' => $item['column_type'] ?? 'string',
+ 'validate_type' => $item['validate_type'] ?? '',
+ 'validate_rule' => $params['rule'] ?? []
];
}
(new GenerateColumn())->saveAll($add_column_data);
@@ -309,6 +402,8 @@ class GenerateService extends BaseAdminService
$id = $params['id'];
$table_info = (new GenerateTable())->where([ ['id', '=', $id] ])->field('*')->find()->toArray();
$table_info['fields'] = (new GenerateColumn())->where([ ['table_id', '=', $id] ])->field('*')->select()->toArray();
+ $synchronous_number = $table_info['synchronous_number'] +1;
+ (new GenerateTable())->where([ ['id', '=', $id] ])->save(['synchronous_number' => $synchronous_number]);
$generator = new Generate();
$generator->delOutFiles();
$flag = array_unique(array_column($table_info, 'table_name'));
@@ -456,7 +551,7 @@ class GenerateService extends BaseAdminService
if($data['addon'] == 'system')
{
//获取系统模型
- $modulePath = base_path() . '\\model\\';
+ $modulePath = dirname(root_path()) . '/niucloud/app/model/';
if(!is_dir($modulePath)) {
return [];
}
@@ -489,13 +584,13 @@ class GenerateService extends BaseAdminService
}
}else{
//获取插件模型
- $path = dirname(root_path())."\\niucloud\\addon\\".$data['addon']."\\app\\model";
+ $path = dirname(root_path())."/niucloud/addon/".$data['addon']."/app/model";
if(!is_dir($path)) {
return [];
}
- $modulefiles = glob($path . '\*');
+ $modulefiles = glob($path . '/*');
$targetFiles = [];
foreach ($modulefiles as $file) {
diff --git a/niucloud/app/service/admin/generator/core/AdminApiRouteGenerator.php b/niucloud/app/service/admin/generator/core/AdminApiRouteGenerator.php
index e99da373a..80c7867a8 100644
--- a/niucloud/app/service/admin/generator/core/AdminApiRouteGenerator.php
+++ b/niucloud/app/service/admin/generator/core/AdminApiRouteGenerator.php
@@ -38,7 +38,9 @@ class AdminApiRouteGenerator extends BaseGenerator
'{MODULE_NAME}',
'{ROUTE_NAME}',
'{ROUTE_PATH}',
- '{ROUTE}'
+ '{ROUTE}',
+ '{BEGIN}',
+ '{END}'
];
$new = [
@@ -51,6 +53,8 @@ class AdminApiRouteGenerator extends BaseGenerator
$this->getRouteName(),
$this->getRoutePath(),
$this->getRoute(),
+ $this->getBegin(),
+ $this->getEnd()
];
$vmPath = $this->getvmPath('admin_api_route');
@@ -88,7 +92,17 @@ class AdminApiRouteGenerator extends BaseGenerator
if(file_exists($file))
{
- $route = file_get_contents($file);
+ $content = file_get_contents($file);
+ $code_begin = 'USER_CODE_BEGIN -- '.$this->getTableName();
+ $code_end = 'USER_CODE_END -- '.$this->getTableName();
+ if(strpos($content,$code_begin) !== false && strpos($content,$code_end) !== false)
+ {
+ // 清除相应对应代码块
+ $pattern = "/\s+\/\/ {$code_begin}[\S\s]+\/\/ {$code_end}(\n,)?/";
+ $route = preg_replace($pattern, '', $content);
+ }else{
+ $route = $content;
+ }
}else{
$route = "getTableName();
+ return $begin;
+ }
+
+ public function getEnd()
+ {
+ $end = '// USER_CODE_END -- '.$this->getTableName();
+ return $end;
+ }
+
+
/**
* 获取表主键
* @return mixed|string
@@ -232,12 +259,13 @@ use app\adminapi\middleware\AdminLog;";
{
return 'route.php';
}else{
- //如果是某个模块下的功能,公用一个路由
- if($this->moduleName && ($this->getLCaseTableName() != $this->moduleName)){
- return Str::lower($this->moduleName) . '.php';
- }else{
- return 'route.php';
- }
+ return Str::lower($this->moduleName) . '.php';
+// //如果是某个模块下的功能,公用一个路由
+// if($this->moduleName && ($this->getLCaseTableName() != $this->moduleName)){
+// return Str::lower($this->moduleName) . '.php';
+// }else{
+// return 'route.php';
+// }
}
}
diff --git a/niucloud/app/service/admin/generator/core/BaseGenerator.php b/niucloud/app/service/admin/generator/core/BaseGenerator.php
index 85c85465c..6272895e9 100644
--- a/niucloud/app/service/admin/generator/core/BaseGenerator.php
+++ b/niucloud/app/service/admin/generator/core/BaseGenerator.php
@@ -169,7 +169,11 @@ abstract class BaseGenerator
}
// 写入内容
- if($path) file_put_contents($path, $this->text);
+ if(!empty($this->getFileName()))
+ {
+ file_put_contents($path, $this->text);
+ }
+
}
@@ -179,12 +183,19 @@ abstract class BaseGenerator
*/
public function fileInfo(): array
{
- return [
- 'name' => $this->getFileName(),
- 'type' => 'php',
- 'content' => $this->text,
- 'file_dir' => $this->getFilePath(),
- ];
+ if(!empty($this->getFileName()))
+ {
+ return
+ [
+ 'name' => $this->getFileName(),
+ 'type' => 'php',
+ 'content' => $this->text,
+ 'file_dir' => $this->getFilePath(),
+ ];
+ }else{
+ return [];
+ }
+
}
/**
@@ -415,4 +426,5 @@ abstract class BaseGenerator
return str_replace($old, $new, file_get_contents($template));
}
+
}
diff --git a/niucloud/app/service/admin/generator/core/MenuSqlGenerator.php b/niucloud/app/service/admin/generator/core/MenuSqlGenerator.php
index 5e643f9da..60cc855ff 100644
--- a/niucloud/app/service/admin/generator/core/MenuSqlGenerator.php
+++ b/niucloud/app/service/admin/generator/core/MenuSqlGenerator.php
@@ -33,8 +33,8 @@ class MenuSqlGenerator extends BaseGenerator
$old = [
'{SQL}',
];
-
- $new = [$this->getMenuSql(),];
+ $res = $this->getMenuSql();
+ $new = [$res['sql'],];
if($this->table['generate_type'] == 3)
{
@@ -57,8 +57,14 @@ class MenuSqlGenerator extends BaseGenerator
{
$dir = dirname(root_path());
$file = $dir.'\niucloud\addon\\'.$this->addonName.'\\sql\\install.sql';
- $addSql = $this->getMenuSql();
- file_put_contents($file,$addSql,FILE_APPEND);
+ $res = $this->getMenuSql();
+ $key = $res['data'][0]['menu_key'];
+ $result = (new SysMenu())->where([['menu_key','=',$key]])->find()->toArray();
+ if(!$result){
+ $addSql = $res['sql'];
+ file_put_contents($file,$addSql,FILE_APPEND);
+ }
+
}
}
/**
@@ -145,11 +151,18 @@ class MenuSqlGenerator extends BaseGenerator
} else {
$table_content = '';
}
+
+ if(!empty($this->className))
+ {
+ $name = $this->className;
+ }else{
+ $name = $this->table['table_name'];
+ }
if(!empty($this->addonName))
{
- $key = $this->addonName.'_'.$this->table['table_name'].'_'.$this->moduleName.'_'.$this->getUCaseClassName();
+ $key = $this->addonName.'_'.$this->table['table_name'].'_'.$this->moduleName.'_'.$name;
}else{
- $key = $this->table['table_name'].'_'.$this->moduleName.'_'.$this->getUCaseClassName();
+ $key = $this->table['table_name'].'_'.$this->moduleName.'_'.$name;
}
$data = [
[
@@ -177,8 +190,8 @@ class MenuSqlGenerator extends BaseGenerator
'menu_type' => 1,
'icon' => '',
'api_url' => $this->getRouteName(),
- 'router_path' => $this->className.'_list',
- 'view_path' => $this->moduleName.'/'.$this->className.'_list',
+ 'router_path' => 'list',
+ 'view_path' => $this->moduleName.'/'.'list',
'methods' => 'get',
'sort' => 90,
'status' => 1,
@@ -188,33 +201,33 @@ class MenuSqlGenerator extends BaseGenerator
'addon' => $this->addonName,
'source' => MenuDict::GENERATOR
],
- [
- 'menu_name' => $table_content.'详情',
- 'menu_key' => $key.'_info',
- 'parent_key' => $key,
- 'menu_type' => 1,
- 'icon' => '',
- 'api_url' => $this->getRouteName().'/<'.'id>',
- 'router_path' => $this->moduleName,
- 'view_path' => $this->moduleName.'/'.$this->className.'_list',
- 'methods' => 'get',
- 'sort' => 80,
- 'status' => 1,
- 'is_show' => 1,
- 'create_time' => time(),
- 'delete_time' => 0,
- 'addon' => $this->addonName,
- 'source' => MenuDict::GENERATOR
- ],
+// [
+// 'menu_name' => $table_content.'详情',
+// 'menu_key' => $key.'_info',
+// 'parent_key' => $key,
+// 'menu_type' => 1,
+// 'icon' => '',
+// 'api_url' => $this->getRouteName().'/<'.'id>',
+// 'router_path' => $this->moduleName,
+// 'view_path' => $this->moduleName.'/'.$this->className.'_list',
+// 'methods' => 'get',
+// 'sort' => 80,
+// 'status' => 1,
+// 'is_show' => 1,
+// 'create_time' => time(),
+// 'delete_time' => 0,
+// 'addon' => $this->addonName,
+// 'source' => MenuDict::GENERATOR
+// ],
[
'menu_name' => $table_content.'添加',
'menu_key' => $key.'_add',
'parent_key' => $key,
- 'menu_type' => 1,
+ 'menu_type' => 2,
'icon' => '',
'api_url' => $this->getRouteName(),
- 'router_path' => $this->className.'_edit',
- 'view_path' => $this->moduleName.'/'.$this->className.'_edit',
+ 'router_path' => 'edit',
+ 'view_path' => $this->moduleName.'/'.'edit',
'methods' => 'post',
'sort' => 70,
'status' => 1,
@@ -228,11 +241,13 @@ class MenuSqlGenerator extends BaseGenerator
'menu_name' => $table_content.'编辑',
'menu_key' => $key.'_edit',
'parent_key' => $key,
- 'menu_type' => 1,
+ 'menu_type' => 2,
'icon' => '',
'api_url' => $this->getRouteName().'/<'.'id>',
- 'router_path' => $this->className.'_edit',
- 'view_path' => $this->moduleName.'/'.$this->className.'_edit',
+ 'router_path' => 'edit',
+ 'view_path' => $this->moduleName.'/'.'edit',
+// 'router_path' => $this->className.'_edit',
+// 'view_path' => $this->moduleName.'/'.$this->className.'_edit',
'methods' => 'put',
'sort' => 60,
'status' => 1,
@@ -264,7 +279,11 @@ class MenuSqlGenerator extends BaseGenerator
$sql = Db::name('sys_menu')->fetchSql(true)->insertAll($data);
$sql = str_replace(' (', PHP_EOL.'(', $sql);
- return $sql;
+ $res = [
+ 'data' => $data,
+ 'sql' => $sql
+ ];
+ return $res;
}
@@ -302,11 +321,17 @@ class MenuSqlGenerator extends BaseGenerator
} else {
$table_content = '';
}
+ if(!empty($this->className))
+ {
+ $name = $this->className;
+ }else{
+ $name = $this->table['table_name'];
+ }
if(!empty($this->addonName))
{
- $key = $this->addonName.'_'.$this->table['table_name'].'_'.$this->moduleName.'_'.$this->getUCaseClassName();
+ $key = $this->addonName.'_'.$this->table['table_name'].'_'.$this->moduleName.'_'.$name;
}else{
- $key = $this->table['table_name'].'_'.$this->moduleName.'_'.$this->getUCaseClassName();
+ $key = $this->table['table_name'].'_'.$this->moduleName.'_'.$name;
}
$data = [
[
@@ -334,8 +359,8 @@ class MenuSqlGenerator extends BaseGenerator
'menu_type' => 1,
'icon' => '',
'api_url' => $this->getRouteName(),
- 'router_path' => $this->className.'_list',
- 'view_path' => $this->moduleName.'/'.$this->className.'_list',
+ 'router_path' => 'list',
+ 'view_path' => $this->moduleName.'/'.'list',
'methods' => 'get',
'sort' => 90,
'status' => 1,
@@ -345,33 +370,33 @@ class MenuSqlGenerator extends BaseGenerator
'addon' => $this->addonName,
'source' => MenuDict::GENERATOR
],
- [
- 'menu_name' => $table_content.'详情',
- 'menu_key' => $key.'_info',
- 'parent_key' => $key,
- 'menu_type' => 1,
- 'icon' => '',
- 'api_url' => $this->getRouteName().'/<'.'id>',
- 'router_path' => $this->moduleName,
- 'view_path' => $this->moduleName.'/'.$this->className.'_list',
- 'methods' => 'get',
- 'sort' => 80,
- 'status' => 1,
- 'is_show' => 1,
- 'create_time' => time(),
- 'delete_time' => 0,
- 'addon' => $this->addonName,
- 'source' => MenuDict::GENERATOR
- ],
+// [
+// 'menu_name' => $table_content.'详情',
+// 'menu_key' => $key.'_info',
+// 'parent_key' => $key,
+// 'menu_type' => 1,
+// 'icon' => '',
+// 'api_url' => $this->getRouteName().'/<'.'id>',
+// 'router_path' => $this->moduleName,
+// 'view_path' => $this->moduleName.'/'.$this->className.'_list',
+// 'methods' => 'get',
+// 'sort' => 80,
+// 'status' => 1,
+// 'is_show' => 1,
+// 'create_time' => time(),
+// 'delete_time' => 0,
+// 'addon' => $this->addonName,
+// 'source' => MenuDict::GENERATOR
+// ],
[
'menu_name' => $table_content.'添加',
'menu_key' => $key.'_add',
'parent_key' => $key,
- 'menu_type' => 1,
+ 'menu_type' => 2,
'icon' => '',
'api_url' => $this->getRouteName(),
- 'router_path' => $this->className.'_edit',
- 'view_path' => $this->moduleName.'/'.$this->className.'_edit',
+ 'router_path' => 'edit',
+ 'view_path' => $this->moduleName.'/'.'edit',
'methods' => 'post',
'sort' => 70,
'status' => 1,
@@ -385,11 +410,13 @@ class MenuSqlGenerator extends BaseGenerator
'menu_name' => $table_content.'编辑',
'menu_key' => $key.'_edit',
'parent_key' => $key,
- 'menu_type' => 1,
+ 'menu_type' => 2,
'icon' => '',
'api_url' => $this->getRouteName().'/<'.'id>',
- 'router_path' => $this->className.'_edit',
- 'view_path' => $this->moduleName.'/'.$this->className.'_edit',
+ 'router_path' => 'edit',
+ 'view_path' => $this->moduleName.'/'.'edit',
+// 'router_path' => $this->className.'_edit',
+// 'view_path' => $this->moduleName.'/'.$this->className.'_edit',
'methods' => 'put',
'sort' => 60,
'status' => 1,
@@ -419,9 +446,15 @@ class MenuSqlGenerator extends BaseGenerator
],
];
$menu_model = new SysMenu();
- (new $menu_model())->saveAll($data);
- $cache_tag_name = 'menu_cache';
- Cache::tag($cache_tag_name)->clear();
+
+ $result = (new SysMenu())->where([['menu_key','=',$key]])->find();
+
+ if(empty($result)){
+ (new $menu_model())->saveAll($data);
+ $cache_tag_name = 'menu_cache';
+ Cache::tag($cache_tag_name)->clear();
+ }
+
return true;
}
}
diff --git a/niucloud/app/service/admin/generator/core/ModelGenerator.php b/niucloud/app/service/admin/generator/core/ModelGenerator.php
index d11c177c3..08d145d7c 100644
--- a/niucloud/app/service/admin/generator/core/ModelGenerator.php
+++ b/niucloud/app/service/admin/generator/core/ModelGenerator.php
@@ -294,7 +294,7 @@ class ModelGenerator extends BaseGenerator
$data['deleteColumnValue'] = '';
}else{
$data['softDelete'] = ' use SoftDelete;';
- $data['deleteColumn'] = '/**'.PHP_EOL.' * 定义软删除标记字段.'.PHP_EOL.' * @var string'.PHP_EOL.' */'.PHP_EOL.' protected $deleteTime = '."'".$column['column_name']."'";
+ $data['deleteColumn'] = '/**'.PHP_EOL.' * 定义软删除标记字段.'.PHP_EOL.' * @var string'.PHP_EOL.' */'.PHP_EOL.' protected $deleteTime = '."'".$column['column_name']."';";
$data['deleteColumnValue'] = '/**'.PHP_EOL.' * 定义软删除字段的默认值.'.PHP_EOL.' * @var int'.PHP_EOL.' */'.PHP_EOL.' protected $defaultSoftDelete = 0;';
}
}
@@ -307,37 +307,43 @@ class ModelGenerator extends BaseGenerator
public function getRelationModel()
{
$tpl = '';
-// $this->table['relations'] = '[{"name":"test","model":"\\app\\common\\model\\Config","type":"has_one","local_key":"id","foreign_key":"id"}]';
+
if ($this->table['relations'] == '[]') {
return $tpl;
}
// 遍历关联配置
- $relations = json_decode($this->table['relations'],true);
+ if(!empty($this->table['relations']))
+ {
+ $relations = json_decode($this->table['relations'],true);
- foreach ($relations as $config) {
- if (empty($config) || empty($config['name']) || empty($config['model'])) {
- continue;
+ foreach ($relations as $config) {
+ if (empty($config) || empty($config['name']) || empty($config['model'])) {
+ continue;
+ }
+
+ $needReplace = [
+ '{RELATION_NAME}',
+ '{RELATION_MODEL}',
+ '{FOREIGN_KEY}',
+ '{LOCAL_KEY}',
+ ];
+
+ $waitReplace = [
+ $config['name'],
+ $config['model'],
+ $config['foreign_key'],
+ $config['local_key'],
+ ];
+
+ $vmPath = $this->getvmPath('php/model/'.$config['type']);
+ $tpl .= $this->replaceFileText($needReplace, $waitReplace, $vmPath). PHP_EOL;
}
-
- $needReplace = [
- '{RELATION_NAME}',
- '{RELATION_MODEL}',
- '{FOREIGN_KEY}',
- '{LOCAL_KEY}',
- ];
-
- $waitReplace = [
- $config['name'],
- $config['model'],
- $config['foreign_key'],
- $config['local_key'],
- ];
-
- $vmPath = $this->getvmPath('php/model/'.$config['type']);
- $tpl .= $this->replaceFileText($needReplace, $waitReplace, $vmPath). PHP_EOL;
+ return $tpl;
+ }else{
+ return '';
}
- return $tpl;
+
}
}
diff --git a/niucloud/app/service/admin/generator/core/ValidateGenerator.php b/niucloud/app/service/admin/generator/core/ValidateGenerator.php
index d3327f2ee..fd54f4749 100644
--- a/niucloud/app/service/admin/generator/core/ValidateGenerator.php
+++ b/niucloud/app/service/admin/generator/core/ValidateGenerator.php
@@ -65,9 +65,43 @@ class ValidateGenerator extends BaseGenerator
{
$content = "";
foreach ($this->tableColumn as $column) {
- if (!$column['is_pk']) {
- $content .= "'" . $column['column_name'] . "' => 'require'," . PHP_EOL;
+
+ if($column['is_required'] == 1){
+ if(!empty($column['validate_type']))
+ {
+ $column['validate_type'] = json_decode($column['validate_type'],true);
+ if($column['validate_type'][0] == 'max')
+ {
+ $content .= "'".$column['column_name']."' => 'require|".$column['validate_type'][0].":".$column['validate_type'][1][0]."',". PHP_EOL;
+ }else if($column['validate_type'][0] == 'min')
+ {
+ $content .= "'".$column['column_name']."' => 'require|".$column['validate_type'][0].":".$column['validate_type'][1][0]."',". PHP_EOL;
+ }else if($column['validate_type'][0] == 'between'){
+ $content .= "'".$column['column_name']."' => 'require|".$column['validate_type'][0].":".$column['validate_type'][1][0].','.$column['validate_type'][1][1]."',". PHP_EOL;
+ }else{
+ $content .= "'".$column['column_name']."' => 'require|".$column['validate_type'][0]."',". PHP_EOL;
+ }
+ }else{
+ $content .= "'".$column['column_name'] . "' => 'require'," . PHP_EOL;
+ }
+ }else{
+ if(!empty($column['validate_type']))
+ {
+ $column['validate_type'] = json_decode($column['validate_type'],true);
+ if($column['validate_type'][0] == 'max')
+ {
+ $content .= "'".$column['column_name']."' => '".$column['validate_type'][0].":".$column['validate_type'][1][0]."',". PHP_EOL;
+ }else if($column['validate_type'][0] == 'min')
+ {
+ $content .= "'".$column['column_name']."' => '".$column['validate_type'][0].":".$column['validate_type'][1][0]."',". PHP_EOL;
+ }else if($column['validate_type'][0] == 'between'){
+ $content .= "'".$column['column_name']."' => '".$column['validate_type'][0].":".$column['validate_type'][1][0].','.$column['validate_type'][1][1]."',". PHP_EOL;
+ }else{
+ $content .= "'".$column['column_name']."' => '".$column['validate_type'][0]."',". PHP_EOL;
+ }
+ }
}
+
}
$content = substr($content, 0, -2);
$content = $this->setBlankSpace($content, " ");
@@ -80,7 +114,36 @@ class ValidateGenerator extends BaseGenerator
*/
public function getMessage()
{
- return '[]';
+ $content = "";
+ foreach ($this->tableColumn as $column) {
+
+ if($column['is_required'] == 1)
+ {
+ $content .= "'".$column['column_name'].".require"."' => "."['".'common_validate.require'."', ['".$column['column_name']."']]".','. PHP_EOL;
+ }
+ if(!empty($column['validate_type']))
+ {
+ $column['validate_type'] = json_decode($column['validate_type'],true);
+ if($column['validate_type'][0] == 'max')
+ {
+ $content .= "'".$column['column_name'].".".$column['validate_type'][0]."' => "."['".'common_validate.'.$column['validate_type'][0]."', ['".$column['column_name']."','".$column['validate_type'][1][0]."']]".','. PHP_EOL;
+
+ }else if($column['validate_type'][0] == 'min')
+ {
+ $content .= "'".$column['column_name'].".".$column['validate_type'][0]."' => "."['".'common_validate.'.$column['validate_type'][0]."', ['".$column['column_name']."','".$column['validate_type'][1][0]."']]".','. PHP_EOL;
+
+ }else if($column['validate_type'][0] == 'between'){
+ $content .= "'".$column['column_name'].".".$column['validate_type'][0]."' => "."['".'common_validate.'.$column['validate_type'][0]."', ['".$column['column_name']."','".$column['validate_type'][1][0]."','".$column['validate_type'][1][1]."']]".','. PHP_EOL;
+
+ }else{
+ $content .= "'".$column['column_name'].".".$column['validate_type'][0]."' => "."['".'common_validate.'.$column['validate_type'][0]."', ['".$column['column_name']."']]".','. PHP_EOL;
+
+ }
+ }
+ }
+ $content = substr($content, 0, -2);
+ $content = $this->setBlankSpace($content, " ");
+ return '['.PHP_EOL.$content.PHP_EOL.' ]';
}
/**
@@ -97,8 +160,8 @@ class ValidateGenerator extends BaseGenerator
if ($column['is_update'] == 1 && !$column['is_pk']) $update_arr[] = "'".$column['column_name']."'";
}
- $content .= '"add" => ['.implode(',', $add_arr).'],'.PHP_EOL;
- $content .= '"edit" => ['.implode(',', $update_arr).']';
+ $content .= '"add" => ['.implode(', ', $add_arr).'],'.PHP_EOL;
+ $content .= '"edit" => ['.implode(', ', $update_arr).']';
$content = $this->setBlankSpace($content, " ");
return '['.PHP_EOL.$content.PHP_EOL.' ]';
}
@@ -132,14 +195,21 @@ class ValidateGenerator extends BaseGenerator
*/
public function getClassComment()
{
- if (!empty($this->table['table_content'])) {
- $tpl = $this->table['table_content'] . '验证器';
- } else {
- $tpl = $this->getUCaseName() . '验证器';
- }
+ $tpl = $this->getNotes() . '验证器';
return $tpl;
}
+ public function getNotes()
+ {
+ $end_str = substr($this->table['table_content'],-3);
+ if($end_str == '表')
+ {
+ return substr($this->table['table_content'],0,strlen($this->table['table_content'])-3);
+ }else{
+ return $this->table['table_content'];
+ }
+ }
+
/**
* 获取包名
diff --git a/niucloud/app/service/admin/generator/core/WebApiGenerator.php b/niucloud/app/service/admin/generator/core/WebApiGenerator.php
index 936725ded..923091928 100644
--- a/niucloud/app/service/admin/generator/core/WebApiGenerator.php
+++ b/niucloud/app/service/admin/generator/core/WebApiGenerator.php
@@ -40,7 +40,9 @@ class WebApiGenerator extends BaseGenerator
'{UCASE_NAME}',
'{MODULE_NAME}',
'{ROUTE_GROUP_NAME}',
- '{IMPORT}'
+ '{IMPORT}',
+ '{BEGIN}',
+ '{END}',
];
$new = [
@@ -53,6 +55,8 @@ class WebApiGenerator extends BaseGenerator
$this->moduleName,
$this->getRouteGroupName(),
$this->getImport(),
+ $this->getBegin(),
+ $this->getEnd(),
];
$vmPath = $this->getvmPath('web_api');
@@ -79,7 +83,13 @@ class WebApiGenerator extends BaseGenerator
*/
public function getModuleOutDir()
{
- $dir = dirname(app()->getRootPath()) . '/admin/src/api/';
+ if(!empty($this->addonName))
+ {
+ $dir = dirname(app()->getRootPath()) . '/admin/src/api/';
+ }else{
+ $dir = dirname(app()->getRootPath()) . '/admin/src/app/api/';
+ }
+
$this->checkDir($dir);
return $dir;
}
@@ -101,14 +111,40 @@ class WebApiGenerator extends BaseGenerator
if(file_exists($file))
{
- $import = file_get_contents($file);
+
+ $content = file_get_contents($file);
+ $code_begin = 'USER_CODE_BEGIN -- '.$this->getTableName();
+ $code_end = 'USER_CODE_END -- '.$this->getTableName();
+
+ if(strpos($content,$code_begin) !== false && strpos($content,$code_end) !== false)
+ {
+ // 清除相应对应代码块
+ $pattern = "/\s+\/\/ {$code_begin}[\S\s]+\/\/ {$code_end}(\n,)?/";
+
+ $import = preg_replace($pattern, '', $content);
+
+ }else{
+ $import = $content;
+ }
}else{
- $import = "import request from '@//utils//request'";
+ $import = "import request from '@/utils/request'";
}
return $import;
}
+ public function getBegin()
+ {
+ $begin = '// USER_CODE_BEGIN -- '.$this->getTableName();
+ return $begin;
+ }
+
+ public function getEnd()
+ {
+ $end = '// USER_CODE_END -- '.$this->getTableName();
+ return $end;
+ }
+
/**
* 获取文件生成到runtime的文件夹路径
* @return string
@@ -137,7 +173,7 @@ class WebApiGenerator extends BaseGenerator
{
$dir = $this->rootDir . '/admin/src/'.$this->addonName.'/api/';
}else{
- $dir = $this->rootDir . '/admin/src/api/';
+ $dir = $this->rootDir . '/admin/src/app/api/';
}
$this->checkDir($dir);
diff --git a/niucloud/app/service/admin/generator/core/WebEditGenerator.php b/niucloud/app/service/admin/generator/core/WebEditGenerator.php
index 8058ab8ff..8457f786a 100644
--- a/niucloud/app/service/admin/generator/core/WebEditGenerator.php
+++ b/niucloud/app/service/admin/generator/core/WebEditGenerator.php
@@ -44,6 +44,9 @@ class WebEditGenerator extends BaseGenerator
'{PK}',
'{MODULE_NAME}',
'{API_PATH}',
+ '{DICT_DATA}',
+ '{DICT_LIST}',
+
];
$new = [
@@ -55,6 +58,8 @@ class WebEditGenerator extends BaseGenerator
$this->getPk(),
$this->moduleName,
$this->getApiPath(),
+ $this->getDictDataContent(),
+ $this->getDictList(),
];
$vmPath = $this->getvmPath('web_edit');
@@ -88,6 +93,8 @@ class WebEditGenerator extends BaseGenerator
return $this->setBlankSpace($content, ' ');
}
+
+
/**
* 获取表单内容
* @return string
@@ -104,15 +111,37 @@ class WebEditGenerator extends BaseGenerator
'{COLUMN_NAME}',
'{LCASE_COLUMN_NAME}',
'{PROP}',
- ];
- $new = [
- $column['column_comment'],
- $column['column_name'],
- Str::camel($column['column_name']),
- $column['is_required'] ? 'prop="'.$column['column_name'].'"' : ''
- ];
+ '{DICT_TYPE}',
- $vmPath = $this->getvmPath('form/' . $column['view_type']);
+ ];
+ if(empty($column['dict_type']))
+ {
+ $new = [
+ $column['column_comment'],
+ $column['column_name'],
+ Str::camel($column['column_name']),
+ $column['is_required'] ? 'prop="'.$column['column_name'].'"' : '',
+ ''
+ ];
+ if($column['view_type'] == 'select' || $column['view_type'] == 'radio' || $column['view_type'] == 'checkbox')
+ {
+ $vmName = $column['view_type'].'2';
+ }else{
+ $vmName = $column['view_type'];
+ }
+
+ }else{
+ $new = [
+ $column['column_comment'],
+ $column['column_name'],
+ Str::camel($column['column_name']),
+ $column['is_required'] ? 'prop="'.$column['column_name'].'"' : '',
+ $column['column_name'].'List',
+ ];
+ $vmName = $column['view_type'];
+ }
+
+ $vmPath = $this->getvmPath('form/' . $vmName);
if (!file_exists($vmPath)) {
continue;
}
@@ -127,11 +156,32 @@ class WebEditGenerator extends BaseGenerator
$old[] = '{ITEM_VALUE}';
$new[] = $vmItemValue;
}
-
+ // 数字框处理
+ if ($column['view_type'] == 'number') {
+ if(!empty($column['validate_type']))
+ {
+ $validate = json_decode($column['validate_type'],true);
+ if($validate[0] == 'min')
+ {
+ $rule = ':min = "'.$validate[1][0].'"';
+ }
+ if($validate[0] == 'max')
+ {
+ $rule = ':max = "'.$validate[1][0].'"';
+ }
+ if($validate[0] == 'between')
+ {
+ $rule = ':min = "'.$validate[1][0].'"'.' max = "'.$validate[1][1].'"';
+ }
+ }else{
+ $rule = '';
+ }
+ $old[] = '{RULE}';
+ $new[] = $rule;
+ }
$content .= $this->replaceFileText($old, $new, $vmPath) . PHP_EOL;
}
-
if (!empty($content)) {
$content = substr($content, 0, -1);
}
@@ -139,6 +189,63 @@ class WebEditGenerator extends BaseGenerator
return $this->setBlankSpace($content, ' ');
}
+ /**
+ * 获取数据字典内容
+ * @return string
+ */
+ public function getDictDataContent()
+ {
+ $content = '';
+ $isExist = [];
+ foreach ($this->tableColumn as $column) {
+ if (empty($column['dict_type']) || $column['is_pk']) {
+ continue;
+ }
+ if (in_array($column['dict_type'], $isExist)) {
+ continue;
+ }
+ $content .= $column['dict_type'] . ': ' . "[]," . PHP_EOL;
+ $isExist[] = $column['dict_type'];
+ }
+ if (!empty($content)) {
+ $content = substr($content, 0, -1);
+ }
+ return $this->setBlankSpace($content, ' ');
+ }
+
+
+ /**
+ * 获取API数据字典内容
+ * @return string
+ */
+ public function getDictDataApiContent()
+ {
+ $content = '';
+ $isExist = [];
+ foreach ($this->tableColumn as $column) {
+ if (empty($column['dict_type']) || $column['is_pk']) {
+ continue;
+ }
+ if (in_array($column['dict_type'], $isExist)) {
+ continue;
+ }
+ $needReplace = [
+ '{DICT_TYPE}',
+ ];
+ $waitReplace = [
+ $column['column_name'].'List',
+ ];
+ $templatePath = $this->getTemplatePath('/other/dictDataApi');
+ if (!file_exists($templatePath)) {
+ continue;
+ }
+ $content .= $this->replaceFileData($needReplace, $waitReplace, $templatePath) . '' . PHP_EOL;
+
+ $isExist[] = $column['dict_type'];
+ }
+ $content = substr($content, 0, -1);
+ return $content;
+ }
/**
* 获取表单默认字段内容
@@ -182,9 +289,9 @@ class WebEditGenerator extends BaseGenerator
$specDictType = ['input', 'textarea', 'editor'];
foreach ($this->tableColumn as $column) {
- if (!$column['is_required'] || $column['is_pk']) {
- continue;
- }
+// if (!$column['is_pk']) {
+// continue;
+// }
if (!$column['is_insert'] || !$column['is_update'] ) {
continue;
}
@@ -197,10 +304,18 @@ class WebEditGenerator extends BaseGenerator
$old = [
'{COLUMN_NAME}',
'{VALIDATE_MSG}',
+ '{VERIFY}'
];
+ if(!empty($column['validate_type']))
+ {
+ $validate = json_decode($column['validate_type'],true);
+ }else{
+ $validate = [];
+ }
$new = [
$column['column_name'],
$validateMsg,
+ $this->getVerify($validate)
];
$vmPath = $this->getvmPath('other/formValidate');
if (!file_exists($vmPath)) {
@@ -214,6 +329,39 @@ class WebEditGenerator extends BaseGenerator
return substr($content, 0, -2);
}
+ public function getVerify($validateType)
+ {
+ if(!empty($validateType))
+ {
+ if(!empty($validateType[1]))
+ {
+ if($validateType[0] == 'min')
+ {
+ $min = '0,'.$validateType[1][0];
+ $content = '{ validator: (rule: any, value: string, callback: any) => { '.
+ ' if (value && !/^\d{0,'.$min.'}$/.test(value)) {'.
+ "callback(new Error(t('".'generateMin'."')))".'} else { callback() }}},';
+ }
+ if($validateType[0] == 'max')
+ {
+ $max = '0,'.$validateType[1][0];
+ $content = '{ validator: (rule: any, value: string, callback: any) => { '.
+ ' if (value && !/^\d{0,'.$max.'}$/.test(value)) {'.
+ " callback(new Error(t('".'generateMax'."')))".' } else { callback() }}},';
+ }
+ if($validateType[0] == 'between')
+ {
+ $between = $validateType[1][0].','.$validateType[1][1];
+ $content = '{ validator: (rule: any, value: string, callback: any) => { '.
+ ' if (value && !/^\d{'.$between.'}$/.test(value)) {'. " callback(new Error(t('".'generateBetween'."')))".'} else { callback() }}},';
+ }
+ }
+ }else{
+ $content = '';
+ }
+
+ return $content;
+ }
/**
* 获取文件生成到模块的文件夹路径
@@ -243,7 +391,7 @@ class WebEditGenerator extends BaseGenerator
{
$dir = $this->outDir . '/addon/'.$this->addonName.'/admin/src/views/' . $this->moduleName . '/';
}else{
- $dir = $this->outDir . 'admin/src/views/' . $this->moduleName . '/';
+ $dir = $this->outDir . 'admin/src/app/views/' . $this->moduleName . '/';
}
$dir .= 'components/';
@@ -262,8 +410,7 @@ class WebEditGenerator extends BaseGenerator
{
$dir = $this->rootDir . '/admin/src/'.$this->addonName.'/views/'. $this->moduleName . '/';
}else{
-// $dir = '';
- $dir = $this->rootDir . '/admin/src/views/'. $this->moduleName . '/';
+ $dir = $this->rootDir . '/admin/src/app/views/'. $this->moduleName . '/';
}
$dir .= 'components/';
@@ -296,10 +443,8 @@ class WebEditGenerator extends BaseGenerator
if($this->table['edit_type'] != 1) {
return '';
}
- if($this->className){
- return Str::lower($this->className) . '-edit.vue';
- }
- return str_replace('_', '-', Str::lower($this->getTableName())).'-edit.vue';
+ return 'edit.vue';
+
}
/**
@@ -312,7 +457,31 @@ class WebEditGenerator extends BaseGenerator
{
return $this->addonName.'/api/'.$this->moduleName;
}else{
- return 'api/'.$this->moduleName;
+ return '/app/api/'.$this->moduleName;
}
}
+
+
+ /**
+ * 调用字典方法
+ * @return void
+ */
+ public function getDictList()
+ {
+ $content = '';
+ foreach ($this->tableColumn as $column)
+ {
+ if(empty($column['dict_type']))
+ {
+ continue;
+ }
+ $content.= 'let '.$column['column_name'].'List = ref([])'.PHP_EOL.'const '.$column['column_name'].'DictList = async () => {'.PHP_EOL.$column['column_name'].'List.value = await (await useDictionary(' ."'".$column['dict_type']."'".')).data.dictionary'.PHP_EOL.'}'.PHP_EOL. $column['column_name'].'DictList();'.PHP_EOL;
+ }
+
+ if(!empty($content))
+ {
+ $content = substr($content, 0, -1);
+ }
+ return $this->setBlankSpace($content, ' ');
+ }
}
diff --git a/niucloud/app/service/admin/generator/core/WebEditLangGenerator.php b/niucloud/app/service/admin/generator/core/WebEditLangGenerator.php
index a52ca861c..72860282d 100644
--- a/niucloud/app/service/admin/generator/core/WebEditLangGenerator.php
+++ b/niucloud/app/service/admin/generator/core/WebEditLangGenerator.php
@@ -132,7 +132,7 @@ class WebEditLangGenerator extends BaseGenerator
{
$dir = $this->rootDir . '/admin/src/'.$this->addonName.'/lang/zh-cn/';
}else{
- $dir = $this->rootDir . '/admin/src/lang/zh-cn/';
+ $dir = $this->rootDir . '/admin/src/app/lang/zh-cn/';
}
$this->checkDir($dir);
diff --git a/niucloud/app/service/admin/generator/core/WebEditPageGenerator.php b/niucloud/app/service/admin/generator/core/WebEditPageGenerator.php
index 58dedb131..01a72d313 100644
--- a/niucloud/app/service/admin/generator/core/WebEditPageGenerator.php
+++ b/niucloud/app/service/admin/generator/core/WebEditPageGenerator.php
@@ -45,6 +45,8 @@ class WebEditPageGenerator extends BaseGenerator
'{LCASE_CLASS_NAME}',
'{MODULE_NAME}',
'{API_PATH}',
+ '{DICT_DATA}',
+ '{DICT_LIST}'
];
$new = [
@@ -58,6 +60,8 @@ class WebEditPageGenerator extends BaseGenerator
$this->getLCaseClassName(),
$this->moduleName,
$this->getApiPath(),
+ $this->getDictDataContent(),
+ $this->getDictList(),
];
$vmPath = $this->getvmPath('web_edit_page');
@@ -68,6 +72,54 @@ class WebEditPageGenerator extends BaseGenerator
$this->setText($text);
}
+ /**
+ * 获取数据字典内容
+ * @return string
+ */
+ public function getDictDataContent()
+ {
+ $content = '';
+ $isExist = [];
+ foreach ($this->tableColumn as $column) {
+ if (empty($column['dict_type']) || $column['is_pk']) {
+ continue;
+ }
+ if (in_array($column['dict_type'], $isExist)) {
+ continue;
+ }
+ $content .= $column['dict_type'] . ': ' . "[]," . PHP_EOL;
+ $isExist[] = $column['dict_type'];
+ }
+ if (!empty($content)) {
+ $content = substr($content, 0, -1);
+ }
+ return $this->setBlankSpace($content, ' ');
+ }
+
+ /**
+ * 调用字典方法
+ * @return void
+ */
+ public function getDictList()
+ {
+ $content = '';
+ foreach ($this->tableColumn as $column)
+ {
+ if(empty($column['dict_type']))
+ {
+ continue;
+ }
+ $content.= 'let '.$column['column_name'].'List = ref([])'.PHP_EOL.'const '.$column['column_name'].'DictList = async () => {'.PHP_EOL.$column['column_name'].'List.value = await (await useDictionary(' ."'".$column['dict_type']."'".')).data.dictionary'.PHP_EOL.'}'.PHP_EOL. $column['column_name'].'DictList();'.PHP_EOL;
+ }
+
+ if(!empty($content))
+ {
+ $content = substr($content, 0, -1);
+ }
+ return $this->setBlankSpace($content, ' ');
+ }
+
+
/**
* 表单日期处理
* @return string
@@ -108,15 +160,36 @@ class WebEditPageGenerator extends BaseGenerator
'{COLUMN_NAME}',
'{LCASE_COLUMN_NAME}',
'{PROP}',
+ '{DICT_TYPE}',
];
- $new = [
- $column['column_comment'],
- $column['column_name'],
- Str::camel($column['column_name']),
- $column['is_required'] ? 'prop="'.$column['column_name'].'"' : ''
- ];
+ if(empty($column['dict_type']))
+ {
+ $new = [
+ $column['column_comment'],
+ $column['column_name'],
+ Str::camel($column['column_name']),
+ $column['is_required'] ? 'prop="'.$column['column_name'].'"' : '',
+ ''
+ ];
+ if($column['view_type'] == 'select' || $column['view_type'] == 'radio' || $column['view_type'] == 'checkbox')
+ {
+ $vmName = $column['view_type'].'2';
+ }else{
+ $vmName = $column['view_type'];
+ }
- $vmPath = $this->getvmPath('form/' . $column['view_type']);
+ }else{
+ $new = [
+ $column['column_comment'],
+ $column['column_name'],
+ Str::camel($column['column_name']),
+ $column['is_required'] ? 'prop="'.$column['column_name'].'"' : '',
+ $column['column_name'].'List',
+ ];
+ $vmName = $column['view_type'];
+ }
+
+ $vmPath = $this->getvmPath('form/' . $vmName);
if (!file_exists($vmPath)) {
continue;
}
@@ -131,7 +204,32 @@ class WebEditPageGenerator extends BaseGenerator
$old[] = '{ITEM_VALUE}';
$new[] = $vmItemValue;
}
+ // 数字框处理
+ if ($column['view_type'] == 'number') {
+ if(!empty($column['validate_type']))
+ {
+ $validate = json_decode($column['validate_type'],true);
+ if($validate[0] == 'min')
+ {
+ $rule = ':min = '."'".$validate[1][0]."'";
+ }
+ if($validate[0] == 'max')
+ {
+ $rule = ':max = '."'".$validate[1][0]."'";
+ }
+ if($validate[0] == 'between')
+ {
+ $rule = ':min = "'.$validate[1][0].'"'.' :max = "'.$validate[1][1].'"';
+ }
+ $old[] = '{RULE}';
+ $new[] = $rule;
+ dd($rule);
+ }else{
+ $old[] = '{RULE}';
+ $new[] = '';
+ }
+ }
$content .= $this->replaceFileText($old, $new, $vmPath) . PHP_EOL;
}
@@ -139,7 +237,6 @@ class WebEditPageGenerator extends BaseGenerator
if (!empty($content)) {
$content = substr($content, 0, -1);
}
-
return $this->setBlankSpace($content, ' ');
}
@@ -188,9 +285,6 @@ class WebEditPageGenerator extends BaseGenerator
$specDictType = ['input', 'textarea', 'editor'];
foreach ($this->tableColumn as $column) {
- if (!$column['is_required'] || $column['is_pk']) {
- continue;
- }
if (!$column['is_insert'] || !$column['is_update'] ) {
continue;
}
@@ -203,10 +297,18 @@ class WebEditPageGenerator extends BaseGenerator
$old = [
'{COLUMN_NAME}',
'{VALIDATE_MSG}',
+ '{VERIFY}'
];
+ if(!empty($column['validate_type']))
+ {
+ $validate = json_decode($column['validate_type'],true);
+ }else{
+ $validate = [];
+ }
$new = [
$column['column_name'],
$validateMsg,
+ $this->getVerify($validate)
];
$vmPath = $this->getvmPath('other/formValidate');
if (!file_exists($vmPath)) {
@@ -220,6 +322,44 @@ class WebEditPageGenerator extends BaseGenerator
return substr($content, 0, -2);
}
+ /**
+ * 输入信息验证
+ * @param $validateType
+ * @return string
+ */
+ public function getVerify($validateType)
+ {
+ if(!empty($validateType))
+ {
+ if(!empty($validateType[1]))
+ {
+ if($validateType[0] == 'min')
+ {
+ $min = '0,'.$validateType[1][0];
+ $content = '{ validator: (rule: any, value: string, callback: any) => { '.
+ ' if (value && !/^\d{0,'.$min.'}$/.test(value)) {'.
+ "callback(new Error(t('".'generateMin'."')))".'} else { callback() }}},';
+ }
+ if($validateType[0] == 'max')
+ {
+ $max = '0,'.$validateType[1][0];
+ $content = '{ validator: (rule: any, value: string, callback: any) => { '.
+ ' if (value && !/^\d{0,'.$max.'}$/.test(value)) {'.
+ " callback(new Error(t('".'generateMax'."')))".' } else { callback() }}},';
+ }
+ if($validateType[0] == 'between')
+ {
+ $between = $validateType[1][0].','.$validateType[1][1];
+ $content = '{ validator: (rule: any, value: string, callback: any) => { '.
+ ' if (value && !/^\d{'.$between.'}$/.test(value)) {'. " callback(new Error(t('".'generateBetween'."')))".'} else { callback() }}},';
+ }
+ }
+ }else{
+ $content = '';
+ }
+
+ return $content;
+ }
/**
* 获取文件生成到模块的文件夹路径
@@ -247,13 +387,11 @@ class WebEditPageGenerator extends BaseGenerator
}
if(!empty($this->addonName))
{
- $dir = $this->outDir . 'addon/'.$this->addonName.'/admin/src/views/' . $this->moduleName . '/';
-
+ $dir = $this->outDir . '/addon/'.$this->addonName.'/admin/src/views/' . $this->moduleName . '/';
}else{
- $dir = $this->outDir . 'admin/src/views/' . $this->moduleName . '/';
+ $dir = $this->outDir . 'admin/src/app/views/' . $this->moduleName . '/';
}
-
$this->checkDir($dir);
return $dir;
@@ -268,11 +406,12 @@ class WebEditPageGenerator extends BaseGenerator
if($this->table['edit_type'] != 2) {
return '';
}
+
if(!empty($this->addonName))
{
- $dir = $this->rootDir . '/admin/src/'.$this->addonName.'/views/'.$this->moduleName.'/';
+ $dir = $this->rootDir . '/admin/src/'.$this->addonName.'/views/'. $this->moduleName . '/';
}else{
- $dir = $this->rootDir . '/admin/src/views/' . $this->moduleName . '/';
+ $dir = $this->rootDir . '/admin/src/app/views/'. $this->moduleName . '/';
}
$this->checkDir($dir);
@@ -284,13 +423,14 @@ class WebEditPageGenerator extends BaseGenerator
if($this->table['edit_type'] != 2) {
return '';
}
+
if(!empty($this->addonName))
{
$dir = 'addon/'.$this->addonName.'/admin/'.$this->addonName.'/views/' . $this->moduleName . '/';
-
}else{
$dir = 'admin/app/views/' . $this->moduleName . '/';
}
+
return $dir;
}
@@ -303,9 +443,9 @@ class WebEditPageGenerator extends BaseGenerator
if($this->table['edit_type'] != 2) {
return '';
}
- if($this->className){
- return Str::lower($this->className).'_edit.vue';
- }
+// if($this->className){
+// return Str::lower($this->className).'_edit.vue';
+// }
return 'edit.vue';
}
@@ -319,7 +459,8 @@ class WebEditPageGenerator extends BaseGenerator
{
return $this->addonName.'/api/'.$this->moduleName;
}else{
- return 'api/'.$this->moduleName;
+ return '/app/api/'.$this->moduleName;
}
+
}
}
diff --git a/niucloud/app/service/admin/generator/core/WebIndexGenerator.php b/niucloud/app/service/admin/generator/core/WebIndexGenerator.php
index b154e409e..25338eee5 100644
--- a/niucloud/app/service/admin/generator/core/WebIndexGenerator.php
+++ b/niucloud/app/service/admin/generator/core/WebIndexGenerator.php
@@ -49,6 +49,7 @@ class WebIndexGenerator extends BaseGenerator
'{ADD_EVENT}',
'{EDIT_EVENT}',
'{API_PATH}',
+ '{DICT_LIST}'
];
$new = [
@@ -68,6 +69,8 @@ class WebIndexGenerator extends BaseGenerator
$this->getAddEvent(),
$this->getEditEvent(),
$this->getApiPath(),
+// $this->getDictDataContent(),
+ $this->getDictList(),
];
$vmPath = $this->getvmPath('web_index');
@@ -101,15 +104,16 @@ class WebIndexGenerator extends BaseGenerator
{
if($this->table['edit_type'] == 2) return "import { useRouter } from 'vue-router'";
$path = 'components/';
- $file_name = str_replace('_', '-', Str::lower($this->getTableName())).'-edit.vue';
- if($this->className){
- $file_name = Str::lower($this->className) . '-edit.vue';
- }
+// $file_name = str_replace('_', '-', Str::lower($this->getTableName())).'-edit.vue';
+ $file_name = 'edit.vue';
+// if($this->className){
+// $file_name = Str::lower($this->className) . '-edit.vue';
+// }
if(!empty($this->addonName))
{
- return "import ".$this->getUCaseClassName()."Edit from '@/".$this->addonName."/views/".$this->moduleName."/".$path.$file_name."'";
+ return "import "."Edit from '@/".$this->addonName."/views/".$this->moduleName."/".$path.$file_name."'";
}else{
- return "import ".$this->getUCaseClassName()."Edit from '@/views/".$this->moduleName."/".$path.$file_name."'";
+ return "import "."Edit from '@/app/views/".$this->moduleName."/".$path.$file_name."'";
}
}
@@ -120,13 +124,8 @@ class WebIndexGenerator extends BaseGenerator
public function getEditView()
{
if($this->table['edit_type'] == 2) return '';
-
- $file_name = str_replace('_', '-', Str::lower($this->getTableName())).'-edit';
- if($this->className){
- $file_name = Str::lower($this->className) . '-edit';
- }
-
- return '<'.$file_name.' ref="edit'.$this->getUCaseClassName().'Dialog" @complete="load'.$this->getUCaseName().'List" />';
+ $file_name = 'edit';
+ return '<'.$file_name.' ref="edit'.$this->getUCaseClassName().'Dialog" @complete="load'.$this->getUCaseClassName().'List" />';
}
/**
@@ -148,7 +147,7 @@ class WebIndexGenerator extends BaseGenerator
$class_name = $this->className ? '/'.Str::lower($this->className) : '';
if($this->table['edit_type'] == 2){
//打开新页面
- $content = "router.push('/".$this->moduleName.$class_name."/edit')";
+ $content = "router.push('/".$this->moduleName."/edit')";
}else{
$content = 'edit'.$this->getUCaseClassName().'Dialog.value.setFormData()'.PHP_EOL.'edit'.$this->getUCaseClassName().'Dialog.value.showDialog = true';
}
@@ -165,7 +164,7 @@ class WebIndexGenerator extends BaseGenerator
{
$class_name = $this->className ? '/'.Str::lower($this->className) : '';
if($this->table['edit_type'] == 2){
- $content = "router.push('/".$this->moduleName.$class_name."/edit?id='+data.".$this->getPk().")";
+ $content = "router.push('/".$this->moduleName."/edit?id='+data.".$this->getPk().")";
}else{
$content = 'edit'.$this->getUCaseClassName().'Dialog.value.setFormData(data)'.PHP_EOL.'edit'.$this->getUCaseClassName().'Dialog.value.showDialog = true';
}
@@ -191,18 +190,40 @@ class WebIndexGenerator extends BaseGenerator
'{LCASE_CLASS_NAME}',
'{LCASE_COLUMN_NAME}',
];
- $new = [
- $column['column_comment'],
- $column['column_name'],
- $column['dict_type'],
- $this->getLCaseClassName(),
- Str::camel($column['column_name']),
- ];
+ if(empty($column['dict_type']))
+ {
+ $new = [
+ $column['column_comment'],
+ $column['column_name'],
+ $column['dict_type'],
+ $this->getLCaseClassName(),
+ Str::camel($column['column_name']),
+ ];
+ }else{
+ $new = [
+ $column['column_comment'],
+ $column['column_name'],
+ $column['column_name'].'List',
+ $this->getLCaseClassName(),
+ Str::camel($column['column_name']),
+ ];
+ }
+
$searchVmType = $column['view_type'];
if ($column['view_type'] == 'radio') {
$searchVmType = 'select';
}
+ if(empty($column['dict_type']))
+ {
+ if ($column['view_type'] == 'radio' || $column['view_type'] == 'select' || $column['view_type'] == 'checkbox' ) {
+ $searchVmType = 'select2';
+ }
+ }else{
+ if ($column['view_type'] == 'radio') {
+ $searchVmType = 'select';
+ }
+ }
$vmPath = $this->getvmPath('search/' . $searchVmType);
if (!file_exists($vmPath)) {
@@ -357,7 +378,7 @@ class WebIndexGenerator extends BaseGenerator
{
$dir = $this->rootDir . '/admin/src/'.$this->addonName.'/views/'. $this->moduleName . '/';
}else{
- $dir = $this->rootDir . '/admin/src/views/' . $this->moduleName . '/';
+ $dir = $this->rootDir . '/admin/src/app/views/' . $this->moduleName . '/';
}
$this->checkDir($dir);
@@ -381,7 +402,7 @@ class WebIndexGenerator extends BaseGenerator
*/
public function getFileName()
{
- if($this->className) return Str::lower($this->className).'_list.vue';
+// if($this->className) return Str::lower($this->className).'_list.vue';
return 'list.vue';
}
@@ -393,9 +414,58 @@ class WebIndexGenerator extends BaseGenerator
{
if(!empty($this->addonName))
{
- return $this->addonName.'/api/'.$this->moduleName;
+ return '/'.$this->addonName.'/api/'.$this->moduleName;
}else{
- return 'api/'.$this->moduleName;
+ return '/app/api/'.$this->moduleName;
}
}
+
+ public function getDictDataContent()
+ {
+ $content = '';
+ $isExist = [];
+ foreach ($this->tableColumn as $column) {
+ if (empty($column['dict_type']) || $column['is_pk']) {
+ continue;
+ }
+ if (in_array($column['dict_type'], $isExist)) {
+ continue;
+ }
+ $content .= $column['dict_type'] . ': ' . "[]," . PHP_EOL;
+ $isExist[] = $column['dict_type'];
+ }
+ if (!empty($content)) {
+ $content = substr($content, 0, -1);
+ }
+ return $this->setBlankSpace($content, ' ');
+ }
+
+
+ /**
+ * 调用字典方法
+ * @return void
+ */
+ public function getDictList()
+ {
+ $content = '';
+ foreach ($this->tableColumn as $column)
+ {
+ if(empty($column['dict_type']))
+ {
+ continue;
+ }
+ if($column['view_type'] == 'select')
+ {
+ $content.= 'let '.$column['column_name'].'List = ref([])'.PHP_EOL.'const '.$column['column_name'].'DictList = async () => {'.PHP_EOL.$column['column_name'].'List.value = await (await useDictionary(' ."'".$column['dict_type']."'".')).data.dictionary'.PHP_EOL.'}'.PHP_EOL. $column['column_name'].'DictList();'.PHP_EOL;
+
+ }
+ }
+
+ if(!empty($content))
+ {
+ $content = substr($content, 0, -1);
+ }
+
+ return $this->setBlankSpace($content, ' ');
+ }
}
diff --git a/niucloud/app/service/admin/generator/core/WebLangGenerator.php b/niucloud/app/service/admin/generator/core/WebLangGenerator.php
index 2bdd254b0..9cce00b03 100644
--- a/niucloud/app/service/admin/generator/core/WebLangGenerator.php
+++ b/niucloud/app/service/admin/generator/core/WebLangGenerator.php
@@ -75,7 +75,7 @@ class WebLangGenerator extends BaseGenerator
}
$lang .= '"add'.$this->getUCaseClassName() .'":"添加'.$table_content.'",'.PHP_EOL;
$lang .= '"update'.$this->getUCaseClassName() .'":"编辑'.$table_content.'",'.PHP_EOL;
- $lang .= '"'.$this->getLCaseClassName() .'DeleteTips":"确定要删除该'.$table_content.'吗?",'.PHP_EOL;
+ $lang .= '"'.$this->getLCaseClassName() .'DeleteTips":"确定要删除该数据吗?",'.PHP_EOL;
$lang = trim(trim($lang), ',');
return '{'.PHP_EOL.$this->setBlankSpace($lang, " ").PHP_EOL.'}';
}
@@ -120,7 +120,7 @@ class WebLangGenerator extends BaseGenerator
{
$dir = $this->rootDir . '/admin/src/'.$this->addonName.'/lang/zh-cn/';
}else{
- $dir = $this->rootDir . '/admin/src/lang/zh-cn/';
+ $dir = $this->rootDir . '/admin/src/app/lang/zh-cn/';
}
$this->checkDir($dir);
@@ -146,7 +146,7 @@ class WebLangGenerator extends BaseGenerator
public function getFileName()
{
if($this->className){
- return $this->moduleName.'.'.Str::lower($this->className).'_list.json';
+ return $this->moduleName.'.'.'list.json';
}
return $this->moduleName.'.list.json';
}
diff --git a/niucloud/app/service/admin/generator/vm/admin_api_route.vm b/niucloud/app/service/admin/generator/vm/admin_api_route.vm
index 88c84d7f6..1fd2cf0d4 100644
--- a/niucloud/app/service/admin/generator/vm/admin_api_route.vm
+++ b/niucloud/app/service/admin/generator/vm/admin_api_route.vm
@@ -1,9 +1,9 @@
{ROUTE}
+{BEGIN}
Route::group('{ROUTE_GROUP_NAME}', function () {
- /***************************************************** {NOTES}管理 ****************************************************/
//{NOTES}列表
Route::get('{ROUTE_NAME}', '{ROUTE_PATH}lists');
//{NOTES}详情
@@ -20,3 +20,4 @@ Route::group('{ROUTE_GROUP_NAME}', function () {
AdminCheckRole::class,
AdminLog::class
]);
+{END}
diff --git a/niucloud/app/service/admin/generator/vm/form/checkbox.vm b/niucloud/app/service/admin/generator/vm/form/checkbox.vm
index bc5f957c8..6782ea691 100644
--- a/niucloud/app/service/admin/generator/vm/form/checkbox.vm
+++ b/niucloud/app/service/admin/generator/vm/form/checkbox.vm
@@ -1,6 +1,11 @@
-