doc.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>File Input Example</title>
  7. </head>
  8. <body>
  9. <input type="file" id="fileInput" onchange="displayFileName()">
  10. <div id="fileNameDisplay"></div>
  11. <button onclick="invokeJS()">调用download</button>
  12. <button onclick="invokeCamera()">调用相机</button>
  13. <button onclick="selectFile()">Select File</button>
  14. <div id="fileDisplay"></div>
  15. <script>
  16. function displayFileName() {
  17. const fileInput = document.getElementById('fileInput');
  18. const fileNameDisplay = document.getElementById('fileNameDisplay');
  19. if (fileInput.files.length > 0) {
  20. fileNameDisplay.textContent = fileInput.files[0].name;
  21. } else {
  22. fileNameDisplay.textContent = '';
  23. }
  24. }
  25. function invokeJS() {
  26. openHarmonyBridge.download(JSON.stringify({
  27. token: "ddddd",
  28. path: "这是路径"
  29. }));
  30. }
  31. function invokeCamera() {
  32. let promise = navigator.mediaDevices.getUserMedia(constraints);
  33. // then()异步,调用MediaStream对象作为参数
  34. promise.then(function (MediaStream) {
  35. });
  36. }
  37. function selectFile() {
  38. const fileInput = document.getElementById('fileInput');
  39. fileInput.click();
  40. }
  41. document.getElementById('fileInput').addEventListener('change', function() {
  42. const fileDisplay = document.getElementById('fileDisplay');
  43. const fileInput = document.getElementById('fileInput');
  44. if (fileInput.files.length > 0) {
  45. const file = fileInput.files[0];
  46. const reader = new FileReader();
  47. reader.onload = function(e) {
  48. fileDisplay.textContent = e.target.result;
  49. };
  50. reader.readAsText(file);
  51. } else {
  52. fileDisplay.textContent = '';
  53. }
  54. console.log("dddd")
  55. });
  56. </script>
  57. </body>
  58. </html>