Index.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace app\web\controller;
use think\Request;
use think\Cookie;
/**
 * 首页
 * Class Index
 * @package app\admin\controller
 */
class Index extends Controller
{
    //登录页面
    public function login()
    {
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    public function tologin(Request $request)
    {
        $data = $request->param();
        $name="ybao";
        $pwd="ybao888";
        if($name != $data['name']){
            $data=[
                'code'=>100,
                'msg'=>'用户名错误'
            ];
            return json_encode($data);
        }elseif($pwd != $data['pwd']){
            $data=[
                'code'=>100,
                'msg'=>'密码错误'
            ];
            return json_encode($data);
        }else{
            Cookie::set('name',$name);
            //session('name', $name);
            $data=[
                'code'=>200,
                'msg'=>'验证成功'
            ];
            return json_encode($data);
        }
    }
    /**
     * 框架页面
     * @return array|mixed
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $user=Cookie::get('name');
        if(!$user){
            //重定向到指定的URL地址
            $this->error('您未进行登录', 'web/index/login'); exit;
        }
        $this->view->engine->layout(false);
        return $this->fetch('index');
    }
    public function loginout()
    {
        Cookie::delete('name');
        $this->view->engine->layout(false);
        return $this->fetch('login');
    }
	public function quick_menu()
    {
        $this->view->engine->layout(false);
        return $this->fetch('quick_menu');
    }
}