常用的包:

npm 二维码生成

目标 基于 (图片地址 / 网页地址) 生成二维码
首先,需要安装生成二维码的插件

$ yarn add qrcode

qrcode的用法是

QrCode.toCanvas(dom, info)

dom为一个canvas的dom对象, info为转化二维码的信息

<canvas></canvas>

案例1.点击图片成二维码 (手机可以扫)

a. 准备弹层

<!-- 分享展示, 预览的二维码的弹层 -->
<el-dialog title="二维码" :visible="showCodeDialog" @close="closeDialog">
  二维码
</el-dialog>

b. 注册点击事件

<el-table-column label="头像" prop="staffPhoto">
  <template #default="{ row }">
    <img v-imgerror="defaultImg" class="staff" :src="row.staffPhoto" alt="" @click="clickShowCodeDialog(row.staffPhoto)">
  </template>
</el-table-column>
clickShowCodeDialog(url) {
    
    
  if (!url) return // 有图片才显示弹层
  this.showCodeDialog = true
}
<el-dialog width="300px" title="二维码" :visible="showCodeDialog" @close="closeDialog">
  <el-row type="flex" justify="center">
    <canvas ref="myCanvas" />
  </el-row>
</el-dialog>

c. 将canvas标签放到dialog的弹层中

<el-dialog width="300px" title="二维码" :visible="showCodeDialog" @close="closeDialog">
  <el-row type="flex" justify="center">
    <canvas ref="myCanvas" />
  </el-row>
</el-dialog>

d. 在点击图片时,显示弹层,并将图片地址转化成二维码

import QrCode from 'qrcode'

clickShowCodeDialog(url) {
    
    
  if (!url) return
  this.showCodeDialog = true
  this.$nextTick(() => {
    
    
    // 如果这里 url 写的是网址, 就会跳转到对应网址 (二维码分享效果)
    QrCode.toCanvas(this.$refs.myCanvas, url)
  })
}

二 生成打印Excel 利用vue-print-nb打印

$ yarn add vue-print-nb

a. 首先注册该插件

import Print from 'vue-print-nb'
Vue.use(Print)

配置路由

// 员工打印页
{
    
    
  path: 'print/:id',
  component: () => import('@/views/employees/print'),
  hidden: true,
  meta: {
    
    
    title: '员工打印'
  }
}

准备图标按钮

<el-tab-pane label="个人详情">
  <el-tooltip class="tooltip-box" content="打印基本个人信息">
    <router-link :to="`/employees/print/${userId}?type=personal`">
      <i class="el-icon-printer" />
    </router-link>
  </el-tooltip>
  
  <user-info />
</el-tab-pane>

<el-tab-pane label="岗位信息">
  <el-tooltip class="tooltip-box" content="打印基本岗位信息">
    <router-link :to="`/employees/print/${userId}?type=job`">
      <i class="el-icon-printer" />
    </router-link>
  </el-tooltip>
  
  <job-info />
</el-tab-pane>

样式

<style lang="scss" scoped>
.employees-detail-container {
    
    
  .el-tab-pane {
    
    
    padding-top: 10px;
  }
  .tooltip-box {
    
    
    position: absolute;
    right: 30px;
    top: 10px;
    z-index: 999;
  }
}
</style>

组件 —>组件参考代码

导入excel数据

excel导入功能需要使用npm包**xlsx,所以需要安装xlsx**插件 (new FileReader() 选中了某个文件, 可以通过FileReader去读)

$ yarn add xlsx
// 该文件, 可以进行组件的批量全局注册, 可以以插件的方式使用 => Vue.use(xxx)
// 将来这个插件(对象), 被Vue.use使用时, 会执行内部的install方法, 进行插件的初始化
import PageTools from './PageTools'
import UploadExcel from './UploadExcel'

