基于vue3人力资源管理系统

登录页样式

div class="logo">
      <div class="icon"></div>
      <img src="@/assets/common/login.svg" width="300" alt="" />
      <p>开箱即用的中后台管理系统</p>
    </div>

 手机号规则定义

 <a-form-item
            name="mobile"
            :rules="[
              {
                required: true,
                message: '手机号不能为空',
                trigger: ['change', 'blur']
              },
              {
                pattern: /^1[3-9][0-9]{9}$/,
                message: '手机号格式不正确',
                trigger: ['change', 'blur']
              }
            ]"
          >
<a-input size="large" v-model:value="loginForm.mobile"></a-input>
								双向绑定value
          </a-form-item>

 script代码

 

 定义loginForm函数,属性mobile


密码规则定义

 <a-form-item
            name="password"
            :rules="[
              {
                required: true,
                message: '密码不能为空',
                trigger: ['change', 'blur']    trigger:触发时机
              }
                    ]"
          >
  <a-input-password size="large" v-model:value="loginForm.password">
//双向绑定value
//Value是标签a-input的属性
</a-input-password>
          </a-form-item>

  script代码

定义loginForm函数,属性password

用户使用协议

      <a-form-item
            name="isAgree"
            :rules="[
              {
                validator: validatorAgree
              }
                    ]"
             >
<a-checkbox v-model:checked="loginForm.isAgree">用户平台使用协议</a-checkbox>     
//双向绑定checked
          </a-form-item>

   script代码

登录按钮

        <a-form-item>
<a-button size="large" type="primary" block htmlType="submit">登录</a-button>
          </a-form-item>

绑定onFinish事件

 

   script代码

onst onFinish = async (values) => {
  const { updateToken } = useToken()  调用token文件下的updateToken函数
  console.log(values)

  const data = await login(values)
  updateToken(data)

  router.push('/')
}

权限管理(前置/后置路由守卫)

const whiteList = ['/login', '/404']
router.beforeEach((to, from, next) => {
  nprogress.start()
  const { token } = useToken()
  if (token) {
    // 有token的情况下
    if (to.path === '/login') {
      // 如果在登录页,就直接跳转到首页
      next('/')
    } else {
      next()
      //不在登录页,就直接放行
    }
  } else {
    //没有token的情况下
    if (whiteList.includes(to.path)) {
      // 如果在白名单给放行
      next()
    } else {
      next('/login')
      // 否则重定向回登录页
    }
  }
})


router.afterEach(() => nprogress.done())  

具体代码(login.vue)

<template>
  <div class="login-container">
    <div class="logo">
      <div class="icon"></div>
      <img src="@/assets/common/login.svg" width="300" alt="" />
      <p>开箱即用的中后台管理系统</p>
    </div>
    <div class="form">
      <h3>iHRM 人力资源管理系统</h3>
      <a-card class="login-card">
        <a-form :model="loginForm" autocomplete="off" @finish="onFinish">
          <a-form-item
            name="mobile"
            :rules="[
              {
                required: true,
                message: '手机号不能为空',
                trigger: ['change', 'blur']
              },
              {
                pattern: /^1[3-9][0-9]{9}$/,
                message: '手机号格式不正确',
                trigger: ['change', 'blur']
              }
            ]"
          >
            <a-input size="large" v-model:value="loginForm.mobile"></a-input>
          </a-form-item>
          <a-form-item
            name="password"
            :rules="[
              {
                required: true,
                message: '密码不能为空',
                trigger: ['change', 'blur']
              }
            ]"
          >
            <a-input-password size="large" v-model:value="loginForm.password"></a-input-password>
          </a-form-item>
          <a-form-item
            name="isAgree"
            :rules="[
              {
                validator: validatorAgree
              }
            ]"
          >
            <a-checkbox v-model:checked="loginForm.isAgree">用户平台使用协议</a-checkbox>
          </a-form-item>
          <a-form-item>
            <a-button size="large" type="primary" block htmlType="submit">登录</a-button>
          </a-form-item>
        </a-form>
      </a-card>
    </div>
  </div>
</template>



