Element-ui based top bar

Zelda team e-commerce management system background top bar

Show results:
insert image description here

Code analysis and function description

This code is a Vue component used to render the top bar of the Zelda team e-commerce management system background. Let's go line by line and add detailed comments.

<template>
  
  <div class="app-container">
    <el-header style="box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);">

      <!-- 更改 el-row 的布局方式为 justify 为 center -->
      <el-row type="flex" align="top" justify="center"> 
        <el-col :span="24">
          <div class="header-content">
            <h1 class="title">塞尔达小队电商管理系统后台</h1>
            <el-button v-if="!loggedIn" @click="showLoginDialog" type="primary" class="login-button">登录</el-button>
            <el-avatar v-else :src="user.avatar" :size="36" shape="circle"></el-avatar>
          </div>
        </el-col>
      </el-row>

    </el-header>

    <!-- 其他页面内容 -->
    
    <el-dialog title="用户登录" :visible.sync="loginDialogVisible">
      <!-- 登录表单 -->
    </el-dialog>
  </div>
</template>
  • Line 3: Add styles to the outermost container app-container.
  • Lines 5-8: Create the container for the top bar, use el-headerthe component, and set the shadow effect.
  • Lines 9-14: Use el-rowthe and el-colcomponents for layout, centering the content.
  • Line 10: Sets the layout of the row so justify:centerthat the content is centered horizontally.
  • Line 11: A column is created and occupies all the space of a row.
  • Lines 12-16: Add the content of the top bar.
    • Line 13: Display the website title "Zelda Squad E-commerce Management System Background".
    • Line 14: If the user is not logged in, display a "Login" button and bind the click event showLoginDialog.
    • Line 15: If the user is logged in, display the user avatar.
  • Lines 19-23: Add a dialog component for user login, whose visibility is loginDialogVisiblecontrolled by .
<style>
  .app-container {
      
      
    padding-left: 0;
    margin-bottom: 1%;
  }

  .header-content {
      
      
    display: flex;
    justify-content: space-between; /* 去除左右间隙 */
    align-items: flex-start; /* 垂直居上 */
    padding: 10px 20px; /* 调整内边距 */
  }

  .title {
      
      
    font-size: 20px;
    font-weight: bold;
    color: #409EFF;
    margin-top: 5px; /* 文字向上移动 */
  }
  
  .login-button {
      
      
    border: 1px solid #409EFF !important;
    background-color: transparent !important;
    color: #409EFF !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    margin-top: 5px; /* 按钮向上移动 */
  }
</style>
  • Lines 1-7: Define some style rules for customizing the appearance and layout of the top bar.
    • .app-containerThe class sets the left padding to 0 and the bottom margin to 1%.
    • .header-contentThe class uses a flex layout that aligns content horizontally to the center and vertically to the top. The inner margin is set to 10px up and down, 20px or so.
    • .titleThe class sets the font size to 20px, bold, #409EFF color, and offset 5px up.
    • .login-buttonThe class sets the border to be 1px solid line, the background is transparent, the color is #409EFF, and the padding, border rounded corners and font size are adjusted, and the upward offset is 5px.
<script>
export default {
      
      
  data() {
      
      
    return {
      
      
      loggedIn: false,
      loginDialogVisible: false,
      user: {
      
      
        name: '',
        avatar: ''
      }
    };
  },
  methods: {
      
      
    showLoginDialog() {
      
      
      // 显示登录对话框
      this.loginDialogVisible = true;
    },
    loginSuccess(user) {
      
      
      // 登录成功后的处理
      this.loggedIn = true;
      this.user.name = user.name;
      this.user.avatar = user.avatar;
      this.loginDialogVisible = false; // 关闭登录对话框
    }
  }
};
</script>
  • Lines 3-15: Define the data and methods of the component.
    • loggedInis a boolean value that marks whether the user is logged in or not.
    • loginDialogVisibleis a boolean value that controls the visibility of the login dialog.
    • userIs an object used to store the name and avatar of user information.
  • Lines 9-12: showLoginDialogWhen the method is triggered, loginDialogVisibleset to true, to show the login dialog.
  • Lines 14-19: loginSuccessWhen the method is called, handle the logic of user login success.
    • Mark loggedInas true, indicating that the user is logged in.
    • Set and userin the object to the incoming user information.nameavatar
    • Set loginDialogVisibleto falseto close the login dialog.

The above are the detailed notes and function descriptions of the top bar components in the background of the Zelda Squad e-commerce management system. This top bar provides a simple login functionality and displays user information or a login button in a responsive manner.

  • full code

<template>
  
  <div class="app-container">
    <el-header style="box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);">

      <!-- 布局:居中 -->
      <el-row type="flex" align="top" justify="center"> 
        <el-col :span="24">
          <div class="header-content">
            <!-- 标题 -->
            <h1 class="title">塞尔达小队电商管理系统后台</h1>
            <!-- 登录按钮,当用户未登录时显示 -->
            <el-button v-if="!loggedIn" @click="showLoginDialog" type="primary" class="login-button">登录</el-button>
            <!-- 用户头像,当用户已登录时显示 -->
            <el-avatar v-else :src="user.avatar" :size="36" shape="circle"></el-avatar>
          </div>
        </el-col>
      </el-row>

    </el-header>

    <!-- 其他页面内容 -->
    
    <!-- 用户登录对话框 -->
    <el-dialog title="用户登录" :visible.sync="loginDialogVisible">
      <!-- 登录表单 -->
    </el-dialog>
  </div>
</template>

<style>
  /* 容器样式 */
  .app-container {
      
      
    padding-left: 0;
    margin-bottom: 1%;
  }

  /* 顶部栏内容样式 */
  .header-content {
      
      
    display: flex;
    justify-content: space-between; /* 左右间隙填充 */
    align-items: flex-start; /* 垂直居上 */
    padding: 10px 20px; /* 内边距调整 */
  }

  /* 标题样式 */
  .title {
      
      
    font-size: 20px;
    font-weight: bold;
    color: #409EFF;
    margin-top: 5px; /* 文字向上移动 */
  }
  
  /* 登录按钮样式 */
  .login-button {
      
      
    border: 1px solid #409EFF !important;
    background-color: transparent !important;
    color: #409EFF !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    margin-top: 5px; /* 按钮向上移动 */
  }
</style>

<script>
export default {
      
      
  data() {
      
      
    return {
      
      
      loggedIn: false, // 用户登录状态
      loginDialogVisible: false, // 登录对话框的可见性
      user: {
      
      
        name: '', // 用户名
        avatar: '' // 用户头像
      }
    };
  },
  methods: {
      
      
    // 显示登录对话框
    showLoginDialog() {
      
      
      this.loginDialogVisible = true;
    },
    // 处理用户登录成功的逻辑
    loginSuccess(user) {
      
      
      this.loggedIn = true; // 用户已登录
      this.user.name = user.name; // 设置用户名
      this.user.avatar = user.avatar; // 设置用户头像
      this.loginDialogVisible = false; // 关闭登录对话框
    }
  }
};
</script>

Guess you like

Origin blog.csdn.net/qq_51447496/article/details/131407366