Your Name 6 mesi fa
parent
commit
9be081ee8b

+ 1
- 1
.example.env Vedi File

@@ -1 +1 @@
1
-APP_DEBUG = true

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai

[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = test
USERNAME = username
PASSWORD = password
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true

[LANG]
default_lang = zh-cn
1
+APP_DEBUG = true

DB_TYPE = mysql
DB_HOST = 127.0.0.1
DB_NAME = test
DB_USER = username
DB_PASS = password
DB_PORT = 3306
DB_CHARSET = utf8

DEFAULT_LANG = zh-cn

+ 1
- 1
LICENSE.txt Vedi File

@@ -1,6 +1,6 @@
1 1
 
2 2
 ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
3
-版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
3
+版权所有Copyright © 2006-2023 by ThinkPHP (http://thinkphp.cn)
4 4
 All rights reserved。
5 5
 ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
6 6
 

+ 47
- 24
README.md Vedi File

@@ -1,31 +1,56 @@
1
-ThinkPHP 6.0
1
+![](https://www.thinkphp.cn/uploads/images/20230630/300c856765af4d8ae758c503185f8739.png)
2
+
3
+ThinkPHP 8.0
2 4
 ===============
3 5
 
4
-> 运行环境要求PHP7.2+,兼容PHP8.1
6
+## 特性
7
+
8
+* 基于PHP`8.0+`重构
9
+* 升级`PSR`依赖
10
+* 依赖`think-orm`3.0版本
11
+* `6.0`/`6.1`无缝升级
12
+
13
+
14
+> ThinkPHP8.0的运行环境要求PHP8.0.0+
15
+
16
+现在开始,你可以使用官方提供的[ThinkChat](https://chat.topthink.com/),让你在学习ThinkPHP的旅途中享受私人AI助理服务!
17
+
18
+![](https://www.topthink.com/uploads/assistant/20230630/4d1a3f0ad2958b49bb8189b7ef824cb0.png)
19
+
20
+## 文档
21
+
22
+[完全开发手册](https://doc.thinkphp.cn)
23
+
24
+## 服务
25
+
26
+ThinkPHP生态服务由[顶想云](https://www.topthink.com)(TOPThink Cloud)提供,为生态提供专业的开发者服务和价值之选。
5 27
 
6
-[官方应用服务市场](https://market.topthink.com) | [`ThinkAPI`——官方统一API服务](https://docs.topthink.com/think-api)
28
+## 赞助
29
+全新的[赞助计划](https://www.thinkphp.cn/sponsor)可以让你通过我们的网站、手册、欢迎页及GIT仓库获得巨大曝光,同时提升企业的品牌声誉,也更好保障ThinkPHP的可持续发展。
7 30
 
8
-ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。
31
+[![](https://www.thinkphp.cn/uploads/images/20230630/48396092a0515886a3da6bd268131c8f.png)](http://github.crmeb.net/u/TPSY)
9 32
 
10
-## 主要新特性
33
+[![](https://www.thinkphp.cn/uploads/images/20230630/a12bd248beee0e7491dd0f79dc4dd5e9.png)](https://www.thinkphp.cn/sponsor)
11 34
 
12
-* 采用`PHP7`强类型(严格模式)
13
-* 支持更多的`PSR`规范
14
-* 原生多应用支持
15
-* 更强大和易用的查询
16
-* 全新的事件系统
17
-* 模型事件和数据库事件统一纳入事件系统
18
-* 模板引擎分离出核心
19
-* 内部功能中间件化
20
-* SESSION/Cookie机制改进
21
-* 对Swoole以及协程支持改进
22
-* 对IDE更加友好
23
-* 统一和精简大量用法
35
+[![](https://www.thinkphp.cn/uploads/images/20230630/e7f48d909d41dd5ebaf4a5aa982d0455.png)](https://www.thinkphp.cn/sponsor)
24 36
 
25 37
 ## 安装
26 38
 
27 39
 ~~~
28
-composer create-project topthink/think tp 6.0.*
40
+composer create-project topthink/think tp
41
+~~~
42
+
43
+启动服务
44
+
45
+~~~
46
+cd tp
47
+php think run
48
+~~~
49
+
50
+然后就可以在浏览器中访问
51
+
52
+~~~
53
+http://localhost:8000
29 54
 ~~~
30 55
 
31 56
 如果需要更新框架使用
@@ -33,13 +58,13 @@ composer create-project topthink/think tp 6.0.*
33 58
 composer update topthink/framework
34 59
 ~~~
35 60
 
36
-## 文档
61
+## 命名规范
37 62
 
38
-[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
63
+`ThinkPHP`遵循PSR-2命名规范和PSR-4自动加载规范。
39 64
 
40 65
 ## 参与开发
41 66
 
42
-请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。
67
+直接提交PR或者Issue即可
43 68
 
44 69
 ## 版权信息
45 70
 
@@ -47,9 +72,7 @@ ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
47 72
 
48 73
 本项目包含的第三方源码和二进制文件之版权信息另行标注。
49 74
 
50
-版权所有Copyright © 2006-2021 by ThinkPHP (http://thinkphp.cn)
51
-
52
-All rights reserved。
75
+版权所有Copyright © 2006-2023 by ThinkPHP (http://thinkphp.cn) All rights reserved。
53 76
 
54 77
 ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
55 78
 

+ 1
- 1
app/BaseController.php Vedi File

@@ -64,7 +64,7 @@ abstract class BaseController
64 64
      * @return array|string|true
65 65
      * @throws ValidateException
66 66
      */
67
-    protected function validate(array $data, $validate, array $message = [], bool $batch = false)
67
+    protected function validate(array $data, string|array $validate, array $message = [], bool $batch = false)
68 68
     {
69 69
         if (is_array($validate)) {
70 70
             $v = new Validate();

+ 0
- 17
app/controller/Index.php Vedi File

@@ -1,17 +0,0 @@
1
-<?php
2
-namespace app\controller;
3
-
4
-use app\BaseController;
5
-
6
-class Index extends BaseController
7
-{
8
-    public function index()
9
-    {
10
-        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
11
-    }
12
-
13
-    public function hello($name = 'ThinkPHP6')
14
-    {
15
-        return 'hello,' . $name;
16
-    }
17
-}

+ 18
- 0
app/index/controller/Index.php Vedi File

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace app\index\controller;
4
+
5
+use app\BaseController;
6
+
7
+class Index extends BaseController
8
+{
9
+    public function index()
10
+    {
11
+        return '<style>*{ padding: 0; margin: 0; }</style><iframe src="https://www.thinkphp.cn/welcome?version=' . \think\facade\App::version() . '" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>';
12
+    }
13
+
14
+    public function hello($name = 'ThinkPHP8')
15
+    {
16
+        return 'hello,' . $name;
17
+    }
18
+}

+ 79
- 0
app/work/controller/Push.php Vedi File

@@ -0,0 +1,79 @@
1
+<?php
2
+namespace app\work\controller;
3
+use think\facade\Db;
4
+use think\worker\Server;
5
+use Workerman\Lib\Timer;
6
+use think\facade\View;
7
+
8
+/*
9
+ * 业务需求示例:系统后台监听有新的商品订单,新消息等的通知,推送给所有登陆系统的用户。
10
+逻辑:使用websocket建立连接,并设置定时器发送心跳保持连接不被断开。建立连接后,php端需要设置心跳时间,判断mysql业务表是否有新记录或者订单,如果有就推送消息给所有登陆系统用户,并更新该记录已推送。
11
+ */
12
+class Push extends Server
13
+{
14
+    protected $socket = 'http://0.0.0.0:2346';   //端口自行修改
15
+
16
+    protected static $heartbeat_time = 55;
17
+
18
+    public function onWorkerStart($worker)
19
+    {
20
+        //查看是否有新的充值或提现订单,有就推送给所有用户
21
+        Timer::add(3, function () use ($worker) {
22
+
23
+            $time_now = time();
24
+
25
+
26
+            //是否有新消息
27
+            $count = 10;
28
+
29
+            if ($count > 0) {
30
+
31
+
32
+
33
+                foreach ($worker->connections as $connection) {
34
+                    if (empty($connection->lastMessageTime)) {
35
+                        $connection->lastMessageTime = $time_now;
36
+                    }
37
+
38
+                    if ($time_now - $connection->lastMessageTime > self::$heartbeat_time) {
39
+                        //后台控制连接
40
+                        //前端断了 可以点击重新连接 类似游戏重新登录
41
+                        $connection->close();
42
+                    }
43
+
44
+                    $data = ['time'=> $time_now,'lastMessageTime' => $connection->lastMessageTime];
45
+
46
+                    $connection->send(json_encode($data));
47
+                }
48
+                //处理发送状态 ['is_push' => 1]
49
+            } else {
50
+                foreach ($worker->connections as $connection) {
51
+                    if (empty($connection->lastMessageTime)) {
52
+                        $connection->lastMessageTime = $time_now;
53
+                        continue;
54
+                    }
55
+
56
+                    if ($time_now - $connection->lastMessageTime > self::$heartbeat_time) {      //连接超时
57
+                        $connection->close();
58
+                    }
59
+                }
60
+            }
61
+        });
62
+    }
63
+
64
+    /*
65
+     * 客户端
66
+     * http://workerman.dev.zx2049.com/work/push/index
67
+     */
68
+    public function index(){
69
+
70
+        //获取规则
71
+        $rule = ['默认规则'];
72
+        for ($i = 1; $i <= 10; $i++) {
73
+            $rule[] = '规则'.$i;
74
+        }
75
+        View::assign('rule',$rule);
76
+        return View::fetch();
77
+    }
78
+
79
+}

+ 12
- 8
composer.json Vedi File

@@ -17,16 +17,20 @@
17 17
         {
18 18
             "name": "yunwuxin",
19 19
             "email": "448901948@qq.com"
20
-        }        
20
+        }
21 21
     ],
22 22
     "require": {
23
-        "php": ">=7.2.5",
24
-        "topthink/framework": "^6.0.0",
25
-        "topthink/think-orm": "^2.0"
23
+        "php": ">=8.0.0",
24
+        "topthink/framework": "^8.0",
25
+        "topthink/think-orm": "^3.0",
26
+        "topthink/think-filesystem": "^2.0",
27
+        "topthink/think-worker": "^4.0",
28
+        "topthink/think-multi-app": "^1.0",
29
+        "topthink/think-view": "^2.0"
26 30
     },
27 31
     "require-dev": {
28
-        "symfony/var-dumper": "^4.2",
29
-        "topthink/think-trace":"^1.0"
32
+        "symfony/var-dumper": ">=4.2",
33
+        "topthink/think-trace": "^1.0"
30 34
     },
31 35
     "autoload": {
32 36
         "psr-4": {
@@ -41,8 +45,8 @@
41 45
     },
42 46
     "scripts": {
43 47
         "post-autoload-dump": [
44
-          "@php think service:discover",
45
-          "@php think vendor:publish"
48
+            "@php think service:discover",
49
+            "@php think vendor:publish"
46 50
         ]
47 51
     }
48 52
 }

+ 553
- 154
composer.lock
File diff soppresso perché troppo grande
Vedi File


+ 2
- 2
config/app.php Vedi File

@@ -5,7 +5,7 @@
5 5
 
6 6
 return [
7 7
     // 应用地址
8
-    'app_host'         => env('app.host', ''),
8
+    'app_host'         => env('APP_HOST', ''),
9 9
     // 应用的命名空间
10 10
     'app_namespace'    => '',
11 11
     // 是否启用路由
@@ -28,5 +28,5 @@ return [
28 28
     // 错误显示信息,非调试模式有效
29 29
     'error_message'    => '页面错误!请稍后再试~',
30 30
     // 显示错误信息
31
-    'show_error_msg'   => false,
31
+    'show_error_msg'   => true,
32 32
 ];

+ 1
- 1
config/cache.php Vedi File

@@ -6,7 +6,7 @@
6 6
 
7 7
 return [
8 8
     // 默认缓存驱动
9
-    'default' => env('cache.driver', 'file'),
9
+    'default' => 'file',
10 10
 
11 11
     // 缓存连接方式配置
12 12
     'stores'  => [

+ 10
- 10
config/database.php Vedi File

@@ -2,7 +2,7 @@
2 2
 
3 3
 return [
4 4
     // 默认使用的数据库连接配置
5
-    'default'         => env('database.driver', 'mysql'),
5
+    'default'         => env('DB_DRIVER', 'mysql'),
6 6
 
7 7
     // 自定义时间查询规则
8 8
     'time_query_rule' => [],
@@ -22,23 +22,23 @@ return [
22 22
     'connections'     => [
23 23
         'mysql' => [
24 24
             // 数据库类型
25
-            'type'            => env('database.type', 'mysql'),
25
+            'type'            => env('DB_TYPE', 'mysql'),
26 26
             // 服务器地址
27
-            'hostname'        => env('database.hostname', '127.0.0.1'),
27
+            'hostname'        => env('DB_HOST', '127.0.0.1'),
28 28
             // 数据库名
29
-            'database'        => env('database.database', ''),
29
+            'database'        => env('DB_NAME', ''),
30 30
             // 用户名
31
-            'username'        => env('database.username', 'root'),
31
+            'username'        => env('DB_USER', 'root'),
32 32
             // 密码
33
-            'password'        => env('database.password', ''),
33
+            'password'        => env('DB_PASS', ''),
34 34
             // 端口
35
-            'hostport'        => env('database.hostport', '3306'),
35
+            'hostport'        => env('DB_PORT', '3306'),
36 36
             // 数据库连接参数
37 37
             'params'          => [],
38 38
             // 数据库编码默认采用utf8
39
-            'charset'         => env('database.charset', 'utf8'),
39
+            'charset'         => env('DB_CHARSET', 'utf8'),
40 40
             // 数据库表前缀
41
-            'prefix'          => env('database.prefix', ''),
41
+            'prefix'          => env('DB_PREFIX', ''),
42 42
 
43 43
             // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
44 44
             'deploy'          => 0,
@@ -53,7 +53,7 @@ return [
53 53
             // 是否需要断线重连
54 54
             'break_reconnect' => false,
55 55
             // 监听SQL
56
-            'trigger_sql'     => env('app_debug', true),
56
+            'trigger_sql'     => env('APP_DEBUG', true),
57 57
             // 开启字段缓存
58 58
             'fields_cache'    => false,
59 59
         ],

+ 1
- 1
config/filesystem.php Vedi File

@@ -2,7 +2,7 @@
2 2
 
3 3
 return [
4 4
     // 默认磁盘
5
-    'default' => env('filesystem.driver', 'local'),
5
+    'default' => 'local',
6 6
     // 磁盘列表
7 7
     'disks'   => [
8 8
         'local'  => [

+ 45
- 0
config/gateway_worker.php Vedi File

@@ -0,0 +1,45 @@
1
+<?php
2
+// +----------------------------------------------------------------------
3
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
4
+// +----------------------------------------------------------------------
5
+// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
6
+// +----------------------------------------------------------------------
7
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
+// +----------------------------------------------------------------------
9
+// | Author: liu21st <liu21st@gmail.com>
10
+// +----------------------------------------------------------------------
11
+// +----------------------------------------------------------------------
12
+// | Workerman设置 仅对 php think worker:gateway 指令有效
13
+// +----------------------------------------------------------------------
14
+return [
15
+    // 扩展自身需要的配置
16
+    'protocol'              => 'websocket', // 协议 支持 tcp udp unix http websocket text
17
+    'host'                  => '0.0.0.0', // 监听地址
18
+    'port'                  => 2348, // 监听端口
19
+    'socket'                => '', // 完整监听地址
20
+    'context'               => [], // socket 上下文选项
21
+    'register_deploy'       => true, // 是否需要部署register
22
+    'businessWorker_deploy' => true, // 是否需要部署businessWorker
23
+    'gateway_deploy'        => true, // 是否需要部署gateway
24
+
25
+    // Register配置
26
+    'registerAddress'       => '127.0.0.1:1236',
27
+
28
+    // Gateway配置
29
+    'name'                  => 'thinkphp',
30
+    'count'                 => 1,
31
+    'lanIp'                 => '127.0.0.1',
32
+    'startPort'             => 2000,
33
+    'daemonize'             => false,
34
+    'pingInterval'          => 30,
35
+    'pingNotResponseLimit'  => 0,
36
+    'pingData'              => '{"type":"ping"}',
37
+
38
+    // BusinsessWorker配置
39
+    'businessWorker'        => [
40
+        'name'         => 'BusinessWorker',
41
+        'count'        => 1,
42
+        'eventHandler' => '\think\worker\Events',
43
+    ],
44
+
45
+];

+ 1
- 1
config/lang.php Vedi File

@@ -5,7 +5,7 @@
5 5
 
6 6
 return [
7 7
     // 默认语言
8
-    'default_lang'    => env('lang.default_lang', 'zh-cn'),
8
+    'default_lang'    => env('DEFAULT_LANG', 'zh-cn'),
9 9
     // 允许的语言列表
10 10
     'allow_lang_list' => [],
11 11
     // 多语言自动侦测变量名

+ 1
- 1
config/log.php Vedi File

@@ -5,7 +5,7 @@
5 5
 // +----------------------------------------------------------------------
6 6
 return [
7 7
     // 默认日志记录通道
8
-    'default'      => env('log.channel', 'file'),
8
+    'default'      => 'file',
9 9
     // 日志记录级别
10 10
     'level'        => [],
11 11
     // 日志类型记录的通道 ['error'=>'email',...]

+ 10
- 0
config/trace.php Vedi File

@@ -0,0 +1,10 @@
1
+<?php
2
+// +----------------------------------------------------------------------
3
+// | Trace设置 开启调试模式后有效
4
+// +----------------------------------------------------------------------
5
+return [
6
+    // 内置Html和Console两种方式 支持扩展
7
+    'type'    => 'Html',
8
+    // 读取的日志通道名
9
+    'channel' => '',
10
+];

+ 30
- 0
config/worker.php Vedi File

@@ -0,0 +1,30 @@
1
+<?php
2
+// +----------------------------------------------------------------------
3
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
4
+// +----------------------------------------------------------------------
5
+// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
6
+// +----------------------------------------------------------------------
7
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
+// +----------------------------------------------------------------------
9
+// | Author: liu21st <liu21st@gmail.com>
10
+// +----------------------------------------------------------------------
11
+
12
+// +----------------------------------------------------------------------
13
+// | Workerman设置 仅对 php think worker 指令有效
14
+// +----------------------------------------------------------------------
15
+return [
16
+    // 扩展自身需要的配置
17
+    'host'                  => '0.0.0.0', // 监听地址
18
+    'port'                  => 2346, // 监听端口
19
+    'root'                  => '', // WEB 根目录 默认会定位public目录
20
+    'app_path'              => '', // 应用目录 守护进程模式必须设置(绝对路径)
21
+    'file_monitor'          => false, // 是否开启PHP文件更改监控(调试模式下自动开启)
22
+    'file_monitor_interval' => 2, // 文件监控检测时间间隔(秒)
23
+    'file_monitor_path'     => [], // 文件监控目录 默认监控application和config目录
24
+
25
+    // 支持workerman的所有配置参数
26
+    'name'                  => 'thinkphp',
27
+    'count'                 => 4,
28
+    'daemonize'             => false,
29
+    'pidFile'               => '',
30
+];

+ 55
- 0
config/worker_server.php Vedi File

@@ -0,0 +1,55 @@
1
+<?php
2
+// +----------------------------------------------------------------------
3
+// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
4
+// +----------------------------------------------------------------------
5
+// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
6
+// +----------------------------------------------------------------------
7
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
+// +----------------------------------------------------------------------
9
+// | Author: liu21st <liu21st@gmail.com>
10
+// +----------------------------------------------------------------------
11
+
12
+// +----------------------------------------------------------------------
13
+// | Workerman设置 仅对 php think worker:server 指令有效
14
+// +----------------------------------------------------------------------
15
+return [
16
+    // 扩展自身需要的配置
17
+    'protocol'       => 'websocket', // 协议 支持 tcp udp unix http websocket text
18
+    'host'           => '0.0.0.0', // 监听地址
19
+    'port'           => 2346, // 监听端口
20
+    'socket'         => '', // 完整监听地址
21
+    'context'        => [], // socket 上下文选项
22
+    'worker_class'   => 'app\work\controller\Push', // 自定义Workerman服务类名 支持数组定义多个服务
23
+
24
+    // 支持workerman的所有配置参数
25
+    'name'           => 'thinkphp',
26
+    'count'          => 4,
27
+    'daemonize'      => false,
28
+    'pidFile'        => '',
29
+
30
+    // 支持事件回调
31
+    // onWorkerStart
32
+    'onWorkerStart'  => function ($worker) {
33
+
34
+    },
35
+    // onWorkerReload
36
+    'onWorkerReload' => function ($worker) {
37
+
38
+    },
39
+    // onConnect
40
+    'onConnect'      => function ($connection) {
41
+
42
+    },
43
+    // onMessage
44
+    'onMessage'      => function ($connection, $data) {
45
+        $connection->send('receive success');
46
+    },
47
+    // onClose
48
+    'onClose'        => function ($connection) {
49
+
50
+    },
51
+    // onError
52
+    'onError'        => function ($connection, $code, $msg) {
53
+        echo "error [ $code ] $msg\n";
54
+    },
55
+];

+ 1
- 0
public/.user.ini Vedi File

@@ -0,0 +1 @@
1
+open_basedir=/www/wwwroot/workerman.dev.zx2049.com/tp/:/tmp/

BIN
public/favicon.ico Vedi File


+ 316
- 0
view/work/push/index.html Vedi File

@@ -0,0 +1,316 @@
1
+
2
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+<html xmlns="http://www.w3.org/1999/xhtml">
4
+
5
+<head>
6
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+    <title>上传关键词</title>
8
+    <meta name="keywords" content="御宅男CMS,CMS,YZNCMS,内容管理系统,CMS系统" />
9
+    <meta name="description" content="Yzncms(又名御宅男CMS)是基于最新TP5.1框架的CMS内容管理系统。是一款完全免费开源的项目,他将是您轻松建站的首选利器。框架易于功能扩展,代码维护,方便二次开发,帮助开发者简单高效降低二次开发成本,满足专注业务深度开发的需求。" />
10
+
11
+    <!-- 引入 layui.css -->
12
+    <link href="//unpkg.com/layui@2.9.8/dist/css/layui.css" rel="stylesheet">
13
+    <!-- 引入 layui.js -->
14
+    <script src="//unpkg.com/layui@2.9.8/dist/layui.js"></script>
15
+
16
+
17
+</head>
18
+
19
+<body>
20
+
21
+<div class="" style="width:800px;margin:0 auto;">
22
+    <form class="layui-form" action="" style="margin-top:50px;" id="form_info">
23
+
24
+        <div class="layui-form-item">
25
+            <label class="layui-form-label">选择规则</label>
26
+            <div class="layui-input-block">
27
+                <select name="rule" lay-verify="required">
28
+
29
+                    {foreach $rule as $key=>$vo}
30
+                    <option value="{$key}">{$vo}</option>
31
+                    {/foreach}
32
+
33
+
34
+                </select>
35
+            </div>
36
+        </div>
37
+
38
+
39
+        <div class="layui-form-item">
40
+            <label class="layui-form-label">关键词</label>
41
+            <div class="layui-input-block">
42
+                <input type="text" name="title" required  lay-verify="required" placeholder="请输入关键词(主词)" autocomplete="off" class="layui-input">
43
+            </div>
44
+        </div>
45
+
46
+        <div class="layui-form-item">
47
+            <label class="layui-form-label">输入框</label>
48
+            <div class="layui-input-block">
49
+
50
+                <div class="layui-upload">
51
+                    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" id="testList">选择多文件</button>
52
+                    <div class="layui-upload-list" style="max-width: 1000px;">
53
+                        <table class="layui-table">
54
+                            <colgroup>
55
+                                <col>
56
+                                <col width="150">
57
+                                <col width="260">
58
+                                <col width="150">
59
+                            </colgroup>
60
+                            <thead>
61
+                            <tr><th>文件名</th>
62
+                                <th>大小</th>
63
+                                <th>上传进度</th>
64
+                                <th>操作</th>
65
+                            </tr></thead>
66
+                            <tbody id="demoList"></tbody>
67
+                        </table>
68
+                    </div>
69
+                    <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" id="testListAction">开始上传</button>
70
+                </div>
71
+
72
+
73
+                <input type="hidden" name="url" required  lay-verify="required" id="file_url" value="" />
74
+            </div>
75
+        </div>
76
+
77
+        <!--<div class="layui-form-item">
78
+            <label class="layui-form-label">密码框</label>
79
+            <div class="layui-input-inline">
80
+                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
81
+            </div>
82
+            <div class="layui-form-mid layui-word-aux">辅助文字</div>
83
+        </div>
84
+        <div class="layui-form-item">
85
+            <label class="layui-form-label">选择框</label>
86
+            <div class="layui-input-block">
87
+                <select name="city" lay-verify="required">
88
+                    <option value=""></option>
89
+                    <option value="0">北京</option>
90
+                    <option value="1">上海</option>
91
+                    <option value="2">广州</option>
92
+                    <option value="3">深圳</option>
93
+                    <option value="4">杭州</option>
94
+                </select>
95
+            </div>
96
+        </div>
97
+        <div class="layui-form-item">
98
+            <label class="layui-form-label">复选框</label>
99
+            <div class="layui-input-block">
100
+                <input type="checkbox" name="like[write]" title="写作">
101
+                <input type="checkbox" name="like[read]" title="阅读" checked>
102
+                <input type="checkbox" name="like[dai]" title="发呆">
103
+            </div>
104
+        </div>
105
+        <div class="layui-form-item">
106
+            <label class="layui-form-label">开关</label>
107
+            <div class="layui-input-block">
108
+                <input type="checkbox" name="switch" lay-skin="switch">
109
+            </div>
110
+        </div>
111
+        <div class="layui-form-item">
112
+            <label class="layui-form-label">单选框</label>
113
+            <div class="layui-input-block">
114
+                <input type="radio" name="sex" value="男" title="男">
115
+                <input type="radio" name="sex" value="女" title="女" checked>
116
+            </div>
117
+        </div>
118
+        <div class="layui-form-item layui-form-text">
119
+            <label class="layui-form-label">文本域</label>
120
+            <div class="layui-input-block">
121
+                <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
122
+            </div>
123
+        </div>-->
124
+        <div class="layui-form-item">
125
+            <div class="layui-input-block">
126
+                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
127
+                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
128
+            </div>
129
+        </div>
130
+    </form>
131
+</div>
132
+
133
+<div class="layui-bg-gray" style="padding: 30px;">
134
+    <div class="layui-row layui-col-space15">
135
+        <div class="layui-col-md6">
136
+            <div class="layui-panel">
137
+                <div style="padding: 50px 30px;">一个面板</div>
138
+            </div>
139
+        </div>
140
+        <div class="layui-col-md6">
141
+            <div class="layui-panel">
142
+                <div style="padding: 50px 30px;">一个面板</div>
143
+            </div>
144
+        </div>
145
+    </div>
146
+</div>
147
+
148
+</body>
149
+
150
+</html>
151
+
152
+
153
+<script>
154
+    layui.use(['upload', 'element', 'layer','form'], function(){
155
+
156
+        var form = layui.form;
157
+        var $ = layui.jquery
158
+            ,upload = layui.upload
159
+            ,element = layui.element
160
+            ,layer = layui.layer;
161
+
162
+
163
+        /*$.ajax({  // 定义ajax发送请求
164
+            url:'http://console.zx2049.com/api/ai/uploadCsv',  // 请求发送的地址  有三种填写方式,与form标签的action一致
165
+            method:'get',  // 请求发送的方式
166
+            data: {'num1':0,'num2':1},  // 请求携带的数据
167
+            success:function(data){  // 异步等待,当后端响应成功会回调执行匿名函数,并将数据传递给data参数
168
+              console.log(data);
169
+            }// 使用ajax交互,那么后端返回的数据会被data接收,不在直接影响整个浏览器页面
170
+
171
+        });*/
172
+
173
+
174
+        //演示多文件列表
175
+        var uploadListIns = upload.render({
176
+            elem: '#testList'
177
+            ,elemList: $('#demoList') //列表元素对象
178
+            ,url: 'http://console.zx2049.com/api/ai/uploadCsv' //此处用的是第三方的 http 请求演示,实际使用时改成您自己的上传接口即可。
179
+            ,accept: 'file'
180
+            ,exts: 'xlsx|xls|csv' //只允许上传压缩文件
181
+            ,size: 2000 //限制文件大小,单位 KB
182
+            ,multiple: true
183
+            ,number: 1
184
+            ,auto: false
185
+            ,bindAction: '#testListAction'
186
+            ,choose: function(obj){
187
+                var that = this;
188
+                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
189
+                //读取本地文件
190
+                obj.preview(function(index, file, result){
191
+                    var tr = $(['<tr id="upload-'+ index +'">'
192
+                        ,'<td>'+ file.name +'</td>'
193
+                        ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
194
+                        ,'<td><div class="layui-progress" lay-filter="progress-demo-'+ index +'"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
195
+                        ,'<td>'
196
+                        ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
197
+                        ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
198
+                        ,'</td>'
199
+                        ,'</tr>'].join(''));
200
+
201
+                    //单个重传
202
+                    tr.find('.demo-reload').on('click', function(){
203
+                        obj.upload(index, file);
204
+                    });
205
+
206
+                    //删除
207
+                    tr.find('.demo-delete').on('click', function(){
208
+                        delete files[index]; //删除对应的文件
209
+                        tr.remove();
210
+                        uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
211
+                    });
212
+
213
+                    that.elemList.append(tr);
214
+                    element.render('progress'); //渲染新加的进度条组件
215
+                });
216
+            }
217
+            ,done: function(res, index, upload){ //成功的回调
218
+                var that = this;
219
+                //if(res.code == 0){ //上传成功
220
+                var tr = that.elemList.find('tr#upload-'+ index)
221
+                    ,tds = tr.children();
222
+                tds.eq(3).html(''); //清空操作
223
+                delete this.files[index]; //删除文件队列已经上传成功的文件
224
+
225
+                //赋值 //如果选择多次 上传多次 不管 最后一次上传为主即可
226
+                //var url = $('#file_url').val();
227
+                $('#file_url').val(res.data.src); // + ',' + url
228
+
229
+                return;
230
+                //}
231
+                this.error(index, upload);
232
+            }
233
+            ,allDone: function(obj){ //多文件上传完毕后的状态回调
234
+                console.log(obj);
235
+                //
236
+            }
237
+            ,error: function(index, upload){ //错误回调
238
+                var that = this;
239
+                var tr = that.elemList.find('tr#upload-'+ index)
240
+                    ,tds = tr.children();
241
+                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
242
+            }
243
+            ,progress: function(n, elem, e, index){ //注意:index 参数为 layui 2.6.6 新增
244
+                element.progress('progress-demo-'+ index, n + '%'); //执行进度条。n 即为返回的进度百分比
245
+            }
246
+        });
247
+
248
+
249
+        //监听提交
250
+        form.on('submit(formDemo)', function(data){
251
+            //layer.msg(JSON.stringify(data.field));
252
+            $.ajax({  // 定义ajax发送请求
253
+                url:'http://console.zx2049.com/api/ai/uploadCsvFrom',  // 请求发送的地址  有三种填写方式,与form标签的action一致
254
+                method:'post',  // 请求发送的方式
255
+                data: data.field,  // 请求携带的数据
256
+                success:function(res){  // 异步等待,当后端响应成功会回调执行匿名函数,并将数据传递给data参数
257
+                    console.log(res);
258
+
259
+                    if(res.code == 0){
260
+                        layer.msg('提交成功');
261
+                        //重置表单
262
+                        $("#form_info")[0].reset();
263
+                        $('#file_url').val('');
264
+                        $('#demoList').empty();
265
+                    }else{
266
+                        layer.msg(res.msg);
267
+                    }
268
+
269
+
270
+                }// 使用ajax交互,那么后端返回的数据会被data接收,不在直接影响整个浏览器页面
271
+
272
+            });
273
+            return false;
274
+        });
275
+    });
276
+</script>
277
+
278
+
279
+<script>
280
+    let ws = new WebSocket("ws://47.120.56.77:2346")
281
+
282
+    ws.onopen = function() {
283
+        //绑定连接事件
284
+        console.log("连接成功");
285
+
286
+        //每30秒发送一次心跳
287
+        setInterval(function(){
288
+
289
+            // 假设ws是一个WebSocket实例
290
+            if (ws.readyState !== WebSocket.OPEN) {
291
+                // 连接不是打开状态,可能是关闭中或已关闭,不应该发送数据
292
+                console.log('WebSocket is not open.');
293
+                return false;
294
+            }
295
+
296
+            ws.send(JSON.stringify({'type':"peng"}));
297
+            console.log('发送心跳...');
298
+
299
+        },30000)
300
+
301
+    };
302
+
303
+    ws.onmessage = function(evt) {
304
+        //绑定收到消息事件
305
+        data = JSON.parse(evt.data)
306
+        console.log(data);
307
+        //这里处理收到的消息, type类型有两种: connectin、deposit如果有deposit要提示有新的订单
308
+
309
+    };
310
+
311
+
312
+    ws.onclose = function(evt) {
313
+        //绑定关闭或断开连接事件
314
+        console.log("连接已关闭");
315
+    };
316
+</script>

Loading…
Annulla
Salva