<?php
declare (strict_types = 1);

namespace app\index\controller;

use think\facade\View;
use think\facade\Db;
use think\facade\Session;
use think\facade\Request;
use think\facade\Lang;
use think\response\Json;
use think\facade\Env;

class Index extends Common{
	//首页
    public function index(){
        $tables = Db::name('table')->where(['status' => 1])->select()->toArray();
        $user_info = Session::get('user_info');
        $user = Db::name('user')->where(['id' => $user_info['id']])->find();
        $login_token = create_login_token($user);
        $api_token = $login_token;
        Db::name('user')->where(['id' => $user_info['id']])->update(['login_token' => $login_token, 'api_token' => $api_token]);
        View::assign('api_token',$api_token);
        View::assign('login_token',$login_token);
        View::assign('tables',$tables);
        View::assign('user',$user);
        View::assign('websocketUrl',Env::get('system.WEBSOCKET'));
        View::assign('websocketProtocol',Env::get('system.PROTOCOL'));
        return View::fetch();
	}
    function get_lang(): Json
    {
        if(!Request::instance()->isPost()) return json();
        $lang = Lang::get();
        return json(array('status' => 1, 'lang' => $lang));
    }
}