feat: agregar funcionalidad de QR codes con impresión y descarga PNG

- Click derecho en UUIDs muestra menú contextual con opción de imprimir QR
- Modal de vista previa con diseño portrait optimizado para móviles
- Generación de QR codes que redirigen a la URL específica del UUID
- Funcionalidad de impresión directa con estilos embebidos
- Descarga como PNG de alta resolución con todos los estilos preservados
- Diseño de tarjeta con gradiente, información del jugador e instrucciones
- Librerías: qrcode para generación QR, html2canvas para captura PNG
This commit is contained in:
2025-08-15 23:10:34 -06:00
parent ace9f8ee50
commit 9c8a4814eb
3 changed files with 875 additions and 1 deletions

356
client/package-lock.json generated
View File

@@ -9,7 +9,9 @@
"version": "1.0.0",
"dependencies": {
"colyseus.js": "latest",
"html2canvas": "^1.4.1",
"lokijs": "^1.5.12",
"qrcode": "^1.5.4",
"vue": "latest",
"vue-router": "latest"
},
@@ -1148,6 +1150,77 @@
"dev": true,
"license": "MIT"
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/base64-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/camelcase": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/cliui": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
"integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==",
"license": "ISC",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"wrap-ansi": "^6.2.0"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
},
"node_modules/colyseus.js": {
"version": "0.16.19",
"resolved": "https://registry.npmjs.org/colyseus.js/-/colyseus.js-0.16.19.tgz",
@@ -1167,6 +1240,15 @@
"url": "https://github.com/sponsors/endel"
}
},
"node_modules/css-line-break": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
"license": "MIT",
"dependencies": {
"utrie": "^1.0.2"
}
},
"node_modules/csstype": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
@@ -1180,6 +1262,15 @@
"dev": true,
"license": "MIT"
},
"node_modules/decamelize": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
"integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/detect-libc": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz",
@@ -1190,6 +1281,18 @@
"node": ">=8"
}
},
"node_modules/dijkstrajs": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/dijkstrajs/-/dijkstrajs-1.0.3.tgz",
"integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==",
"license": "MIT"
},
"node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"license": "MIT"
},
"node_modules/entities": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
@@ -1265,6 +1368,19 @@
}
}
},
"node_modules/find-up": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
"integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
"license": "MIT",
"dependencies": {
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -1280,6 +1396,15 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
"license": "ISC",
"engines": {
"node": "6.* || 8.* || >= 10.*"
}
},
"node_modules/he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
@@ -1290,6 +1415,40 @@
"he": "bin/he"
}
},
"node_modules/html2canvas": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
"license": "MIT",
"dependencies": {
"css-line-break": "^2.1.0",
"text-segmentation": "^1.0.3"
},
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
"integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
"license": "MIT",
"dependencies": {
"p-locate": "^4.1.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/lokijs": {
"version": "1.5.12",
"resolved": "https://registry.npmjs.org/lokijs/-/lokijs-1.5.12.tgz",
@@ -1367,6 +1526,42 @@
"node-gyp-build-optional-packages-test": "build-test.js"
}
},
"node_modules/p-limit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
"integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
"license": "MIT",
"dependencies": {
"p-try": "^2.0.0"
},
"engines": {
"node": ">=6"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-locate": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
"integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
"license": "MIT",
"dependencies": {
"p-limit": "^2.2.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/path-browserify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz",
@@ -1374,6 +1569,15 @@
"dev": true,
"license": "MIT"
},
"node_modules/path-exists": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@@ -1393,6 +1597,15 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/pngjs": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",
"integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==",
"license": "MIT",
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/postcss": {
"version": "8.5.6",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz",
@@ -1421,6 +1634,38 @@
"node": "^10 || ^12 || >=14"
}
},
"node_modules/qrcode": {
"version": "1.5.4",
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
"integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==",
"license": "MIT",
"dependencies": {
"dijkstrajs": "^1.0.1",
"pngjs": "^5.0.0",
"yargs": "^15.3.1"
},
"bin": {
"qrcode": "bin/qrcode"
},
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/require-main-filename": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==",
"license": "ISC"
},
"node_modules/rollup": {
"version": "4.46.2",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.46.2.tgz",
@@ -1461,6 +1706,12 @@
"fsevents": "~2.3.2"
}
},
"node_modules/set-blocking": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==",
"license": "ISC"
},
"node_modules/source-map-js": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
@@ -1470,6 +1721,41 @@
"node": ">=0.10.0"
}
},
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/text-segmentation": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
"license": "MIT",
"dependencies": {
"utrie": "^1.0.2"
}
},
"node_modules/tinyglobby": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz",
@@ -1514,6 +1800,15 @@
"dev": true,
"license": "MIT"
},
"node_modules/utrie": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
"license": "MIT",
"dependencies": {
"base64-arraybuffer": "^1.0.2"
}
},
"node_modules/vite": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/vite/-/vite-7.0.6.tgz",
@@ -1649,6 +1944,26 @@
"typescript": ">=5.0.0"
}
},
"node_modules/which-module": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz",
"integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==",
"license": "ISC"
},
"node_modules/wrap-ansi": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/ws": {
"version": "8.18.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
@@ -1669,6 +1984,47 @@
"optional": true
}
}
},
"node_modules/y18n": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
"license": "ISC"
},
"node_modules/yargs": {
"version": "15.4.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz",
"integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==",
"license": "MIT",
"dependencies": {
"cliui": "^6.0.0",
"decamelize": "^1.2.0",
"find-up": "^4.1.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^4.2.0",
"which-module": "^2.0.0",
"y18n": "^4.0.0",
"yargs-parser": "^18.1.2"
},
"engines": {
"node": ">=8"
}
},
"node_modules/yargs-parser": {
"version": "18.1.3",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
"integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
"license": "ISC",
"dependencies": {
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"
},
"engines": {
"node": ">=6"
}
}
}
}

