From 6b17bbf818ee7dad672af3e7f96328e6145391d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=98=A5=E6=B3=A2?= Date: Mon, 20 Nov 2023 00:56:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BC=80=E6=94=BE=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E9=85=8D=E7=BD=AE=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=85=B3?= =?UTF-8?q?=E9=97=ADeslint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 + app/admin/controller/PlatformController.php | 54 +++++ app/admin/model/Platform.php | 29 +++ app/common/model/BaseModel.php | 86 +++++++- app/common/model/Platform.php | 15 ++ app/common/model/User.php | 5 +- config/plugin/tinywan/jwt/app.php | 75 +++++++ config/thinkorm.php | 36 ++++ front/.eslintrc.js | 5 +- front/src/api/platform.js | 40 ++++ .../components/GlobalHeader/RightContent.vue | 3 +- front/src/components/Table/index.js | 6 +- front/src/config/router.config.js | 66 +++++- front/src/core/bootstrap.js | 14 +- front/src/permission.js | 9 +- front/src/store/modules/static-router.js | 4 +- front/src/store/modules/user.js | 7 +- front/src/utils/request.js | 17 +- front/src/views/platform/account.vue | 193 ++++++++++++++++++ .../src/views/platform/modules/CreateForm.vue | 82 ++++++++ front/vue.config.js | 2 +- 21 files changed, 721 insertions(+), 32 deletions(-) create mode 100644 .env.example create mode 100644 app/admin/controller/PlatformController.php create mode 100644 app/admin/model/Platform.php create mode 100644 app/common/model/Platform.php create mode 100644 config/plugin/tinywan/jwt/app.php create mode 100644 config/thinkorm.php create mode 100644 front/src/api/platform.js create mode 100644 front/src/views/platform/account.vue create mode 100644 front/src/views/platform/modules/CreateForm.vue diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c55eed6 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DB_HOST = 127.0.0.1 +DB_PORT = 3306 +DB_NAME = +DB_USER = +DB_PASSWORD = \ No newline at end of file diff --git a/app/admin/controller/PlatformController.php b/app/admin/controller/PlatformController.php new file mode 100644 index 0000000..5017fc7 --- /dev/null +++ b/app/admin/controller/PlatformController.php @@ -0,0 +1,54 @@ +post(); + $res = Platform::create($data); + if ($res->id) { + return success(); + } else { + return error('添加失败'); + } + } + + public function edit(Request $request) + { + $data = $request->post(); + $res = Platform::update($data); + if ($res) { + return success(); + } else { + return error('修改失败'); + } + } + + public function delete(Request $request) + { + $id = $request->post('id'); + $res = Platform::destroy($id); + if ($res) { + return success(); + } else { + return error(); + } + } + + /** + * @param Request $request + * @return array|Response + * @throws DbException + */ + public function list(Request $request) + { + return success(Platform::list($request)); + } +} \ No newline at end of file diff --git a/app/admin/model/Platform.php b/app/admin/model/Platform.php new file mode 100644 index 0000000..f3e1710 --- /dev/null +++ b/app/admin/model/Platform.php @@ -0,0 +1,29 @@ +order('id', 'desc') + ->paginate([ + 'page' => $params['current_page'], + 'list_rows' => $params['page_size'] + ])->toArray(); + } +} \ No newline at end of file diff --git a/app/common/model/BaseModel.php b/app/common/model/BaseModel.php index ae37b4a..468f314 100644 --- a/app/common/model/BaseModel.php +++ b/app/common/model/BaseModel.php @@ -2,9 +2,93 @@ namespace app\common\model; +use support\Request; use think\Model; class BaseModel extends Model { - + /** + * @param Request|null $request + * @param array $filter 导出时可能会用到,传数组 + * @param array $pre 关联表需要指明要查的字段属于哪张表 ['erp_enquiry' => ['model', 'user_id', 'create_time']]; + * @param callable|null $callback 自定义查询条件 + * @return array + */ + protected static function buildWhere(Request $request = null, array $filter = [], array $pre = [], callable $callback = null): array + { + $column = array_column(static::$column, null, 'key'); + if (!empty($request)) { + $current_page = $request->input('pageNo', 1); + $page_size = $request->input('pageSize', 10); + $params = $request->except(['token_', 'current', 'pageSize']); + } else { + $current_page = $filter['pageNo'] ?? 1; + $page_size = $filter['pageSize'] ?? 10; + $params = $filter; + } + $where = []; + foreach ($params as $key => $field) { + if (key_exists($key, $column) && !empty($field)) { + if (!is_array($field)) $field = trim($field); + $where_type = $column[$key]['where'] ?? ''; + // 处理关联表 + $keyArr = array_keys($pre); + foreach ($keyArr as $_key) { + if (in_array($key, $pre[$_key])) { + $key = $_key . '.' . $key; + break; + } + } + switch (trim($where_type)) { + case '>': + $where[] = [$key, '>', (int)$field]; + break; + case '>=': + $where[] = [$key, '>=', $field]; + break; + case '<': + $where[] = [$key, '<', (int)$field]; + break; + case '<=': + $where[] = [$key, '<=', $field]; + break; + case 'like%': + $where[] = [$key, 'like', "{$field}%"]; + break; + case '%like': + $where[] = [$key, 'like', "%{$field}"]; + break; + case 'like': + $where[] = [$key, 'like', "%{$field}%"]; + break; + case 'time>': + $where[] = [$key, '>=', strtotime($field)]; + break; + case 'in': + $field = str_replace(',', ',', $field); + $field = explode(',', $field); + $field = array_map('trim', $field); + $where[] = [$key, 'in', $field]; + break; + case 'time_range': + $where[] = [$key, 'between', [strtotime(trim($field[0], '"')), strtotime(trim($field[1], '"'))]]; + break; + case 'custom': + if (is_callable($callback)) { + if ($callback($key, $field) !== false) { + $where[] = $callback($key, $field); + } + } + break; + default: + $where[] = [$key, '=', $field]; + } + } + } + return [ + 'page_size' => $page_size, + 'current_page' => $current_page, + 'where' => $where + ]; + } } \ No newline at end of file diff --git a/app/common/model/Platform.php b/app/common/model/Platform.php new file mode 100644 index 0000000..9cd186e --- /dev/null +++ b/app/common/model/Platform.php @@ -0,0 +1,15 @@ + 'name', 'name' => '公司名称'], + ['key' => 'app_id', 'name' => 'app_id'], + ]; + protected $table = 'platform'; +} \ No newline at end of file diff --git a/app/common/model/User.php b/app/common/model/User.php index e2a2496..c155d0f 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -2,8 +2,9 @@ namespace app\common\model; -use app\common\model\BaseModel; - +/** + * 用户 + */ class User extends BaseModel { protected $table = 'user'; diff --git a/config/plugin/tinywan/jwt/app.php b/config/plugin/tinywan/jwt/app.php new file mode 100644 index 0000000..959a857 --- /dev/null +++ b/config/plugin/tinywan/jwt/app.php @@ -0,0 +1,75 @@ + true, + 'jwt' => [ + /** 算法类型 HS256、HS384、HS512、RS256、RS384、RS512、ES256、ES384、Ed25519 */ + 'algorithms' => 'HS256', + + /** access令牌秘钥 */ + 'access_secret_key' => '2022d3d3LmJq', + + /** access令牌过期时间,单位:秒。默认 2 小时 */ + 'access_exp' => 7200, + + /** refresh令牌秘钥 */ + 'refresh_secret_key' => '2022KTxigxc9o50c', + + /** refresh令牌过期时间,单位:秒。默认 7 天 */ + 'refresh_exp' => 604800, + + /** refresh 令牌是否禁用,默认不禁用 false */ + 'refresh_disable' => false, + + /** 令牌签发者 */ + 'iss' => 'webman.tinywan.cn', + + /** 某个时间点后才能访问,单位秒。(如:30 表示当前时间30秒后才能使用) */ + 'nbf' => 0, + + /** 时钟偏差冗余时间,单位秒。建议这个余地应该不大于几分钟 */ + 'leeway' => 60, + + /** 是否允许单设备登录,默认不允许 false */ + 'is_single_device' => false, + + /** 缓存令牌时间,单位:秒。默认 7 天 */ + 'cache_token_ttl' => 604800, + + /** 缓存令牌前缀,默认 JWT:TOKEN: */ + 'cache_token_pre' => 'JWT:TOKEN:', + + /** 用户信息模型 */ + 'user_model' => function ($uid) { + return []; + }, + + /** access令牌私钥 */ + 'access_private_key' => << << << << 'mysql', + 'connections' => [ + 'mysql' => [ + // 数据库类型 + 'type' => 'mysql', + // 服务器地址 + 'hostname' => getenv('DB_HOST'), + // 数据库名 + 'database' => getenv('DB_NAME'), + // 数据库用户名 + 'username' => getenv('DB_USER'), + // 数据库密码 + 'password' => getenv('DB_PASSWORD'), + // 数据库连接端口 + 'hostport' => getenv('DB_PORT'), + // 数据库连接参数 + 'params' => [ + // 连接超时3秒 + \PDO::ATTR_TIMEOUT => 3, + ], + // 数据库编码默认采用utf8 + 'charset' => 'utf8', + // 数据库表前缀 + 'prefix' => '', + // 断线重连 + 'break_reconnect' => true, + // 关闭SQL监听日志 + 'trigger_sql' => false, + // 自定义分页类 + 'bootstrap' => '' + ], + ], +]; diff --git a/front/.eslintrc.js b/front/.eslintrc.js index 5bece06..977255e 100644 --- a/front/.eslintrc.js +++ b/front/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { }, 'extends': [ 'plugin:vue/strongly-recommended', - '@vue/standard' +// '@vue/standard' ], rules: { 'no-console': 'off', @@ -56,7 +56,8 @@ module.exports = { } ], 'template-curly-spacing': 'off', - 'indent': 'off' + 'indent': 'off', + 'space-before-function-paren': 0 }, parserOptions: { parser: 'babel-eslint' diff --git a/front/src/api/platform.js b/front/src/api/platform.js new file mode 100644 index 0000000..ef432bf --- /dev/null +++ b/front/src/api/platform.js @@ -0,0 +1,40 @@ +import request from '@/utils/request' + +const api = { + Add: '/platform/add', + List: '/platform/list', + Edit: '/platform/edit', + Delete: '/platform/delete' +} + +export function addPlatform(parameter) { + return request({ + url: api.Add, + method: 'post', + data: parameter + }) +} + +export function getPlatform(parameter) { + return request({ + url: api.List, + method: 'get', + params: parameter + }) +} + +export function editPlatform(parameter) { + return request({ + url: api.Edit, + method: 'post', + data: parameter + }) +} + +export function deletePlatform(parameter) { + return request({ + url: api.Delete, + method: 'post', + data: parameter + }) +} diff --git a/front/src/components/GlobalHeader/RightContent.vue b/front/src/components/GlobalHeader/RightContent.vue index 5d0bb80..bafd7e8 100644 --- a/front/src/components/GlobalHeader/RightContent.vue +++ b/front/src/components/GlobalHeader/RightContent.vue @@ -8,6 +8,7 @@ diff --git a/front/src/views/platform/modules/CreateForm.vue b/front/src/views/platform/modules/CreateForm.vue new file mode 100644 index 0000000..c53f560 --- /dev/null +++ b/front/src/views/platform/modules/CreateForm.vue @@ -0,0 +1,82 @@ + + + diff --git a/front/vue.config.js b/front/vue.config.js index 0f54ab4..a20cbb4 100644 --- a/front/vue.config.js +++ b/front/vue.config.js @@ -136,7 +136,7 @@ const vueConfig = { // disable source map in production productionSourceMap: false, - lintOnSave: undefined, + lintOnSave: false, // babel-loader no-ignore node_modules/* transpileDependencies: [] }