群控系统服务端开发模式-应用开发-前端个人信息功能

news/2024/11/14 19:23:37 标签: 分布式, 群控系统, vue

        个人信息功能我把他分为了3部分:第一部分是展示登录者信息;第二步就是登录者登录退出信息;第三部分就是修改个人资料。

一、展示登录者信息

        1、优先添加固定路由

                在根目录下src文件夹下route文件夹下index.js文件中,添加如下代码

{
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
        {
            path: 'index',
            component: () => import('@/views/profile/index'),
            name: 'Profile',
            meta: {title: '个人信息', icon: 'user', noCache: true}
        }
    ]
}

        2、修改公有页面

                在根目录下src文件夹下layout文件夹下components文件夹下Navbar.vue文件中,修改代码如下

<template>
  <div class="navbar">
    <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />

    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />

    <div class="right-menu">
      <template v-if="device!=='mobile'">
        <search id="header-search" class="right-menu-item" />

        <error-log class="errLog-container right-menu-item hover-effect" />

        <screenfull id="screenfull" class="right-menu-item hover-effect" />

        <el-tooltip content="Global Size" effect="dark" placement="bottom">
          <size-select id="size-select" class="right-menu-item hover-effect" />
        </el-tooltip>

      </template>

      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
        <div class="avatar-wrapper">
          <span>欢迎<b style="color:red;">{{username}}</b>使用后台</span>
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/profile/index">
            <el-dropdown-item>个人信息</el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span style="display:block;">退出</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import Search from '@/components/HeaderSearch'

export default {
  components: {
    Breadcrumb,
    Hamburger,
    ErrorLog,
    Screenfull,
    SizeSelect,
    Search
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'username',
      'device'
    ])
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 20px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>

        3、修改展示登录者信息页面

                在根目录下src文件夹下views文件夹下profile文件夹中修改index.vue文件,修改代码如下

<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="24">
        <el-col :span="24" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="登录者中心" name="activity">
                <activity :user="user" />
              </el-tab-pane>
              <el-tab-pane label="登录日志" name="timeline">
                <timeline />
              </el-tab-pane>
              <el-tab-pane label="登录者修改" name="account">
                <account :user="user" />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Activity from './components/Activity'
import Timeline from './components/Timeline'
import Account from './components/Account'

export default {
  name: 'Profile',
  components: { Activity, Timeline, Account },
  data() {
    return {
      user: {},
      activeTab: 'activity'
    }
  },
  computed: {
    ...mapGetters([
      'username',
      'avatar',
      'email',
        'department_title',
        'grade_title',
        'rolename'
    ])
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser() {
      this.user = {
          username: this.username,
        //role: this.roles.join(' | '),
        email: this.email,
        avatar: this.avatar,
          department_title:this.department_title,
          grade_title:this.grade_title,
          rolename:this.rolename
      }
    }
  }
}
</script>

               修改指定页面在同级目录下components文件夹下,修改Activity.vue文件,代码如下

<template>
  <el-container>
    <el-container>
      <el-aside width="200px" style="margin:0;padding:0;background:#fff;">
        <div class="block">
          <div>
            {{user.username}}
          </div>
          <el-image :src="user.avatar"></el-image>
        </div>
      </el-aside>
      <el-container>
        <el-main>
          <span style="width:250px;display: inline-block;"><b>邮箱:</b>{{user.email}}</span>
          <span style="width:250px;display: inline-block;"><b>岗位名称:</b>{{user.department_title}}</span>
          <br />
          <span style="width:250px;display: inline-block;"><b>角色名称:</b>{{user.rolename}}</span>
          <span style="width:250px;display: inline-block;"><b>岗位级别:</b>{{user.grade_title}}</span>
        </el-main>
      </el-container>
      </el-container>
    </el-container>
</template>

<script>
export default {
    props: {
        user: {
            type: Object,
            default: () => {
                return {
                    username: '',
                    email: '',
                    avatar:'',
                    department_title:'',
                    grade_title:'',
                    rolename:''
                }
            }
        }
    },
  data() {
    return {
    }
  }
}
</script>
<style>
  .el-aside {
    text-align: center;
    line-height: 60px;
  }
  .el-main {
    width: 1000px;
    text-align: left;
    line-height: 60px;
    display: block;
  }
</style>

二、修改个人资料

        在根目录下src文件夹下views文件夹下profile文件夹下components文件夹中修改Account.vue文件,修改代码如下

