Index.php 1.9 KB
<?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');
    }
}