<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="{{asset('icon/faviconc.ico')}}" type="image/x-icon"/>
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>@yield('title') {{ config('app.name', '宝时WAS') }}</title>
    @yield('head')
    <!-- Styles -->
    <link href="{{ mix('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">
    <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
        <div class="container-fluid">
            <a class="navbar-brand" href="{{ url('/control/panel/menu') }}" title="宝时 Warehouse Assistance System" style="vertical-align: text-bottom">
                <img src="{{asset('icon/logo100b.png')}}" alt="宝时 Warehouse Assistance System" height="30" >
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                <span class="navbar-toggler-icon"></span>
            </button>
            @component('layouts.menu')@endcomponent
        </div>
    </nav>

    @auth()
        @component('demand._create')@endcomponent
    @endauth
    @yield('content')
    <hr>
</div>
</body>
<!-- Scripts -->
@yield('script')
{{-- 必须在app.js前边--}}
<script src="{{ mix('js/app.js') }}"></script>
<script>
    let isActive=function (name,atSlashLevel) {
        let uriWithNoParam=location.href.split('?')[0];
        let uriParts=uriWithNoParam.split('//')[1].split('/');
        if(!name){
            return uriParts.length===atSlashLevel;
        }
        if(atSlashLevel>uriParts.length||!atSlashLevel)return false;
        return uriParts[atSlashLevel]===name;
    };
    new Vue({
        el:'#nav1',
        methods:{
            isActive:isActive,
        }
    });
    if($('#nav2').length>0)
        new Vue({
            el:'#nav2',
            methods:{
                isActive:isActive,
            }
        });
</script>
<script>
    //后退则刷新页面
    let currentPageUuid=function (){
        let maxPagesOpening = 60;
        let pageUuid="{{$pageUuid}}";
        let pageUuids=localStorage.getItem('pageUuids')
        if(!pageUuids)pageUuids=[];
        try{
            pageUuids=JSON.parse(pageUuids)
        }catch (error){pageUuids=[]}
        if(pageUuids.length>=maxPagesOpening)pageUuids.shift();
        pageUuids.push(pageUuid)
        localStorage.setItem('pageUuids',JSON.stringify(pageUuids))
        return pageUuid;
    }()
    window.addEventListener('pageshow', function(e) {
        let pageUuids=localStorage.getItem('pageUuids')
        if(!pageUuids)return;
        try{
            pageUuids=JSON.parse(pageUuids)
        }catch (error){return}
        let pageReturnedTimes=pageUuids.reduce(function(prev,cur){
            if(cur===currentPageUuid){
                if(!prev)return 1;
                return prev+1;
            }
            if(!prev)return 0;
            if(prev&&prev.length>5)return 0;
            return prev;
        })
        if(pageReturnedTimes>1){
            $('body').remove();
            $('html').append("<h5>刷新中……</h5>")
            location.reload();
        }
    });
</script>
@component('demand._createjs')@endcomponent
@yield('lastScript')
</html>
