检测计划未检、检测中、检测完成都可以绑定新的设备。但是该计划只有未检的设备可以解绑操作,其它的不允许解绑操作
This commit is contained in:
@@ -235,7 +235,7 @@
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
<el-button
|
||||
v-if="!data.disabled && !props.disabled"
|
||||
v-if="modeStore.currentMode === '比对式' ? !data.disabled : (!data.disabled && !props.disabled)"
|
||||
text
|
||||
circle
|
||||
@click="removeNode(data)"
|
||||
@@ -252,7 +252,7 @@
|
||||
</el-row>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, ref, watch } from 'vue'
|
||||
import { computed, nextTick, onMounted, PropType, ref, useSlots, watch } from 'vue'
|
||||
import type {
|
||||
FilterNodeMethodFunction,
|
||||
RenderContentContext,
|
||||
@@ -261,6 +261,7 @@ import type {
|
||||
TreeKey
|
||||
} from 'element-plus'
|
||||
import { Cpu, Lightning, Location, OfficeBuilding, Warning } from '@element-plus/icons-vue'
|
||||
import { useModeStore } from '@/stores/modules/mode' // 引入模式 store
|
||||
|
||||
interface Tree {
|
||||
[key: string]: any
|
||||
@@ -274,6 +275,7 @@ interface Device {
|
||||
type Data = RenderContentContext['data']
|
||||
const modelValue = defineModel<string[]>({ default: [] })
|
||||
const slots = useSlots()
|
||||
const modeStore = useModeStore()
|
||||
const props = defineProps({
|
||||
data: {
|
||||
type: Array as unknown as PropType<Device[]>,
|
||||
@@ -298,7 +300,7 @@ const props = defineProps({
|
||||
expandAll: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
})
|
||||
const leftTreeRef = ref<TreeInstance>()
|
||||
const rightTreeRef = ref<TreeInstance>()
|
||||
@@ -353,6 +355,7 @@ watch(
|
||||
)
|
||||
|
||||
const initTree = (data: Device[]) => {
|
||||
|
||||
// 禁用Key数据
|
||||
disabledKeys.value = data.filter(item => item.disabled).map(item => item.id)
|
||||
// 编辑逻辑
|
||||
@@ -360,11 +363,14 @@ const initTree = (data: Device[]) => {
|
||||
modelValue.value = []
|
||||
}
|
||||
// 左侧树数据
|
||||
leftTreeData.value = convertToTree(data, filter.value.groupBy)
|
||||
leftTreeData.value = convertToTree(data, 0,filter.value.groupBy)
|
||||
|
||||
// 右侧树数据
|
||||
rightTreeData.value = convertToTree(
|
||||
data.filter(item => item.checked),
|
||||
1,
|
||||
filter.value.groupBy
|
||||
|
||||
)
|
||||
defaultCheckedKeys.value = data.filter(item => item.checked).map(item => item.id)
|
||||
modelValue.value = defaultCheckedKeys.value
|
||||
@@ -393,7 +399,7 @@ const setCheckedStatus = (checked: boolean) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
const convertToTree = (data: Device[], groupBy?: string | undefined) => {
|
||||
const convertToTree = (data: Device[], type: number,groupBy?: string | undefined) => {
|
||||
if (groupBy) {
|
||||
// 创建一个映射来存储每个分组
|
||||
const groupMap = new Map()
|
||||
@@ -409,6 +415,41 @@ const convertToTree = (data: Device[], groupBy?: string | undefined) => {
|
||||
|
||||
// 将分组转换为树形结构
|
||||
const treeData: Tree[] = []
|
||||
|
||||
if(modeStore.currentMode == '比对式'){
|
||||
groupMap.forEach((items, groupName) => {
|
||||
let groupNode: Tree;
|
||||
if(type === 0){
|
||||
// 只有当组内所有项目都禁用时,才将组节点设为禁用
|
||||
const allItemsDisabled = (items as any[]).every((item: any) => {
|
||||
return item.disabled === true ;
|
||||
});
|
||||
groupNode = {
|
||||
id: `${groupBy}_${groupName}`,
|
||||
label: groupName,
|
||||
children: (items as any[]).map((item: any) => ({
|
||||
...item,
|
||||
label: item.name,
|
||||
children: [],
|
||||
// disabled: item.disabled ? item.disabled : props.disabled
|
||||
})),
|
||||
// disabled: props.disabled
|
||||
disabled: allItemsDisabled
|
||||
}
|
||||
}else{
|
||||
groupNode = {
|
||||
id: `${groupBy}_${groupName}`,
|
||||
label: groupName,
|
||||
children: (items as any[]).map((item: any) => ({
|
||||
...item,
|
||||
label: item.name,
|
||||
children: [],
|
||||
})),
|
||||
}
|
||||
}
|
||||
treeData.push(groupNode)
|
||||
})
|
||||
}else{
|
||||
groupMap.forEach((items, groupName) => {
|
||||
const groupNode: Tree = {
|
||||
id: `${groupBy}_${groupName}`,
|
||||
@@ -423,6 +464,7 @@ const convertToTree = (data: Device[], groupBy?: string | undefined) => {
|
||||
}
|
||||
treeData.push(groupNode)
|
||||
})
|
||||
}
|
||||
|
||||
return treeData
|
||||
} else {
|
||||
@@ -445,14 +487,17 @@ const filterNode: FilterNodeMethodFunction = (value: string, data: Tree) => {
|
||||
}
|
||||
return data.label.includes(value) || data.cityName.includes(value) || data.manufacturer.includes(value)
|
||||
}
|
||||
|
||||
const handleCommand = (command: string) => {
|
||||
filter.value.groupBy = command
|
||||
const oldCheckedKeys = leftTreeRef.value?.getCheckedKeys() || []
|
||||
leftTreeData.value = convertToTree(props.data, filter.value.groupBy)
|
||||
leftTreeData.value = convertToTree(props.data,0, filter.value.groupBy)
|
||||
leftTreeRef.value?.setCheckedKeys(oldCheckedKeys)
|
||||
rightTreeData.value = convertToTree(
|
||||
props.data.filter(item => oldCheckedKeys.includes(item.id)),
|
||||
1,
|
||||
filter.value.groupBy
|
||||
|
||||
)
|
||||
if (filter.value.checkAll) {
|
||||
setCheckedStatus(true)
|
||||
@@ -467,10 +512,14 @@ const handleCheckChange = () => {
|
||||
.map(key => key.toString())
|
||||
rightTreeData.value = convertToTree(
|
||||
props.data.filter(item => checkedKeys.includes(item.id)),
|
||||
filter.value.groupBy
|
||||
1,
|
||||
filter.value.groupBy,
|
||||
|
||||
)
|
||||
statistics.value.checked = checkedKeys.length || 0
|
||||
filter.value.checkAll = statistics.value.checked === statistics.value.total
|
||||
|
||||
|
||||
}
|
||||
const clearAll = () => {
|
||||
if (statistics.value.checked > 0) {
|
||||
@@ -478,11 +527,44 @@ const clearAll = () => {
|
||||
}
|
||||
}
|
||||
const removeNode = (data: Data) => {
|
||||
|
||||
nextTick(() => {
|
||||
leftTreeRef.value?.setChecked(data, false, true)
|
||||
rightTreeRef.value?.remove(data)
|
||||
})
|
||||
}
|
||||
|
||||
// 获取当前右侧树中的设备ID
|
||||
const getSelectedDeviceIds = () => {
|
||||
const extractDeviceIds = (treeData: Tree[]): string[] => {
|
||||
const ids: string[] = [];
|
||||
|
||||
const traverse = (nodes: Tree[]) => {
|
||||
if (!Array.isArray(nodes)) return;
|
||||
|
||||
nodes.forEach(node => {
|
||||
// 如果节点有 children 且不为空,则递归遍历
|
||||
if (node.children && Array.isArray(node.children) && node.children.length > 0) {
|
||||
traverse(node.children);
|
||||
} else {
|
||||
// 只有叶子节点(设备节点)才添加到 ID 列表中
|
||||
// 设备节点的 ID 不包含下划线
|
||||
if (node.id && !node.id.toString().includes('_')) {
|
||||
ids.push(node.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
traverse(treeData);
|
||||
return ids;
|
||||
};
|
||||
|
||||
return extractDeviceIds(rightTreeData.value);
|
||||
};
|
||||
|
||||
|
||||
defineExpose({ getSelectedDeviceIds });
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.card-header {
|
||||
|
||||
@@ -243,6 +243,7 @@
|
||||
</el-col>
|
||||
<el-col :span="15">
|
||||
<DevSelect
|
||||
ref="devSelectRef"
|
||||
v-model="formContent.devIds"
|
||||
:titles="['被检设备列表', '已选被检设备列表']"
|
||||
filter-placeholder="请输入内容搜索"
|
||||
@@ -459,12 +460,14 @@ import { getTestConfig } from '@/api/system/base'
|
||||
import { getRegRes } from '@/api/system/versionRegister'
|
||||
import DevSelect from '@/views/plan/planList/components/devSelect.vue'
|
||||
import { WarningFilled } from '@element-plus/icons-vue'
|
||||
import { el } from 'element-plus/es/locale'
|
||||
|
||||
const modeStore = useModeStore()
|
||||
const AppSceneStore = useAppSceneStore()
|
||||
const dictStore = useDictStore()
|
||||
// 定义弹出组件元信息
|
||||
const dialogFormRef = ref()
|
||||
const devSelectRef = ref()
|
||||
const mode = ref()
|
||||
const selectByMode = ref(true)
|
||||
const pqSourceList = ref<TestSource.ResTestSource[]>([]) //获取指定模式下所有检测源
|
||||
@@ -513,12 +516,21 @@ const generateData = () => {
|
||||
}
|
||||
}
|
||||
i.checked = boundPqDevIds.length > 0 ? boundPqDevIds.includes(i.id) : false
|
||||
|
||||
if (mode.value === '比对式') {
|
||||
if (i.checkState && i.checkState != 0) {
|
||||
i.disabled = true
|
||||
}else {
|
||||
i.disabled = false
|
||||
}
|
||||
}else{
|
||||
if (i.checkState && i.checkState != 0) {
|
||||
i.disabled = true
|
||||
}
|
||||
if (allDisabled.value) {
|
||||
i.disabled = true
|
||||
}
|
||||
}
|
||||
})
|
||||
// 排序逻辑
|
||||
devData.value = allPqDevList.sort((a, b) => {
|
||||
@@ -533,6 +545,7 @@ const generateData = () => {
|
||||
// 最后按名称排序(升序)
|
||||
return a.name.localeCompare(b.name)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -756,6 +769,7 @@ const save = () => {
|
||||
emit('update:tab')
|
||||
} else {
|
||||
formContent.sourceIds = null
|
||||
formContent.devIds = devSelectRef.value?.getSelectedDeviceIds() || [];
|
||||
await updatePlan(formContent)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user