<template>
    <el-form ref="resForm" :rules="formRules" :model="user">
        <el-form-item label="账号名称" prop="username">
            <el-input v-model.trim="user.username" minlength="2" maxlength="40"/>
        </el-form-item>
        <el-form-item label="真实姓名" prop="realname">
            <el-input v-model.trim="user.realname"/>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
            <el-input v-model.trim="user.email"/>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model.trim="user.password"/>
        </el-form-item>
        <el-form-item label="确认密码" prop="confirm_password">
            <el-input v-model.trim="user.confirm_password"/>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submit">修改</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import {validEmail, validPassword} from '@/utils/validate'
    import {mapGetters} from 'vuex'
    import {err, succ, warn} from '@/utils/message'
    import {updatePersonal} from '@/api/common'
    export default {
        name: 'Account',
        data() {
            // 用户名验证
            const validateEmail = (rule, value, callback) => {
                if (!validEmail(value)) {
                    callback(new Error('请输入正确的邮箱'))
                } else {
                    callback()
                }
            }
            // 密码验证 添加时必须填写 编辑时如果没有填写则不修改,填写了则修改
            const validatePassword = (rule, value, callback) => {
                if (value !== undefined && value !== '') {
                    const pwRel = validPassword(value)
                    if (pwRel !== true) {
                        callback(new Error(pwRel))
                    } else {
                        callback()
                    }
                } else {
                    callback()
                }
            }
            // 确认密码验证 添加时必须填写 编辑时如果没有填写则不验证,填写了且密码也填写了才与密码配对
            const validateConfirmPassword = (rule, value, callback) => {
                if (value !== undefined && this.user.password !== undefined) {
                    if (value !== this.user.password) {
                        callback(new Error('两次密码不一致,请重新输入'))
                    } else {
                        callback()
                    }
                } else {
                    callback()
                }
            }
            return {
                user: {},
                // 要验证数据
                formRules: {
                    username: [
                        {required: true, trigger: 'blur', message: '账号名称必须填写'},
                        {min: 2, max: 40, message: '长度在 2 到 40 个字符', trigger: 'blur'}
                    ],
                    realname: [
                        {required: true, trigger: 'blur', message: '真实必须填写'},
                        {min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur'}
                    ],
                    email: [{required: true, trigger: 'blur', validator: validateEmail}],
                    password: [{required: true, trigger: 'blur', validator: validatePassword}],
                    confirm_password: [{required: true, trigger: 'blur', validator: validateConfirmPassword}]
                }
            }
        },
        computed: {
            ...mapGetters([
                'username',
                'email',
                'avatar',
                'realname'
            ])
        },
        created() {
            this.getUser()
        },
        methods: {
            getUser() {
                this.user = {
                    username: this.username,
                    email: this.email,
                    avatar: this.avatar,
                    realname: this.realname,
                    password: "",
                    confirm_password: ""
                }
            },
            submit() {
                this.$refs.resForm.validate(valid => {
                    if (valid) {
                        updatePersonal(this.user).then(res => {
                            this.$store.state.user.username = this.user.username
                            this.$store.state.user.realname = this.user.realname
                            this.$store.state.user.avatar = this.user.avatar
                            this.$store.state.user.email = this.user.email
                            succ(res.message)
                        })
                    } else {
                        return false
                    }
                })
            }
        }
    }
</script>

三、提前说明

        登录者登录退出信息只能明天搞,今天时间来不及。


http://www.niftyadmin.cn/n/5752324.html

相关文章

C# IEnumerator,IEnumerable ,Iterator

IEnumerator 枚举器接口 在C#语言中&#xff0c;大部分以“I”字母开头命名的都是接口&#xff0c;所以情理之中&#xff0c;IEnumerator也是一个接口。 对于面向对象语言来说&#xff0c;接口就是一份“协议”&#xff0c;它定义了一组方法、属性和事件的契约&#xff0c;任…

学习Three.js:使用导入的模型生成粒子效果

学习Three.js&#xff1a;使用导入的模型生成粒子效果 Three.js是一个基于WebGL的JavaScript库&#xff0c;它使得在网页上创建和显示3D图形变得简单而高效。在Three.js中&#xff0c;你可以创建各种3D对象&#xff0c;如立方体、球体、平面等&#xff0c;还可以导入外部的3D模…

【CSS】absolute定位的默认位置

position: absolute; 属性会使元素脱离正常的文档流&#xff0c;并相对于最近的非 static 定位祖先元素进行定位。如果没有这样的祖先元素&#xff0c;则相对于初始包含块&#xff08;通常是视口&#xff09;进行定位。 但是当top和left没有指定具体值时&#xff0c;元素的在上…

LeetCode【0057】插入区间

本文目录 1 中文题目2 求解方法&#xff1a;基于逻辑2.1 方法思路2.2 Python代码2.3 复杂度分析 3 题目总结 1 中文题目 给定一个 无重叠的 &#xff0c;按照区间起始端点排序的区间列表 i n t e r v a l s intervals intervals&#xff0c;其中 i n t e r v a l s [ i ] […

HBase压测 ycsb

## ycsb 导入数据 rootXX.14.40.1971、对portrait压测 ansible hadoop -i hosts_hbase_portrait_20230730.txt -m shell -a "hostname && chdir/data/workspace/ycsb-0.17.0 nohup bin/ycsb load hbase20 -P workloads/workload_insert -cp /usr/local/fqlhadoop/…

前 K 个高频元素

前 K 个高频元素 ​ 给你一个整数数组 nums 和一个整数 k &#xff0c;请你返回其中出现频率前 k 高的元素。你可以按 任意顺序 返回答案。 示例 1: 输入: nums [1,1,1,2,2,3], k 2 输出: [1,2]示例 2: 输入: nums [1], k 1 输出: [1]提示&#xff1a; 1 < nums.le…

Hadoop生态圈框架部署(六)- HBase完全分布式部署

文章目录 前言一、Hbase完全分布式部署&#xff08;手动部署&#xff09;1. 下载Hbase2. 上传安装包3. 解压HBase安装包4. 配置HBase配置文件4.1 修改hbase-env.sh配置文件4.2 修改hbase-site.xml配置文件4.3 修改regionservers配置文件4.4 删除hbase中slf4j-reload4j-1.7.33.j…

力扣 LeetCode 242. 有效的字母异位词(Day3:哈希表)

解题思路&#xff1a; 哈希表三种数据结构的选择 1. 数组&#xff1a;适用于数据量小的情况 2. set&#xff1a;适用于数据量大的情况 3. map&#xff1a;适用于key-value 什么时候用哈希表&#xff1f; 给你一个元素&#xff0c;判断该元素在这个集合里是否出现过 本题使…