Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jj_learn_word
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
jj_learn_word
Commits
d5e53c2b
Commit
d5e53c2b
authored
May 08, 2025
by
chunsen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 处理属性 int
parent
68086014
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
22 deletions
+70
-22
form.component.ts
form/src/app/form/form.component.ts
+70
-22
No files found.
form/src/app/form/form.component.ts
View file @
d5e53c2b
...
...
@@ -63,8 +63,14 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this
.
item
=
{};
// 获取父窗口URL中的courseId参数作为pictureBookId
const
courseId
=
this
.
getParentUrlParam
(
'
courseId
'
);
if
(
courseId
)
{
const
courseIdStr
=
this
.
getParentUrlParam
(
'
courseId
'
);
let
courseId
=
0
;
if
(
courseIdStr
)
{
courseId
=
parseInt
(
courseIdStr
,
10
);
if
(
isNaN
(
courseId
))
{
courseId
=
0
;
}
console
.
log
(
'
从父窗口URL获取到courseId:
'
,
courseId
);
}
...
...
@@ -81,12 +87,18 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this
.
initItem
();
// 确保pictureBookId存在
if
(
courseId
&&
(
!
this
.
item
.
pictureBookId
||
this
.
item
.
pictureBookId
===
''
)
)
{
// 确保pictureBookId存在
并且是整数
if
(
courseId
>
0
)
{
this
.
item
.
pictureBookId
=
courseId
;
}
else
if
(
this
.
item
.
pictureBookId
)
{
// 确保现有的pictureBookId是整数
const
pictureBookId
=
parseInt
(
this
.
item
.
pictureBookId
,
10
);
this
.
item
.
pictureBookId
=
isNaN
(
pictureBookId
)
?
0
:
pictureBookId
;
}
else
{
this
.
item
.
pictureBookId
=
0
;
}
// 确保每个单词都有
ID
// 确保每个单词都有
正确的ID(pictureBookId + 索引)
this
.
ensureWordIds
();
console
.
log
(
"
this.item:
"
,
JSON
.
stringify
(
this
.
item
));
...
...
@@ -105,9 +117,12 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this
.
item
.
data
=
[];
}
// 确保pictureBookId存在
if
(
!
this
.
item
.
pictureBookId
)
{
this
.
item
.
pictureBookId
=
''
;
// 确保pictureBookId存在且为整数
if
(
this
.
item
.
pictureBookId
)
{
const
pictureBookId
=
parseInt
(
this
.
item
.
pictureBookId
,
10
);
this
.
item
.
pictureBookId
=
isNaN
(
pictureBookId
)
?
0
:
pictureBookId
;
}
else
{
this
.
item
.
pictureBookId
=
0
;
}
// 确保每个单词都有正确的backContent结构
...
...
@@ -124,6 +139,14 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 确保answer数组存在
word
.
backContent
.
answer
=
[];
}
// 确保pictureBookId是整数
if
(
word
.
pictureBookId
)
{
const
pictureBookId
=
parseInt
(
word
.
pictureBookId
,
10
);
word
.
pictureBookId
=
isNaN
(
pictureBookId
)
?
0
:
pictureBookId
;
}
else
{
word
.
pictureBookId
=
this
.
item
.
pictureBookId
;
}
});
}
}
...
...
@@ -134,14 +157,23 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
return
;
}
const
pictureBookId
=
this
.
item
.
pictureBookId
||
''
;
// 确保pictureBookId是整数
let
pictureBookId
=
0
;
if
(
this
.
item
.
pictureBookId
)
{
pictureBookId
=
parseInt
(
this
.
item
.
pictureBookId
,
10
);
if
(
isNaN
(
pictureBookId
))
{
pictureBookId
=
0
;
}
}
this
.
item
.
pictureBookId
=
pictureBookId
;
// 为每个
没有id的单词生成id
// 为每个
单词生成id(pictureBookId + 索引)
this
.
item
.
data
.
forEach
((
word
,
index
)
=>
{
if
(
!
word
.
id
||
word
.
id
.
trim
()
===
''
)
{
// 使用pictureBookId + 索引生成单词ID
word
.
id
=
`
${
pictureBookId
}${
index
+
1
}
`
;
}
// 生成id为pictureBookId和索引的拼接
const
wordIndex
=
index
+
1
;
// 将id设置为pictureBookId和单词索引的拼接形式
word
.
id
=
parseInt
(
`
${
pictureBookId
}${
wordIndex
}
`
,
10
);
// 更新pictureBookId
word
.
pictureBookId
=
pictureBookId
;
});
...
...
@@ -156,10 +188,18 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 添加示例数据
addSampleData
()
{
// 确保pictureBookId是整数
let
pictureBookId
=
0
;
if
(
this
.
item
.
pictureBookId
)
{
pictureBookId
=
parseInt
(
this
.
item
.
pictureBookId
,
10
);
if
(
isNaN
(
pictureBookId
))
{
pictureBookId
=
0
;
}
}
this
.
item
.
data
.
push
({
id
:
''
,
pictureBookId
:
this
.
item
.
pictureBookId
||
''
,
id
:
0
,
// 临时ID,将在ensureWordIds中设置正确的值
pictureBookId
:
pictureBookId
,
word
:
''
,
displayType
:
'
3
'
,
// 默认为"核心单词"
partOfSpeech
:
''
,
...
...
@@ -206,11 +246,10 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 深拷贝item对象
const
newItem
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
item
));
// 删除可能存在的
quesArr
属性
// 删除可能存在的属性
if
(
newItem
.
quesArr
)
{
delete
newItem
.
quesArr
;
}
return
newItem
;
}
...
...
@@ -242,7 +281,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
return
;
}
// 确保所有单词都有
ID
// 确保所有单词都有
正确的ID(pictureBookId + 索引)
this
.
ensureWordIds
();
const
newItem
=
this
.
getNewSortItem
();
...
...
@@ -266,9 +305,18 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 添加新单词到data数组中
addNewWord
()
{
// 确保pictureBookId是整数
let
pictureBookId
=
0
;
if
(
this
.
item
.
pictureBookId
)
{
pictureBookId
=
parseInt
(
this
.
item
.
pictureBookId
,
10
);
if
(
isNaN
(
pictureBookId
))
{
pictureBookId
=
0
;
}
}
this
.
item
.
data
.
push
({
id
:
''
,
pictureBookId
:
this
.
item
.
pictureBookId
||
''
,
id
:
0
,
// 临时ID,将在ensureWordIds中设置正确的值
pictureBookId
:
pictureBookId
,
word
:
''
,
displayType
:
'
3
'
,
// 默认为"核心单词"
partOfSpeech
:
''
,
...
...
@@ -289,7 +337,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
createdTime
:
new
Date
().
toISOString
()
});
// 确保所有单词都有
ID
// 确保所有单词都有
正确的ID(pictureBookId + 索引)
this
.
ensureWordIds
();
this
.
save
();
...
...
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