Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos
Commits
ee7feabe
Commit
ee7feabe
authored
Aug 16, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove idb
parent
e679bb9c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
34 deletions
+23
-34
src/api/forbiddens.ts
src/api/forbiddens.ts
+23
-34
No files found.
src/api/forbiddens.ts
View file @
ee7feabe
//! 禁限卡表
import
{
clear
,
createStore
,
get
,
setMany
}
from
"
idb-keyval
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
useConfig
}
from
"
@/config
"
;
const
{
lflistUrl
}
=
useConfig
();
const
{
lflistUrl
}
=
useConfig
();
type
Forbiddens
=
Map
<
number
,
number
>
;
type
Forbiddens
=
Map
<
number
,
number
>
;
const
IDB_NAME
=
"
forbiddens
"
;
// 禁限卡表的时间,比如 [2023.4] - 2023年4月表
export
let
forbiddenTime
=
"
?
"
;
export
let
forbiddenTime
=
"
?
"
;
const
idb
=
createStore
(
IDB_NAME
,
IDB_NAME
);
export
async
function
initForbiddens
():
Promise
<
void
>
{
export
async
function
initForbiddens
():
Promise
<
void
>
{
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
forbiddenTime
=
time
;
forbiddenTime
=
time
;
setForbiddens
(
forbiddens
);
}
// 先清掉之前的记录
const
forbiddensMap
:
Forbiddens
=
new
Map
<
number
,
number
>
();
clear
(
idb
);
// 设置新记录
function
setForbiddens
(
forbiddens
:
Forbiddens
):
void
{
await
setMany
(
Array
.
from
(
forbiddens
));
forbiddensMap
.
clear
();
for
(
const
[
cardId
,
limitCount
]
of
forbiddens
)
{
forbiddensMap
.
set
(
cardId
,
limitCount
);
}
}
}
// 获取禁限信息
export
function
getForbiddenInfo
(
id
:
number
):
number
|
undefined
{
export
async
function
getForbiddenInfo
(
return
forbiddensMap
.
get
(
id
);
id
:
number
,
):
Promise
<
number
|
undefined
>
{
return
await
get
(
id
,
idb
);
}
}
// 解析函数,提取卡片编号和限制张数
function
extractForbiddensFromText
(
text
:
string
):
{
function
parseCardInfo
(
time
:
string
;
forbiddens
:
Forbiddens
;
}
{
function
parseCardInfo
(
input
:
string
,
input
:
string
,
):
{
cardId
:
number
;
limitCount
:
number
}
|
null
{
):
{
cardId
:
number
;
limitCount
:
number
}
|
null
{
const
match
=
input
.
match
(
/^
(\d
+
)\s
+
(\d
+
)\s
+--/
);
const
match
=
input
.
match
(
/^
(\d
+
)\s
+
(\d
+
)\s
+--/
);
if
(
match
)
{
if
(
match
)
{
const
cardId
=
parseInt
(
match
[
1
]);
const
cardId
=
parseInt
(
match
[
1
]);
...
@@ -44,18 +40,11 @@ function parseCardInfo(
...
@@ -44,18 +40,11 @@ function parseCardInfo(
return
{
cardId
,
limitCount
};
return
{
cardId
,
limitCount
};
}
}
return
null
;
return
null
;
}
}
// 分割文本为行,并提取每行的限制信息
function
extractForbiddensFromText
(
text
:
string
):
{
time
:
string
;
forbiddens
:
Forbiddens
;
}
{
const
lines
=
text
.
split
(
"
\n
"
);
const
lines
=
text
.
split
(
"
\n
"
);
const
forbiddens
=
new
Map
<
number
,
number
>
(
[]
);
const
forbiddens
=
new
Map
<
number
,
number
>
();
// remove first line
lines
.
shift
();
// remove first line
lines
.
shift
();
let
time
=
"
?
"
;
let
time
=
"
?
"
;
...
...
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