export default {
    
    
  // 插件的初始化, 插件给你提供的全局的功能, 都可以在这里配置
  install(Vue) {
    
    
    // 进行组件的全局注册
    Vue.component('PageTools', PageTools) // 注册工具栏组件
    Vue.component('UploadExcel', UploadExcel) // 注册导入excel组件
  }
}

过滤器 - 处理时间格式

入职时间,我们可以采用 作用域插槽 用过滤器进行处理

<el-table-column label="入职时间" prop="timeOfEntry" sortable="">
  <template #default="{ row }">
    {
    
    {
    
     row.timeOfEntry | 过滤器名字 }}
  </template>
</el-table-column>
yarn add moment  // 安装moment
yarn add dayjs  // 安装datjs
// 导入moment
import moment from 'moment'

// 格式化日期
export function formatDate(value, str = 'YYYY年MM月DD日') {
    
    
  return moment(value).format(str)
}

在**main.js**中将工具方法转化成过滤器

import * as filters from '@/filters' // 引入工具类
// 注册全局的过滤器
Object.keys(filters).forEach(key => {
    
    
  // 注册过滤器
  Vue.filter(key, filters[key])
})

注册全局组件

import component from '@/components'
Vue.use(component)
现在可以愉快的用过滤器的方式使用工具类的方法了
<el-table-column label="入职时间" prop="timeOfEntry" sortable="">
  <template #default="{ row }">
    {
    
    {
    
     row.timeOfEntry | formatDate }}
  </template>
</el-table-column>

注册全局的导入excel组件

git版本控制

git --version #查看git安装版本

npm淘宝镜像

$ npm config set registry https://registry.npm.taobao.org/ #设置淘宝镜像地址
$ npm config get registry #查看镜像地址

vscode编辑器

vscode编辑器是目前前端开发的编码利器, 以及丰富的插件系统,非常适合开发前端项目

vscode编辑器插件 + vetur + eslint

vetur是基于 单文件组件开发的支持插件, eslint是 基于代码校验的插件工具
在这里插入图片描述

除此之外, eslint需要在vscode中进行一些参数的配置

{
    
     
    "editor.codeActionsOnSave": {
    
    
        "source.fixAll.eslint": true
    },
    ...
}

项目文件介绍

├── build                      # 构建打包相关
├── mock                       # 项目mock 模拟数据
├── public                     # 静态资源
│   │── favicon.ico            # favicon图标
│   └── index.html             # html模板
├── src                        # 源代码
│   ├── api                    # 所有请求
│   ├── assets                 # 主题 字体等静态资源
│   ├── components             # 全局公用组件
│   ├── icons                  # 项目所有 svg icons
│   ├── layout                 # 全局 layout
│   ├── router                 # 路由
│   ├── store                  # 全局 store管理
│   ├── styles                 # 全局样式
│   ├── utils                  # 全局公用方法
│   ├── vendor                 # 公用vendor
│   ├── views                  # views 所有页面
│   ├── App.vue                # 入口页面
│   ├── main.js                # 入口文件 加载组件 初始化等
│   └── permission.js          # 权限管理
│   └── settings.js          # 配置文件
├── tests                      # 测试
├── .env.xxx                   # 环境变量配置
├── .eslintrc.js               # eslint 配置项
├── .babelrc                   # babel-loader 配置
├── .travis.yml                # 自动化CI配置
├── vue.config.js              # vue-cli 配置
├── postcss.config.js          # postcss 配置
└── package.json               # package.json

src包介绍

├── src                        # 源代码
│   ├── api                    # 所有请求
│   ├── assets                 # 主题 字体等静态资源
│   ├── components             # 全局公用组件
│   ├── icons                  # 项目所有 svg icons
│   ├── layout                 # 全局 layout
│   ├── router                 # 路由
│   ├── store                  # 全局 store管理
│   ├── styles                 # 全局样式
│   ├── utils                  # 全局公用方法
│   ├── vendor                 # 公用vendor
│   ├── views                  # views 所有页面
│   ├── App.vue                # 入口页面
│   ├── main.js                # 入口文件 加载组件 初始化等
│   └── permission.js          # 权限管理
│   └── settings.js            # 配置文件

