|
|
@@ -215,7 +215,7 @@
|
|
|
<el-row :gutter="16">
|
|
|
<el-col :span="24">
|
|
|
<div style="margin: 8px 0">
|
|
|
- <el-input v-model="searchText" placeholder="请扫描设备条码添加" style="width: 300px" @keyup.enter="handleScanSearch" />
|
|
|
+ <el-input ref="searchInputRef" v-model="searchText" placeholder="请扫描设备条码添加" style="width: 300px" @keyup.enter.prevent="handleScanSearch" />
|
|
|
<el-button type="primary" style="margin-left: 16px" @click="handleAdd">手动借用</el-button>
|
|
|
</div>
|
|
|
<el-table :data="deviceList" border style="width: 100%">
|
|
|
@@ -284,7 +284,7 @@
|
|
|
<el-row :gutter="16">
|
|
|
<el-col :span="24">
|
|
|
<div style="margin: 8px 0" v-if="!isView" >
|
|
|
- <el-input :disabled="isView" v-model="returnSearchText" placeholder="请扫描设备条码添加" style="width: 300px" @keyup.enter="handleReturnScanSearch" />
|
|
|
+ <el-input ref="returnSearchInputRef" :disabled="isView" v-model="returnSearchText" placeholder="请扫描设备条码添加" style="width: 300px" @keyup.enter.prevent="handleReturnScanSearch" />
|
|
|
<el-button type="primary" style="margin-left: 16px" @click="handleAdd" :disabled="isView">手动归还</el-button>
|
|
|
</div>
|
|
|
<el-table :data="returnDeviceList" border style="width: 100%" >
|
|
|
@@ -670,6 +670,10 @@ const timeline = ref({
|
|
|
const activeName = ref('first');
|
|
|
const returnStatus = ref('未归还'); // 添加独立的状态变量
|
|
|
|
|
|
+// 输入框引用
|
|
|
+const searchInputRef = ref<any>(null);
|
|
|
+const returnSearchInputRef = ref<any>(null);
|
|
|
+
|
|
|
// 借用列表相关数据
|
|
|
const searchText = ref('');
|
|
|
const deviceList = ref<DeviceListItem[]>([]);
|
|
|
@@ -907,7 +911,12 @@ const handleViewAbnormal = (index: number) => {
|
|
|
};
|
|
|
|
|
|
// 处理扫码搜索
|
|
|
-const handleScanSearch = async () => {
|
|
|
+const handleScanSearch = async (event?: Event) => {
|
|
|
+ // 阻止默认行为,防止表单提交导致页面刷新
|
|
|
+ if (event) {
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ }
|
|
|
if (!searchText.value.trim()) return;
|
|
|
|
|
|
try {
|
|
|
@@ -922,6 +931,10 @@ const handleScanSearch = async () => {
|
|
|
const device = res.data[0];
|
|
|
if (device.available_quantity <= 0) {
|
|
|
ElMessage.warning('该设备当前无可用数量');
|
|
|
+ // 重新聚焦输入框
|
|
|
+ nextTick(() => {
|
|
|
+ searchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -953,6 +966,10 @@ const handleScanSearch = async () => {
|
|
|
ElMessage.error('搜索设备失败');
|
|
|
} finally {
|
|
|
searchText.value = ''; // 清空搜索框
|
|
|
+ // 重新聚焦输入框,保持选中状态
|
|
|
+ nextTick(() => {
|
|
|
+ searchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -970,7 +987,12 @@ const normalizeReturnStatus = (status?: { value?: number | string; label?: strin
|
|
|
};
|
|
|
|
|
|
// 处理归还扫码搜索
|
|
|
-const handleReturnScanSearch = async () => {
|
|
|
+const handleReturnScanSearch = async (event?: Event) => {
|
|
|
+ // 阻止默认行为,防止表单提交导致页面刷新
|
|
|
+ if (event) {
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ }
|
|
|
if (!returnSearchText.value.trim()) return;
|
|
|
|
|
|
try {
|
|
|
@@ -1018,6 +1040,10 @@ const handleReturnScanSearch = async () => {
|
|
|
ElMessage.error('搜索设备失败');
|
|
|
} finally {
|
|
|
returnSearchText.value = ''; // 清空搜索框
|
|
|
+ // 重新聚焦输入框,保持选中状态
|
|
|
+ nextTick(() => {
|
|
|
+ returnSearchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -1205,6 +1231,17 @@ function onDeviceSelected(devices: Device[]) {
|
|
|
|
|
|
function handleClick(tab: TabsPaneContext) {
|
|
|
console.log('Tab clicked:', tab.props.name);
|
|
|
+ // 当切换到设备清单标签页时,自动聚焦输入框
|
|
|
+ if (tab.props.name === 'second') {
|
|
|
+ nextTick(() => {
|
|
|
+ searchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
+ } else if (tab.props.name === 'third') {
|
|
|
+ // 当切换到归还设备清单标签页时,自动聚焦输入框
|
|
|
+ nextTick(() => {
|
|
|
+ returnSearchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function handleUploadSuccess(response: any, file: any, fileList: any) {
|
|
|
@@ -1310,7 +1347,20 @@ onMounted(() => {
|
|
|
|
|
|
watch(
|
|
|
() => props.visible,
|
|
|
- (v) => (visible.value = v)
|
|
|
+ (v) => {
|
|
|
+ visible.value = v;
|
|
|
+ // 当对话框打开且当前标签页是设备清单时,自动聚焦输入框
|
|
|
+ if (v && activeName.value === 'second' && isCollect.value) {
|
|
|
+ nextTick(() => {
|
|
|
+ searchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
+ } else if (v && activeName.value === 'third' && !isView.value) {
|
|
|
+ // 当对话框打开且当前标签页是归还设备清单时,自动聚焦输入框
|
|
|
+ nextTick(() => {
|
|
|
+ returnSearchInputRef.value?.focus?.();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
);
|
|
|
|
|
|
watch(() => props.modelValue, async (val) => {
|