[Day 39] 心情隨筆後台及前台(一) - 心情隨筆列表

心情隨筆後台及前台

心情隨筆後台及前台

今天我們終於要進行心情隨筆的部分,
首先是要建後台畫面及功能,
我們的心情隨筆就建純文字就好了,
首先我們預計會有這些路由,
routes/web.php

Route::group(['middleware'=>['auth.admin']], function(){
    Route::group(['prefix' => 'admin'], function(){
        //心情隨筆相關
        Route::group(['prefix' => 'mind'], function(){
            //心情隨筆列表頁面
            Route::get('/', 'AdminController@mindListPage');
            //新增心情隨筆資料
            Route::get('/add', 'AdminController@addMindPage');
            //處理心情隨筆資料
            Route::post('/edit', 'AdminController@editMindProcess');
            //單一資料
            Route::group(['prefix' => '{mind_id}'], function(){
                //編輯心情隨筆資料
                Route::get('/edit', 'AdminController@editMindPage');
                //刪除心情隨筆資料
                Route::get('/delete', 'AdminController@deleteMindProcess');
            });
        });
    });
});

我們在第11天已經建立mind這個資料表,
然後在第23天也建立了mind的Entity檔案,

接下來要先做列表頁面,
所以我們要寫mindListPage這個方法,
app/http/controllers/AdminController.php

use App\Entity\Mind;
...
//心情隨筆列表頁面
public function mindListPage()
{
    Log::notice('取得心情隨筆列表');
    //先取得自己的資料
    $User = $this->GetUserData();
    //取得心情隨筆列表
    $list = Mind::where('user_id', $User->id)->get();
    $name = 'mind';

    $binding = [
        'title' => ShareData::TITLE,
        'page' => $this->page,
        'name' => $name,
        'User' => $User,
        'List' => $list,
        'result' => '',
    ];
    return view('admin.mindlist', $binding);
}

然後前端做一個這樣的畫面,目前反正沒有List資料, 所以先不處理, 先放個空的table就好
resources/views/admin/mindlist.blade.php

<!-- 指定繼承 layout.master 母模板 -->
@extends('layout.master')

<!-- 傳送資料到母模板,並指定變數為title -->
@section('title', $title)

<!-- 傳送資料到母模板,並指定變數為content -->
@section('content')
<!-- 自動產生 csrf_token 隱藏欄位-->
{!! csrf_field() !!}
<div class="normal_form">
    <div class="form_title">心情隨筆列表</div>
    <div class="btn_group">
        <button type="button" class="btn btn-primary btn_form" onclick="AddData()">新增</button>
    </div>
    <div class="table-responsive">
        <table class="table table-hover form_label">
            <thead>
                <tr>
                    <th>日期</th>
                    <th>內容</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </div>
<div>

<script>
function AddData()
{
    location.href = "/admin/mind/add";
}
</script>
@endsection

附上scss檔案

$mainTitleHeight: 56px;
$mainSideWidth: 130px;
$loginFormWidth: 360px;
$formImageWidth: 150px;
$formImageWidth2: 100px;
$bodyMenuHeight: 46px;
$bodyTitleHeight: 64px;

$mainColor: #0097A7;
$textColor: #FFF;
//背景顏色
$BackWhiteColor: #FFFFFF;
$BackWhiteColor2: #FAFAFA;
$lightgrayColor: #A7A7A7;
$lightgrayColor2: #E8E8E8;

$mainFont: 24px;
$mainFont2: 16px;
$toolBarFont: 16px;
$loginTitleFont: 32px;
$formMainFont: 20px;
$formTextBoxTextFont: 16px;
$formIconFont: 14px;
$formTextBoxBorderFont: 40px;
$formTextBoxBorderFont2: 24px;
$bodyTitleFont: 24px;
$bodyTitleFont2: 20px;

$mainLeftMargin: 24px;
$bodyFormMargin: 16px;
$bodyFormMargin1: 20px;
$bodyFormMargin2: 12px;
$bodyFormRowMargin: 40px;
$bodyFormPadding1: 24px;



//上面Bar的樣式
.toolbar_section{
    height: $mainTitleHeight;
    background: $mainColor;

    .toolbar_title{
        line-height: $mainTitleHeight;
        font-size: $mainFont;
        margin-left: $mainLeftMargin;
        color: $textColor;
    }

    .toolbar_title2{
        line-height: $mainTitleHeight;
        font-size: $mainFont2;
        margin-left: $mainLeftMargin;
        color: $textColor;
    }

    .toolbar_right{
        float: right;
        height: $mainTitleHeight;
        margin-right: 24px;
        font-size: $toolBarFont;
    }

    .toolbar_text{
        margin-left: 12px;
        color: $textColor;
        line-height: $mainTitleHeight;
    }
}

//註冊登入表單
.login_form{
    width: $loginFormWidth;
    margin: auto;

    .login_title{
        margin-top: 15px;
        margin-bottom: 30px;
        font-size: $loginTitleFont;
        font-weight: 600;
        text-align: center;
    }

    .login_label{
        font-size: $formMainFont;
        font-weight: 600;
        margin-bottom: 12px;
    }

    .login_textbox{
        font-size: $formTextBoxTextFont;
        line-height: $formTextBoxBorderFont;
        margin-bottom: 20px;
        .form_textbox{
            padding-left: 12px;
            width: 100%;
        }
    }

    .login_error {
        font-size: $formTextBoxTextFont;
    }

    .btn_group{
        text-align: right;
        .btn_login{
            font-size: $formMainFont;
            height: 40px;
            width: 120px;
            color: $textColor;
            box-shadow: none;
            border-radius: 3px;
            border-width: 0;
        }
    }
}