建立远程仓库

远程仓库建立只需要在网站上直接操作即可

本地项目提交

注意: 由于我们之前的项目是直接 **克隆而来,里面拥有原来的提交记录, 需要先将原来的.git**文件夹删除掉

并且对项目进行git初始化

$ git init  #初始化项目
$  git add . #将修改添加到暂存
$  git commit -m '人资项目初始化' #将暂存提到本地仓库

查看版本日志

$ git log --oneline #查看版本日志

推送到远程仓库

推送到远程仓库一般先将**远程仓库地址**用本地仓库别名代替

$ git remote add origin <远程仓库地址>  #添加远程仓库地址

当我们不清楚自己的仓库对应的origin地址时, 我们可以通过命令查看当前的远程仓库地址

$ git remote #查看本地仓库的远程仓库地址映射

推送master分支到远程仓库

$ git push -u origin master #将master分支推送到origin所代表的远程仓库地址

本节任务: 根据以上操作,将拉取下的项目提交到自己的仓库里面

组件参考代码

<template>
  <div id="myPrint" class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-breadcrumb separator="/" class="titInfo ">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>
            <router-link :to="{'path':'/employees'}">员工管理</router-link>
          </el-breadcrumb-item>
          <el-breadcrumb-item>打印</el-breadcrumb-item>
        </el-breadcrumb>
        <div v-if="type === 'personal'">
          <h2 class="centInfo">员工信息表</h2>
          <table cellspacing="0" width="100%" class="tableList">
            <tr class="title">
              <td colspan="8" class="centInfo">基本信息</td>
            </tr>
            <tr>
              <th style="width:10%">姓名</th>
              <td colspan="6" style="width:80%">{
    
    {
    
     formData.username }}</td>
              <td rowspan="5" style="width:10%"><img style="width:155px;height:218px" :src="formData.staffPhoto"></td>

            </tr>
            <tr>
              <th>性别</th>
              <td colspan="6">{
    
    {
    
     formData.sex }}</td>
            </tr>
            <tr>
              <th>手机</th>
              <td colspan="6">{
    
    {
    
     formData.mobile }}</td>
            </tr>
            <tr>
              <th>出生日期</th>
              <td colspan="6">{
    
    {
    
     formData.dateOfBirth | formatDate }}</td>
            </tr>
            <tr>
              <th>最高学历</th>
              <td colspan="6">{
    
    {
    
     formData.theHighestDegreeOfEducation }}</td>
            </tr>
            <tr>
              <th style="width:10%">是否可编辑</th>
              <td style="width:35%">{
    
    {
    
     formData.isItEditable }}</td>
              <th style="width:10%">是否隐藏号码</th>
              <td colspan="5" style="width:45%">{
    
    {
    
     formData.doYouHideNumbers }}</td>
            </tr>
            <tr>
              <th>国家地区</th>
              <td>{
    
    {
    
     formData.nationalArea }}</td>
              <th>护照号</th>
              <td colspan="5">{
    
    {
    
     formData.passportNo }}</td>
            </tr>
            <tr>
              <th>身份证号</th>
              <td>{
    
    {
    
     formData.idNumber }}</td>
              <th>身份证照片</th>
              <td colspan="5">{
    
    {
    
     formData.iDCardPhoto }}</td>
            </tr>
            <tr>
              <th>籍贯</th>
              <td>{
    
    {
    
     formData.nativePlace }}</td>
              <th>民族</th>
              <td colspan="5">{
    
    {
    
     formData.nation }}</td>
            </tr>
            <tr>
              <th>英文名</th>
              <td>{
    
    {
    
     formData.englishName }}</td>
              <th>婚姻状况</th>
              <td colspan="5">{
    
    {
    
     formData.maritalStatus }}</td>
            </tr>
            <tr>
              <th>员工照片</th>
              <td>{
    
    {
    
     formData.staffPhoto }}</td>
              <th>生日</th>
              <td colspan="5">{
    
    {
    
     formData.birthday }}</td>
            </tr>
            <tr>
              <th>属相</th>
              <td>{
    
    {
    
     formData.zodiac }}</td>
              <th>年龄</th>
              <td colspan="5">{
    
    {
    
     formData.age }}</td>
            </tr>
            <tr>
              <th>星座</th>
              <td>{
    
    {
    
     formData.constellation }}</td>
              <th>血型</th>
              <td colspan="5">{
    
    {
    
     formData.bloodType }}</td>
            </tr>
            <tr>
              <th>户籍所在地</th>
              <td>{
    
    {
    
     formData.domicile }}</td>
              <th>政治面貌</th>
              <td colspan="5">{
    
    {
    
     formData.politicalOutlook }}</td>
            </tr>
            <tr>
              <th>入党时间</th>
              <td>{
    
    {
    
     formData.timeToJoinTheParty }}</td>
              <th>存档机构</th>
              <td colspan="5">{
    
    {
    
     formData.archivingOrganization }}</td>
            </tr>
            <tr>
              <th>子女状态</th>
              <td>{
    
    {
    
     formData.stateOfChildren }}</td>
              <th>子女有无商业保险</th>
              <td colspan="5">{
    
    {
    
     formData.doChildrenHaveCommercialInsurance }}</td>
            </tr>
            <tr>
              <th>有无违法违纪行为</th>
              <td>{
    
    {
    
     formData.isThereAnyViolationOfLawOrDiscipline }}</td>
              <th>有无重大病史</th>
              <td colspan="5">{
    
    {
    
     formData.areThereAnyMajorMedicalHistories }}</td>
            </tr>
            <tr class="title">
              <td colspan="8" class="centInfo">通讯信息</td>
            </tr>
            <tr>
              <th>QQ</th>
              <td>{
    
    {
    
     formData.qQ }}</td>
              <th>微信</th>
              <td colspan="5">{
    
    {
    
     formData.weChat }}</td>
            </tr>
            <tr>
              <th>居住证城市</th>
              <td>{
    
    {
    
     formData.residenceCardCity }}</td>
              <th>居住证办理日期</th>
              <td colspan="5">{
    
    {
    
     formData.dateOfResidencePermit }}</td>
            </tr>
            <tr>
              <th>居住证截止日期</th>
              <td>{
    
    {
    
     formData.residencePermitDeadline }}</td>
              <th>现居住地</th>
              <td colspan="5">{
    
    {
    
     formData.placeOfResidence }}</td>
            </tr>
            <tr>
              <th>通讯地址</th>
              <td>{
    
    {
    
     formData.postalAddress }}</td>
              <th>联系手机</th>
              <td colspan="5">{
    
    {
    
     formData.contactTheMobilePhone }}</td>
            </tr>
            <tr>
              <th>个人邮箱</th>
              <td>{
    
    {
    
     formData.personalMailbox }}</td>
              <th>紧急联系人</th>
              <td colspan="5">{
    
    {
    
     formData.emergencyContact }}</td>
            </tr>
            <tr>
              <th>紧急联系电话</th>
              <td colspan="7">{
    
    {
    
     formData.emergencyContactNumber }}</td>
            </tr>
            <tr class="title">
              <td colspan="8" class="centInfo">账号信息</td>
            </tr>
            <tr>
              <th>社保电脑号</th>
              <td>{
    
    {
    
     formData.socialSecurityComputerNumber }}</td>
              <th>公积金账号</th>
              <td colspan="5">{
    
    {
    
     formData.providentFundAccount }}</td>
            </tr>
            <tr>
              <th>银行卡号</th>
              <td>{
    
    {
    
     formData.bankCardNumber }}</td>
              <th>开户行</th>
              <td colspan="5">{
    
    {
    
     formData.openingBank }}</td>
            </tr>
            <tr class="title">
              <td colspan="8" class="centInfo">教育信息</td>
            </tr>
            <tr>
              <th>学历类型</th>
              <td>{
    
    {
    
     formData.educationalType }}</td>
              <th>毕业学校</th>
              <td colspan="5">{
    
    {
    
     formData.graduateSchool }}</td>
            </tr>
            <tr>
              <th>入学时间</th>
              <td>{
    
    {
    
     formData.enrolmentTime }}</td>
              <th>毕业时间</th>
              <td colspan="5">{
    
    {
    
     formData.graduationTime }}</td>
            </tr>
            <tr>
              <th>专业</th>
              <td>{
    
    {
    
     formData.major }}</td>
              <th>毕业证书</th>
              <td colspan="5">{
    
    {
    
     formData.graduationCertificate }}</td>
            </tr>
            <tr>
              <th>学位证书</th>
              <td colspan="7">{
    
    {
    
     formData.certificateOfAcademicDegree }}</td>
            </tr>
            <tr class="title">
              <td colspan="8" class="centInfo">从业信息</td>
            </tr>
            <tr>
              <th>上家公司</th>
              <td>{
    
    {
    
     formData.homeCompany }}</td>
              <th>职称</th>
              <td colspan="5">{
    
    {
    
     formData.title }}</td>
            </tr>
            <tr>
              <th>简历</th>
              <td>{
    
    {
    
     formData.resume }}</td>
              <th>有无竞业限制</th>
              <td colspan="5">{
    
    {
    
     formData.isThereAnyCompetitionRestriction }}</td>
            </tr>
            <tr>
              <th>前公司离职证明</th>
              <td>{
    
    {
    
     formData.proofOfDepartureOfFormerCompany }}</td>
              <th>备注</th>
              <td colspan="5">{
    
    {
    
     formData.remarks }}</td>
            </tr>
          </table>
          <div class="foot">签字:___________日期:___________</div>
        </div>
        <div v-else>
          <h2 class="centInfo">岗位信息表</h2>
          <table cellspacing="0" width="100%" class="tableList">
            <tr class="title">
              <td colspan="4" class="centInfo">基本信息</td>
            </tr>
            <tr>
              <th style="width:10%">姓名</th>
              <td style="width:40%">{
    
    {
    
     formData.username }}</td>
              <th style="width:10%">入职日期</th>
              <td style="width:40%">{
    
    {
    
     formData.dateOfEntry }}</td>
            </tr>
            <tr>
              <th>部门</th>
              <td>{
    
    {
    
     formData.departmentName }}</td>
              <th>岗位</th>
              <td>{
    
    {
    
     formData.post }}</td>
            </tr>
            <tr>
              <th>工作邮箱</th>
              <td>{
    
    {
    
     formData.workMailbox }}</td>
              <th>工号</th>
              <td>{
    
    {
    
     formData.workNumber }}</td>
            </tr>
            <tr>
              <th>转正日期</th>
              <td>{
    
    {
    
     formData.dateOfCorrection }}</td>
              <th>转正状态</th>
              <td>{
    
    {
    
     formData.stateOfCorrection }}</td>
            </tr>
            <tr>
              <th>职级</th>
              <td>{
    
    {
    
     formData.rank }}</td>
              <th>汇报对象</th>
              <td>{
    
    {
    
     formData.reportName }}</td>
            </tr>
            <tr>
              <th>HRBP</th>
              <td>{
    
    {
    
     formData.hRBP }}</td>
              <th>聘用形式</th>
              <td>{
    
    {
    
     formData.formOfEmployment }}</td>
            </tr>

            <tr>
              <th>管理形式</th>
              <td>{
    
    {
    
     formData.formOfManagement }}</td>
              <th>调整司龄</th>
              <td>{
    
    {
    
     formData.adjustmentAgedays }}</td>
            </tr>
            <tr>
              <th>司龄</th>
              <td>{
    
    {
    
     formData.ageOfDivision }}</td>
              <th>首次参加工作时间</th>
              <td>{
    
    {
    
     formData.workingTimeForTheFirstTime }}</td>
            </tr>

            <tr>
              <th>调整工龄天</th>
              <td>{
    
    {
    
     formData.adjustmentOfLengthOfService }}</td>
              <th>工龄</th>
              <td>{
    
    {
    
     formData.workingYears }}</td>
            </tr>
            <tr>
              <th>纳税城市</th>
              <td>{
    
    {
    
     formData.taxableCity }}</td>
              <th>转正评价</th>
              <td>{
    
    {
    
     formData.correctionEvaluation }}</td>
            </tr>
            <tr class="title">
              <td colspan="4" class="centInfo">合同信息</td>
            </tr>
            <tr>
              <th>首次合同开始时间</th>
              <td>{
    
    {
    
     formData.initialContractStartTime }}</td>
              <th>首次合同结束时间</th>
              <td>{
    
    {
    
     formData.firstContractTerminationTime }}</td>
            </tr>
            <tr>
              <th>现合同开始时间</th>
              <td>{
    
    {
    
     formData.currentContractStartTime }}</td>
              <th>现合同结束时间</th>
              <td>{
    
    {
    
     formData.closingTimeOfCurrentContract }}</td>
            </tr>

            <tr>
              <th>合同期限</th>
              <td>{
    
    {
    
     formData.contractPeriod }}</td>
              <th>合同文件</th>
              <td>{
    
    {
    
     formData.contractDocuments }}</td>
            </tr>
            <tr>
              <th>续签次数</th>
              <td colspan="3">{
    
    {
    
     formData.renewalNumber }}</td>
            </tr>
            <tr class="title">
              <td colspan="4" class="centInfo">招聘信息</td>
            </tr>
            <tr>
              <th>其他招聘渠道</th>
              <td>{
    
    {
    
     formData.otherRecruitmentChannels }}</td>
              <th>招聘渠道</th>
              <td>{
    
    {
    
     formData.recruitmentChannels }}</td>
            </tr>
            <tr>
              <th>社招校招</th>
              <td>{
    
    {
    
     formData.socialRecruitment }}</td>
              <th>推荐企业人</th>
              <td>{
    
    {
    
     formData.recommenderBusinessPeople }}</td>
            </tr>
          </table>
          <div class="foot">签字:___________日期:___________</div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import {
    
     reqGetPersonalDetail, reqGetJobDetail } from '@/api/employees'