View File

@@ -10,7 +10,9 @@
},
"dependencies": {
"colyseus.js": "latest",
"html2canvas": "^1.4.1",
"lokijs": "^1.5.12",
"qrcode": "^1.5.4",
"vue": "latest",
"vue-router": "latest"
},

View File

@@ -24,6 +24,7 @@
class="uuid-card"
:class="{ 'has-name': uuidInfo.hasName }"
@click="selectUuid(uuidInfo.uuid)"
@contextmenu.prevent="showContextMenu($event, uuidInfo)"
:style="{ animationDelay: `${index * 0.02}s` }"
>
<div class="uuid-number">{{ getUuidIndex(uuidInfo.uuid) }}</div>
@@ -31,6 +32,48 @@
<div class="uuid-text">{{ formatUuid(uuidInfo.uuid) }}</div>
</div>
</div>
<!-- Context Menu -->
<div
v-if="contextMenu.visible"
class="context-menu"
:style="{ top: contextMenu.y + 'px', left: contextMenu.x + 'px' }"
@click="contextMenu.visible = false"
>
<div class="context-menu-item" @click="printQR(contextMenu.uuid)">
🖨 Imprimir QR
</div>
</div>
<!-- QR Print Modal -->
<div v-if="printModal.visible" class="print-modal-overlay" @click="closePrintModal">
<div class="print-modal-content" @click.stop>
<button class="close-button" @click="closePrintModal"></button>
<div class="print-container" ref="printContainer">
<div class="qr-print-page">
<div class="qr-header">
<h2>🎮 Snatch Game</h2>
<p class="player-info">{{ printModal.name || 'Jugador' }}</p>
</div>
<div class="qr-code-container">
<canvas ref="qrCanvas"></canvas>
</div>
<div class="qr-footer">
<p class="uuid-display">UUID: {{ printModal.uuidShort }}</p>
<p class="url-display">{{ printModal.url }}</p>
<div class="instructions">
<p>📱 Escanea este código QR</p>
<p>para acceder al juego</p>
</div>
</div>
</div>
</div>
<div class="modal-buttons">
<button class="btn-download" @click="downloadPNG">📥 Descargar PNG</button>
<button class="btn-print" @click="executePrint">🖨 Imprimir</button>
</div>
</div>
</div>
<div v-else class="loading">
<div class="spinner"></div>
@@ -50,8 +93,10 @@
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ref, onMounted, nextTick } from 'vue';
import { useRouter } from 'vue-router';
import QRCode from 'qrcode';
import html2canvas from 'html2canvas';
interface UuidInfo {
uuid: string;
@@ -64,6 +109,25 @@ const loading = ref(true);
const allUuids = ref<UuidInfo[]>([]);
const searchQuery = ref('');
const filteredUuids = ref<UuidInfo[]>([]);
const qrCanvas = ref<HTMLCanvasElement>();
const printContainer = ref<HTMLElement>();
// Context menu state
const contextMenu = ref({
visible: false,
x: 0,
y: 0,
uuid: null as UuidInfo | null
});
// Print modal state
const printModal = ref({
visible: false,
uuid: '',
name: '',
uuidShort: '',
url: ''
});
onMounted(async () => {
try {
@@ -116,6 +180,280 @@ function selectRandom() {
function goToDashboard() {
router.push('/dashboard');
}
// Context menu functions
function showContextMenu(event: MouseEvent, uuidInfo: UuidInfo) {
contextMenu.value = {
visible: true,
x: event.clientX,
y: event.clientY,
uuid: uuidInfo
};
}
// Hide context menu when clicking elsewhere
onMounted(() => {
document.addEventListener('click', () => {
contextMenu.value.visible = false;
});
});
// QR Print functions
async function printQR(uuidInfo: UuidInfo | null) {
if (!uuidInfo) return;
contextMenu.value.visible = false;
// Get the base URL (production or development)
const baseUrl = window.location.origin;
const fullUrl = `${baseUrl}/${uuidInfo.uuid}`;
printModal.value = {
visible: true,
uuid: uuidInfo.uuid,
name: uuidInfo.name || '',
uuidShort: uuidInfo.uuid.substring(0, 8),
url: fullUrl
};
// Wait for modal to render
await nextTick();
// Generate QR code
if (qrCanvas.value) {
await QRCode.toCanvas(qrCanvas.value, fullUrl, {
width: 256,
margin: 2,
color: {
dark: '#000000',
light: '#FFFFFF'
}
});
}
}
function closePrintModal() {
printModal.value.visible = false;
}
function executePrint() {
if (!printContainer.value) return;
const printContent = printContainer.value.innerHTML;
const printWindow = window.open('', '_blank', 'width=400,height=600');
if (!printWindow) return;
printWindow.document.write(`
<!DOCTYPE html>
<html>
<head>
<title>QR Code - ${printModal.value.name || printModal.value.uuidShort}</title>
<style>
@page {
size: portrait;
margin: 0;
}
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.qr-print-page {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 40px 20px;
box-sizing: border-box;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.qr-header {
text-align: center;
}
.qr-header h2 {
font-size: 36px;
margin: 0 0 10px 0;
}
.player-info {
font-size: 24px;
font-weight: bold;
margin: 0;
}
.qr-code-container {
background: white;
padding: 20px;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.qr-code-container canvas {
display: block;
}
.qr-footer {
text-align: center;
}
.uuid-display {
font-family: monospace;
font-size: 14px;
margin: 10px 0;
opacity: 0.9;
}
.url-display {
font-size: 12px;
opacity: 0.7;
margin: 5px 0;
}
.instructions {
margin-top: 20px;
font-size: 18px;
}
.instructions p {
margin: 5px 0;
}
</style>
</head>
<body>
${printContent}
</body>
</html>
`);
printWindow.document.close();
printWindow.focus();
// Add canvas to print window
const printCanvas = printWindow.document.querySelector('canvas');
if (printCanvas && qrCanvas.value) {
const ctx = printCanvas.getContext('2d');
if (ctx) {
printCanvas.width = qrCanvas.value.width;
printCanvas.height = qrCanvas.value.height;
ctx.drawImage(qrCanvas.value, 0, 0);
}
}
setTimeout(() => {
printWindow.print();
printWindow.close();
}, 250);
}
async function downloadPNG() {
if (!printContainer.value || !qrCanvas.value) return;
try {
// Create a dedicated container for PNG generation
const pngContainer = document.createElement('div');
pngContainer.style.position = 'absolute';
pngContainer.style.left = '-9999px';
pngContainer.style.top = '0';
pngContainer.style.width = '400px';
pngContainer.style.height = '600px';
// Create the QR card HTML with inline styles
const qrDataURL = qrCanvas.value.toDataURL('image/png');
pngContainer.innerHTML = `
<div style="
width: 400px;
height: 600px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 40px 20px;
box-sizing: border-box;
color: white;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
">
<div style="text-align: center;">
<h2 style="
font-size: 36px;
margin: 0 0 10px 0;
font-weight: bold;
">🎮 Snatch Game</h2>
<p style="
font-size: 24px;
font-weight: bold;
margin: 0;
">${printModal.value.name || 'Jugador'}</p>
</div>
<div style="
background: white;
padding: 20px;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
">
<img src="${qrDataURL}" style="
display: block;
width: 256px;
height: 256px;
" />
</div>
<div style="text-align: center;">
<p style="
font-family: monospace;
font-size: 14px;
margin: 10px 0;
opacity: 0.9;
">UUID: ${printModal.value.uuidShort}</p>
<p style="
font-size: 12px;
opacity: 0.7;
margin: 5px 0;
">${printModal.value.url}</p>
<div style="margin-top: 20px;">
<p style="
margin: 5px 0;
font-size: 18px;
">📱 Escanea este código QR</p>
<p style="
margin: 5px 0;
font-size: 18px;
">para acceder al juego</p>
</div>
</div>
</div>
`;
document.body.appendChild(pngContainer);
// Capture with html2canvas
const canvas = await html2canvas(pngContainer, {
width: 400,
height: 600,
scale: 2,
backgroundColor: null,
useCORS: true,
allowTaint: false,
logging: false,
removeContainer: false
});
// Remove the temporary container
document.body.removeChild(pngContainer);
// Create download link
const link = document.createElement('a');
link.download = `qr-code-${printModal.value.name || printModal.value.uuidShort}.png`;
link.href = canvas.toDataURL('image/png', 1.0);
// Trigger download
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error('Error generating PNG:', error);
alert('Error al generar la imagen PNG');
}
}
</script>
<style scoped>
@@ -355,6 +693,175 @@ function goToDashboard() {
box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
}
/* Context Menu */
.context-menu {
position: fixed;
background: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
padding: 8px 0;
z-index: 1000;
min-width: 150px;
}
.context-menu-item {
padding: 10px 16px;
cursor: pointer;
transition: background 0.2s;
color: #333;
font-size: 14px;
display: flex;
align-items: center;
gap: 8px;
}
.context-menu-item:hover {
background: #f5f5f5;
}
/* Print Modal */
.print-modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 2000;
animation: fadeIn 0.3s ease-out;
}
.print-modal-content {
background: white;
border-radius: 20px;
padding: 30px;
max-width: 500px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
position: relative;
animation: slideUp 0.3s ease-out;
}
.close-button {
position: absolute;
top: 15px;
right: 15px;
background: none;
border: none;
font-size: 24px;
cursor: pointer;
color: #666;
transition: color 0.2s;
}
.close-button:hover {
color: #333;
}
.print-container {
margin: 20px 0;
}
.qr-print-page {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 30px;
border-radius: 15px;
color: white;
text-align: center;
}
.qr-header h2 {
margin: 0 0 10px 0;
font-size: 28px;
}
.player-info {
font-size: 20px;
font-weight: bold;
margin: 0 0 20px 0;
}
.qr-code-container {
background: white;
padding: 20px;
border-radius: 15px;
display: inline-block;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
margin: 20px 0;
}
.qr-code-container canvas {
display: block;
}
.qr-footer {
margin-top: 20px;
}
.uuid-display {
font-family: monospace;
font-size: 12px;
opacity: 0.9;
margin: 10px 0;
}
.url-display {
font-size: 11px;
opacity: 0.7;
margin: 5px 0;
}
.instructions {
margin-top: 15px;
}
.instructions p {
margin: 5px 0;
font-size: 14px;
}
.modal-buttons {
display: flex;
gap: 10px;
margin-top: 20px;
}
.btn-download,
.btn-print {
flex: 1;
padding: 12px;
border: none;
border-radius: 10px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
}
.btn-download {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
color: white;
}
.btn-download:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
}
.btn-print {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-print:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
/* Responsive */
@media (max-width: 768px) {
.selector-card {
@@ -377,5 +884,14 @@ function goToDashboard() {
.btn-dashboard {
width: 100%;
}
.print-modal-content {
width: 95%;
padding: 20px;
}
.modal-buttons {
flex-direction: column;
}
}
</style>