//一般表單
.normal_form{
    width: 100%;
    margin: auto;

    .form_title{
        margin-top: 15px;
        margin-bottom: 30px;
        font-size: $loginTitleFont;
        font-weight: 600;
        text-align: center;
    }

    .form_label{
        font-size: $formMainFont;
        font-weight: 600;
        margin-bottom: 12px;
    }

    .form_textbox_region{
        font-size: $formTextBoxTextFont;
        line-height: $formTextBoxBorderFont;
        margin-bottom: 20px;
        .form_textbox{
            padding-left: 12px;
            width: 100%;
        }

        .form_select {
            height: calc(#{$formTextBoxBorderFont} + 4px);
            padding-left: 12px;
            width: 100%;
        }

        .form_textarea{
            line-height: $formTextBoxBorderFont2;
            padding-left: 12px;
            width: 100%;
            height: calc(#{$formTextBoxBorderFont2}*8);
        }
    }

    .form_error {
        font-size: $formTextBoxTextFont;
    }

    .btn_group{
        text-align: right;
        .btn_form{
            font-size: $formMainFont;
            height: 40px;
            width: 120px;
            color: $textColor;
            box-shadow: none;
            border-radius: 3px;
            border-width: 0;
        }
    }

    .btn_group_middle{
        text-align: center;
        .btn_form{
            font-size: $formMainFont;
            height: 40px;
            width: 120px;
            color: $textColor;
            box-shadow: none;
            border-radius: 3px;
            border-width: 0;
        }
    }
}


.background_white {
    min-height: calc(100vh - #{$mainTitleHeight});
    background: $BackWhiteColor;
}

.background_white2 {
    min-height: calc(100vh - #{$mainTitleHeight});
    background: $BackWhiteColor2;
}

.main_region
{
    padding: 10px;
}

.col-10
{
    width: 10%;
    float: left;

    .circle_img {
        margin: auto;
        cursor: pointer;
        width: calc(9vw - 10px - 2px);
        height: calc(9vw - 10px - 2px);
        border-radius: 100%;
    }
}

.div_clear
{
    clear:both;
}

.body_title {
    font-size: $bodyTitleFont;
    font-weight: 600;
    margin-top: $bodyFormMargin1;
    margin-bottom: $bodyFormMargin2;
}

.body_form_title {
    font-size: $bodyTitleFont2;
    font-weight: 600;
}

.body_img {
    width: $formImageWidth2;
    height: $formImageWidth2;
    border-radius: 100%;
}

.body_form_row {
    margin-top: $bodyFormRowMargin;
}

.body_show_region {
    min-height: calc(100vh - #{$bodyFormMargin * 2} - #{$bodyFormMargin1} - #{$bodyFormMargin} - #{$bodyTitleFont} - #{$mainTitleHeight});
    width: calc(100% - #{$bodyFormMargin});
    margin: 0;
    margin-top: $bodyFormMargin;
    margin-bottom: $bodyFormMargin;
    padding: $bodyFormPadding1;
    border: solid 1px $lightgrayColor2;
    position: relative;

    &.menu {
        min-height: calc(100vh - #{$bodyFormMargin * 2} - #{$bodyFormMargin1} - #{$bodyFormMargin} - #{$bodyTitleFont} - #{$mainTitleHeight} - #{$bodyMenuHeight} - #{$bodyTitleHeight});
        margin-top: 0;
        padding: 0;
    }

    .bottom {
        position: absolute;
        bottom: 20px;
        width: calc(100% - #{$bodyFormPadding1 * 2});

        .center_button_region {
            text-align:center;
        }
    }
}


/****************圖片上傳相關****************/

.inputfile
{
    width: 0.1px; 
    height: 0.1px; 
    opacity: 0; 
    overflow: hidden; 
    position: absolute; 
    z-index: -1;
}

.inputfile + label 
{
    color: white;
    background-color: #EF5350;
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.5rem 2rem;
    border-radius: 0.5rem;
}
.inputfile + label:hover 
{
    background-color: #D2302E;
    cursor: pointer;
}

.upload_img {
    width: $formImageWidth;
    height: $formImageWidth;
    border-radius: 100%;
}

/****************改變Bootstrap樣式****************/


.container {
    width: 100vw;
    padding: 0;
    background: $BackWhiteColor2;
}

//排版
.form.col-sm-1 {
    padding: 0;
    min-width: $mainSideWidth;
}

.form.col-sm-11 {
    max-width: calc(100vw - #{$mainSideWidth});
}

//選單
.nav-pills>li{

    &>a{
        border-radius: 0;
        color: $lightgrayColor;
        font-size: $formTextBoxTextFont;

        &:hover{
            background: #E9E9E9;
        }
    }

    &.active{
        border-right: solid 4px $mainColor;

        &>a, {
            color: $mainColor;
            background: transparent;

            &:hover{
                color: $mainColor;
                background: #E9E9E9;
            }
        }
    }
}

畫面就會像這樣
 

https://ithelp.ithome.com.tw/upload/images/20210424/20105694LFyPZHhGKc.png