import {
    
     reqGetUserDetailById } from '@/api/user'
export default {
    
    
  data() {
    
    
    return {
    
    
      formData: {
    
    }
    }
  },
  computed: {
    
    
    userId() {
    
    
      return this.$route.params.id
    },
    type() {
    
    
      return this.$route.query.type
    }
  },
  // 创建完毕状态
  created() {
    
    
    if (this.type === 'personal') {
    
    
      this.getPersonalDetail()
    } else {
    
    
      this.getJobDetail()
    }
  },
  // 组件更新
  methods: {
    
    
    async getPersonalDetail() {
    
    
      const {
    
     data: userInfo } = await reqGetUserDetailById(this.userId) // 获取个人基本信息(顶部)
      const {
    
     data: detail } = await reqGetPersonalDetail(this.userId) // 获取个人基本信息(底部)
      this.formData = {
    
     ...detail, ...userInfo }
    },
    async getJobDetail() {
    
    
      const {
    
     data: userInfo } = await reqGetUserDetailById(this.userId)
      const {
    
     data: jobInfo } = await reqGetJobDetail(this.userId) // 获取个人基本信息
      this.formData = {
    
     ...jobInfo, ...userInfo }
    }
  }
}
</script>

<style lang="scss">
.foot {
    
    
  padding: 30px 0;
  text-align: right;
}
</style>

猜你喜欢

转载自blog.csdn.net/qq_43944285/article/details/125164665
今日推荐