✨ feat(mes): 更新车间和工作站选择器,增加 tooltip 展示详情
parent
88552dc6a2
commit
9b686628be
|
|
@ -9,6 +9,7 @@ export interface MdWorkstationVO {
|
||||||
workshopId: number // 所在车间 ID
|
workshopId: number // 所在车间 ID
|
||||||
workshopName: string // 所在车间名称
|
workshopName: string // 所在车间名称
|
||||||
processId: number // 工序 ID
|
processId: number // 工序 ID
|
||||||
|
processName: string // 工序名称
|
||||||
warehouseId: number // 线边库 ID
|
warehouseId: number // 线边库 ID
|
||||||
locationId: number // 库区 ID
|
locationId: number // 库区 ID
|
||||||
areaId: number // 库位 ID
|
areaId: number // 库位 ID
|
||||||
|
|
@ -23,10 +24,6 @@ export const MdWorkstationApi = {
|
||||||
return await request.get({ url: `/mes/md-workstation/page`, params })
|
return await request.get({ url: `/mes/md-workstation/page`, params })
|
||||||
},
|
},
|
||||||
|
|
||||||
// 查询工作站精简列表
|
|
||||||
getWorkstationSimpleList: async () => {
|
|
||||||
return await request.get({ url: `/mes/md-workstation/simple-list` })
|
|
||||||
},
|
|
||||||
|
|
||||||
// 查询工作站详情
|
// 查询工作站详情
|
||||||
getWorkstation: async (id: number) => {
|
getWorkstation: async (id: number) => {
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,34 @@
|
||||||
<!-- MES 车间选择器:纯下拉,前端过滤(支持 name、code) -->
|
<!-- MES 车间选择器:纯下拉,前端过滤(支持 name、code),悬停 tooltip 展示详情 -->
|
||||||
<template>
|
<template>
|
||||||
<el-select
|
<el-tooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||||
v-model="selectValue"
|
<template #content>
|
||||||
:placeholder="placeholder"
|
<div v-if="selectedItem" class="leading-6">
|
||||||
:disabled="disabled"
|
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||||
:clearable="clearable"
|
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||||
filterable
|
<div>面积:{{ selectedItem.area != null ? selectedItem.area + ' ㎡' : '-' }}</div>
|
||||||
:filter-method="handleFilter"
|
<div>负责人:{{ selectedItem.chargeUserName || '-' }}</div>
|
||||||
class="!w-1/1"
|
|
||||||
@change="handleChange"
|
|
||||||
>
|
|
||||||
<el-option v-for="item in filteredList" :key="item.id" :label="item.name" :value="item.id">
|
|
||||||
<div class="flex items-center gap-8px">
|
|
||||||
<span>{{ item.name }}</span>
|
|
||||||
<el-tag v-if="item.code" size="small" type="info" class="ml-4px">
|
|
||||||
编号: {{ item.code }}
|
|
||||||
</el-tag>
|
|
||||||
</div>
|
</div>
|
||||||
</el-option>
|
</template>
|
||||||
</el-select>
|
<el-select
|
||||||
|
v-model="selectValue"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
:clearable="clearable"
|
||||||
|
filterable
|
||||||
|
:filter-method="handleFilter"
|
||||||
|
class="!w-1/1"
|
||||||
|
@change="handleChange"
|
||||||
|
>
|
||||||
|
<el-option v-for="item in filteredList" :key="item.id" :label="item.name" :value="item.id">
|
||||||
|
<div class="flex items-center gap-8px">
|
||||||
|
<span>{{ item.name }}</span>
|
||||||
|
<el-tag v-if="item.code" size="small" type="info" class="ml-4px">
|
||||||
|
编号: {{ item.code }}
|
||||||
|
</el-tag>
|
||||||
|
</div>
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
@ -47,6 +57,7 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
const allList = ref<MdWorkshopVO[]>([])
|
const allList = ref<MdWorkshopVO[]>([])
|
||||||
const filteredList = ref<MdWorkshopVO[]>([])
|
const filteredList = ref<MdWorkshopVO[]>([])
|
||||||
|
const selectedItem = ref<MdWorkshopVO | undefined>() // 当前选中的车间对象(用于 tooltip 展示)
|
||||||
|
|
||||||
const selectValue = computed({
|
const selectValue = computed({
|
||||||
get: () => props.modelValue,
|
get: () => props.modelValue,
|
||||||
|
|
@ -69,12 +80,32 @@ const handleFilter = (query: string) => {
|
||||||
/** 选中变化 */
|
/** 选中变化 */
|
||||||
const handleChange = (val: number | undefined) => {
|
const handleChange = (val: number | undefined) => {
|
||||||
const item = allList.value.find((o) => o.id === val)
|
const item = allList.value.find((o) => o.id === val)
|
||||||
|
selectedItem.value = item
|
||||||
emit('change', item)
|
emit('change', item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 根据 modelValue 同步 selectedItem(用于编辑回显) */
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(val) => {
|
||||||
|
if (val == null) {
|
||||||
|
selectedItem.value = undefined
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 仅在列表已加载且当前 selectedItem 不匹配时更新
|
||||||
|
if (selectedItem.value?.id !== val && allList.value.length > 0) {
|
||||||
|
selectedItem.value = allList.value.find((o) => o.id === val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
/** 加载车间列表 */
|
/** 加载车间列表 */
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
allList.value = await MdWorkshopApi.getWorkshopSimpleList()
|
allList.value = await MdWorkshopApi.getWorkshopSimpleList()
|
||||||
filteredList.value = allList.value
|
filteredList.value = allList.value
|
||||||
|
// 列表加载完成后,回显 selectedItem
|
||||||
|
if (props.modelValue != null) {
|
||||||
|
selectedItem.value = allList.value.find((o) => o.id === props.modelValue)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,66 @@
|
||||||
<!-- MES 工作站选择器:纯下拉,前端过滤(支持 name、code) -->
|
<!--
|
||||||
|
MES 工作站选择器:只读输入框 + 点击弹窗选择
|
||||||
|
|
||||||
|
交互:显示为只读 el-input,点击打开弹窗(单选模式)进行选择
|
||||||
|
Props:
|
||||||
|
modelValue — 绑定的工作站 ID(v-model)
|
||||||
|
disabled — 是否禁用
|
||||||
|
clearable — 是否允许清空(鼠标悬停时显示清除图标)
|
||||||
|
placeholder — 占位文字
|
||||||
|
Events:
|
||||||
|
update:modelValue — v-model 更新
|
||||||
|
change(item) — 选中工作站变化时触发,传递完整 MdWorkstationVO(清空时为 undefined)
|
||||||
|
-->
|
||||||
<template>
|
<template>
|
||||||
<el-select
|
<div
|
||||||
v-model="selectValue"
|
v-bind="attrs"
|
||||||
:placeholder="placeholder"
|
class="w-full"
|
||||||
:disabled="disabled"
|
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
||||||
:clearable="clearable"
|
@click="handleClick"
|
||||||
filterable
|
@mouseenter="hovering = true"
|
||||||
:filter-method="handleFilter"
|
@mouseleave="hovering = false"
|
||||||
class="!w-1/1"
|
|
||||||
@change="handleChange"
|
|
||||||
>
|
>
|
||||||
<el-option v-for="item in filteredList" :key="item.id" :label="item.name" :value="item.id">
|
<el-tooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||||
<div class="flex items-center gap-8px">
|
<template #content>
|
||||||
<span>{{ item.name }}</span>
|
<div v-if="selectedItem" class="leading-6">
|
||||||
<el-tag v-if="item.code" size="small" type="info" class="ml-4px">
|
<div>编码:{{ selectedItem.code }}</div>
|
||||||
编号: {{ item.code }}
|
<div>名称:{{ selectedItem.name }}</div>
|
||||||
</el-tag>
|
<div>所在车间:{{ selectedItem.workshopName || '-' }}</div>
|
||||||
</div>
|
<div>所属工序:{{ selectedItem.processName || '-' }}</div>
|
||||||
</el-option>
|
<div>地点:{{ selectedItem.address || '-' }}</div>
|
||||||
</el-select>
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-input
|
||||||
|
:model-value="displayLabel"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
readonly
|
||||||
|
:suffix-icon="suffixIcon"
|
||||||
|
:class="disabled ? 'is-select-disabled' : 'is-select-clickable'"
|
||||||
|
/>
|
||||||
|
</el-tooltip>
|
||||||
|
</div>
|
||||||
|
<!-- 弹窗必须放在 div 外部,否则弹窗内的点击事件会冒泡到 div 触发 handleClick -->
|
||||||
|
<MdWorkstationSelectDialog ref="dialogRef" :multiple="false" @selected="handleSelected" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { MdWorkstationApi, MdWorkstationVO } from '@/api/mes/md/workstation'
|
import { MdWorkstationApi, MdWorkstationVO } from '@/api/mes/md/workstation'
|
||||||
|
import { Search, CircleClose } from '@element-plus/icons-vue'
|
||||||
|
import MdWorkstationSelectDialog from './MdWorkstationSelectDialog.vue'
|
||||||
|
|
||||||
defineOptions({ name: 'MdWorkstationSelect' })
|
// 组件有两个根节点(div + Dialog),Vue 不会自动继承 attrs;
|
||||||
|
// 手动透传到外层 div,确保父组件传入的 class / style 等生效
|
||||||
|
const attrs = useAttrs()
|
||||||
|
|
||||||
|
defineOptions({ name: 'MdWorkstationSelect', inheritAttrs: false })
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
modelValue?: number
|
modelValue?: number // 绑定的工作站 ID
|
||||||
disabled?: boolean
|
disabled?: boolean // 是否禁用
|
||||||
clearable?: boolean
|
clearable?: boolean // 是否允许清空
|
||||||
placeholder?: string
|
placeholder?: string // 占位文字
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|
@ -45,36 +74,98 @@ const emit = defineEmits<{
|
||||||
change: [item: MdWorkstationVO | undefined]
|
change: [item: MdWorkstationVO | undefined]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const allList = ref<MdWorkstationVO[]>([])
|
const dialogRef = ref() // 弹窗 Ref
|
||||||
const filteredList = ref<MdWorkstationVO[]>([])
|
const hovering = ref(false) // 鼠标是否悬停
|
||||||
|
|
||||||
const selectValue = computed({
|
// ==================== 名称回显 ====================
|
||||||
get: () => props.modelValue,
|
const selectedItem = ref<MdWorkstationVO | undefined>() // 当前选中的工作站对象
|
||||||
set: (val) => emit('update:modelValue', val)
|
|
||||||
|
/** 输入框显示文本:只展示工作站名称,保持简洁 */
|
||||||
|
const displayLabel = computed(() => {
|
||||||
|
return selectedItem.value?.name ?? ''
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 前端过滤(name + code) */
|
/** 是否显示清除图标 */
|
||||||
const handleFilter = (query: string) => {
|
const showClear = computed(() => {
|
||||||
if (!query) {
|
return props.clearable && !props.disabled && hovering.value && props.modelValue != null
|
||||||
filteredList.value = allList.value
|
})
|
||||||
|
|
||||||
|
/** 后缀图标:悬停且有值时显示清除,否则显示搜索 */
|
||||||
|
const suffixIcon = computed(() => {
|
||||||
|
return showClear.value ? CircleClose : Search
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 根据 ID 单条查询工作站信息(用于编辑回显) */
|
||||||
|
const resolveItemById = async (id: number | undefined) => {
|
||||||
|
if (id == null) {
|
||||||
|
selectedItem.value = undefined
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const keyword = query.toLowerCase()
|
if (selectedItem.value?.id === id) {
|
||||||
filteredList.value = allList.value.filter(
|
return
|
||||||
(item) =>
|
}
|
||||||
item.name?.toLowerCase().includes(keyword) || item.code?.toLowerCase().includes(keyword)
|
try {
|
||||||
)
|
selectedItem.value = await MdWorkstationApi.getWorkstation(id)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[MdWorkstationSelect] resolveItemById failed:', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 选中变化 */
|
/** 监听 modelValue 变化,触发回显 */
|
||||||
const handleChange = (val: number | undefined) => {
|
watch(
|
||||||
const item = allList.value.find((o) => o.id === val)
|
() => props.modelValue,
|
||||||
|
(val) => {
|
||||||
|
resolveItemById(val)
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 点击交互 ====================
|
||||||
|
|
||||||
|
/** 点击组件:清除或打开弹窗 */
|
||||||
|
const handleClick = (e: MouseEvent) => {
|
||||||
|
if (props.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 点击清除图标:清空选中
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
if (showClear.value && target.closest('.el-input__suffix')) {
|
||||||
|
e.stopPropagation()
|
||||||
|
selectedItem.value = undefined
|
||||||
|
emit('update:modelValue', undefined)
|
||||||
|
emit('change', undefined)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 打开弹窗,传入当前选中 ID 用于预选高亮
|
||||||
|
const selectedIds = props.modelValue != null ? [props.modelValue] : []
|
||||||
|
dialogRef.value.open(selectedIds)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 弹窗选中回调 */
|
||||||
|
const handleSelected = (rows: MdWorkstationVO[]) => {
|
||||||
|
if (!rows || rows.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const item = rows[0]
|
||||||
|
selectedItem.value = item
|
||||||
|
emit('update:modelValue', item.id)
|
||||||
emit('change', item)
|
emit('change', item)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 加载工作站列表 */
|
|
||||||
onMounted(async () => {
|
|
||||||
allList.value = await MdWorkstationApi.getWorkstationSimpleList()
|
|
||||||
filteredList.value = allList.value
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
/* :deep 用于穿透 el-input 内部元素的 cursor 样式,UnoCSS 无法直接处理组件内部 DOM */
|
||||||
|
.is-select-clickable {
|
||||||
|
:deep(.el-input__wrapper),
|
||||||
|
:deep(.el-input__inner) {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-select-disabled {
|
||||||
|
:deep(.el-input__wrapper),
|
||||||
|
:deep(.el-input__inner) {
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,276 @@
|
||||||
|
<!--
|
||||||
|
MES 工作站弹窗选择器(支持单选/多选)
|
||||||
|
|
||||||
|
搜索字段:工作站编码、所属工序、所在车间(对齐 KTG simpletableSingle.vue)
|
||||||
|
表格列:工作站编码、工作站名称、工作站地点、所在车间、所属工序、备注
|
||||||
|
|
||||||
|
Props:
|
||||||
|
multiple — true 多选(checkbox),false 单选(radio);默认 true
|
||||||
|
Events:
|
||||||
|
selected(rows: MdWorkstationVO[]) — 确认选择后触发,单选时数组长度为 1
|
||||||
|
Expose:
|
||||||
|
open(selectedIds?: number[]) — 打开弹窗,可传入已选 ID 用于预选高亮
|
||||||
|
-->
|
||||||
|
<template>
|
||||||
|
<Dialog title="工作站选择" v-model="dialogVisible" width="80%">
|
||||||
|
<!-- 搜索 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<el-form :inline="true" :model="queryParams" label-width="85px">
|
||||||
|
<el-form-item label="工作站编码">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.code"
|
||||||
|
placeholder="请输入工作站编码"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="所属工序">
|
||||||
|
<ProProcessSelect
|
||||||
|
v-model="queryParams.processId"
|
||||||
|
placeholder="请选择工序"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="所在车间">
|
||||||
|
<MdWorkshopSelect
|
||||||
|
v-model="queryParams.workshopId"
|
||||||
|
placeholder="请选择车间"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
|
||||||
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</ContentWrap>
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<el-table
|
||||||
|
ref="tableRef"
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
row-key="id"
|
||||||
|
:highlight-current-row="!multiple"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
|
@row-click="handleRowClick"
|
||||||
|
@row-dblclick="handleRowDblClick"
|
||||||
|
>
|
||||||
|
<!-- 多选:checkbox(reserve-selection 保证跨页勾选不丢失) -->
|
||||||
|
<el-table-column
|
||||||
|
v-if="multiple"
|
||||||
|
type="selection"
|
||||||
|
:reserve-selection="true"
|
||||||
|
width="50"
|
||||||
|
align="center"
|
||||||
|
/>
|
||||||
|
<!-- 单选:radio -->
|
||||||
|
<el-table-column v-else width="50" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-radio
|
||||||
|
v-model="selectedRadioId"
|
||||||
|
:value="row.id"
|
||||||
|
class="radio-no-label"
|
||||||
|
@change="handleRadioChange(row)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="工作站编码" align="center" prop="code" width="140" />
|
||||||
|
<el-table-column label="工作站名称" align="center" prop="name" min-width="160" />
|
||||||
|
<el-table-column label="工作站地点" align="center" prop="address" min-width="140" />
|
||||||
|
<el-table-column label="所在车间" align="center" prop="workshopName" width="120" />
|
||||||
|
<el-table-column label="所属工序" align="center" prop="processName" width="120" />
|
||||||
|
<el-table-column label="备注" align="center" prop="remark" min-width="120" />
|
||||||
|
</el-table>
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
<template #footer>
|
||||||
|
<el-button type="primary" @click="confirmSelect">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { MdWorkstationApi, MdWorkstationVO } from '@/api/mes/md/workstation'
|
||||||
|
import ProProcessSelect from '@/views/mes/pro/process/components/ProProcessSelect.vue'
|
||||||
|
import MdWorkshopSelect from '@/views/mes/md/workstation/components/MdWorkshopSelect.vue'
|
||||||
|
|
||||||
|
defineOptions({ name: 'MdWorkstationSelectDialog' })
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
multiple?: boolean // true 多选(checkbox),false 单选(radio)
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
multiple: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const message = useMessage()
|
||||||
|
const emit = defineEmits<{
|
||||||
|
selected: [rows: MdWorkstationVO[]]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗是否展示
|
||||||
|
const loading = ref(false) // 列表加载中
|
||||||
|
const list = ref<MdWorkstationVO[]>([]) // 工作站列表
|
||||||
|
const total = ref(0) // 总条数
|
||||||
|
|
||||||
|
// ==================== 选中状态 ====================
|
||||||
|
const tableRef = ref() // 表格 Ref
|
||||||
|
const selectedRows = ref<MdWorkstationVO[]>([]) // 多选模式:选中行
|
||||||
|
const selectedRadioId = ref<number>() // 单选模式:选中 ID
|
||||||
|
const currentRadioRow = ref<MdWorkstationVO>() // 单选模式:选中行对象
|
||||||
|
const preSelectedIds = ref<number[]>([]) // 打开弹窗时传入的已选 ID
|
||||||
|
|
||||||
|
/** 多选:checkbox 变化 */
|
||||||
|
const handleSelectionChange = (rows: MdWorkstationVO[]) => {
|
||||||
|
if (props.multiple) {
|
||||||
|
selectedRows.value = rows
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单选:radio 变化 */
|
||||||
|
const handleRadioChange = (row: MdWorkstationVO) => {
|
||||||
|
currentRadioRow.value = row
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单击行:单选模式下点击整行即选中(降低操作成本),多选不处理(避免和 dblclick 冲突) */
|
||||||
|
const handleRowClick = (row: MdWorkstationVO) => {
|
||||||
|
if (props.multiple) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
selectedRadioId.value = row.id
|
||||||
|
currentRadioRow.value = row
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 双击行:多选模式切换勾选,单选模式直接确认 */
|
||||||
|
const handleRowDblClick = (row: MdWorkstationVO) => {
|
||||||
|
if (props.multiple) {
|
||||||
|
tableRef.value?.toggleRowSelection(row)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
selectedRadioId.value = row.id
|
||||||
|
currentRadioRow.value = row
|
||||||
|
confirmSelect()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 工作站查询 ====================
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1, // 页码
|
||||||
|
pageSize: 10, // 每页条数
|
||||||
|
code: undefined as string | undefined, // 工作站编码
|
||||||
|
processId: undefined as number | undefined, // 工序编号
|
||||||
|
workshopId: undefined as number | undefined // 车间编号
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 查询工作站列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const data = await MdWorkstationApi.getWorkstationPage(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
await nextTick()
|
||||||
|
applyPreSelection()
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 恢复预选状态(当前页可见范围内) */
|
||||||
|
const applyPreSelection = () => {
|
||||||
|
if (preSelectedIds.value.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (props.multiple) {
|
||||||
|
const table = tableRef.value
|
||||||
|
if (!table) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
list.value.forEach((row) => {
|
||||||
|
if (preSelectedIds.value.includes(row.id)) {
|
||||||
|
table.toggleRowSelection(row, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const match = list.value.find((row) => preSelectedIds.value.includes(row.id))
|
||||||
|
if (match) {
|
||||||
|
selectedRadioId.value = match.id
|
||||||
|
currentRadioRow.value = match
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置查询条件 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryParams.code = undefined
|
||||||
|
queryParams.processId = undefined
|
||||||
|
queryParams.workshopId = undefined
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 确认选择 */
|
||||||
|
const confirmSelect = () => {
|
||||||
|
if (props.multiple) {
|
||||||
|
if (selectedRows.value.length === 0) {
|
||||||
|
message.warning('请至少选择一条数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('selected', selectedRows.value)
|
||||||
|
} else {
|
||||||
|
if (!currentRadioRow.value) {
|
||||||
|
message.warning('请选择一条数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('selected', [currentRadioRow.value])
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 打开弹窗 ====================
|
||||||
|
|
||||||
|
/** 打开弹窗,可传入已选 ID 用于预选高亮 */
|
||||||
|
const open = async (selectedIds?: number[]) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
// 重置查询条件 + 页码,避免二次打开继承上次过滤上下文
|
||||||
|
queryParams.code = undefined
|
||||||
|
queryParams.processId = undefined
|
||||||
|
queryParams.workshopId = undefined
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
// 清空上一次的选中状态
|
||||||
|
selectedRows.value = []
|
||||||
|
selectedRadioId.value = undefined
|
||||||
|
currentRadioRow.value = undefined
|
||||||
|
preSelectedIds.value = selectedIds ?? []
|
||||||
|
// 多选模式清空跨页缓存的勾选
|
||||||
|
await nextTick()
|
||||||
|
tableRef.value?.clearSelection()
|
||||||
|
await getList()
|
||||||
|
}
|
||||||
|
defineExpose({ open })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
/* 隐藏 radio 的 label 文字,只保留圆圈 */
|
||||||
|
.radio-no-label {
|
||||||
|
:deep(.el-radio__label) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue