✨ feat(mes): 增强设备选择器和类型选择器功能
- 更新设备选择器,支持只读输入框和弹窗选择,提升用户体验。 - 增加设备编码、名称、品牌和规格的展示信息。 - 优化设备类型选择器,添加 tooltip 显示选中项的详细信息。 - 移除不再使用的 API 接口,简化代码结构。 这些改动旨在提升用户在选择设备和设备类型时的交互体验,确保信息的完整性和可读性。pull/871/MERGE
parent
16012a5efd
commit
65a0be187f
|
|
@ -44,11 +44,6 @@ export const DvMachineryApi = {
|
||||||
return await request.delete({ url: `/mes/dv/machinery/delete?id=` + id })
|
return await request.delete({ url: `/mes/dv/machinery/delete?id=` + id })
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获得设备精简列表(下拉选项用)
|
|
||||||
getSimpleList: async () => {
|
|
||||||
return await request.get({ url: `/mes/dv/machinery/simple-list` })
|
|
||||||
},
|
|
||||||
|
|
||||||
// 导出设备台账 Excel
|
// 导出设备台账 Excel
|
||||||
exportMachinery: async (params: any) => {
|
exportMachinery: async (params: any) => {
|
||||||
return await request.download({ url: `/mes/dv/machinery/export-excel`, params })
|
return await request.download({ url: `/mes/dv/machinery/export-excel`, params })
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,6 @@ export const DvSubjectApi = {
|
||||||
return await request.delete({ url: `/mes/dv/subject/delete?id=` + id })
|
return await request.delete({ url: `/mes/dv/subject/delete?id=` + id })
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获得点检保养项目精简列表(下拉选项用)
|
|
||||||
getSimpleList: async () => {
|
|
||||||
return await request.get({ url: `/mes/dv/subject/simple-list` })
|
|
||||||
},
|
|
||||||
|
|
||||||
// 导出点检保养项目 Excel
|
// 导出点检保养项目 Excel
|
||||||
exportSubject: async (params: any) => {
|
exportSubject: async (params: any) => {
|
||||||
return await request.download({ url: `/mes/dv/subject/export-excel`, params })
|
return await request.download({ url: `/mes/dv/subject/export-excel`, params })
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,65 @@
|
||||||
<!-- MES 设备选择器:远程搜索下拉(支持 name、code) -->
|
<!--
|
||||||
|
MES 设备选择器:只读输入框 + 点击弹窗选择
|
||||||
|
|
||||||
|
交互:显示为只读 el-input,点击打开弹窗(单选模式)进行选择
|
||||||
|
Props:
|
||||||
|
modelValue — 绑定的设备 ID(v-model)
|
||||||
|
disabled — 是否禁用
|
||||||
|
clearable — 是否允许清空(鼠标悬停时显示清除图标)
|
||||||
|
placeholder — 占位文字
|
||||||
|
Events:
|
||||||
|
update:modelValue — v-model 更新
|
||||||
|
change(item) — 选中设备变化时触发,传递完整 DvMachineryVO(清空时为 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"
|
||||||
remote
|
@mouseleave="hovering = false"
|
||||||
remote-show-suffix
|
|
||||||
reserve-keyword
|
|
||||||
:remote-method="handleRemoteSearch"
|
|
||||||
class="!w-1/1"
|
|
||||||
@change="handleChange"
|
|
||||||
>
|
>
|
||||||
<el-option v-for="item in optionList" :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">{{ item.code }}</el-tag>
|
<div>设备编码:{{ selectedItem.code }}</div>
|
||||||
</div>
|
<div>设备名称:{{ selectedItem.name }}</div>
|
||||||
</el-option>
|
<div v-if="selectedItem.brand">品牌:{{ selectedItem.brand }}</div>
|
||||||
</el-select>
|
<div v-if="selectedItem.spec">规格型号:{{ selectedItem.spec }}</div>
|
||||||
|
</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 -->
|
||||||
|
<DvMachinerySelectDialog ref="dialogRef" :multiple="false" @selected="handleSelected" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { DvMachineryApi, DvMachineryVO } from '@/api/mes/dv/machinery'
|
import { DvMachineryApi, DvMachineryVO } from '@/api/mes/dv/machinery'
|
||||||
|
import { Search, CircleClose } from '@element-plus/icons-vue'
|
||||||
|
import DvMachinerySelectDialog from './DvMachinerySelectDialog.vue'
|
||||||
|
|
||||||
defineOptions({ name: 'DvMachinerySelect' })
|
// 组件有两个根节点(div + Dialog),Vue 不会自动继承 attrs;
|
||||||
|
// 手动透传到外层 div,确保父组件传入的 class / style 等生效
|
||||||
|
const attrs = useAttrs()
|
||||||
|
|
||||||
|
defineOptions({ name: 'DvMachinerySelect', 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,
|
||||||
|
|
@ -46,34 +73,98 @@ const emit = defineEmits<{
|
||||||
change: [item: DvMachineryVO | undefined]
|
change: [item: DvMachineryVO | undefined]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const optionList = ref<DvMachineryVO[]>([])
|
const dialogRef = ref() // 弹窗 Ref
|
||||||
|
const hovering = ref(false) // 鼠标是否悬停
|
||||||
|
|
||||||
const selectValue = computed({
|
// ==================== 名称回显 ====================
|
||||||
get: () => props.modelValue,
|
const selectedItem = ref<DvMachineryVO | undefined>() // 当前选中的设备对象
|
||||||
set: (val) => emit('update:modelValue', val)
|
|
||||||
|
/** 输入框显示文本:只展示设备名称,保持简洁 */
|
||||||
|
const displayLabel = computed(() => {
|
||||||
|
return selectedItem.value?.name ?? ''
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 远程搜索 */
|
/** 是否显示清除图标 */
|
||||||
const handleRemoteSearch = async (query: string) => {
|
const showClear = computed(() => {
|
||||||
const data = await DvMachineryApi.getMachineryPage({ name: query, pageNo: 1, pageSize: 20 })
|
return props.clearable && !props.disabled && hovering.value && props.modelValue != null
|
||||||
optionList.value = data.list
|
})
|
||||||
|
|
||||||
|
/** 后缀图标:悬停且有值时显示清除,否则显示搜索 */
|
||||||
|
const suffixIcon = computed(() => {
|
||||||
|
return showClear.value ? CircleClose : Search
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 根据 ID 单条查询设备信息(用于编辑回显) */
|
||||||
|
const resolveItemById = async (id: number | undefined) => {
|
||||||
|
if (id == null) {
|
||||||
|
selectedItem.value = undefined
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (selectedItem.value?.id === id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
selectedItem.value = await DvMachineryApi.getMachinery(id)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[DvMachinerySelect] resolveItemById failed:', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 选中变化 */
|
/** 监听 modelValue 变化,触发回显 */
|
||||||
const handleChange = (val: number | undefined) => {
|
|
||||||
const item = optionList.value.find((o) => o.id === val)
|
|
||||||
emit('change', item)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 回显:根据 modelValue 加载初始选项 */
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
async (val) => {
|
(val) => {
|
||||||
if (val && !optionList.value.find((o) => o.id === val)) {
|
resolveItemById(val)
|
||||||
const item = await DvMachineryApi.getMachinery(val)
|
|
||||||
if (item) optionList.value = [item, ...optionList.value]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ 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: DvMachineryVO[]) => {
|
||||||
|
if (!rows || rows.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const item = rows[0]
|
||||||
|
selectedItem.value = item
|
||||||
|
emit('update:modelValue', item.id)
|
||||||
|
emit('change', item)
|
||||||
|
}
|
||||||
</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,318 @@
|
||||||
|
<!--
|
||||||
|
MES 设备弹窗选择器(支持单选/多选)
|
||||||
|
-->
|
||||||
|
<template>
|
||||||
|
<Dialog title="设备选择" v-model="dialogVisible" width="80%">
|
||||||
|
<el-row :gutter="20">
|
||||||
|
<!-- 左侧分类树 -->
|
||||||
|
<el-col :span="4" :xs="24">
|
||||||
|
<ContentWrap class="h-1/1">
|
||||||
|
<MachineryTypeTree @node-click="handleTypeNodeClick" />
|
||||||
|
</ContentWrap>
|
||||||
|
</el-col>
|
||||||
|
<!-- 右侧设备数据 -->
|
||||||
|
<el-col :span="20" :xs="24">
|
||||||
|
<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="设备名称">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入设备名称"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="所属车间">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.workshopId"
|
||||||
|
placeholder="请选择所属车间"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in workshopList"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery">
|
||||||
|
<Icon icon="ep:search" class="mr-5px" /> 搜索
|
||||||
|
</el-button>
|
||||||
|
<el-button @click="resetQuery">
|
||||||
|
<Icon icon="ep:refresh" class="mr-5px" /> 重置
|
||||||
|
</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="120" />
|
||||||
|
<el-table-column label="设备名称" align="left" prop="name" min-width="120" />
|
||||||
|
<el-table-column label="品牌" align="left" prop="brand" min-width="120" />
|
||||||
|
<el-table-column label="规格型号" align="left" prop="spec" min-width="120" />
|
||||||
|
<el-table-column label="所属车间" align="center" prop="workshopName" width="120" />
|
||||||
|
<el-table-column label="设备状态" align="center" prop="status" width="100">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.MES_DV_MACHINERY_STATUS" :value="scope.row.status" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
label="创建时间"
|
||||||
|
align="center"
|
||||||
|
prop="createTime"
|
||||||
|
:formatter="dateFormatter"
|
||||||
|
width="160"
|
||||||
|
/>
|
||||||
|
</el-table>
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<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 { DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
import { DvMachineryApi, DvMachineryVO } from '@/api/mes/dv/machinery'
|
||||||
|
import { MdWorkshopApi, MdWorkshopVO } from '@/api/mes/md/workstation/workshop'
|
||||||
|
import MachineryTypeTree from '../MachineryTypeTree.vue'
|
||||||
|
|
||||||
|
defineOptions({ name: 'DvMachinerySelectDialog' })
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
multiple?: boolean // true 多选(checkbox),false 单选(radio)
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
multiple: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const message = useMessage()
|
||||||
|
const emit = defineEmits<{
|
||||||
|
selected: [rows: DvMachineryVO[]]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗是否展示
|
||||||
|
const loading = ref(false) // 列表加载中
|
||||||
|
const list = ref<DvMachineryVO[]>([]) // 设备列表
|
||||||
|
const total = ref(0) // 总条数
|
||||||
|
|
||||||
|
// ==================== 选中状态 ====================
|
||||||
|
const tableRef = ref() // 表格 Ref
|
||||||
|
const selectedRows = ref<DvMachineryVO[]>([]) // 多选模式:选中行
|
||||||
|
const selectedRadioId = ref<number>() // 单选模式:选中 ID
|
||||||
|
const currentRadioRow = ref<DvMachineryVO>() // 单选模式:选中行对象
|
||||||
|
const preSelectedIds = ref<number[]>([]) // 打开弹窗时传入的已选 ID
|
||||||
|
|
||||||
|
const workshopList = ref<MdWorkshopVO[]>([]) // 车间列表
|
||||||
|
|
||||||
|
/** 多选:checkbox 变化 */
|
||||||
|
const handleSelectionChange = (rows: DvMachineryVO[]) => {
|
||||||
|
if (props.multiple) {
|
||||||
|
selectedRows.value = rows
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单选:radio 变化 */
|
||||||
|
const handleRadioChange = (row: DvMachineryVO) => {
|
||||||
|
currentRadioRow.value = row
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单击行:单选模式下点击整行即选中(降低操作成本),多选不处理(避免和 dblclick 冲突) */
|
||||||
|
const handleRowClick = (row: DvMachineryVO) => {
|
||||||
|
if (props.multiple) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
selectedRadioId.value = row.id
|
||||||
|
currentRadioRow.value = row
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 双击行:多选模式切换勾选,单选模式直接确认 */
|
||||||
|
const handleRowDblClick = (row: DvMachineryVO) => {
|
||||||
|
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, // 设备编码
|
||||||
|
name: undefined as string | undefined, // 设备名称
|
||||||
|
workshopId: undefined as number | undefined, // 所属车间
|
||||||
|
machineryTypeId: undefined as number | undefined // 设备类型
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const data = await DvMachineryApi.getMachineryPage(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.name = undefined
|
||||||
|
queryParams.workshopId = undefined
|
||||||
|
// 不重置 machineryTypeId,保持左侧树的选中状态
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理分类树节点点击 */
|
||||||
|
const handleTypeNodeClick = (row: any) => {
|
||||||
|
queryParams.machineryTypeId = row?.id
|
||||||
|
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.name = undefined
|
||||||
|
queryParams.workshopId = undefined
|
||||||
|
queryParams.machineryTypeId = undefined
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
// 清空上一次的选中状态
|
||||||
|
selectedRows.value = []
|
||||||
|
selectedRadioId.value = undefined
|
||||||
|
currentRadioRow.value = undefined
|
||||||
|
preSelectedIds.value = selectedIds ?? []
|
||||||
|
|
||||||
|
if (workshopList.value.length === 0) {
|
||||||
|
workshopList.value = await MdWorkshopApi.getWorkshopSimpleList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 多选模式清空跨页缓存的勾选
|
||||||
|
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>
|
||||||
|
|
@ -1,17 +1,26 @@
|
||||||
<!-- MES 设备类型选择器:树形下拉,只允许选择叶节点 -->
|
<!-- MES 设备类型选择器:树形下拉,只允许选择叶节点 -->
|
||||||
<template>
|
<template>
|
||||||
<el-tree-select
|
<el-tooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||||
v-model="selectValue"
|
<template #content>
|
||||||
:data="treeData"
|
<div v-if="selectedItem" class="leading-6">
|
||||||
:props="defaultProps"
|
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||||
:placeholder="placeholder"
|
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||||
:disabled="disabled"
|
<div>备注:{{ selectedItem.remark || '-' }}</div>
|
||||||
check-strictly
|
</div>
|
||||||
default-expand-all
|
</template>
|
||||||
filterable
|
<el-tree-select
|
||||||
class="!w-1/1"
|
v-model="selectValue"
|
||||||
@change="handleChange"
|
:data="treeData"
|
||||||
/>
|
:props="defaultProps"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
check-strictly
|
||||||
|
default-expand-all
|
||||||
|
filterable
|
||||||
|
class="!w-1/1"
|
||||||
|
@change="handleChange"
|
||||||
|
/>
|
||||||
|
</el-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
@ -39,6 +48,7 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
const allList = ref<DvMachineryTypeVO[]>([])
|
const allList = ref<DvMachineryTypeVO[]>([])
|
||||||
const treeData = ref<any[]>([])
|
const treeData = ref<any[]>([])
|
||||||
|
const selectedItem = ref<DvMachineryTypeVO | undefined>() // 当前选中的分类对象(用于 tooltip 展示)
|
||||||
|
|
||||||
const selectValue = computed({
|
const selectValue = computed({
|
||||||
get: () => props.modelValue,
|
get: () => props.modelValue,
|
||||||
|
|
@ -47,6 +57,7 @@ const selectValue = computed({
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,8 +71,26 @@ const markParentsDisabled = (nodes: any[]): any[] => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 根据 modelValue 同步 selectedItem(用于编辑回显) */
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(val) => {
|
||||||
|
if (val == null) {
|
||||||
|
selectedItem.value = undefined
|
||||||
|
return
|
||||||
|
}
|
||||||
|
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 DvMachineryTypeApi.getMachineryTypeSimpleList()
|
allList.value = await DvMachineryTypeApi.getMachineryTypeSimpleList()
|
||||||
treeData.value = markParentsDisabled(handleTree(allList.value))
|
treeData.value = markParentsDisabled(handleTree(allList.value))
|
||||||
|
// 列表加载完成后,回显 selectedItem
|
||||||
|
if (props.modelValue != null) {
|
||||||
|
selectedItem.value = allList.value.find((o) => o.id === props.modelValue)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue