From 71279b2439afeb02b21004fb6f981387adf04907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=94=E5=AD=90?= <49477914+racns@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:10:03 +0800 Subject: [PATCH] v2.0.1 --- app/admin/controller/Base.php | 2 +- app/api/controller/default/Location.php | 6 +- app/install/controller/Handle.php | 90 +++++++----------------- composer.json | 2 +- config/inis.php | 4 +- config/inis_db.php | 92 +++++++++++++++++++++++++ public/admin/js/install/index.js | 46 ++++--------- public/admin/js/pages/login.js | 16 +++++ 8 files changed, 152 insertions(+), 106 deletions(-) create mode 100644 config/inis_db.php diff --git a/app/admin/controller/Base.php b/app/admin/controller/Base.php index c819952..3d16e2b 100644 --- a/app/admin/controller/Base.php +++ b/app/admin/controller/Base.php @@ -59,7 +59,7 @@ public function initialize() // 开启了自动更新 $autoUpdate = Options::where(['keys'=>'config:system'])->value('opt'); - $autoUpdate = json_decode($autoUpdate, true); + $autoUpdate = json_decode($autoUpdate ?? '', true); $autoUpdate = $autoUpdate['system']['autoUpdate'] ?? false; $autoUpdate = $autoUpdate == 'true' or $autoUpdate === true ? true : false; diff --git a/app/api/controller/default/Location.php b/app/api/controller/default/Location.php index 65e6487..97aad43 100644 --- a/app/api/controller/default/Location.php +++ b/app/api/controller/default/Location.php @@ -108,7 +108,7 @@ public function ip($request) $code = 400; $msg = Lang::get('无数据!'); - $ip = !empty($param['ip']) ? $param['ip'] : $this->helper->GetClientIP(); + $ip = !empty($param['ip']) ? $param['ip'] : $this->utils->get->ip()['ip']; // 设置缓存名称 $cache_name = json_encode(array_merge(['IAPI'=>'location'], $param)); @@ -118,12 +118,12 @@ public function ip($request) else { // 获取数据 - $result = $this->helper->get($this->config['official']['api'] . 'gothe', ['ip'=>$ip], ['origin'=>$this->helper->domain()]); + $result = $this->utils->curl->get($this->config['official']['api'] . 'gothe', ['ip'=>$ip], ['origin'=>$this->helper->domain()]); if ($result['code'] == 200) $data = $result['data']; else $data = $result; - if ($this->ApiCache) Cache::tag(['gothe',$cache_name])->set($cache_name, json_encode($data)); + if ($this->ApiCache) Cache::tag(['gothe', $cache_name])->set($cache_name, json_encode($data)); } diff --git a/app/install/controller/Handle.php b/app/install/controller/Handle.php index d2f39a4..f3b22b0 100644 --- a/app/install/controller/Handle.php +++ b/app/install/controller/Handle.php @@ -11,13 +11,11 @@ class Handle extends BaseController { protected $File; protected $helper; - protected $DBUPDATE; public function __construct() { $this->File = new File; $this->helper = new helper; - $this->DBUPDATE = Config::get('dbupdate'); $path = app()->getRootPath() . '/extend'; $dir = $this->File->getDir($path)['dir']; @@ -164,58 +162,48 @@ public function fulfill() $this->File->unlinkFile('install.env'); $this->File->writeFile($route, $text); } - - // 批量建表 - public function createTables(Request $request) + + // 批量导入数据 + public function initDB(Request $request) { - if ($request->isPost()) - { + + if ($request->isPost()) { + $data = []; $code = 200; $msg = 'ok'; - + $param = $request->param(); $db = !empty($param['db']) ? $param['db'] : 'mysql'; - // 获取表信息 - $tabs = $this->helper->get(config('inis.official.api') . $db . '/created'); + // 获取数据信息 + $array = config('inis_db.' . $db); - if ($tabs['code'] != 200) return $this->create([], $tabs['msg'], 400); + try { - // 数据库 - $conn = Db::connect($db); + foreach ($array as $key => $val) { - // SQL 语句 - $sqls = []; - if (!empty($tabs['data'])) { + // 数据库 + $conn = Db::connect($db); - // mysql 驱动 - if ($db == 'mysql') foreach ($tabs['data'] as $key => $val) { + // 如果表不存在,先创建该表 + if (!in_array($key, $conn->getTables())) $conn->execute($val['sql']); - // 如果表已存在,先删除该表 - if (in_array($key, $conn->getTables())) $conn->execute('DROP TABLE '. $key); + if (!empty($val['data'])) { - $sqls[] = $val; - // 重新设置自增起始值 - $sqls[] = "ALTER TABLE " . $key . " AUTO_INCREMENT=1;"; - } - // sqlite 驱动 - else if ($db == 'sqlite') foreach ($tabs['data'] as $key => $val) { - - // 如果表已存在,先删除该表 - if (in_array($key, $conn->getTables())) $conn->execute('DROP TABLE '. $key); + // 重新设置自增起始值 + $conn->execute("ALTER TABLE " . $key . " AUTO_INCREMENT=1;"); + + // 清空表数据 + $conn->execute('TRUNCATE TABLE ' . $key); - $sqls[] = $val; + // 批量插入数据 + $conn->table($key)->insertAll($val['data']); + } } - } - - try { - // 执行 SQL 语句 - if (!empty($sqls)) foreach ($sqls as $val) $conn->execute($val); - } catch (\Exception $e) { - + $code = 400; $msg = $e->getMessage(); } @@ -223,32 +211,4 @@ public function createTables(Request $request) return $this->create($data, $msg, $code); } } - - // 批量导入数据 - public function insertAll(Request $request) - { - if ($request->isPost()) - { - $data = []; - $code = 200; - $msg = 'ok'; - $param = $request->param(); - - $db = !empty($param['db']) ? $param['db'] : 'mysql'; - - // 获取默认数据 - $result= $this->helper->get(config('inis.official.api') . $db . '/data'); - - // 估计是没有权限 - 或者网络问题 - if ($result['code'] != 200) return $this->create([], $result['msg'], (int)$result['code']); - - // 先判断数据有没有 - if (!empty($result['data'])) foreach ($result['data'] as $key => $val) { - // 批量插入数据 - Db::connect($db)->table($key)->insertAll($val); - } - - return $this->create($result, $msg, $code); - } - } } \ No newline at end of file diff --git a/composer.json b/composer.json index 84f323f..d3ccfc3 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=8.0.0", "topthink/framework": "^6.0.0", "topthink/think-orm": "^2.0", "topthink/think-view": "^1.0", diff --git a/config/inis.php b/config/inis.php index 68cbf5a..5821830 100644 --- a/config/inis.php +++ b/config/inis.php @@ -15,7 +15,7 @@ ], 'valid_time' => 5 * 60, // 验证码有效时间 - 单位秒 'jwt' => [ - 'key' => 'inis-api', // KEY - 用于校验 TOKEN 是否合法 + 'key' => 'inis-api-asd', // KEY - 用于校验 TOKEN 是否合法 'encrypt' => 'HS256', // 加密方式 'array' => ['HS256','HS384','HS512'], // 可用加密方式 ], @@ -65,5 +65,5 @@ ] ], - 'version' => '2.0.0', // inis 版本号 - 请不要自行更改,后果自负 + 'version' => '2.0.1', // inis 版本号 - 请不要自行更改,后果自负 ]; diff --git a/config/inis_db.php b/config/inis_db.php new file mode 100644 index 0000000..2937547 --- /dev/null +++ b/config/inis_db.php @@ -0,0 +1,92 @@ + [ + 'inis_article'=>[ + 'sql' => "CREATE TABLE `inis_article` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `title` varchar(255) CHARACTER SET utf8mb4 DEFAULT '未命名文章' COMMENT '标题',\n `description` text CHARACTER SET utf8mb4 COMMENT '摘要',\n `content` longtext CHARACTER SET utf8mb4 COMMENT '内容',\n `is_top` int(255) DEFAULT '0' COMMENT '是否置顶',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `img_src` varchar(255) DEFAULT NULL COMMENT '图片地址',\n `views` int(255) DEFAULT NULL COMMENT '浏览次数',\n `font_count` int(255) DEFAULT NULL COMMENT '字数统计',\n `sort_id` text COMMENT '分类ID',\n `tag_id` text COMMENT '标签ID',\n `users_id` int(255) DEFAULT NULL COMMENT '用户ID',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `delete_time` varchar(255) DEFAULT NULL COMMENT '删除时间',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间\\\n',\n `last_update_time` varchar(255) DEFAULT NULL COMMENT '最后修改时间',\n PRIMARY KEY (`id`),\n UNIQUE KEY `id` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data' => [ + ['title'=>'欢迎使用,inis 博客系统','description'=>'当你看到这篇文章,就表示您的系统已经搭建成功!','content'=>'当你看到这篇文章,就表示您的系统已经搭建成功!','font_count'=>18,'users_id'=>1,'create_time'=>time(),'update_time'=>time(),'opt'=>'{"password":"","auth":"anyone","comments":{"show":"true","allow":"true"}}','last_update_time'=>time()], + ] + ], + 'inis_article_sort'=>[ + 'sql'=>"CREATE TABLE `inis_article_sort` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `name` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '分类名称',\n `description` text COMMENT '分类描述',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + 'data'=>[ + ['name'=>'默认分类','description'=>'默认分类','is_show'=>1,'create_time'=>time(),'update_time'=>time()], + ] + ], + 'inis_banner' => [ + 'sql'=>"CREATE TABLE `inis_banner` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) DEFAULT NULL COMMENT '标题',\n `description` varchar(255) DEFAULT NULL COMMENT '描述',\n `url` varchar(255) DEFAULT NULL COMMENT '跳转地址',\n `img` varchar(255) DEFAULT NULL COMMENT '图片地址',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_comments'=>[ + 'sql'=>"CREATE TABLE `inis_comments` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `pid` int(255) DEFAULT '0' COMMENT '父ID',\n `content` text CHARACTER SET utf8mb4 COMMENT '评论内容',\n `nickname` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '评论者昵称',\n `email` varchar(255) DEFAULT NULL COMMENT '用户邮箱',\n `url` varchar(255) DEFAULT NULL COMMENT '用户网址',\n `ip` varchar(255) DEFAULT NULL COMMENT 'IP',\n `type` varchar(255) DEFAULT 'article' COMMENT '评论属性',\n `status` int(255) DEFAULT '1' COMMENT '状态',\n `agent` text COMMENT '代理信息',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `users_id` int(255) DEFAULT NULL COMMENT '评论者',\n `article_id` int(255) DEFAULT NULL COMMENT '外键',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(255) DEFAULT NULL COMMENT '修改时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_music' => [ + 'sql'=>"CREATE TABLE `inis_music` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) DEFAULT NULL COMMENT '标题',\n `description` varchar(255) DEFAULT NULL COMMENT '描述',\n `url` varchar(255) DEFAULT NULL COMMENT '音乐地址',\n `head_img` varchar(255) DEFAULT NULL COMMENT '头像地址',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data'=>[ + ['title'=>'默认歌单','url'=>'https://c.y.qq.com/base/fcgi-bin/u?__=ZhpZFd43','head_img'=>'//q.qlogo.cn/g?b=qq&nk=97783391&s=640','create_time'=>time(),'update_time'=>time()] + ] + ], + 'inis_page' => [ + 'sql'=>"CREATE TABLE `inis_page` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '标题',\n `alias` varchar(255) DEFAULT NULL COMMENT '别名',\n `content` longtext CHARACTER SET utf8mb4 COMMENT '内容',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data'=>[ + ['title'=>'友链库','alias'=>'links','content'=>'友链库页面,自由发挥!','create_time'=>time(),'update_time'=>time()] + ] + ], + 'inis_links'=>[ + 'sql'=>"CREATE TABLE `inis_links` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `name` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '昵称',\n `url` varchar(255) DEFAULT NULL COMMENT '地址',\n `head_img` varchar(255) DEFAULT NULL COMMENT '头像',\n `description` varchar(255) CHARACTER SET utf8mb4 DEFAULT '这是一个很神秘的人!' COMMENT '描述',\n `sort_id` int(255) DEFAULT NULL COMMENT '分类ID',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(11) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(11) DEFAULT NULL COMMENT '修改时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_links_sort'=>[ + 'sql'=>"CREATE TABLE `inis_links_sort` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `name` varchar(255) DEFAULT NULL COMMENT '分类名称',\n `description` text COMMENT '分类描述',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data'=>[ + ['name'=>'默认分组','description'=>'这是默认的友链分组','create_time'=>time(),'update_time'=>time()] + ] + ], + 'inis_options'=>[ + 'sql'=>"CREATE TABLE `inis_options` (\n `keys` varchar(255) NOT NULL COMMENT '键',\n `value` longtext CHARACTER SET utf8mb4 COMMENT '值',\n `opt` longtext CHARACTER SET utf8mb4 COMMENT 'JSON字段',\n PRIMARY KEY (`keys`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + 'data'=>[ + ['keys'=>'config:email-serve','opt'=>'{"port": "587", "smtp": "smtp.qq.com", "email": "", "encry": "tls", "encoded": "UTF-8", "email_cc": "", "nickname": "inis", "password": ""}','value'=>'{"template_1":"

