laravel和admin-lte的结合 npm模式搭建后台

先上图

laravel和admin-lte的结合 npm模式搭建后台_第1张图片

1、先搭建环境,我用的是phpstudy2018

nginx配置


server {
        listen       80;
        server_name  crm.com crm.cn;
        root   "F:\phpstudy\PHPTutorial\WWW\crm7\public";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
             try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

2、切换到www,然后安装laravel,

composer create-project --prefer-dist laravel/laravel name

3、laravel目录下package.json引入adminlte 并把bootstrap修改版本

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^3.4.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10",
        "admin-lte":"^2.4.16"
    }
}

4、安装前端依赖并执行命令

#安装依赖
cnpm i  //如果不成功  删除node_module重新执行cnpm rebuild  然后继续安装依赖

# 开启文件监听
cnpm run watch

5、修改resources/js/app.js

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');
require('admin-lte');

window.Vue = require('vue');

/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> 
 */

// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));

Vue.component('example-component', require('./components/ExampleComponent.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

const app = new Vue({
    el: '#app',
});

6、修改resources/sass/app.scss 此处有坑,因为用的是booot3注意路径

// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');

// Variables
@import 'variables';

// Bootstrap
@import '~bootstrap/dist/css/bootstrap.min.css';

//Admin-Lte
@import '~admin-lte/dist/css/AdminLTE.min.css';
@import '~admin-lte/dist/css/skins/_all-skins.css';

7、增加风格脚本public/js/demo.js

/**
 * AdminLTE Demo Menu
 * ------------------
 * You should not use this file in production.
 * This file is for demo purposes only.
 */
$(function () {
    'use strict'

    /**
     * Get access to plugins
     */

    $('[data-toggle="control-sidebar"]').controlSidebar()
    $('[data-toggle="push-menu"]').pushMenu()
    var $pushMenu = $('[data-toggle="push-menu"]').data('lte.pushmenu')
    var $controlSidebar = $('[data-toggle="control-sidebar"]').data('lte.controlsidebar')
    var $layout = $('body').data('lte.layout')
    $(window).on('load', function() {
        // Reinitialize variables on load
        $pushMenu = $('[data-toggle="push-menu"]').data('lte.pushmenu')
        $controlSidebar = $('[data-toggle="control-sidebar"]').data('lte.controlsidebar')
        $layout = $('body').data('lte.layout')
    })

    /**
     * List of all the available skins
     *
     * @type Array
     */
    var mySkins = [
        'skin-blue',
        'skin-black',
        'skin-red',
        'skin-yellow',
        'skin-purple',
        'skin-green',
        'skin-blue-light',
        'skin-black-light',
        'skin-red-light',
        'skin-yellow-light',
        'skin-purple-light',
        'skin-green-light'
    ]

    /**
     * Get a prestored setting
     *
     * @param String name Name of of the setting
     * @returns String The value of the setting | null
     */
    function get(name) {
        if (typeof (Storage) !== 'undefined') {
            return localStorage.getItem(name)
        } else {
            window.alert('Please use a modern browser to properly view this template!')
        }
    }

    /**
     * Store a new settings in the browser
     *
     * @param String name Name of the setting
     * @param String val Value of the setting
     * @returns void
     */
    function store(name, val) {
        if (typeof (Storage) !== 'undefined') {
            localStorage.setItem(name, val)
        } else {
            window.alert('Please use a modern browser to properly view this template!')
        }
    }

    /**
     * Toggles layout classes
     *
     * @param String cls the layout class to toggle
     * @returns void
     */
    function changeLayout(cls) {
        $('body').toggleClass(cls)
        $layout.fixSidebar()
        if ($('body').hasClass('fixed') && cls == 'fixed') {
            $pushMenu.expandOnHover()
            $layout.activate()
        }
        $controlSidebar.fix()
    }

    /**
     * Replaces the old skin with the new skin
     * @param String cls the new skin class
     * @returns Boolean false to prevent link's default action
     */
    function changeSkin(cls) {
        $.each(mySkins, function (i) {
            $('body').removeClass(mySkins[i])
        })

        $('body').addClass(cls)
        store('skin', cls)
        return false
    }

    /**
     * Retrieve default settings and apply them to the template
     *
     * @returns void
     */
    function setup() {
        var tmp = get('skin')
        if (tmp && $.inArray(tmp, mySkins))
            changeSkin(tmp)

        // Add the change skin listener
        $('[data-skin]').on('click', function (e) {
            if ($(this).hasClass('knob'))
                return
            e.preventDefault()
            changeSkin($(this).data('skin'))
        })

        // Add the layout manager
        $('[data-layout]').on('click', function () {
            changeLayout($(this).data('layout'))
        })

        $('[data-controlsidebar]').on('click', function () {
            changeLayout($(this).data('controlsidebar'))
            var slide = !$controlSidebar.options.slide

            $controlSidebar.options.slide = slide
            if (!slide)
                $('.control-sidebar').removeClass('control-sidebar-open')
        })

        $('[data-sidebarskin="toggle"]').on('click', function () {
            var $sidebar = $('.control-sidebar')
            if ($sidebar.hasClass('control-sidebar-dark')) {
                $sidebar.removeClass('control-sidebar-dark')
                $sidebar.addClass('control-sidebar-light')
            } else {
                $sidebar.removeClass('control-sidebar-light')
                $sidebar.addClass('control-sidebar-dark')
            }
        })

        $('[data-enable="expandOnHover"]').on('click', function () {
            $(this).attr('disabled', true)
            $pushMenu.expandOnHover()
            if (!$('body').hasClass('sidebar-collapse'))
                $('[data-layout="sidebar-collapse"]').click()
        })

        //  Reset options
        if ($('body').hasClass('fixed')) {
            $('[data-layout="fixed"]').attr('checked', 'checked')
        }
        if ($('body').hasClass('layout-boxed')) {
            $('[data-layout="layout-boxed"]').attr('checked', 'checked')
        }
        if ($('body').hasClass('sidebar-collapse')) {
            $('[data-layout="sidebar-collapse"]').attr('checked', 'checked')
        }

    }

    // Create the new tab
    var $tabPane = $('
', { 'id': 'control-sidebar-theme-demo-options-tab', 'class': 'tab-pane active' }) // Create the tab button var $tabButton = $('
  • ', {'class': 'active'}) .html('' + '' + '') // Add the tab button to the right sidebar tabs $('[href="#control-sidebar-home-tab"]') .parent() .before($tabButton) // Create the menu var $demoSettings = $('
    ') // Layout options $demoSettings.append( '

    ' + 'Layout Options' + '

    ' // Fixed layout + '
    ' + '' + '

    Activate the fixed layout. You can\'t use fixed and boxed layouts together

    ' + '
    ' // Boxed layout + '
    ' + '' + '

    Activate the boxed layout

    ' + '
    ' // Sidebar Toggle + '
    ' + '' + '

    Toggle the left sidebar\'s state (open or collapse)

    ' + '
    ' // Sidebar mini expand on hover toggle + '
    ' + '' + '

    Let the sidebar mini expand on hover

    ' + '
    ' // Control Sidebar Toggle + '
    ' + '' + '

    Toggle between slide over content and push content effects

    ' + '
    ' // Control Sidebar Skin Toggle + '
    ' + '' + '

    Toggle between dark and light skins for the right sidebar

    ' + '
    ' ) var $skinsList = $('
      ', {'class': 'list-unstyled clearfix'}) // Dark sidebar skins var $skinBlue = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Blue

      ') $skinsList.append($skinBlue) var $skinBlack = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Black

      ') $skinsList.append($skinBlack) var $skinPurple = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Purple

      ') $skinsList.append($skinPurple) var $skinGreen = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Green

      ') $skinsList.append($skinGreen) var $skinRed = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Red

      ') $skinsList.append($skinRed) var $skinYellow = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Yellow

      ') $skinsList.append($skinYellow) // Light sidebar skins var $skinBlueLight = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Blue Light

      ') $skinsList.append($skinBlueLight) var $skinBlackLight = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Black Light

      ') $skinsList.append($skinBlackLight) var $skinPurpleLight = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Purple Light

      ') $skinsList.append($skinPurpleLight) var $skinGreenLight = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Green Light

      ') $skinsList.append($skinGreenLight) var $skinRedLight = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Red Light

      ') $skinsList.append($skinRedLight) var $skinYellowLight = $('
    • ', {style: 'float:left; width: 33.33333%; padding: 5px;'}) .append('' + '
      ' + '
      ' + '
      ' + '

      Yellow Light

      ') $skinsList.append($skinYellowLight) $demoSettings.append('

      Skins

      ') $demoSettings.append($skinsList) $tabPane.append($demoSettings) $('#control-sidebar-home-tab').after($tabPane) setup() $('[data-toggle="tooltip"]').tooltip() })
  • 8、参考我代码resources/views/layouts/master.blade.php

    
    
        
            
            
            
            Module Admin
            
            
           {{-- Laravel Mix - CSS File --}}
           {{--  --}}
        
            
            
            
            
            
            
    
    
            
            
    
        
    
            @yield('content')
    
            {{-- Laravel Mix - JS File --}}
            {{--  --}}
            
        
            
            
        
    
    

    9、resources/views/index.blade.php

    @extends('admin::layouts.master')
    
    @section('content')
        
        

    Page Header Optional description

    Copyright © 2016 Company. All rights reserved.
    @stop

    搞定

    你可能感兴趣的:(技术心得,adminlte,laravel后台)