<script setup>
// 实现表单的校验
// 1. 声明响应式数据
import { reactive } from 'vue'
import { useRouter } from 'vue-router' //引入方法
import { login } from '@/api/login'
import useToken from '@/stores/token'

const router = useRouter() //得到一个router实例
//useRouter需要放置在最上层-初始化的关系

const loginForm = reactive({
  mobile: '13800000002',
  password: '123456',
  isAgree: false
})

const onFinish = async (values) => {
  const { updateToken } = useToken()
  console.log(values)

  const data = await login(values)
  updateToken(data)

  router.push('/')
}

const validatorAgree = (rule, value) => {
  return value ? Promise.resolve() : Promise.reject(new Error('您必须同意用户协议'))
}
</script>


<style lang="less" scoped>
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url(../../assets/common/logBg.png) no-repeat center / cover;
    border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
    .icon {
      background: url(../../assets/common/logo.png) no-repeat 70px center / contain;
      width: 300px;
      height: 50px;
      margin-bottom: 50px;
    }
    p {
      color: #fff;
      font-size: 18px;
      margin-top: 20px;
      width: 300px;
      text-align: center;
    }
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 50px;
    .ant-card {
      width: 320px;
      border: none;
      padding: 0;
    }
    h3 {
      padding-left: 30px;
      font-size: 24px;
    }
  }
}
</style>

具体代码(permission.js)

//做权限控制
import router from '@/router' //可以不写index.js
import useToken from '@/stores/token'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'  //引入进度条样式


const whiteList = ['/login', '/404']
router.beforeEach((to, from, next) => {
  nprogress.start()
  const { token } = useToken()
  if (token) {
    // 有token的情况下
    if (to.path === '/login') {
      // 如果在登录页,就直接跳转到首页
      next('/')
    } else {
      next()
      //不在登录页,就直接放行
    }
  } else {
    //没有token的情况下
    if (whiteList.includes(to.path)) {
      // 如果在白名单给放行
      next()
    } else {
      next('/login')
      // 否则重定向回登录页
    }
  }
})


router.afterEach(() => nprogress.done())  

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
摘 要 在如今这个人才需求量大的时代,各方企业为了永葆企业的活力与生机,在不断开 拓进取的同时,又广泛纳用人才,为企业的长久发展奠定了基础。于是,各个企业与部 门机构,都不可避免地会接触到人力资源管理的问题。 Hrm 是一款人力资源管理系统,其主要功能模块有员工个人信息修改、请假、员工 的薪资管理、考勤管理、社保管理。其中考勤管理实现了员工考勤状态的修改与员工考 勤月报表的导出,以及通过员工考勤记录的导入来实现员工考勤状态的判断。社保管理, 主要实现了员工社保的计算以及明细的修改。薪资管理,实现了员工工资的调整,以及 员工月工资报表的导出。 本项目采用了前后端分离的技术,前端是基于 Vue+ElementUI+Axios 开发的,后端 则是基于 Spring Boot+MyBatis Plus+ Jwt+Mysql。本项目实现了权限菜单管理,通过员 工的权限动态渲染菜单,并动态生成路由。通过 Jwt token 来判断当前登录的员工以及 员工的登录状态。 关键词:人力资源管理系统,Spring Boot,Vue,权限管 人力资源管理是企业运营中必不可少的一环,它关系到企业的前途与发展。尤其对 于中小微企业来说,对企业的发展有着举足轻重的作用。随着近年来,政府对创业项目 的大力扶持,我国创业型企业蓬勃发展。据统计,2019 年,我国创业企业数量已达 1810 万余家,占全国企业数的 97%,截止 2020 年,我国创业企业数量达到了 2030 万,同比 增长 10%。虽然我国创业企业的基数在不断增大,但是能够长久存活的企业却少之又少。 在创业初期,随着企业初具规模,大多数创业者开始将主要精力集中在市场调研和 开发产品上,而忽略了团队的内部管理。据调查,中国企业的平均寿命是 7.02 年,但 70%的企业存活不超过 5 年,究其原因有很多,其中最重要的一点就是,人力资源管理 未能有效推动企业向前发展

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值