您的《{article}》有了新的评论:

{nickname} 给您的评论:

{text}

详细信息:

IP:{ip}
邮箱:{email}

查看回复的完整內容

©2019-2021 Copyright{site}

","template_2":"
亲爱的{nickname}

您在《{article}》的评论有了新的回复:

您的评论:

{text}

{author} 给您的回复:

{content}

萤火虫消失之后,那光的轨迹仍久久地印在我的脑际。那微弱浅淡的光点,仿佛迷失方向的魂灵,在漆黑厚重的夜幕中彷徨。——《挪威的森林》村上春树

查看回复的完整內容

本邮件为系统自动发送,请勿直接回复~

©2019-2021 Copyright{site}

","template_3":"
{email},您好!

以下是您用于验证身份的验证码,请在{valid_time}内输入并完成验证。如非本人操作,请忽略此邮件。


{code}




此邮件由系统自动发出,系统不接受回信,因此请勿直接回复。
安全使用您的帐号注意事项:
1、请不要在其他网站上使用相同的邮箱和密码进行注册。
2、请不要告知任何人您的帐号密码信息。

如果您错误的收到本电子邮件,请您忽略上述内容。



{site}
{time}
"}'], + ['keys'=>'config:security','opt'=>'{"token": {"open": 0, "value": "", "status": 0}, "domain": {"status": 0}}','value'=>'*'], + ['keys'=>'site','opt'=>'{"title":"INIS API","keywords":"INIS API,inis博客系统,inis程序,inis系统","description":"inis · 新一代博客系统!这是市面上为数不多的新一代博客系统,整站封装,全站分离,真正意义上的前后端分离。每一行代码都用心设计,用最少的代码量和最优雅架构设计,实现最完美的系统,让你拥有更极致的体验。复杂的研究留给我们,简单的体验留给用户!","image":"\/\/q.qlogo.cn\/g?b=qq&nk=97783391&s=640","favicon":"\/\/q.qlogo.cn\/g?b=qq&nk=97783391&s=640","url":"","copy":"备案号"}','value'=>null], + ['keys'=>'config:applets','opt'=>'{"qq":{"show":{"comments":"true"}},"wechat":{"show":{"comments":"true"}},"other":{"show":{"comments":"true"}}}','value'=>null], + ['keys'=>'config:system','opt'=>'{"article":{"comments":{"show":"true","allow":"true"}},"optimize":{"cdn":""}}','value'=>null], + ] + ], + 'inis_log'=>[ + 'sql'=>"CREATE TABLE `inis_log` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `types` varchar(255) DEFAULT NULL COMMENT '日志类型',\n `ip` varchar(255) DEFAULT NULL COMMENT 'IP',\n `content` varchar(255) DEFAULT NULL COMMENT '内容',\n `msg` varchar(255) DEFAULT NULL COMMENT '备注',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_placard'=>[ + 'sql'=>"CREATE TABLE `inis_placard` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) DEFAULT NULL COMMENT '标题',\n `type` varchar(255) DEFAULT NULL COMMENT '类型',\n `content` varchar(255) DEFAULT NULL COMMENT '内容',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_tag'=>[ + 'sql'=>"CREATE TABLE `inis_tag` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `name` varchar(255) DEFAULT NULL COMMENT '标签名称',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_users'=>[ + 'sql'=>"CREATE TABLE `inis_users` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `account` varchar(52) DEFAULT NULL COMMENT '帐号',\n `password` varchar(255) NOT NULL COMMENT '密码',\n `nickname` varchar(32) CHARACTER SET utf8mb4 NOT NULL COMMENT '昵称',\n `sex` varchar(32) DEFAULT '保密' COMMENT '性别',\n `email` varchar(255) NOT NULL COMMENT '邮箱',\n `phone` varchar(255) DEFAULT NULL COMMENT '手机',\n `head_img` varchar(255) DEFAULT NULL COMMENT '头像地址',\n `description` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '描述',\n `status` int(11) NOT NULL DEFAULT '1' COMMENT '状态',\n `level` varchar(255) DEFAULT 'user' COMMENT '分组',\n `address_url` varchar(255) DEFAULT NULL COMMENT '主页地址',\n `remarks` varchar(255) DEFAULT NULL COMMENT '备注',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n `last_login_time` varchar(255) DEFAULT NULL COMMENT '上次登录时间',\n PRIMARY KEY (`id`),\n UNIQUE KEY `id` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + ], + 'inis_verify_code'=>[ + 'sql'=>"CREATE TABLE `inis_verify_code` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `code` varchar(255) DEFAULT NULL COMMENT '验证码',\n `types` varchar(255) DEFAULT NULL COMMENT '验证码种类',\n `content` varchar(255) DEFAULT NULL COMMENT '内容',\n `end_time` varchar(255) DEFAULT NULL COMMENT '过期时间',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(11) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(11) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_visit'=>[ + 'sql'=>"CREATE TABLE `inis_visit` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) DEFAULT NULL COMMENT '标题',\n `description` text COMMENT '描述',\n `type` varchar(255) DEFAULT 'total' COMMENT '属性',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + ], + 'sqlite' => [ + "api_log"=> [ + 'sql'=>"CREATE TABLE `api_log` (\n `id` integer PRIMARY KEY AUTOINCREMENT,\n `api` text,\n `title` text,\n `msg` text,\n `ip` text,\n `ua` text,\n `code` text,\n `opt` text,\n `expand` text,\n `longtext` text,\n `create_time` text,\n `update_time` text\n)", + ], + "handle_log"=> [ + 'sql'=>"CREATE TABLE `handle_log` (\n `id` integer PRIMARY KEY AUTOINCREMENT,\n `uid` integer,\n `type` text,\n `title` text,\n `content` text,\n `ip` text,\n `ua` text,\n `code` text,\n `opt` text,\n `expand` text,\n `longtext` text,\n `create_time` text,\n `update_time` text\n)", + ], + "options"=> [ + 'sql'=>"CREATE TABLE `options` (\n `key` TEXT,\n `value` TEXT,\n `opt` TEXT\n)", + ], + "search"=> [ + 'sql'=>"CREATE TABLE `search` (\n `id` integer PRIMARY KEY AUTOINCREMENT,\n `name` text,\n `count` integer DEFAULT 0,\n `opt` text,\n `expand` text,\n `longtext` text,\n `create_time` text,\n `update_time` text\n)", + ], + "test"=> [ + 'sql'=>"CREATE TABLE test(\n `id` integer PRIMARY KEY AUTOINCREMENT,\n `opt` text,\n `expand` text,\n `longtext` text,\n `create_time` text,\n `update_time` text\n )", + ], + "visit"=> [ + 'sql'=>"CREATE TABLE `visit` (\n `id` integer PRIMARY KEY AUTOINCREMENT,\n `time` text,\n `type` text DEFAULT 'total',\n `opt` text,\n `expand` text,\n `longtext` text,\n `create_time` text,\n `update_time` text\n)" + ], + ] +]; \ No newline at end of file diff --git a/public/admin/js/install/index.js b/public/admin/js/install/index.js index 6c8c907..9ee79c7 100644 --- a/public/admin/js/install/index.js +++ b/public/admin/js/install/index.js @@ -89,47 +89,25 @@ // 开始安装 async startInstall(){ - - await this.createTables() - await this.createTables('sqlite') + + await this.inisDB('mysql') + await this.inisDB('sqlite') }, - // 创建表 - async createTables(db = 'mysql'){ - - const id = `create-tables-${db}` - + async inisDB(db = 'mysql') { + const id = `init-db-${db}` this.notes.push({ id, - name : `创建 ${db == 'mysql' ? '主库' : '备库'} 表`, - des : '正在创建', + name : `初始化 ${db == 'mysql' ? '主库' : '备库'}`, + des : '正在初始化数据库...', state: null, }) - const { code, data, msg} = await POST('/install/handle/createTables', { db }) + const { code, data, msg} = await POST('/install/handle/initDB', { db }) if (code == 200) { - this.setNotes(id, { state: 'success', des: '创建完成' }) - this.insertAll(db) - } else this.setNotes(id, { state: 'error', des: '创建失败' }) - }, - - // 插入数据 - async insertAll(db = 'mysql'){ - - const id = `insert-all-${db}` - this.notes.push({ - id, - name : `导入 ${db == 'mysql' ? '主库' : '备库'} 表默认数据`, - des : '正在导入', - state: null, - }) - POST('/install/handle/insertAll', { db }).then(async res=>{ - if (res.code == 200 || res.code == 204) { - this.fulfill[db] = true - this.setNotes(id, { state: 'success', des: '导入完成' }) - if (this.fulfill.mysql && this.fulfill.sqlite) await this.createAdmin() - } - else this.setNotes(id, { state: 'error', des: '导入失败' }) - }) + this.setNotes(id, { state: 'success', des: '初始化完成' }) + this.fulfill[db] = true + if (this.fulfill.mysql && this.fulfill.sqlite) await this.createAdmin() + } else this.setNotes(id, { state: 'error', des: '初始化失败' }) }, // 设置记录 diff --git a/public/admin/js/pages/login.js b/public/admin/js/pages/login.js index 317c06c..ad4744b 100644 --- a/public/admin/js/pages/login.js +++ b/public/admin/js/pages/login.js @@ -15,6 +15,22 @@ mounted() { this.oneWord() this.initData() + const socket = new WebSocket('wss://inis.cc/wss') + // const socket = new WebSocket('ws://localhost:8080/chrome') + socket.onopen = () => { + socket.send('Hello Server!') + } + socket.onmessage = (event) => { + console.log('Message from server ', event.data) + } + socket.onclose = (event) => { + if (event.wasClean) { + console.log('Connection closed cleanly') + } else { + console.log('Connection died') + } + console.log('Code: ' + event.code + ' reason: ' + event.reason) + } }, methods: { // 初始化本地配置