From ac7d9e20978e710a54164b2e74ea464027754b7e Mon Sep 17 00:00:00 2001
From: Your Name <123456>
Date: Tue, 02 Aug 2022 09:09:57 +0800
Subject: [PATCH] Merge branch 'master' of https://sinanoaq.cn:8888/r/gtqt
---
src/views/basicRightsManagement/personnelShiftManagement/workingHours/index.vue | 638 +++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 439 insertions(+), 199 deletions(-)
diff --git a/src/views/basicRightsManagement/personnelShiftManagement/workingHours/index.vue b/src/views/basicRightsManagement/personnelShiftManagement/workingHours/index.vue
index bb15eed..682c49e 100644
--- a/src/views/basicRightsManagement/personnelShiftManagement/workingHours/index.vue
+++ b/src/views/basicRightsManagement/personnelShiftManagement/workingHours/index.vue
@@ -1,12 +1,12 @@
<template>
<div class="home-container">
- <el-scrollbar height="100%">
+ <div style="height: 100%">
<el-row class="homeCard">
<el-col :span="8">
<div class="grid-content topInfo">
<el-input v-model="searchWord" placeholder="工作时段名称"></el-input>
- <el-button type="primary">查询</el-button>
- <el-button plain>重置</el-button>
+ <el-button type="primary" @click="searchRecord">查询</el-button>
+ <el-button plain @click="clearSearch">重置</el-button>
</div>
</el-col>
</el-row>
@@ -16,57 +16,70 @@
<el-col :span="12" class="mainCardBtn">
<el-button type="primary" :icon="Plus" size="default" @click="dialogAddRecord=true">新建</el-button>
<!-- <el-button type="warning" :icon="Edit" size="default" plain>修改</el-button>-->
- <el-button type="danger" :icon="Delete" size="default" plain>删除</el-button>
+ <el-button type="danger" :icon="Delete" size="default" plain @click="deleteWorkTimePeriods">删除</el-button>
</el-col>
- <el-button type="primary" :icon="Refresh" size="default"/>
+ <el-button type="primary" :icon="Refresh" size="default" @click="reLoadData()"/>
</el-row>
<el-table
ref="multipleTableRef"
:data="tableData"
style="width: 100%"
+ height="calc(100% - 100px)"
:header-cell-style="{background: '#fafafa'}"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="100" />
<el-table-column property="name" label="工作时段名称"/>
- <el-table-column property="range" label="排班时段"/>
+ <el-table-column property="startTime" label="开始时间"/>
+ <el-table-column property="endTime" label="结束时间"/>
+ <el-table-column property="info" label="描述信息"/>
<el-table-column fixed="right" label="操作" align="center" width="250">
<template #default="scope">
<el-button link type="primary" size="small" :icon="View" @click="viewRecord(scope.row)">查看</el-button>
<el-button link type="primary" size="small" :icon="Edit" @click="editRecord(scope.$index ,scope.row)">修改</el-button>
- <el-button link type="danger" size="small" :icon="Delete" @click="deleteRecord(scope.$index)">删除</el-button>
+ <el-button link type="danger" size="small" :icon="Delete" @click="deleteRecord(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
- </div>
- <div class="pageBtn">
- <el-pagination
- v-model:currentPage="currentPage"
- v-model:page-size="pageSize"
- :page-sizes="[10, 15]"
- small=false
- background
- layout="total, sizes, prev, pager, next, jumper"
- :total="100"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
+ <div class="pageBtn">
+ <el-pagination
+ v-model:currentPage="pageIndex"
+ v-model:page-size="pageSize"
+ :page-sizes="[10, 15]"
+ small=false
+ background
+ layout="total, sizes, prev, pager, next, jumper"
+ :total="totalSize"
+ @size-change="handleSizeChange"
+ @current-change="handleCurrentChange"
+ />
+ </div>
</div>
</div>
- </el-scrollbar>
+ </div>
<el-dialog v-model="dialogDetails" title="工作时段">
<el-form :model="details" label-width="120px">
<el-form-item label="工作时段名称">
<el-input
v-model="details.name"
- class="input-with-select"
readonly
/>
</el-form-item>
- <el-form-item label="排班时段">
+ <el-form-item label="开始时间">
<el-input
- v-model="details.range"
- class="input-with-select"
+ v-model="details.startTime"
+ readonly
+ />
+ </el-form-item>
+ <el-form-item label="结束时间">
+ <el-input
+ v-model="details.endTime"
+ readonly
+ />
+ </el-form-item>
+ <el-form-item label="描述信息">
+ <el-input
+ v-model="details.info"
readonly
/>
</el-form-item>
@@ -75,7 +88,7 @@
</el-form-item>
</el-form>
</el-dialog>
- <el-dialog v-model="dialogAddRecord" title="工作时段编辑" @close="closeAdd">
+ <el-dialog v-model="dialogAddRecord" title="工作时段编辑" @close="closeAdd" @open="openAdd">
<el-form :model="addRecord" label-width="120px" ref="addRef" :rules="addRules">
<el-form-item label="工作时段名称" prop="name">
<el-input
@@ -84,22 +97,27 @@
</el-input>
</el-form-item>
<el-form-item label="上班开始时间" prop="startTime">
- <el-time-select
+ <el-time-picker
v-model="addRecord.startTime"
- start="00:00"
- step="00:15"
- end="24:00"
+ format="HH:mm"
+ value-format="HH:mm"
placeholder="Select time"
/>
</el-form-item>
<el-form-item label="上班结束时间" prop="endTime">
- <el-time-select
+ <el-time-picker
v-model="addRecord.endTime"
- start="00:00"
- step="00:15"
- end="24:00"
+ format="HH:mm"
+ value-format="HH:mm"
placeholder="Select time"
/>
+ </el-form-item>
+ <el-form-item label="描述信息" prop="info">
+ <el-input
+ v-model="addRecord.info"
+ type="textarea"
+ >
+ </el-input>
</el-form-item>
<el-form-item>
<el-button type="warning" @click="dialogAddRecord = false" size="default" plain>取消</el-button>
@@ -119,167 +137,420 @@
</div>
</template>
-<script lang="ts" setup>
- import { toRefs, reactive, ref } from 'vue';
+<script lang="ts">
+ import { toRefs, reactive, ref, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
import { initBackEndControlRoutes } from '/@/router/backEnd';
import {useUserInfo} from "/@/stores/userInfo";
import { Session } from '/@/utils/storage';
import { Edit, View, Plus, Delete, Refresh, Search, Download } from '@element-plus/icons-vue'
import { ElTable } from 'element-plus'
- import { FormInstance, FormRules } from 'element-plus'
- let global: any = {
- homeChartOne: null,
- homeChartTwo: null,
- homeCharThree: null,
- dispose: [null, '', undefined],
- };
+ import { FormInstance, FormRules, ElMessage } from 'element-plus'
+ import { workingHoursApi } from '/@/api/basicDateManage/personShiftManage/workingHours';
+
+
+ // 定义接口来定义对象的类型
interface stateType {
- homeOne: Array <type>
+ tableData: Array<string>,
+ multipleSelection: Array<any>,
+ deleteArr: Array<any>,
+ dialogDetails: boolean,
+ dialogAddRecord: boolean,
+ deleteDialog: boolean,
+ pageIndex: number,
+ pageSize: number,
+ searchWord: string,
+ totalSize: number,
+ addRecord: {
+ name: string,
+ startTime: string,
+ endTime: string,
+ info: string
+ },
+ details: {
+ name: string,
+ startTime: string,
+ endTime: string,
+ info: string
+ }
}
- interface type {
- }
- // export default defineComponent({
- // name: 'workCheckinRecord',
- // setup() {
- const userInfo = useUserInfo()
- const { userInfos } = storeToRefs(userInfo);
- const state = reactive<stateType>({});
- const currentPage = ref(1)
- const pageSize = ref(10)
- const chosenIndex = ref(-1)
- const handleSizeChange = (val: number) => {
- console.log(`${val} items per page`)
- }
- const handleCurrentChange = (val: number) => {
- console.log(`current page: ${val}`)
- }
- const tableData = reactive(
- [
- {
- name: '四班三倒早班',
- range: '04:00 - 12:00'
- },
- {
- name: '四班三倒中班',
- range: '12:00 - 20:00'
- },
- {
- name: '四班三倒中班',
- range: '20:00 - 次日04:00'
- },
- {
- name: '常白班',
- range: '08:00 - 18:00'
- }
- ]
- )
- const addRef = ref<FormInstance>()
- const addRules = reactive<FormRules>({
- name:[{required: true, message: '该内容不能为空',trigger:'blur'}],
- startTime:[{required: true, message: '该内容不能为空',trigger:'blur'}],
- endTime:[{required: true, message: '该内容不能为空',trigger:'blur'}]
- })
- const dialogDetails = ref(false)
- const dialogAddRecord = ref(false)
- const deleteDialog = ref(false)
- const addRecord = ref({})
- const details = ref({})
- const viewRecord = (row) =>{
- details.value = JSON.parse(JSON.stringify(row))
- dialogDetails.value = true
- }
- const deleteRecord = (index) =>{
- chosenIndex.value = index
- deleteDialog.value = true
- }
- const conFirmDelete = ()=> {
- tableData.splice(chosenIndex.value,1)
- deleteDialog.value = false
- }
- const confirmAddRecord = async (formEl: FormInstance | undefined) =>{
- if (!formEl) return
- await formEl.validate((valid, fields) => {
- if (valid) {
- if(chosenIndex.value == -1){
- if(addRecord.value.startTime >= addRecord.value.endTime){
- addRecord.value.endTime = '次日' + addRecord.value.endTime
- }
- addRecord.value.range = addRecord.value.startTime + '\xa0-\xa0' + addRecord.value.endTime
- tableData.unshift(addRecord.value)
- }else{
- if(addRecord.value.startTime >= addRecord.value.endTime){
- addRecord.value.endTime = '次日' + addRecord.value.endTime
- }
- addRecord.value.range = addRecord.value.startTime + '\xa0-\xa0' + addRecord.value.endTime
- tableData[chosenIndex.value] = addRecord.value
- }
- dialogAddRecord.value =false
- } else {
- console.log('error submit!', fields)
- }
+ export default {
+ name: 'workingHours',
+ components:{},
+ setup() {
+ const userInfo = useUserInfo()
+ const {userInfos} = storeToRefs(userInfo);
+
+ const state = reactive<stateType>({
+ pageIndex: 1,
+ pageSize: 10,
+ totalSize: 0,
+ chosenIndex: null,
+ searchWord: '',
+ tableData: [],
+ multipleSelection: [],
+ dialogDetails: false,
+ dialogAddRecord: false,
+ deleteDialog: false,
+ addRecord: {
+ name: '',
+ startTime: '',
+ endTime: '',
+ info: ''
+ },
+ details: {
+ name: '',
+ startTime: '',
+ endTime: '',
+ info: ''
+ },
+ deleteId: null,
+ deleteArr: []
+ })
+ interface User {
+ name: string,
+ startTime: string,
+ endTime: string,
+ info: string
+ }
+ const multipleTableRef = ref<InstanceType<typeof ElTable>>()
+ const toggleSelection = (rows?: User[]) => {
+ if (rows) {
+ rows.forEach((row) => {
+ // TODO: improvement typing when refactor table
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-expect-error
+ multipleTableRef.value!.toggleRowSelection(row, undefined)
})
+ } else {
+ multipleTableRef.value!.clearSelection()
+ }
+ }
+ // 多选
+ const handleSelectionChange = (val: User[]) => {
+ state.multipleSelection = JSON.parse(JSON.stringify(val))
+ state.deleteArr = state.multipleSelection.map((item)=>{
+ item = item.id
+ return item
+ })
+ }
+
+ const addRef = ref<FormInstance>()
+ const addRules = reactive<FormRules>({
+ name: [{required: true, message: '该内容不能为空', trigger: 'blur'}],
+ startTime: [{required: true, message: '该内容不能为空', trigger: 'blur'}],
+ endTime: [{required: true, message: '该内容不能为空', trigger: 'blur'}]
+ })
+
+ // 页面载入时执行方法
+ onMounted(() => {
+ // getWorkTimePeriod()
+ getListByPage()
+ })
+
+ // 获取工作时段列表
+ const getWorkTimePeriod = async () => {
+ let res = await workingHoursApi().getWorkTimePeriod({name: state.searchWord});
+ if (res.data.code === '200') {
+ state.tableData = res.data.data.map((item)=>{
+ item.startHour = item.startHour==null?'00':(item.startHour.toString()[1]?item.startHour.toString():'0'+item.startHour.toString())
+ item.startMin = item.startMin==null?'00':(item.startMin.toString()[1]?item.startMin.toString():'0'+item.startMin.toString())
+ item.endHour = item.endHour==null?'00':(item.endHour.toString()[1]?item.endHour.toString():'0'+item.endHour.toString())
+ item.endMin = item.endMin==null?'00':(item.endMin.toString()[1]?item.endMin.toString():'0'+item.endMin.toString())
+ item.startTime = item.startHour + ':' + item.startMin
+ item.endTime = item.endHour + ':' + item.endMin
+ return item
+ })
+ } else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
}
- const closeAdd =()=>{
- addRecord.value={}
- chosenIndex.value = -1
+ }
+
+ // 分页获取工作时段列表
+ const getListByPage = async ()=>{
+ const data = {pageSize: state.pageSize,pageIndex: state.pageIndex,searchParams:{name: state.searchWord}}
+ let res = await workingHoursApi().postPeriodPage(data);
+ if (res.data.code === '200') {
+ state.tableData = res.data.data.map((item)=>{
+ item.startHour = item.startHour==null?'00':(item.startHour.toString()[1]?item.startHour.toString():'0'+item.startHour.toString())
+ item.startMin = item.startMin==null?'00':(item.startMin.toString()[1]?item.startMin.toString():'0'+item.startMin.toString())
+ item.endHour = item.endHour==null?'00':(item.endHour.toString()[1]?item.endHour.toString():'0'+item.endHour.toString())
+ item.endMin = item.endMin==null?'00':(item.endMin.toString()[1]?item.endMin.toString():'0'+item.endMin.toString())
+ item.startTime = item.startHour + ':' + item.startMin
+ item.endTime = item.endHour + ':' + item.endMin
+ return item
+ })
+ state.totalSize = res.data.total
+ } else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
}
- const indexClear = ()=>{
- chosenIndex.value = -1
+ }
+
+ // 关键词查询记录
+ const searchRecord = async()=>{
+ if(state.searchWord==''){
+ ElMessage({
+ type: 'warning',
+ message: '请输入查询关键词'
+ });
+ }else{
+ getListByPage()
}
- const editRecord =(index, row)=>{
- dialogAddRecord.value = true
- chosenIndex.value = index
- addRecord.value = JSON.parse(JSON.stringify(row))
- addRecord.value.startTime = addRecord.value.range.substring(0,5)
- addRecord.value.endTime = addRecord.value.range.substring(8)
+ }
+
+ const clearSearch = async()=>{
+ state.searchWord=''
+ getListByPage()
+ }
+
+ // 添加工作时段
+ const addWorkTimePeriod = async (data:any) => {
+ let res = await workingHoursApi().postWorkTimePeriod(data);
+ if (res.data.code === '200') {
+ ElMessage({
+ type: 'success',
+ message: res.data.msg
+ });
+ getListByPage()
+ } else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
}
- // 折线图
- const renderMenu = async (value: string) => {
- Session.set('projectId',value)
- userInfos.value.projectId = value
- await initBackEndControlRoutes();
- };
- // return {
- // renderMenu,
- // multipleTableRef,
- // tableData,
- // currentPage,
- // pageSize,
- // dialogDetails,
- // details,
- // deleteDialog,
- // dialogAddRecord,
- // viewRecord,
- // deleteRecord,
- // handleSizeChange,
- // handleCurrentChange,
- // Plus,
- // Edit,
- // Delete,
- // Search,
- // Download,
- // handleSelectionChange,
- // Refresh,
- // ...toRefs(state),
- // };
- // },
- // });
+ };
+
+ // 修改工作时段
+ const editWorkTimePeriod = async (data:any) => {
+ let res = await workingHoursApi().updateWorkTimePeriod(data);
+ if (res.data.code === '200') {
+ ElMessage({
+ type: 'success',
+ message: res.data.msg
+ });
+ getListByPage()
+ } else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
+ }
+ }
+
+ // 删除工作时段
+ const deleteWorkTimePeriod = async (data:any) => {
+ let res = await workingHoursApi().deletWorkTimePeriod(data);
+ if (res.data.code === '200') {
+ ElMessage({
+ type: 'success',
+ message: res.data.msg
+ });
+ getListByPage()
+ } else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
+ }
+ }
+
+ const deleteRecord = (row) => {
+ state.deleteId = row.id
+ state.deleteDialog = true
+ }
+
+ const conFirmDelete = () => {
+ deleteWorkTimePeriod({ id: state.deleteId })
+ state.deleteDialog = false
+ }
+
+ // 批量删除
+ const deleteWorkTimePeriods = async () => {
+ if(state.deleteArr.length>0){
+ console.log(state.deleteArr)
+ let res = await workingHoursApi().deleteBatchWorkTimePeriod({ids: state.deleteArr});
+ if (res.data.code === '200') {
+ ElMessage({
+ type: 'success',
+ message: res.data.msg
+ });
+ getListByPage()
+ } else {
+ ElMessage({
+ type: 'warning',
+ message: res.data.msg
+ });
+ }
+ }else{
+ ElMessage({
+ type: 'warning',
+ message: '请先选择要删除的记录'
+ });
+ }
+ }
+
+ const handleSizeChange = (val: number) => {
+ state.pageSize = val
+ getListByPage()
+ }
+ const handleCurrentChange = (val: number) => {
+ state.pageIndex = val
+ getListByPage()
+ }
+
+ // 查看记录
+ const viewRecord = (row) => {
+ state.details = row
+ state.dialogDetails = true
+ }
+
+ // 刷新
+ const reLoadData = async () =>{
+ getListByPage()
+ }
+ const editRecord = (index, row) => {
+ state.dialogAddRecord = true
+ state.chosenIndex = index
+ state.addRecord = JSON.parse(JSON.stringify(row))
+ }
+
+ // 新增修改记录
+ const confirmAddRecord = async (formEl: FormInstance | undefined) => {
+ if (!formEl) return
+ await formEl.validate(async (valid, fields) => {
+ if (valid) {
+ const data = {
+ name: state.addRecord.name,
+ info: state.addRecord.info,
+ startHour: Number(state.addRecord.startTime.substring(0, 2)),
+ startMin: Number(state.addRecord.startTime.substring(3)),
+ endHour: Number(state.addRecord.endTime.substring(0, 2)),
+ endMin: Number(state.addRecord.endTime.substring(3))
+ }
+ if (state.chosenIndex == null) {
+ // if (state.addRecord.startTime >= state.addRecord.endTime) {
+ // state.addRecord.endTime = '次日' + state.addRecord.endTime
+ // }
+ // state.tableData.unshift(data)
+ await addWorkTimePeriod(data)
+ } else {
+ // if (state.addRecord.startTime >= state.addRecord.endTime) {
+ // state.addRecord.endTime = '次日' + state.addRecord.endTime
+ // }
+ // state.tableData[state.chosenIndex] = state.addRecord
+ data.id = state.addRecord.id,
+ await editWorkTimePeriod(data)
+ }
+ state.dialogAddRecord = false
+ } else {
+ console.log('error submit!', fields)
+ }
+ })
+
+ }
+ const closeAdd = () => {
+ state.addRecord = {}
+ state.chosenIndex = null
+ }
+ const openAdd = () => {
+ if (state.chosenIndex == null) {
+ state.addRecord.info = ''
+ }
+ }
+ const indexClear = () => {
+ state.deleteId = null
+ }
+
+ // 折线图
+ const renderMenu = async (value: string) => {
+ Session.set('projectId', value)
+ userInfos.value.projectId = value
+ await initBackEndControlRoutes();
+ };
+ return {
+ addRef,
+ addRules,
+ View,
+ Edit,
+ Delete,
+ Refresh,
+ Plus,
+ toggleSelection,
+ handleSelectionChange,
+ deleteWorkTimePeriods,
+ searchRecord,
+ clearSearch,
+ viewRecord,
+ deleteRecord,
+ conFirmDelete,
+ getWorkTimePeriod,
+ getListByPage,
+ reLoadData,
+ deleteWorkTimePeriod,
+ handleSizeChange,
+ handleCurrentChange,
+ confirmAddRecord,
+ closeAdd,
+ openAdd,
+ indexClear,
+ editRecord,
+ ...toRefs(state)
+ };
+ }
+ }
</script>
<style scoped lang="scss">
$homeNavLengh: 8;
.home-container {
- height: 100%;
+ height: calc(100vh - 114px);
+ box-sizing: border-box;
overflow: hidden;
.homeCard{
width: 100%;
padding: 20px;
+ box-sizing: border-box;
background: #fff;
border-radius: 4px;
+
+ .main-card{
+ width: 100%;
+ height: 100%;
+ .cardTop{
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin-bottom: 20px;
+ .mainCardBtn{
+ margin: 0;
+ }
+ }
+ .pageBtn{
+ height: 60px;
+ display: flex;
+ align-items: center;
+ justify-content: right;
+
+ .demo-pagination-block + .demo-pagination-block {
+ margin-top: 10px;
+ }
+ .demo-pagination-block .demonstration {
+ margin-bottom: 16px;
+ }
+ }
+ }
+ &:last-of-type{
+ height: calc(100% - 100px);
+ }
}
.el-row{
display: flex;
@@ -303,37 +574,6 @@
white-space: nowrap;
margin-right: 20px;
}
- }
- }
- .mainPages{
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .main-card{
- width: 100%;
- .cardTop{
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 20px;
- .mainCardBtn{
- margin: 0;
- }
- }
- }
- .pageBtn{
- display: flex;
- align-items: center;
- justify-content: right;
- margin-top: 20px;
-
- .demo-pagination-block + .demo-pagination-block {
- margin-top: 10px;
- }
- .demo-pagination-block .demonstration {
- margin-bottom: 16px;
}
}
}
--
Gitblit v1.9.2