feat(mes): 新增当前用户工作站绑定状态 VO 和相关接口

pull/871/MERGE
YunaiV 2026-04-05 23:38:23 +08:00
parent 6c276d6ae3
commit 00ff024328
4 changed files with 150 additions and 119 deletions

View File

@ -13,6 +13,18 @@ export interface ProWorkRecordLogVO {
createTime: Date createTime: Date
} }
// MES 当前工作站绑定状态 VO
export interface ProWorkRecordVO {
userId: number
userNickname: string
workstationId: number
workstationCode: string
workstationName: string
type: number // 1=上工 2=下工
clockInTime: Date
clockOutTime: Date
}
// MES 工作记录 API // MES 工作记录 API
export const ProWorkRecordApi = { export const ProWorkRecordApi = {
// 查询工作记录分页 // 查询工作记录分页

View File

@ -0,0 +1,116 @@
<!-- 我的工作站 - 上下工状态栏 -->
<template>
<div
class="flex items-center justify-between p-12px mb-16px rounded-8px border border-solid border-[var(--el-border-color-lighter)] bg-[var(--el-fill-color-light)]"
>
<div class="flex items-center gap-8px">
<span class="font-600 text-14px text-[var(--el-text-color-primary)]">我的工作站</span>
<el-divider direction="vertical" />
<template v-if="isClockIn">
<el-tag type="success" effect="plain" round class="!inline-flex !items-center">
<Icon icon="ep:check" class="mr-4px" />
{{ myWorkstation!.workstationCode }} - {{ myWorkstation!.workstationName }}
</el-tag>
<span class="ml-4px text-13px text-[var(--el-text-color-secondary)]">
上工时间{{ formatDate(myWorkstation!.clockInTime) }}
</span>
</template>
<template v-else>
<el-tag type="info" effect="plain" round>当前未上工</el-tag>
</template>
</div>
<div class="flex-shrink-0">
<el-popover
v-if="!isClockIn"
:visible="clockInPopoverVisible"
placement="bottom-end"
:width="320"
trigger="click"
>
<template #reference>
<el-button type="success" plain @click="clockInPopoverVisible = true">
<Icon icon="ep:video-play" class="mr-5px" /> 上工
</el-button>
</template>
<div>
<p class="mb-8px font-bold">选择工作站</p>
<MdWorkstationSelect
v-model="selectedWorkstationId"
placeholder="请选择工作站"
class="w-full"
/>
<div class="mt-12px text-right">
<el-button size="small" @click="clockInPopoverVisible = false">取消</el-button>
<el-button
size="small"
type="success"
:disabled="!selectedWorkstationId"
@click="handleClockIn"
>
确认上工
</el-button>
</div>
</div>
</el-popover>
<el-button v-if="isClockIn" type="danger" plain @click="handleClockOut">
<Icon icon="ep:video-pause" class="mr-5px" /> 下工
</el-button>
</div>
</div>
</template>
<script setup lang="ts">
import { formatDate } from '@/utils/formatTime'
import { ProWorkRecordApi, type ProWorkRecordVO } from '@/api/mes/pro/workrecord'
import MdWorkstationSelect from '@/views/mes/md/workstation/components/MdWorkstationSelect.vue'
import { MesProWorkRecordTypeEnum } from '@/views/mes/utils/constants'
defineOptions({ name: 'WorkRecordStatusBar' })
const emit = defineEmits<{
(e: 'change'): void // /
}>()
const message = useMessage() //
const myWorkstation = ref<ProWorkRecordVO | null>(null) //
const clockInPopoverVisible = ref(false) //
const selectedWorkstationId = ref<number>() //
const isClockIn = computed(
() => myWorkstation.value?.type === MesProWorkRecordTypeEnum.CLOCK_IN
) //
/** 查询当前用户工作站 */
const loadMyWorkstation = async () => {
myWorkstation.value = await ProWorkRecordApi.getMyWorkRecord()
}
/** 上工 */
const handleClockIn = async () => {
if (!selectedWorkstationId.value) {
return
}
try {
await ProWorkRecordApi.clockInWorkRecord(selectedWorkstationId.value)
message.success('上工成功')
clockInPopoverVisible.value = false
selectedWorkstationId.value = undefined
await loadMyWorkstation()
emit('change')
} catch {}
}
/** 下工 */
const handleClockOut = async () => {
try {
await message.confirm('确认下工当前工作站?')
await ProWorkRecordApi.clockOutWorkRecord()
message.success('下工成功')
await loadMyWorkstation()
emit('change')
} catch {}
}
/** 初始化 */
onMounted(() => loadMyWorkstation())
</script>

View File

@ -1,68 +1,7 @@
<!-- MES 工作记录列表 --> <!-- MES 工作记录列表 -->
<template> <template>
<ContentWrap> <ContentWrap>
<!-- 当前工作站绑定状态 --> <WorkRecordStatusBar @change="getList" />
<el-card shadow="never" class="mb-16px">
<template #header>
<div class="flex items-center justify-between">
<span class="font-bold">我的工作站</span>
</div>
</template>
<div class="flex items-center justify-between">
<div v-if="myWorkstation">
<el-tag type="success" size="large" effect="dark">
<Icon icon="ep:monitor" class="mr-4px" />
已上工{{ myWorkstation.workstationCode }} - {{ myWorkstation.workstationName }}
</el-tag>
<span class="ml-8px text-gray-400 text-sm">
上工时间{{ formatDate(myWorkstation.createTime) }}
</span>
</div>
<div v-else>
<el-tag type="info" size="large">
<Icon icon="ep:warning" class="mr-4px" />
当前未绑定工作站
</el-tag>
</div>
<div class="flex gap-8px">
<el-popover
v-if="!myWorkstation"
:visible="clockInPopoverVisible"
placement="bottom"
:width="320"
trigger="click"
>
<template #reference>
<el-button type="success" @click="clockInPopoverVisible = true">
<Icon icon="ep:video-play" class="mr-5px" /> 上工
</el-button>
</template>
<div>
<p class="mb-8px font-bold">选择工作站</p>
<MdWorkstationSelect
v-model="selectedWorkstationId"
placeholder="请选择工作站"
class="w-full"
/>
<div class="mt-12px text-right">
<el-button size="small" @click="clockInPopoverVisible = false">取消</el-button>
<el-button
size="small"
type="success"
:disabled="!selectedWorkstationId"
@click="handleClockIn"
>
确认上工
</el-button>
</div>
</div>
</el-popover>
<el-button v-if="myWorkstation" type="danger" @click="handleClockOut">
<Icon icon="ep:video-pause" class="mr-5px" /> 下工
</el-button>
</div>
</div>
</el-card>
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<el-form <el-form
@ -134,18 +73,14 @@
row-key="id" row-key="id"
> >
<el-table-column label="编号" align="center" prop="id" width="80" /> <el-table-column label="编号" align="center" prop="id" width="80" />
<el-table-column label="用户" align="center" prop="userNickname" width="120" /> <el-table-column label="用户" align="center" prop="userNickname" />
<el-table-column label="工作站编码" align="center" prop="workstationCode" width="140" /> <el-table-column label="工作站编码" align="center" prop="workstationCode" />
<el-table-column label="工作站名称" align="center" prop="workstationName" width="160" /> <el-table-column label="工作站名称" align="center" prop="workstationName" />
<el-table-column label="操作类型" align="center" prop="type" width="100"> <el-table-column label="操作类型" align="center" prop="type" width="100">
<template #default="scope"> <template #default="scope">
<dict-tag <dict-tag :type="DICT_TYPE.MES_PRO_WORK_RECORD_TYPE" :value="scope.row.type" />
:type="DICT_TYPE.MES_PRO_WORK_RECORD_TYPE"
:value="scope.row.type"
/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="备注" align="center" prop="remark" min-width="200" />
<el-table-column <el-table-column
label="创建时间" label="创建时间"
align="center" align="center"
@ -165,21 +100,22 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { dateFormatter, formatDate } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import download from '@/utils/download' import download from '@/utils/download'
import { ProWorkRecordApi, ProWorkRecordLogVO } from '@/api/mes/pro/workrecord' import { ProWorkRecordApi, type ProWorkRecordLogVO } from '@/api/mes/pro/workrecord'
import MdWorkstationSelect from '@/views/mes/md/workstation/components/MdWorkstationSelect.vue' import MdWorkstationSelect from '@/views/mes/md/workstation/components/MdWorkstationSelect.vue'
import UserSelect from '@/views/system/user/components/UserSelect.vue' import UserSelect from '@/views/system/user/components/UserSelect.vue'
import WorkRecordStatusBar from './WorkRecordStatusBar.vue'
defineOptions({ name: 'MesProWorkRecordLog' }) defineOptions({ name: 'MesProWorkRecordLog' })
const message = useMessage() const message = useMessage() //
const loading = ref(true) const loading = ref(true) //
const list = ref<ProWorkRecordLogVO[]>([]) const total = ref(0) //
const total = ref(0) const list = ref<ProWorkRecordLogVO[]>([]) //
const exportLoading = ref(false) const exportLoading = ref(false) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
@ -188,43 +124,7 @@ const queryParams = reactive({
type: undefined, type: undefined,
createTime: undefined createTime: undefined
}) })
const queryFormRef = ref() const queryFormRef = ref() //
// ========== ==========
const myWorkstation = ref<ProWorkRecordLogVO | null>(null)
const clockInPopoverVisible = ref(false)
const selectedWorkstationId = ref<number>()
/** 查询当前用户工作站 */
const loadMyWorkstation = async () => {
myWorkstation.value = await ProWorkRecordApi.getMyWorkRecord()
}
/** 上线 */
const handleClockIn = async () => {
if (!selectedWorkstationId.value) return
try {
await ProWorkRecordApi.clockInWorkRecord(selectedWorkstationId.value)
message.success('上线成功')
clockInPopoverVisible.value = false
selectedWorkstationId.value = undefined
await loadMyWorkstation()
await getList()
} catch {}
}
/** 下线 */
const handleClockOut = async () => {
try {
await message.confirm('确认下线当前工作站?')
await ProWorkRecordApi.clockOutWorkRecord()
message.success('下线成功')
await loadMyWorkstation()
await getList()
} catch {}
}
// ========== ==========
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
@ -246,7 +146,7 @@ const handleQuery = () => {
/** 重置按钮操作 */ /** 重置按钮操作 */
const resetQuery = () => { const resetQuery = () => {
queryFormRef.value.resetFields() queryFormRef.value?.resetFields()
handleQuery() handleQuery()
} }
@ -264,8 +164,5 @@ const handleExport = async () => {
} }
/** 初始化 */ /** 初始化 */
onMounted(async () => { onMounted(() => getList())
await loadMyWorkstation()
await getList()
})
</script> </script>

View File

@ -222,6 +222,12 @@ export const MesProAndonLevelEnum = {
LEVEL3: 3 // 三级 LEVEL3: 3 // 三级
} }
/** MES 上下工操作类型枚举 */
export const MesProWorkRecordTypeEnum = {
CLOCK_IN: 1, // 上工
CLOCK_OUT: 2 // 下工
}
/** MES 生产报工类型枚举 */ /** MES 生产报工类型枚举 */
export const MesProFeedbackTypeEnum = { export const MesProFeedbackTypeEnum = {
SELF: 1, // 自行报工 SELF: 1, // 自行报工