Storage.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. function Storage(Fevent) {
  2. const indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
  3. if ( indexedDB === undefined ) {
  4. console.warn( 'Storage: IndexedDB not available.' );
  5. return { init: function () {}, get: function () {}, set: function () {}, clear: function () {} };
  6. }
  7. const name = 'threejs-editor';
  8. const version = 1;
  9. let database;
  10. const requestx = indexedDB.open( name, version );
  11. // 打开数据库
  12. const request = indexedDB.open( name, version );
  13. var db;
  14. request.onsuccess = function(event) {
  15. db = event.target.result;
  16. // 存储数据
  17. var transaction = db.transaction( [ 'states' ], 'readwrite' );
  18. var store = transaction.objectStore('states');
  19. // store.add({ id: 1, data: 'some data' });
  20. // 检索数据
  21. var getRequest = store.get(window.parkId);
  22. getRequest.onsuccess = function(event) {
  23. var result = event.target.result;
  24. Fevent(result)
  25. };
  26. };
  27. //
  28. //
  29. // request.onupgradeneeded = function ( event ) {
  30. //
  31. // const db = event.target.result;
  32. //
  33. // if ( db.objectStoreNames.contains( 'states' ) === false ) {
  34. //
  35. // db.createObjectStore( 'states' );
  36. //
  37. // }
  38. //
  39. // };
  40. //
  41. // request.onsuccess = function ( event ) {
  42. //
  43. // database = event.target.result;
  44. //
  45. // callback();
  46. //
  47. // };
  48. //
  49. // request.onerror = function ( event ) {
  50. //
  51. // console.error( 'IndexedDB', event );
  52. //
  53. // };
  54. //
  55. //
  56. // const transaction = database.transaction( [ 'states' ], 'readwrite' );
  57. // const objectStore = transaction.objectStore( 'states' );
  58. // const request = objectStore.get( 0 );
  59. // request.onsuccess = function ( event ) {
  60. //
  61. // callback( event.target.result );
  62. //
  63. // };
  64. //
  65. return ;
  66. }
  67. export { Storage };