完成Banner,设备管理模块,进行中 水电表
This commit is contained in:
@@ -12,6 +12,24 @@
|
||||
</div>
|
||||
|
||||
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1050">
|
||||
<nav class="flex flex-items-center mb-8">
|
||||
<div class="flex flex-items-center">
|
||||
<div style="width: 70px; text-align: right; padding-right: 10px">员工姓名</div>
|
||||
<div class="mr-5 flex-1">
|
||||
<el-input style="width: 170px" clearable v-model="queryParams.nickName" placeholder="请输入员工姓名" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-items-center">
|
||||
<div style="width: 70px; text-align: right; padding-right: 10px">手机号</div>
|
||||
<div class="mr-5 flex-1">
|
||||
<el-input style="width: 170px" clearable v-model="queryParams.phonenumber" placeholder="请输入手机号" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<el-button type="primary" @click="getlist">查询</el-button>
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</div>
|
||||
</nav>
|
||||
<el-table @row-click="handleRowClick" ref="multipleTableRef" :data="tableData" border @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="序号" align="center" width="55" type="index" />
|
||||
@@ -21,7 +39,7 @@
|
||||
<dict-tag :options="sys_user_sex" :value="row.sex" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="角色" align="center" width="85" prop="roleName" />
|
||||
<el-table-column label="角色" align="center" prop="roleName" />
|
||||
<el-table-column label="手机号码" align="center" prop="phonenumber" />
|
||||
</el-table>
|
||||
|
||||
@@ -51,8 +69,6 @@ import { getUserByRoleKey } from '@/api/system/user';
|
||||
import { ref, watch, nextTick, getCurrentInstance, ComponentInternalInstance, toRefs } from 'vue';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { com_resident_type } = toRefs<any>(proxy?.useDict('com_resident_type'));
|
||||
const { com_certification_status } = toRefs<any>(proxy?.useDict('com_certification_status'));
|
||||
const { sys_user_sex } = toRefs<any>(proxy?.useDict('sys_user_sex'));
|
||||
|
||||
interface tableType extends ResidentVO {
|
||||
@@ -61,7 +77,7 @@ interface tableType extends ResidentVO {
|
||||
|
||||
const props = defineProps({
|
||||
userid: {
|
||||
type: [String, Number],
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
returnvalue: {
|
||||
@@ -97,15 +113,8 @@ const dialog = ref({
|
||||
const queryParams = ref({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
date: null,
|
||||
type: null,
|
||||
status: '',
|
||||
ownerRelationship: null,
|
||||
name: null,
|
||||
houseId: null,
|
||||
villageId: null,
|
||||
buildingId: null,
|
||||
unitNo: null
|
||||
nickName: null,
|
||||
phonenumber: null
|
||||
});
|
||||
|
||||
const multipleTableRef = ref();
|
||||
@@ -121,21 +130,31 @@ const isMultiple = computed(() => props.isMultiple ?? false);
|
||||
// 优化 handleUserSelection,避免重复查找
|
||||
const handleUserSelection = () => {
|
||||
if (!userid.value || !tableData.value.length) return;
|
||||
const target = tableData.value.find((item) => item.userId == userid.value);
|
||||
if (target && !multipleSelection.value.some((sel) => sel.id === target.id)) {
|
||||
multipleSelection.value = [target];
|
||||
|
||||
multipleSelection.value = [];
|
||||
if (userid.value.trim() !== '') {
|
||||
const arr = userid.value.split(',');
|
||||
arr.forEach((item) => {
|
||||
const target = tableData.value.find((row) => row.userId == item);
|
||||
target && multipleSelection.value.push(target);
|
||||
});
|
||||
nextTick(() => {
|
||||
multipleTableRef.value?.setSelection([target]);
|
||||
if (multipleTableRef.value) {
|
||||
multipleTableRef.value.clearSelection();
|
||||
multipleSelection.value.forEach((item) => {
|
||||
multipleTableRef.value.toggleRowSelection(item, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 监听
|
||||
// 监听优化:只在 userid 变化时触发
|
||||
watch(userid, handleUserSelection, { immediate: true });
|
||||
watch(tableData, () => {
|
||||
if (userid.value) handleUserSelection(); // 仅在有 userid 时重新处理
|
||||
});
|
||||
// watch(userid, handleUserSelection, { immediate: true });
|
||||
// watch(tableData, () => {
|
||||
// if (userid.value) handleUserSelection(); // 仅在有 userid 时重新处理
|
||||
// });
|
||||
|
||||
// ====================== 方法 ======================
|
||||
// 打开选择框
|
||||
@@ -172,18 +191,25 @@ function handleSelectionChange(selection: tableType[]) {
|
||||
// ==============================================
|
||||
// 优化 handleRowClick,避免重复
|
||||
function handleRowClick(row: tableType) {
|
||||
if (!multipleTableRef.value) return;
|
||||
|
||||
if (isMultiple.value) {
|
||||
const index = multipleSelection.value.findIndex((item) => item.id === row.id);
|
||||
if (index > -1) {
|
||||
// 取消选中
|
||||
multipleSelection.value.splice(index, 1);
|
||||
multipleTableRef.value?.toggleRowSelection(row, false);
|
||||
} else {
|
||||
// 选中
|
||||
multipleSelection.value.push(row);
|
||||
multipleTableRef.value?.toggleRowSelection(row, true);
|
||||
}
|
||||
} else {
|
||||
// 【单选模式】先清空,再选中当前行
|
||||
multipleSelection.value = [];
|
||||
multipleTableRef.value.clearSelection();
|
||||
multipleSelection.value = [row];
|
||||
multipleTableRef.value?.setSelection([row]);
|
||||
multipleTableRef.value.toggleRowSelection(row, true);
|
||||
}
|
||||
}
|
||||
// 重置查询
|
||||
@@ -191,15 +217,8 @@ function resetQuery() {
|
||||
queryParams.value = {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
ownerRelationship: null,
|
||||
name: null,
|
||||
date: null,
|
||||
type: null,
|
||||
status: '',
|
||||
houseId: null,
|
||||
villageId: null,
|
||||
buildingId: null,
|
||||
unitNo: null
|
||||
nickName: null,
|
||||
phonenumber: null
|
||||
};
|
||||
getlist();
|
||||
}
|
||||
@@ -215,31 +234,32 @@ function conback() {
|
||||
// ==============================================
|
||||
function confirm() {
|
||||
dialog.value.dialogVisible = false;
|
||||
if (multipleSelection.value.length > 0) {
|
||||
if (isMultiple.value) {
|
||||
// 多选
|
||||
if (returnvalue.value === '*') {
|
||||
// ✅ 返回整个对象数组
|
||||
emit('change', multipleSelection.value);
|
||||
} else {
|
||||
// 返回指定字段数组
|
||||
emit(
|
||||
'change',
|
||||
multipleSelection.value.map((item) => item[returnvalue.value as keyof tableType])
|
||||
);
|
||||
}
|
||||
if (isMultiple.value) {
|
||||
// 多选
|
||||
if (returnvalue.value === '*') {
|
||||
// ✅ 返回整个对象数组
|
||||
emit('change', multipleSelection.value);
|
||||
} else {
|
||||
// 单选
|
||||
if (returnvalue.value === '*') {
|
||||
// ✅ 返回整个对象
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
console.log(multipleSelection.value[0], returnvalue.value);
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof tableType]);
|
||||
}
|
||||
// 返回指定字段数组
|
||||
emit(
|
||||
'change',
|
||||
multipleSelection.value.map((item) => item[returnvalue.value as keyof tableType])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 单选
|
||||
if (returnvalue.value === '*') {
|
||||
// ✅ 返回整个对象
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
console.log(multipleSelection.value[0], returnvalue.value);
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof tableType]);
|
||||
}
|
||||
}
|
||||
|
||||
multipleSelection.value = [];
|
||||
multipleTableRef.value.clearSelection();
|
||||
}
|
||||
// 初始化
|
||||
getlist();
|
||||
@@ -247,6 +267,7 @@ getlist();
|
||||
defineExpose({
|
||||
open: () => {
|
||||
dialog.value.dialogVisible = true;
|
||||
handleUserSelection();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user