tien_nemo

demo

Showing 1 changed file with 21 additions and 11 deletions
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
134 selectingIndex: null, 134 selectingIndex: null,
135 isMappingManually: false, 135 isMappingManually: false,
136 isSelecting: false, 136 isSelecting: false,
137 - activeField: null, 137 + activeIndex: null,
138 manualField: "", 138 manualField: "",
139 formData: { export_date: "", order_code: "", customer: "", address: "", staff: "" }, 139 formData: { export_date: "", order_code: "", customer: "", address: "", staff: "" },
140 fieldOptions: [ 140 fieldOptions: [
...@@ -193,7 +193,7 @@ ...@@ -193,7 +193,7 @@
193 this.imageWidth = img.naturalWidth; 193 this.imageWidth = img.naturalWidth;
194 this.imageHeight = img.naturalHeight; 194 this.imageHeight = img.naturalHeight;
195 }, 195 },
196 - getBoxStyle(item) { 196 + getBoxStyle(item, index) {
197 if (!this.imageWidth || !this.imageHeight || !this.$refs.pdfImage) return {}; 197 if (!this.imageWidth || !this.imageHeight || !this.$refs.pdfImage) return {};
198 198
199 const [x1, y1, x2, y2] = item.bbox; 199 const [x1, y1, x2, y2] = item.bbox;
...@@ -209,8 +209,8 @@ ...@@ -209,8 +209,8 @@
209 top: `${Math.round(y1 * scaleY)}px`, 209 top: `${Math.round(y1 * scaleY)}px`,
210 width: `${Math.round((x2 - x1) * scaleX)}px`, 210 width: `${Math.round((x2 - x1) * scaleX)}px`,
211 height: `${Math.round((y2 - y1) * scaleY)}px`, 211 height: `${Math.round((y2 - y1) * scaleY)}px`,
212 - border: item.hideBorder ? 'none' : '2px solid ' + (this.activeField === item.field ? '#199601' : '#ff5252'), 212 + border: item.hideBorder ? 'none' : '2px solid ' + (index === this.activeIndex ? '#199601' : '#ff5252'),
213 - //backgroundColor: item.hideBorder ? 'transparent' : (this.activeField === item.field ? 'rgba(33,150,243,0.3)' : 'rgba(255,82,82,0.2)'), 213 + //backgroundColor: item.hideBorder ? 'transparent' : (this.activeIndex === item.field ? 'rgba(33,150,243,0.3)' : 'rgba(255,82,82,0.2)'),
214 boxSizing: 'border-box', 214 boxSizing: 'border-box',
215 cursor: 'pointer', 215 cursor: 'pointer',
216 zIndex: item.isManual ? 30 : 10 216 zIndex: item.isManual ? 30 : 10
...@@ -218,7 +218,16 @@ ...@@ -218,7 +218,16 @@
218 }, 218 },
219 219
220 highlightField(field) { 220 highlightField(field) {
221 - this.activeField = field; 221 + // tìm box gần nhất match field này
222 + let idx = -1;
223 + for (let i = this.ocrData.length - 1; i >= 0; i--) {
224 + const it = this.ocrData[i];
225 + if (!it.isDeleted && it.field === field) {
226 + idx = i;
227 + break;
228 + }
229 + }
230 + this.activeIndex = idx; // nếu không tìm thấy thì = -1
222 }, 231 },
223 232
224 startSelect(e) { 233 startSelect(e) {
...@@ -307,14 +316,14 @@ ...@@ -307,14 +316,14 @@
307 316
308 if (item && item.isManual) { 317 if (item && item.isManual) {
309 this.manualIndex = this.selectingIndex; 318 this.manualIndex = this.selectingIndex;
310 - this.manualField = item.field; // đảm bảo sync field hiện tại 319 + this.manualField = item.field || "";
311 this.applyManualMapping(); 320 this.applyManualMapping();
312 return; 321 return;
313 } 322 }
314 323
315 if (item.field) { 324 if (item.field) {
316 this.formData[item.field] = item.text; 325 this.formData[item.field] = item.text;
317 - this.activeField = item.field; 326 + this.activeIndex = this.selectingIndex;
318 } 327 }
319 this.selectingIndex = null; 328 this.selectingIndex = null;
320 }, 329 },
...@@ -335,9 +344,9 @@ ...@@ -335,9 +344,9 @@
335 const finalText = combinedText.join(" "); 344 const finalText = combinedText.join(" ");
336 this.ocrData[manualIndex].field = this.manualField; 345 this.ocrData[manualIndex].field = this.manualField;
337 this.formData[this.manualField] = finalText; 346 this.formData[this.manualField] = finalText;
338 - this.activeField = this.manualField; 347 + this.activeIndex = manualIndex;
339 348
340 - console.log('manualField',this.manualField,this.manualIndex) 349 + console.log('manualField', this.manualField, this.manualIndex)
341 // Reset trạng thái chọn 350 // Reset trạng thái chọn
342 this.isMappingManually = false; 351 this.isMappingManually = false;
343 this.selectBox.show = false; 352 this.selectBox.show = false;
...@@ -372,7 +381,7 @@ ...@@ -372,7 +381,7 @@
372 return text.substring(startIndex, endIndex).trim(); 381 return text.substring(startIndex, endIndex).trim();
373 }, 382 },
374 getSelectStyle(item) { 383 getSelectStyle(item) {
375 - if (!this.imageWidth) return { position: 'absolute' }; 384 + if (!this.imageWidth) return {position: 'absolute'};
376 385
377 const [x1, y1, x2, y2] = item.bbox; 386 const [x1, y1, x2, y2] = item.bbox;
378 const displayedWidth = this.$refs.pdfImage.clientWidth; 387 const displayedWidth = this.$refs.pdfImage.clientWidth;
...@@ -394,4 +403,5 @@ ...@@ -394,4 +403,5 @@
394 </script> 403 </script>
395 404
396 405
397 -</body></html> 406 +</body>
407 +</html>
......