forget,time,layui
1
.example.env
Normal file
@ -0,0 +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
|
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
/.idea
|
||||
/.vscode
|
||||
/vendor
|
||||
*.log
|
||||
*.sql
|
||||
.env
|
22
app/AppService.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Service;
|
||||
|
||||
/**
|
||||
* 应用服务类
|
||||
*/
|
||||
class AppService extends Service
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
// 服务注册
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// 服务启动
|
||||
}
|
||||
}
|
@ -72,7 +72,7 @@ abstract class BaseController
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
list($validate, $scene) = explode('.', $validate);
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
|
@ -35,7 +35,12 @@ class Index extends AdminController
|
||||
|
||||
public function home(){
|
||||
$sys = Db::name('system')->find(1);
|
||||
View::assign('sys',$sys);
|
||||
$now = time();
|
||||
$count = $now-$sys['create_time'];
|
||||
$days = floor($count/86400);
|
||||
$hos = floor(($count%86400)/3600);
|
||||
$mins = floor(($count%3600)/60);
|
||||
View::assign(['sys'=>$sys,'day'=>$days,'hos'=>$hos,'mins'=>$mins]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Login extends BaseController
|
||||
->check($data);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return json(['code'=>0,'msg'=>$e->getError()]);
|
||||
return json(['code'=>-1,'msg'=>$e->getError()]);
|
||||
}
|
||||
$data['name'] = $data['email'];
|
||||
unset($data['email']);
|
||||
@ -49,16 +49,16 @@ class Login extends BaseController
|
||||
->check($data);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return json(['code'=>0,'msg'=>$e->getError()]);
|
||||
return json(['code'=>-1,'msg'=>$e->getError()]);
|
||||
}
|
||||
}
|
||||
//登陆请求
|
||||
$user = new \app\common\model\User();
|
||||
$res = $user->login($data);
|
||||
if ($res == 1) {
|
||||
return json(['code'=>'1','msg'=>'登陆成功','url'=>'/']);
|
||||
return json(['code'=>0,'msg'=>'登陆成功','url'=>'/']);
|
||||
} else {
|
||||
return json(['code'=>'0','msg'=>$res]);
|
||||
return json(['code'=>-1,'msg'=>$res]);
|
||||
}
|
||||
}
|
||||
return View::fetch('login');
|
||||
@ -76,16 +76,16 @@ class Login extends BaseController
|
||||
->scene('Reg')
|
||||
->check($data);
|
||||
} catch (ValidateException $e) {
|
||||
return json(['code'=>0,'msg'=>$e->getError()]);
|
||||
return json(['code'=>-1,'msg'=>$e->getError()]);
|
||||
}
|
||||
|
||||
$user = new userModel;
|
||||
$result = $user->reg($data);
|
||||
|
||||
if ($result == 1) {
|
||||
$res = ['code'=>1,'msg'=>'注册成功','url'=>'/'];
|
||||
$res = ['code'=>0,'msg'=>'注册成功','url'=>'/index/login'];
|
||||
}else {
|
||||
$res = ['code'=>0,'msg'=>$result];
|
||||
$res = ['code'=>-1,'msg'=>$result];
|
||||
}
|
||||
return json($res);
|
||||
}
|
||||
@ -104,7 +104,7 @@ class Login extends BaseController
|
||||
->scene('Forget')
|
||||
->check($data);
|
||||
} catch (ValidateException $e) {
|
||||
return json(['code'=>0,'msg'=>$e->getError()]);
|
||||
return json(['code'=>-1,'msg'=>$e->getError()]);
|
||||
}
|
||||
//查询用户
|
||||
$user = Db::name('user')->where('email',$data['email'])->find();
|
||||
@ -116,12 +116,12 @@ class Login extends BaseController
|
||||
$result = mailto($data['email'],'重置密码','Hi亲爱的'.$user['name'].':</br>您正在维护您的信息,请在10分钟内验证,您的验证码为:'.$code);
|
||||
if($result){
|
||||
Cache::set('repass',1,60); //设置repass标志为1存入Cache
|
||||
$res = ['code'=>1,'msg'=>'验证码已发送成功,请去邮箱查看!','url'=>'/index/login/postcode'];
|
||||
$res = ['code'=>0,'msg'=>'验证码已发送成功,请去邮箱查看!','url'=>'/index/postcode'];
|
||||
} else {
|
||||
$res = ['code'=>0,'msg'=>'验证码发送失败!'];
|
||||
$res = ['code'=>-1,'msg'=>'验证码发送失败!'];
|
||||
}
|
||||
}else{
|
||||
$res = ['code' =>0,'msg'=>'邮箱错误或不存在'];
|
||||
$res = ['code' =>-1,'msg'=>'邮箱错误或不存在'];
|
||||
}
|
||||
return json($res);
|
||||
}
|
||||
@ -132,7 +132,7 @@ class Login extends BaseController
|
||||
public function postcode()
|
||||
{
|
||||
if(Cache::get('repass') != 1){
|
||||
return json(['code'=>0,'msg'=>'请求错误!','url'=>'/index/login/forget']);
|
||||
return redirect('/index/forget');
|
||||
}
|
||||
if(Request::isAjax()){
|
||||
$code = Request::only(['code']);
|
||||
@ -141,15 +141,15 @@ class Login extends BaseController
|
||||
->scene('Code')
|
||||
->check($code);
|
||||
} catch (ValidateException $e) {
|
||||
return json(['code'=>0,'msg'=>$e->getError()]);
|
||||
return json(['code'=>-1,'msg'=>$e->getError()]);
|
||||
}
|
||||
|
||||
if(Cache::get('code')==$code['code']) { //无任何输入情况下需排除code为0和Cache为0的情况
|
||||
//Cache::delete('repass');
|
||||
Cache::set('repass',2,60);
|
||||
$res = ['code'=>'1','msg'=>'验证成功','url'=>'/index/login/respass'];
|
||||
$res = ['code'=>0,'msg'=>'验证成功','url'=>'/index/respass'];
|
||||
} else {
|
||||
$res = ['code'=>0,'msg'=>'验证码错误或已过期!'];
|
||||
$res = ['code'=>-1,'msg'=>'验证码错误或已过期!'];
|
||||
}
|
||||
return json($res);
|
||||
}
|
||||
@ -160,7 +160,7 @@ class Login extends BaseController
|
||||
public function respass()
|
||||
{
|
||||
if(Cache::get('repass') != 2){
|
||||
return json(['code'=>0,'msg'=>'请求错误!','url'=>'/index/login/forget']);
|
||||
return redirect('/index/forget');
|
||||
}
|
||||
if(Request::isAjax()){
|
||||
$data = Request::param();
|
||||
@ -169,16 +169,16 @@ class Login extends BaseController
|
||||
->scene('Repass')
|
||||
->check($data);
|
||||
} catch (ValidateException $e) {
|
||||
return json(['code'=>0,'msg'=>$e->getError()]);
|
||||
return json(['code'=>-1,'msg'=>$e->getError()]);
|
||||
}
|
||||
|
||||
$data['uid'] = Cache::get('userid');
|
||||
$user = new \app\common\model\User();
|
||||
$res = $user->respass($data);
|
||||
if ($res == 1) {
|
||||
return json(['code'=>'1','msg'=>'修改成功','url'=>'/index/login/index']);
|
||||
return json(['code'=>0,'msg'=>'修改成功','url'=>'/index/login']);
|
||||
} else {
|
||||
return json(['code'=>'0','msg'=>'$res']);
|
||||
return json(['code'=>-1,'msg'=>'$res']);
|
||||
}
|
||||
}
|
||||
return View::fetch('forget');
|
||||
|
9
app/service.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use app\AppService;
|
||||
|
||||
// 系统服务定义文件
|
||||
// 服务在完成全局初始化之后执行
|
||||
return [
|
||||
AppService::class,
|
||||
];
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* php think build 自动生成应用的目录结构的定义示例
|
||||
*/
|
||||
return [
|
||||
// 需要自动创建的文件
|
||||
'__file__' => [],
|
||||
// 需要自动创建的目录
|
||||
'__dir__' => ['controller', 'model', 'view'],
|
||||
// 需要自动创建的控制器
|
||||
'controller' => ['Index'],
|
||||
// 需要自动创建的模型
|
||||
'model' => ['User'],
|
||||
// 需要自动创建的模板
|
||||
'view' => ['index/index'],
|
||||
];
|
@ -17,13 +17,8 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"topthink/framework": "6.0.*-dev",
|
||||
"topthink/think-orm": "2.0.*-dev",
|
||||
"topthink/think-view": "^1.0",
|
||||
"topthink/think-multi-app": "^1.0",
|
||||
"topthink/think-captcha": "^3.0",
|
||||
"xiaodi/think-auth": "^3.0",
|
||||
"phpmailer/phpmailer": "^6.1"
|
||||
"topthink/framework": "^6.0.0",
|
||||
"topthink/think-orm": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
@ -3,19 +3,15 @@
|
||||
// | 应用设置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
return [
|
||||
// 应用地址
|
||||
'app_host' => Env::get('app.host', ''),
|
||||
'app_host' => env('app.host', ''),
|
||||
// 应用的命名空间
|
||||
'app_namespace' => '',
|
||||
// 是否启用路由
|
||||
'with_route' => true,
|
||||
// 是否启用事件
|
||||
'with_event' => true,
|
||||
// 开启应用快速访问
|
||||
'app_express' => true,
|
||||
// 默认应用
|
||||
'default_app' => 'index',
|
||||
// 默认时区
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
use think\facade\Env;
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | 缓存设置
|
||||
@ -7,7 +6,7 @@ use think\facade\Env;
|
||||
|
||||
return [
|
||||
// 默认缓存驱动
|
||||
'default' => Env::get('cache.driver', 'file'),
|
||||
'default' => env('cache.driver', 'file'),
|
||||
|
||||
// 缓存连接方式配置
|
||||
'stores' => [
|
||||
@ -19,7 +18,7 @@ return [
|
||||
// 缓存前缀
|
||||
'prefix' => '',
|
||||
// 缓存有效期 0表示永久缓存
|
||||
'expire' => 600,
|
||||
'expire' => 0,
|
||||
// 缓存标签前缀
|
||||
'tag_prefix' => 'tag:',
|
||||
// 序列化机制 例如 ['serialize', 'unserialize']
|
||||
|
@ -1,10 +1,8 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
return [
|
||||
// 默认磁盘
|
||||
'default' => Env::get('filesystem.driver', 'local'),
|
||||
'default' => env('filesystem.driver', 'local'),
|
||||
// 磁盘列表
|
||||
'disks' => [
|
||||
'local' => [
|
||||
@ -22,16 +20,5 @@ return [
|
||||
'visibility' => 'public',
|
||||
],
|
||||
// 更多的磁盘配置信息
|
||||
|
||||
'tmp' => [
|
||||
// 磁盘类型
|
||||
'type' => 'local',
|
||||
// 磁盘路径
|
||||
'root' => app()->getRootPath() . 'tmp/web',
|
||||
// 磁盘路径对应的外部URL路径
|
||||
'url' => '/web',
|
||||
// 可见性
|
||||
'visibility' => 'tmp',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
@ -3,11 +3,9 @@
|
||||
// | 多语言设置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
return [
|
||||
// 默认语言
|
||||
'default_lang' => Env::get('lang.default_lang', 'zh-cn'),
|
||||
'default_lang' => env('lang.default_lang', 'zh-cn'),
|
||||
// 允许的语言列表
|
||||
'allow_lang_list' => [],
|
||||
// 多语言自动侦测变量名
|
||||
|
@ -1,12 +1,11 @@
|
||||
<?php
|
||||
use think\facade\Env;
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | 日志设置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
// 默认日志记录通道
|
||||
'default' => Env::get('log.channel', 'file'),
|
||||
'default' => env('log.channel', 'file'),
|
||||
// 日志记录级别
|
||||
'level' => [],
|
||||
// 日志类型记录的通道 ['error'=>'email',...]
|
||||
|
@ -18,12 +18,6 @@ return [
|
||||
'route_rule_merge' => false,
|
||||
// 路由是否完全匹配
|
||||
'route_complete_match' => false,
|
||||
// 是否开启路由缓存
|
||||
'route_check_cache' => false,
|
||||
// 路由缓存连接参数
|
||||
'route_cache_option' => [],
|
||||
// 路由缓存Key
|
||||
'route_check_cache_key' => '',
|
||||
// 访问控制器层名称
|
||||
'controller_layer' => 'controller',
|
||||
// 空控制器名
|
||||
|
@ -13,5 +13,7 @@
|
||||
if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) {
|
||||
return false;
|
||||
} else {
|
||||
$_SERVER["SCRIPT_FILENAME"] = __DIR__ . '/index.php';
|
||||
|
||||
require __DIR__ . "/index.php";
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
/** layui-v2.5.5 MIT License By https://www.layui.com */
|
||||
html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #e2e2e2;border-left-width:6px;background-color:#F2F2F2;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:32px;line-height:32px;border-bottom:1px solid #e2e2e2}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 5px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}
|
Before Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 701 B |
Before Width: | Height: | Size: 1.7 KiB |
@ -1,96 +0,0 @@
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>聊天记录</title>
|
||||
|
||||
<link rel="stylesheet" href="http://local.res.layui.com/layui/src/css/layui.css">
|
||||
<style>
|
||||
body .layim-chat-main{height: auto;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="layim-chat-main">
|
||||
<ul id="LAY_view"></ul>
|
||||
</div>
|
||||
|
||||
<div id="LAY_page" style="margin: 0 10px;"></div>
|
||||
|
||||
|
||||
<textarea title="消息模版" id="LAY_tpl" style="display:none;">
|
||||
{{# layui.each(d.data, function(index, item){
|
||||
if(item.id == parent.layui.layim.cache().mine.id){ }}
|
||||
<li class="layim-chat-mine"><div class="layim-chat-user"><img src="{{ item.avatar }}"><cite><i>{{ layui.data.date(item.timestamp) }}</i>{{ item.username }}</cite></div><div class="layim-chat-text">{{ layui.layim.content(item.content) }}</div></li>
|
||||
{{# } else { }}
|
||||
<li><div class="layim-chat-user"><img src="{{ item.avatar }}"><cite>{{ item.username }}<i>{{ layui.data.date(item.timestamp) }}</i></cite></div><div class="layim-chat-text">{{ layui.layim.content(item.content) }}</div></li>
|
||||
{{# }
|
||||
}); }}
|
||||
</textarea>
|
||||
|
||||
<!--
|
||||
上述模版采用了 laytpl 语法,不了解的同学可以去看下文档:http://www.layui.com/doc/modules/laytpl.html
|
||||
|
||||
-->
|
||||
|
||||
|
||||
<script src="http://local.res.layui.com/layui/src/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['layim', 'laypage'], function(){
|
||||
var layim = layui.layim
|
||||
,layer = layui.layer
|
||||
,laytpl = layui.laytpl
|
||||
,$ = layui.jquery
|
||||
,laypage = layui.laypage;
|
||||
|
||||
//聊天记录的分页此处不做演示,你可以采用laypage,不了解的同学见文档:http://www.layui.com/doc/modules/laypage.html
|
||||
|
||||
|
||||
//开始请求聊天记录
|
||||
var param = location.search //获得URL参数。该窗口url会携带会话id和type,他们是你请求聊天记录的重要凭据
|
||||
|
||||
//实际使用时,下述的res一般是通过Ajax获得,而此处仅仅只是演示数据格式
|
||||
,res = {
|
||||
code: 0
|
||||
,msg: ''
|
||||
,data: [{
|
||||
username: '纸飞机'
|
||||
,id: 100000
|
||||
,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
|
||||
,timestamp: 1480897882000
|
||||
,content: 'face[抱抱] face[心] 你好啊小美女'
|
||||
}, {
|
||||
username: 'Z_子晴'
|
||||
,id: 108101
|
||||
,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
|
||||
,timestamp: 1480897892000
|
||||
,content: '你没发错吧?face[微笑]'
|
||||
},{
|
||||
username: 'Z_子晴'
|
||||
,id: 108101
|
||||
,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
|
||||
,timestamp: 1480897898000
|
||||
,content: '你是谁呀亲。。我爱的是贤心!我爱的是贤心!我爱的是贤心!重要的事情要说三遍~'
|
||||
},{
|
||||
username: 'Z_子晴'
|
||||
,id: 108101
|
||||
,avatar: 'http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg'
|
||||
,timestamp: 1480897908000
|
||||
,content: '注意:这些都是模拟数据,实际使用时,需将其中的模拟接口改为你的项目真实接口。\n该模版文件所在目录(相对于layui.js):\n/css/modules/layim/html/chatlog.html'
|
||||
}]
|
||||
}
|
||||
|
||||
//console.log(param)
|
||||
|
||||
var html = laytpl(LAY_tpl.value).render({
|
||||
data: res.data
|
||||
});
|
||||
$('#LAY_view').html(html);
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,38 +0,0 @@
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>发现</title>
|
||||
|
||||
<link rel="stylesheet" href="http://local.res.layui.com/layui/src/css/layui.css">
|
||||
<style>
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div style="margin: 15px;">
|
||||
<blockquote class="layui-elem-quote">此为自定义的【查找】页面,因需求不一,所以官方暂不提供该模版结构与样式,实际使用时,可移至该文件到你的项目中,对页面自行把控。
|
||||
<br>文件所在目录(相对于layui.js):/css/modules/layim/html/find.html</blockquote>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script src="http://local.res.layui.com/layui/src/layui.js"></script>
|
||||
<script>
|
||||
layui.use(['layim', 'laypage'], function(){
|
||||
var layim = layui.layim
|
||||
,layer = layui.layer
|
||||
,laytpl = layui.laytpl
|
||||
,$ = layui.jquery
|
||||
,laypage = layui.laypage;
|
||||
|
||||
//一些添加好友请求之类的交互参见文档
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,87 +0,0 @@
|
||||
{
|
||||
"code": 0,
|
||||
"pages": 1,
|
||||
"data": [
|
||||
{
|
||||
"id": 76,
|
||||
"content": "申请添加你为好友",
|
||||
"uid": 168,
|
||||
"from": 166488,
|
||||
"from_group": 0,
|
||||
"type": 1,
|
||||
"remark": "有问题要问",
|
||||
"href": null,
|
||||
"read": 1,
|
||||
"time": "刚刚",
|
||||
"user": {
|
||||
"id": 166488,
|
||||
"avatar": "http://q.qlogo.cn/qqapp/101235792/B704597964F9BD0DB648292D1B09F7E8/100",
|
||||
"username": "李彦宏",
|
||||
"sign": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 75,
|
||||
"content": "申请添加你为好友",
|
||||
"uid": 168,
|
||||
"from": 347592,
|
||||
"from_group": 0,
|
||||
"type": 1,
|
||||
"remark": "你好啊!",
|
||||
"href": null,
|
||||
"read": 1,
|
||||
"time": "刚刚",
|
||||
"user": {
|
||||
"id": 347592,
|
||||
"avatar": "http://q.qlogo.cn/qqapp/101235792/B78751375E0531675B1272AD994BA875/100",
|
||||
"username": "麻花疼",
|
||||
"sign": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 62,
|
||||
"content": "雷军 拒绝了你的好友申请",
|
||||
"uid": 168,
|
||||
"from": null,
|
||||
"from_group": null,
|
||||
"type": 1,
|
||||
"remark": null,
|
||||
"href": null,
|
||||
"read": 1,
|
||||
"time": "10天前",
|
||||
"user": {
|
||||
"id": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 60,
|
||||
"content": "马小云 已经同意你的好友申请",
|
||||
"uid": 168,
|
||||
"from": null,
|
||||
"from_group": null,
|
||||
"type": 1,
|
||||
"remark": null,
|
||||
"href": null,
|
||||
"read": 1,
|
||||
"time": "10天前",
|
||||
"user": {
|
||||
"id": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 61,
|
||||
"content": "贤心 已经同意你的好友申请",
|
||||
"uid": 168,
|
||||
"from": null,
|
||||
"from_group": null,
|
||||
"type": 1,
|
||||
"remark": null,
|
||||
"href": null,
|
||||
"read": 1,
|
||||
"time": "10天前",
|
||||
"user": {
|
||||
"id": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>消息盒子</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../layui.css?v=1">
|
||||
<style>
|
||||
.layim-msgbox{margin: 15px;}
|
||||
.layim-msgbox li{position: relative; margin-bottom: 10px; padding: 0 130px 10px 60px; padding-bottom: 10px; line-height: 22px; border-bottom: 1px dotted #e2e2e2;}
|
||||
.layim-msgbox .layim-msgbox-tips{margin: 0; padding: 10px 0; border: none; text-align: center; color: #999;}
|
||||
.layim-msgbox .layim-msgbox-system{padding: 0 10px 10px 10px;}
|
||||
.layim-msgbox li p span{padding-left: 5px; color: #999;}
|
||||
.layim-msgbox li p em{font-style: normal; color: #FF5722;}
|
||||
|
||||
.layim-msgbox-avatar{position: absolute; left: 0; top: 0; width: 50px; height: 50px;}
|
||||
.layim-msgbox-user{padding-top: 5px;}
|
||||
.layim-msgbox-content{margin-top: 3px;}
|
||||
.layim-msgbox .layui-btn-small{padding: 0 15px; margin-left: 5px;}
|
||||
.layim-msgbox-btn{position: absolute; right: 0; top: 12px; color: #999;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<ul class="layim-msgbox" id="LAY_view"></ul>
|
||||
|
||||
<div style="margin: 0 15px;">
|
||||
<blockquote class="layui-elem-quote">注意:这些都是模拟数据,实际使用时,需将其中的模拟接口改为你的项目真实接口。
|
||||
<br>该模版文件所在目录(相对于layui.js):/css/modules/layim/html/msgbox.html</blockquote>
|
||||
</div>
|
||||
|
||||
<textarea title="消息模版" id="LAY_tpl" style="display:none;">
|
||||
{{# layui.each(d.data, function(index, item){
|
||||
if(item.from){ }}
|
||||
<li data-uid="{{ item.from }}" data-fromGroup="{{ item.from_group }}">
|
||||
<a href="/u/{{ item.from }}/" target="_blank">
|
||||
<img src="{{ item.user.avatar }}" class="layui-circle layim-msgbox-avatar">
|
||||
</a>
|
||||
<p class="layim-msgbox-user">
|
||||
<a href="/u/{{ item.from }}/" target="_blank">{{ item.user.username||'' }}</a>
|
||||
<span>{{ item.time }}</span>
|
||||
</p>
|
||||
<p class="layim-msgbox-content">
|
||||
{{ item.content }}
|
||||
<span>{{ item.remark ? '附言: '+item.remark : '' }}</span>
|
||||
</p>
|
||||
<p class="layim-msgbox-btn">
|
||||
<button class="layui-btn layui-btn-small" data-type="agree">同意</button>
|
||||
<button class="layui-btn layui-btn-small layui-btn-primary" data-type="refuse">拒绝</button>
|
||||
</p>
|
||||
</li>
|
||||
{{# } else { }}
|
||||
<li class="layim-msgbox-system">
|
||||
<p><em>系统:</em>{{ item.content }}<span>{{ item.time }}</span></p>
|
||||
</li>
|
||||
{{# }
|
||||
}); }}
|
||||
</textarea>
|
||||
|
||||
<!--
|
||||
上述模版采用了 laytpl 语法,不了解的同学可以去看下文档:http://www.layui.com/doc/modules/laytpl.html
|
||||
-->
|
||||
|
||||
|
||||
<script src="../../../../layui.js?v=1"></script>
|
||||
<script>
|
||||
layui.use(['layim', 'flow'], function(){
|
||||
var layim = layui.layim
|
||||
,layer = layui.layer
|
||||
,laytpl = layui.laytpl
|
||||
,$ = layui.jquery
|
||||
,flow = layui.flow;
|
||||
|
||||
var cache = {}; //用于临时记录请求到的数据
|
||||
|
||||
//请求消息
|
||||
var renderMsg = function(page, callback){
|
||||
|
||||
//实际部署时,请将下述 getmsg.json 改为你的接口地址
|
||||
|
||||
$.get('getmsg.json', {
|
||||
page: page || 1
|
||||
}, function(res){
|
||||
if(res.code != 0){
|
||||
return layer.msg(res.msg);
|
||||
}
|
||||
|
||||
//记录来源用户信息
|
||||
layui.each(res.data, function(index, item){
|
||||
cache[item.from] = item.user;
|
||||
});
|
||||
|
||||
callback && callback(res.data, res.pages);
|
||||
});
|
||||
};
|
||||
|
||||
//消息信息流
|
||||
flow.load({
|
||||
elem: '#LAY_view' //流加载容器
|
||||
,isAuto: false
|
||||
,end: '<li class="layim-msgbox-tips">暂无更多新消息</li>'
|
||||
,done: function(page, next){ //加载下一页
|
||||
renderMsg(page, function(data, pages){
|
||||
var html = laytpl(LAY_tpl.value).render({
|
||||
data: data
|
||||
,page: page
|
||||
});
|
||||
next(html, page < pages);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//打开页面即把消息标记为已读
|
||||
/*
|
||||
$.post('/message/read', {
|
||||
type: 1
|
||||
});
|
||||
*/
|
||||
|
||||
//操作
|
||||
var active = {
|
||||
//同意
|
||||
agree: function(othis){
|
||||
var li = othis.parents('li')
|
||||
,uid = li.data('uid')
|
||||
,from_group = li.data('fromGroup')
|
||||
,user = cache[uid];
|
||||
|
||||
//选择分组
|
||||
parent.layui.layim.setFriendGroup({
|
||||
type: 'friend'
|
||||
,username: user.username
|
||||
,avatar: user.avatar
|
||||
,group: parent.layui.layim.cache().friend //获取好友分组数据
|
||||
,submit: function(group, index){
|
||||
|
||||
//将好友追加到主面板
|
||||
parent.layui.layim.addList({
|
||||
type: 'friend'
|
||||
,avatar: user.avatar //好友头像
|
||||
,username: user.username //好友昵称
|
||||
,groupid: group //所在的分组id
|
||||
,id: uid //好友ID
|
||||
,sign: user.sign //好友签名
|
||||
});
|
||||
parent.layer.close(index);
|
||||
othis.parent().html('已同意');
|
||||
|
||||
|
||||
//实际部署时,请开启下述注释,并改成你的接口地址
|
||||
/*
|
||||
$.post('/im/agreeFriend', {
|
||||
uid: uid //对方用户ID
|
||||
,from_group: from_group //对方设定的好友分组
|
||||
,group: group //我设定的好友分组
|
||||
}, function(res){
|
||||
if(res.code != 0){
|
||||
return layer.msg(res.msg);
|
||||
}
|
||||
|
||||
//将好友追加到主面板
|
||||
parent.layui.layim.addList({
|
||||
type: 'friend'
|
||||
,avatar: user.avatar //好友头像
|
||||
,username: user.username //好友昵称
|
||||
,groupid: group //所在的分组id
|
||||
,id: uid //好友ID
|
||||
,sign: user.sign //好友签名
|
||||
});
|
||||
parent.layer.close(index);
|
||||
othis.parent().html('已同意');
|
||||
});
|
||||
*/
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//拒绝
|
||||
,refuse: function(othis){
|
||||
var li = othis.parents('li')
|
||||
,uid = li.data('uid');
|
||||
|
||||
layer.confirm('确定拒绝吗?', function(index){
|
||||
$.post('/im/refuseFriend', {
|
||||
uid: uid //对方用户ID
|
||||
}, function(res){
|
||||
if(res.code != 0){
|
||||
return layer.msg(res.msg);
|
||||
}
|
||||
layer.close(index);
|
||||
othis.parent().html('<em>已拒绝</em>');
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$('body').on('click', '.layui-btn', function(){
|
||||
var othis = $(this), type = othis.data('type');
|
||||
active[type] ? active[type].call(this, othis) : '';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 277 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 777 B |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 2.2 KiB |