Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
14422fd4
authored
Jan 05, 2022
by
董文博
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix (database) 数据的存取
parent
8931da86
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
database/dev-tools.ts
database/dev-tools.ts
View file @
14422fd4
...
...
@@ -79,6 +79,61 @@ class DevAppTools {
});
});
}
public
getDataByKey
(
key
:
string
)
{
return
new
Promise
<
any
>
((
resolve
)
=>
{
this
.
onReady
().
finally
(()
=>
{
if
(
!
this
.
db
)
{
return
resolve
(
false
);
}
setTimeout
(()
=>
{
const
store
=
this
.
buildStore
(
this
.
table
);
const
r
=
store
.
get
(
key
);
r
.
onsuccess
=
((
o
)
=>
{
const
result
=
(
o
.
target
as
any
).
result
;
if
(
result
)
{
resolve
(
result
.
content
)
}
else
{
resolve
(
result
)
}
});
r
.
onerror
=
()
=>
resolve
(
false
);
},
300
);
});
});
}
public
addData
(
data
:
any
,
key
:
string
)
{
return
new
Promise
<
boolean
>
((
resolve
)
=>
{
this
.
onReady
().
finally
(()
=>
{
if
(
!
this
.
db
)
{
return
resolve
(
false
);
}
setTimeout
(()
=>
{
const
store
=
this
.
buildStore
(
this
.
table
);
const
r
=
store
.
add
({
value
:
key
,
content
:
data
});
r
.
onsuccess
=
()
=>
resolve
(
true
);
r
.
onerror
=
()
=>
resolve
(
false
);
},
300
);
});
});
}
public
deleteData
(
key
:
string
)
{
return
new
Promise
<
boolean
>
((
resolve
)
=>
{
this
.
onReady
().
finally
(()
=>
{
if
(
!
this
.
db
)
{
return
resolve
(
false
);
}
setTimeout
(()
=>
{
const
store
=
this
.
buildStore
(
this
.
table
);
const
r
=
store
.
delete
(
key
);
r
.
onsuccess
=
()
=>
resolve
(
true
);
r
.
onerror
=
()
=>
resolve
(
false
);
},
300
);
});
});
}
}
export
const
devAppTools
=
new
DevAppTools
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment