From 9969a655a27b403a20febb94c954d2625909206b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Fri, 2 Aug 2024 08:59:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20github=20actions=20?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.github/workflows/release.yml | 26 + plugin/think-library/.gitignore | 8 + plugin/think-library/composer.json | 60 + plugin/think-library/license | 21 + plugin/think-library/phpunit.xml.dist | 19 + plugin/think-library/readme.md | 397 +++++++ plugin/think-library/src/Builder.php | 411 +++++++ plugin/think-library/src/Command.php | 124 ++ plugin/think-library/src/Controller.php | 324 ++++++ plugin/think-library/src/Exception.php | 65 ++ plugin/think-library/src/Helper.php | 124 ++ plugin/think-library/src/Library.php | 155 +++ plugin/think-library/src/Model.php | 117 ++ plugin/think-library/src/Plugin.php | 235 ++++ plugin/think-library/src/Queue.php | 127 +++ plugin/think-library/src/Service.php | 64 ++ plugin/think-library/src/Storage.php | 203 ++++ plugin/think-library/src/common.php | 462 ++++++++ .../src/contract/StorageInterface.php | 99 ++ .../src/contract/StorageUsageTrait.php | 143 +++ .../src/contract/StreamInterface.php | 85 ++ .../think-library/src/extend/CodeExtend.php | 168 +++ .../think-library/src/extend/DataExtend.php | 91 ++ .../think-library/src/extend/ExcelExtend.php | 81 ++ .../src/extend/FaviconExtend.php | 204 ++++ .../think-library/src/extend/HttpExtend.php | 176 +++ .../think-library/src/extend/ImageVerify.php | 261 +++++ .../src/extend/JsonRpcClient.php | 105 ++ .../src/extend/JsonRpcServer.php | 125 ++ plugin/think-library/src/extend/JwtExtend.php | 244 ++++ .../think-library/src/extend/PhinxExtend.php | 309 +++++ .../think-library/src/extend/ToolsExtend.php | 141 +++ .../think-library/src/extend/VirtualModel.php | 190 +++ .../think-library/src/helper/DeleteHelper.php | 95 ++ .../think-library/src/helper/FormHelper.php | 79 ++ .../think-library/src/helper/PageHelper.php | 194 ++++ .../think-library/src/helper/QueryHelper.php | 398 +++++++ .../think-library/src/helper/SaveHelper.php | 78 ++ .../think-library/src/helper/TokenHelper.php | 71 ++ .../src/helper/ValidateHelper.php | 78 ++ plugin/think-library/src/lang/en-us.php | 143 +++ plugin/think-library/src/lang/zh-tw.php | 76 ++ plugin/think-library/src/model/SystemAuth.php | 76 ++ plugin/think-library/src/model/SystemBase.php | 82 ++ .../think-library/src/model/SystemConfig.php | 30 + plugin/think-library/src/model/SystemData.php | 30 + plugin/think-library/src/model/SystemFile.php | 71 ++ plugin/think-library/src/model/SystemMenu.php | 54 + plugin/think-library/src/model/SystemNode.php | 36 + .../think-library/src/model/SystemOplog.php | 42 + .../think-library/src/model/SystemQueue.php | 77 ++ plugin/think-library/src/model/SystemUser.php | 114 ++ .../src/service/AdminService.php | 334 ++++++ .../src/service/CaptchaService.php | 185 +++ .../src/service/ExpressService.php | 162 +++ .../src/service/InterfaceService.php | 275 +++++ .../think-library/src/service/MenuService.php | 103 ++ .../src/service/MessageService.php | 505 ++++++++ .../src/service/ModuleService.php | 100 ++ .../think-library/src/service/NodeService.php | 218 ++++ .../src/service/ProcessService.php | 236 ++++ .../src/service/QueueService.php | 299 +++++ .../src/service/RuntimeService.php | 263 +++++ .../src/service/SystemService.php | 411 +++++++ .../src/service/ZtSmsService.php | 296 +++++ .../think-library/src/service/bin/captcha.ttf | Bin 0 -> 34852 bytes .../think-library/src/service/bin/console.exe | Bin 0 -> 1536 bytes .../src/service/bin/package.stub | 110 ++ .../src/storage/AliossStorage.php | 286 +++++ .../src/storage/AlistStorage.php | 322 ++++++ .../src/storage/LocalStorage.php | 167 +++ .../src/storage/QiniuStorage.php | 252 ++++ .../src/storage/TxcosStorage.php | 304 +++++ .../src/storage/UpyunStorage.php | 232 ++++ .../think-library/src/storage/bin/mimes.php | 1015 +++++++++++++++++ plugin/think-library/src/support/Route.php | 39 + plugin/think-library/src/support/Url.php | 203 ++++ .../src/support/command/Database.php | 96 ++ .../src/support/command/Package.php | 158 +++ .../src/support/command/Publish.php | 160 +++ .../src/support/command/Queue.php | 378 ++++++ .../src/support/command/Replace.php | 78 ++ .../src/support/command/Sysmenu.php | 88 ++ .../src/support/middleware/JwtSession.php | 113 ++ .../src/support/middleware/MultAccess.php | 189 +++ .../src/support/middleware/RbacAccess.php | 84 ++ plugin/think-library/tests/CodeTest.php | 22 + plugin/think-library/tests/JwtTest.php | 18 + plugin/think-library/tests/ModelTest.php | 14 + plugin/think-library/tests/StorageTest.php | 19 + plugin/think-library/tests/bootstrap.php | 22 + 91 files changed, 14944 insertions(+) create mode 100644 plugin/think-library/.github/workflows/release.yml create mode 100644 plugin/think-library/.gitignore create mode 100644 plugin/think-library/composer.json create mode 100644 plugin/think-library/license create mode 100644 plugin/think-library/phpunit.xml.dist create mode 100644 plugin/think-library/readme.md create mode 100644 plugin/think-library/src/Builder.php create mode 100644 plugin/think-library/src/Command.php create mode 100644 plugin/think-library/src/Controller.php create mode 100644 plugin/think-library/src/Exception.php create mode 100644 plugin/think-library/src/Helper.php create mode 100644 plugin/think-library/src/Library.php create mode 100644 plugin/think-library/src/Model.php create mode 100644 plugin/think-library/src/Plugin.php create mode 100644 plugin/think-library/src/Queue.php create mode 100644 plugin/think-library/src/Service.php create mode 100644 plugin/think-library/src/Storage.php create mode 100644 plugin/think-library/src/common.php create mode 100644 plugin/think-library/src/contract/StorageInterface.php create mode 100644 plugin/think-library/src/contract/StorageUsageTrait.php create mode 100644 plugin/think-library/src/contract/StreamInterface.php create mode 100644 plugin/think-library/src/extend/CodeExtend.php create mode 100644 plugin/think-library/src/extend/DataExtend.php create mode 100644 plugin/think-library/src/extend/ExcelExtend.php create mode 100644 plugin/think-library/src/extend/FaviconExtend.php create mode 100644 plugin/think-library/src/extend/HttpExtend.php create mode 100644 plugin/think-library/src/extend/ImageVerify.php create mode 100644 plugin/think-library/src/extend/JsonRpcClient.php create mode 100644 plugin/think-library/src/extend/JsonRpcServer.php create mode 100644 plugin/think-library/src/extend/JwtExtend.php create mode 100644 plugin/think-library/src/extend/PhinxExtend.php create mode 100644 plugin/think-library/src/extend/ToolsExtend.php create mode 100644 plugin/think-library/src/extend/VirtualModel.php create mode 100644 plugin/think-library/src/helper/DeleteHelper.php create mode 100644 plugin/think-library/src/helper/FormHelper.php create mode 100644 plugin/think-library/src/helper/PageHelper.php create mode 100644 plugin/think-library/src/helper/QueryHelper.php create mode 100644 plugin/think-library/src/helper/SaveHelper.php create mode 100644 plugin/think-library/src/helper/TokenHelper.php create mode 100644 plugin/think-library/src/helper/ValidateHelper.php create mode 100644 plugin/think-library/src/lang/en-us.php create mode 100644 plugin/think-library/src/lang/zh-tw.php create mode 100644 plugin/think-library/src/model/SystemAuth.php create mode 100644 plugin/think-library/src/model/SystemBase.php create mode 100644 plugin/think-library/src/model/SystemConfig.php create mode 100644 plugin/think-library/src/model/SystemData.php create mode 100644 plugin/think-library/src/model/SystemFile.php create mode 100644 plugin/think-library/src/model/SystemMenu.php create mode 100644 plugin/think-library/src/model/SystemNode.php create mode 100644 plugin/think-library/src/model/SystemOplog.php create mode 100644 plugin/think-library/src/model/SystemQueue.php create mode 100644 plugin/think-library/src/model/SystemUser.php create mode 100644 plugin/think-library/src/service/AdminService.php create mode 100644 plugin/think-library/src/service/CaptchaService.php create mode 100644 plugin/think-library/src/service/ExpressService.php create mode 100644 plugin/think-library/src/service/InterfaceService.php create mode 100644 plugin/think-library/src/service/MenuService.php create mode 100644 plugin/think-library/src/service/MessageService.php create mode 100644 plugin/think-library/src/service/ModuleService.php create mode 100644 plugin/think-library/src/service/NodeService.php create mode 100644 plugin/think-library/src/service/ProcessService.php create mode 100644 plugin/think-library/src/service/QueueService.php create mode 100644 plugin/think-library/src/service/RuntimeService.php create mode 100644 plugin/think-library/src/service/SystemService.php create mode 100644 plugin/think-library/src/service/ZtSmsService.php create mode 100644 plugin/think-library/src/service/bin/captcha.ttf create mode 100644 plugin/think-library/src/service/bin/console.exe create mode 100644 plugin/think-library/src/service/bin/package.stub create mode 100644 plugin/think-library/src/storage/AliossStorage.php create mode 100644 plugin/think-library/src/storage/AlistStorage.php create mode 100644 plugin/think-library/src/storage/LocalStorage.php create mode 100644 plugin/think-library/src/storage/QiniuStorage.php create mode 100644 plugin/think-library/src/storage/TxcosStorage.php create mode 100644 plugin/think-library/src/storage/UpyunStorage.php create mode 100644 plugin/think-library/src/storage/bin/mimes.php create mode 100644 plugin/think-library/src/support/Route.php create mode 100644 plugin/think-library/src/support/Url.php create mode 100644 plugin/think-library/src/support/command/Database.php create mode 100644 plugin/think-library/src/support/command/Package.php create mode 100644 plugin/think-library/src/support/command/Publish.php create mode 100644 plugin/think-library/src/support/command/Queue.php create mode 100644 plugin/think-library/src/support/command/Replace.php create mode 100644 plugin/think-library/src/support/command/Sysmenu.php create mode 100644 plugin/think-library/src/support/middleware/JwtSession.php create mode 100644 plugin/think-library/src/support/middleware/MultAccess.php create mode 100644 plugin/think-library/src/support/middleware/RbacAccess.php create mode 100644 plugin/think-library/tests/CodeTest.php create mode 100644 plugin/think-library/tests/JwtTest.php create mode 100644 plugin/think-library/tests/ModelTest.php create mode 100644 plugin/think-library/tests/StorageTest.php create mode 100644 plugin/think-library/tests/bootstrap.php diff --git a/plugin/think-library/.github/workflows/release.yml b/plugin/think-library/.github/workflows/release.yml new file mode 100644 index 000000000..8672b3b13 --- /dev/null +++ b/plugin/think-library/.github/workflows/release.yml @@ -0,0 +1,26 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Release +permissions: write-all + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false diff --git a/plugin/think-library/.gitignore b/plugin/think-library/.gitignore new file mode 100644 index 000000000..5f92c81a4 --- /dev/null +++ b/plugin/think-library/.gitignore @@ -0,0 +1,8 @@ +.git +.svn +.idea +*.cache +/vendor +/composer.lock +!.gitignore +!composer.json diff --git a/plugin/think-library/composer.json b/plugin/think-library/composer.json new file mode 100644 index 000000000..a2e554d10 --- /dev/null +++ b/plugin/think-library/composer.json @@ -0,0 +1,60 @@ +{ + "name": "zoujingli/think-library", + "license": "MIT", + "homepage": "https://thinkadmin.top", + "description": "Basic Library for ThinkAdmin", + "authors": [ + { + "name": "Anyon", + "email": "zoujingli@qq.com" + } + ], + "support": { + "email": "zoujingli@qq.com", + "wiki": "https://thinkadmin.top", + "forum": "https://thinkadmin.top", + "source": "https://gitee.com/zoujingli/ThinkLibrary", + "issues": "https://gitee.com/zoujingli/ThinkLibrary/issues" + }, + "require": { + "php": ">=7.1", + "ext-gd": "*", + "ext-curl": "*", + "ext-json": "*", + "ext-zlib": "*", + "ext-iconv": "*", + "ext-openssl": "*", + "ext-mbstring": "*", + "symfony/process": "^5.4|^6.0|*", + "topthink/framework": "^6.0|^8.0|*", + "topthink/think-migration": "^3.0|*" + }, + "autoload": { + "files": [ + "src/common.php" + ], + "psr-4": { + "think\\admin\\": "src" + } + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "autoload-dev": { + "psr-4": { + "think\\admin\\tests\\": "tests" + } + }, + "extra": { + "think": { + "services": [ + "think\\admin\\Library" + ] + } + }, + "prefer-stable": true, + "minimum-stability": "dev", + "config": { + "sort-packages": true + } +} \ No newline at end of file diff --git a/plugin/think-library/license b/plugin/think-library/license new file mode 100644 index 000000000..9ce3cc33d --- /dev/null +++ b/plugin/think-library/license @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2014~2024 邹景立 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugin/think-library/phpunit.xml.dist b/plugin/think-library/phpunit.xml.dist new file mode 100644 index 000000000..6ea0d19c7 --- /dev/null +++ b/plugin/think-library/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + ./tests + + + diff --git a/plugin/think-library/readme.md b/plugin/think-library/readme.md new file mode 100644 index 000000000..930b6af1b --- /dev/null +++ b/plugin/think-library/readme.md @@ -0,0 +1,397 @@ +# ThinkLibrary for ThinkPHP6 + +[![Latest Stable Version](https://poser.pugx.org/zoujingli/think-library/v/stable)](https://packagist.org/packages/zoujingli/think-library) +[![Latest Unstable Version](https://poser.pugx.org/zoujingli/think-library/v/unstable)](https://packagist.org/packages/zoujingli/think-library) +[![Total Downloads](https://poser.pugx.org/zoujingli/think-library/downloads)](https://packagist.org/packages/zoujingli/think-library) +[![Monthly Downloads](https://poser.pugx.org/zoujingli/think-library/d/monthly)](https://packagist.org/packages/zoujingli/think-library) +[![Daily Downloads](https://poser.pugx.org/zoujingli/think-library/d/daily)](https://packagist.org/packages/zoujingli/think-library) +[![PHP Version](https://thinkadmin.top/static/icon/php-7.1.svg)](https://thinkadmin.top) +[![License](https://thinkadmin.top/static/icon/license-mit.svg)](https://mit-license.org) + +**ThinkLibrary** 是一个针对 **ThinkPHP 6 & 8** 的封装库,它提供了完整的 **CRUD**(创建、读取、更新、删除)操作和一系列常用工具。 +该库特别注重多应用支持,为开发者提供便利。前端代码的主仓库位于 **Gitee**,而 **GitHub** 则作为镜像仓库用于发布 **Composer** 包,以方便开发者下载和使用。 + +## 功能说明 + +1. 数据列表展示组件 + +* 功能:展示数据列表,支持分页、排序和高级搜索。 +* 优化点:提供友好的用户界面和交互体验,确保数据展示的准确性和实时性。 +* 高级特性:支持多种排序方式、自定义搜索字段和条件。 + +2. 表单处理模块 + +* 功能:用于创建、展示和提交表单数据。 +* 优化点:表单验证和错误处理机制,确保数据的有效性和完整性。 +* 高级特性:支持多种表单元素、表单验证规则和动态表单生成。 + +3. 数据状态快速处理模块 + +* 功能:根据业务需求快速更新数据状态。 +* 优化点:提供简洁的接口和操作方式,支持多字段同时更新。 +* 高级特性:支持条件判断和事务处理,确保数据一致性和完整性。 + +4. 数据安全删除模块 + +* 功能:根据业务需求安全地删除数据。 +* 优化点:提供软删除和硬删除两种方式,确保数据彻底消失或标记为已删除。 +* 高级特性:支持根据条件自动软删除、可配置的软删除标记字段。 + +5. 文件存储通用组件 + +* 功能:支持多种文件存储方式,包括本地服务存储、云存储等。 +* 优化点:提供统一的接口和配置方式,方便开发者快速集成和使用。 +* 高级特性:支持文件上传、下载、删除和版本控制等功能。 + +6. 通用数据保存更新模块 + +* 功能:根据 key 值及 where 条件判断数据是否存在,进行更新或新增操作。 +* 优化点:提供简洁的接口和操作方式,减少冗余代码和重复工作量。 +* 高级特性:支持乐观锁和悲观锁机制,确保并发控制和数据一致性。 + +7. 通用网络请求模块 + +* 功能:支持 GET、POST 和 PUT 请求,可配置请求参数、证书等。 +* 优化点:提供统一的接口和配置方式,方便开发者快速发起网络请求。 +* 高级特性:支持请求重试、超时设置、自动捕获异常等功能。 + +8. 系统参数通用 g-k-v 配置模块 + +* 功能:快速配置系统参数,支持长久化保存。 +* 优化点:提供简洁的接口和操作方式,方便开发者管理和维护系统参数。 +* 高级特性:支持参数加密存储、权限控制和日志记录等功能。 + +9. UTF8 加密算法支持模块 + +* 功能:提供 UTF8 字符串的加密和解密功能。 +* 优化点:确保加密过程的安全性和数据的机密性。 +* 高级特性:支持多种加密算法、密钥管理等功能。 + +10. 接口 CORS 跨域默认支持模块 + +* 功能:默认支持跨域请求,输出标准化 JSON 数据。 +* 优化点:减少开发者的工作量,自动处理跨域问题。 +* 高级特性:支持定制化响应头、跨域请求限制等功能。 + +11. 表单 CSRF 安全验证模块 + +* 功能:自动为表单添加 CSRF 安全验证字段,防止恶意提交。 +* 优化点:简化开发者的工作流程,提高表单提交的安全性。 +* 高级特性:支持自定义验证规则、多种验证方式等功能。 + +## 参考项目 + +#### ThinkAdmin - V6 + +* Gitee 仓库 https://gitee.com/zoujingli/ThinkAdmin +* Github 仓库 https://github.com/zoujingli/ThinkAdmin +* 体验地址(账号密码都是admin)https://v6.thinkadmin.top + +## 代码仓库 + +**ThinkLibrary** 遵循 **MIT** 开源协议发布,并免费提供使用。 + +部分代码来自互联网,若有异议可以联系作者进行删除。 + +* 在线体验地址:https://v6.thinkadmin.top (账号和密码都是 `admin` ) +* **Gitee** 仓库地址:https://gitee.com/zoujingli/ThinkLibrary +* **Github** 仓库地址:https://github.com/zoujingli/ThinkLibrary + +## 使用说明 + +1. **依赖管理**:ThinkLibrary 需要 Composer 支持进行安装和依赖管理。 +2. **安装指南**:您可以使用以下命令通过 Composer 安装 ThinkLibrary:`composer require zoujingli/think-library`。 +3. **使用示例**:在使用 ThinkLibrary 时,确保您的控制器类继承自 `think\admin\Controller`。一旦继承完成,您就可以通过 `$this` 对象访问并使用全部功能。 + +```php +// 定义 MyController 控制器 +class MyController extend \think\admin\Controller { + + // 指定当前数据表名 + protected $dbQuery = '数据表名'; + + // 显示数据列表 + public function index(){ + $this->_page($this->dbQuery); + } + + // 当前列表数据处理 + protected function _index_page_filter(&$data){ + foreach($data as &$vo){ + // @todo 修改原列表 + } + } + +} +``` + +* 必要数据库表SQL(sysdata 函数需要用这个表) + +```sql +CREATE TABLE `system_data` +( + `id` bigint(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(100) DEFAULT NULL COMMENT '配置名', + `value` longtext COMMENT '配置值', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_system_data_name` (`name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统-数据'; +``` + +* 必要数据库表SQl(sysoplog 函数需要用的这个表) + +```sql +CREATE TABLE `system_oplog` +( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `node` varchar(200) NOT NULL DEFAULT '' COMMENT '当前操作节点', + `geoip` varchar(15) NOT NULL DEFAULT '' COMMENT '操作者IP地址', + `action` varchar(200) NOT NULL DEFAULT '' COMMENT '操作行为名称', + `content` varchar(1024) NOT NULL DEFAULT '' COMMENT '操作内容描述', + `username` varchar(50) NOT NULL DEFAULT '' COMMENT '操作人用户名', + `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统-日志'; +``` + +* 必要数据库表SQL(`sysconf`函数需要用到这个表) + +```sql +CREATE TABLE `system_config` +( + `type` varchar(20) DEFAULT '' COMMENT '分类', + `name` varchar(100) DEFAULT '' COMMENT '配置名', + `value` varchar(500) DEFAULT '' COMMENT '配置值', + KEY `idx_system_config_type` (`type`), + KEY `idx_system_config_name` (`name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统-配置'; +``` + +* 系统任务列队支持需要的数据表 + +```sql +CREATE TABLE `system_queue` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `code` varchar(20) DEFAULT '' COMMENT '任务编号', + `title` varchar(50) NOT NULL DEFAULT '' COMMENT '任务名称', + `command` varchar(500) DEFAULT '' COMMENT '执行指令', + `exec_data` longtext COMMENT '执行参数', + `exec_time` bigint(20) unsigned DEFAULT '0' COMMENT '执行时间', + `exec_desc` varchar(500) DEFAULT '' COMMENT '状态描述', + `enter_time` bigint(20) DEFAULT '0' COMMENT '开始时间', + `outer_time` bigint(20) DEFAULT '0' COMMENT '结束时间', + `attempts` bigint(20) DEFAULT '0' COMMENT '执行次数', + `rscript` tinyint(1) DEFAULT '1' COMMENT '单例模式', + `status` tinyint(1) DEFAULT '1' COMMENT '任务状态(1新任务,2处理中,3成功,4失败)', + `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_system_queue_code` (`code`), + KEY `idx_system_queue_title` (`title`) USING BTREE, + KEY `idx_system_queue_status` (`status`) USING BTREE, + KEY `idx_system_queue_rscript` (`rscript`) USING BTREE, + KEY `idx_system_queue_create_at` (`create_at`) USING BTREE, + KEY `idx_system_queue_exec_time` (`exec_time`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统-任务'; +``` + +#### 列表处理 + +```php +// 列表展示 +$this->_page($dbQuery, $isPage, $isDisplay, $total); + +// 列表展示搜索器(按 name、title 模糊搜索;按 status 精确搜索) +$this->_query($dbQuery)->like('name,title')->equal('status')->page(); + +// 对列表查询器进行二次处理 +$query = $this->_query($dbQuery)->like('name, title')->equal('status'); +$db = $query->db(); // @todo 这里可以对db进行操作 +$this->_page($db); // 显示列表分页 +``` + +#### 表单处理 + +```php +// 表单显示及数据更新 +$this->_form($dbQuery, $tplFile, $pkField , $where, $data); +``` + +#### 删除处理 + +```php +// 数据删除处理 +$this->_deleted($dbQuery); +``` + +#### 禁用启用处理 + +```php +// 数据禁用处理 +$this->_save($dbQuery, ['status'=>'0']); + +// 数据启用处理 +$this->_save($dbQuery, ['status'=>'1']); +``` + +#### 文件存储组件( oss 及 qiniu 需要配置参数) + +```php + +// 配置默认存储方式 +sysconf('storage.type','文件存储类型'); + +// 七牛云存储配置 +sysconf('storage.qiniu_region', '文件存储节点'); +sysconf('storage.qiniu_domain', '文件访问域名'); +sysconf('storage.qiniu_bucket', '文件存储空间名称'); +sysconf('storage.qiniu_is_https', '文件HTTP访问协议'); +sysconf('storage.qiniu_access_key', '接口授权AccessKey'); +sysconf('storage.qiniu_secret_key', '接口授权SecretKey'); + + +// 生成文件名称(链接url或文件md5) +$filename = \think\admin\Storage::name($url, $ext, $prv, $fun); + +// 获取文件内容(自动存储方式) +$result = \think\admin\Storage::get($filename); + +// 保存内容到文件(自动存储方式) +$result = \think\admin\Storage::save($filename, $content); + +// 判断文件是否存在 +boolean \think\admin\Storage::has($filename); + +// 获取文件信息 +$result = \think\admin\Storage::info($filename); + +//指定存储类型(调用方法) +$result = \think\admin\Storage::instance('local')->save($filename, $content); +$result = \think\admin\Storage::instance('qiniu')->save($filename, $content); +$result = \think\admin\Storage::instance('txcos')->save($filename, $content); +$result = \think\admin\Storage::instance('upyun')->save($filename, $content); +$result = \think\admin\Storage::instance('alioss')->save($filename, $content); + +// 读取文件内容 +$result = \think\admin\Storage::instance('local')->get($filename); +$result = \think\admin\Storage::instance('qiniu')->get($filename); +$result = \think\admin\Storage::instance('txcos')->get($filename); +$result = \think\admin\Storage::instance('upyun')->get($filename); +$result = \think\admin\Storage::instance('alioss')->get($filename); + +// 生成 URL 访问地址 +$result = \think\admin\Storage::instance('local')->url($filename); +$result = \think\admin\Storage::instance('qiniu')->url($filename); +$result = \think\admin\Storage::instance('txcos')->url($filename); +$result = \think\admin\Storage::instance('upyun')->url($filename); +$result = \think\admin\Storage::instance('alioss')->url($filename); + +// 检查文件是否存在 +boolean \think\admin\Storage::instance('local')->has($filename); +boolean \think\admin\Storage::instance('qiniu')->has($filename); +boolean \think\admin\Storage::instance('txcos')->has($filename); +boolean \think\admin\Storage::instance('upyun')->has($filename); +boolean \think\admin\Storage::instance('alioss')->has($filename); + +// 生成文件信息 +$resutl = \think\admin\Storage::instance('local')->info($filename); +$resutl = \think\admin\Storage::instance('qiniu')->info($filename); +$resutl = \think\admin\Storage::instance('txcos')->info($filename); +$resutl = \think\admin\Storage::instance('upyun')->info($filename); +$resutl = \think\admin\Storage::instance('alioss')->info($filename); +``` + +#### 通用数据保存 + +```php +// 指定关键列更新($where 为扩展条件) +boolean data_save($dbQuery, $data, 'pkname', $where); +``` + +#### 通用网络请求 + +```php +// 发起get请求 +$result = http_get($url, $query, $options); + +// 发起post请求 +$result = http_post($url, $data, $options); +``` + +#### 系统参数配置(基于 system_config 数据表) + +```php +// 设置参数 +sysconf($keyname, $keyvalue); + +// 获取参数 +$keyvalue = sysconf($kename); +``` + +### 数据加密 + +**自研 UTF8 加密** + +```php +// 自研 UTF8 字符串加密操作 +$string = encode($content); + +// 自研 UTF8 加密字符串解密 +$content = decode($string); +``` + +**数据解密** + +```php +use think\admin\extend\CodeExtend; + +// 数据 AES-256-CBC 对称加密 +$encrypt = CodeExtend::encrypt($content, $enckey); + +// 数据 AES-256-CBC 对称解密 +$content = CodeExtend::decrypt($encrypt, $enckey); +``` + +**文本转 UTF8 编码** + +```php +use think\admin\extend\CodeExtend; + +// 文本转 UTF8 编码 +$content = CodeExtend::text2utf8($content) +``` + +**文本 Base64 URL 编码** + +```php +use think\admin\extend\CodeExtend; + +// 文本 Base64 URL 编码 +$safe64 = CodeExtend::enSafe64($content) + +// 文本 Base64 URL 解码 +$content = CodeExtend::deSafe64($safe64) +``` + +### 数据压缩处理 + +```php +use think\admin\extend\CodeExtend; + +// 数据压缩 ( 内容越大效果越好 ) +$enzip = CodeExtend::enzip($content) + +// 数据解压 ( 内容越大效果越好 ) +$content = CodeExtend::dezip($enzip) +``` + +### 数组结构处理 + +```php +use think\admin\extend\CodeExtend; + +// 二维数组 转为 立体数据结构,需要存在 id 及 pid 关系 +$tree = CodeExtend::arr2tree($list); + +// 二维数组 转为 扁平数据结构,需要存在 id 及 pid 关系 +$tree = CodeExtend::arr2table($list); +``` diff --git a/plugin/think-library/src/Builder.php b/plugin/think-library/src/Builder.php new file mode 100644 index 000000000..df0bc4aab --- /dev/null +++ b/plugin/think-library/src/Builder.php @@ -0,0 +1,411 @@ +type = $type; + $this->mode = $mode; + $this->class = $class; + } + + /** + * 创建表单生成器 + * @param string $type 页面类型 + * @param string $mode 页面模式 + * @return \think\admin\Builder + */ + public static function mk(string $type = 'form', string $mode = 'modal'): Builder + { + return Library::$sapp->invokeClass(static::class, ['type' => $type, 'mode' => $mode]); + } + + /** + * 设置表单地址 + * @param string $url + * @return $this + */ + public function setAction(string $url): Builder + { + $this->action = $url; + return $this; + } + + /** + * 设置变量名称 + * @param string $name + * @return $this + */ + public function setVariable(string $name): Builder + { + $this->variable = $name; + return $this; + } + + /** + * 增加输入表单元素 + * @param string $name 字段名称 + * @param string $title 字段标题 + * @param string $subtitle 字段子标题 + * @param string $remark 字段备注 + * @param array $attrs 附加属性 + * @return $this + */ + protected function addInput(string $name, string $title, string $subtitle = '', string $remark = '', array $attrs = []): Builder + { + $html = "\n\t\t" . '"; + return $this; + } + + /** + * 创建文本输入框架 + * @param string $name 字段名称 + * @param string $title 字段标题 + * @param string $substr 字段子标题 + * @param array $attrs 附加属性 + * @return $this + */ + public function addTextArea(string $name, string $title, string $substr = '', bool $required = false, $remark = '', array $attrs = []): Builder + { + if ($required) $attrs['required'] = 'required'; + $html = "\n\t\t" . '