Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSIWB2504
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
SSIWB2504
Commits
0504c46b
Commit
0504c46b
authored
Aug 04, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(play): 实现问题图片展示并优化列表初始化逻辑
parent
528f51a3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
25 deletions
+38
-25
play.component.ts
src/app/play/play.component.ts
+38
-25
No files found.
src/app/play/play.component.ts
View file @
0504c46b
...
@@ -496,14 +496,17 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -496,14 +496,17 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
initListItem
()
{
initListItem
()
{
// // 创建list_item节点作为滑动列表容器
// 获取questions数据
const
questions
=
this
.
g_formData
.
questions
||
[];
console
.
log
(
questions
)
const
totalItems
=
questions
.
length
;
// 创建list_item节点作为滑动列表容器
const
listItem
=
this
.
g_cartoon
.
createCartoonElement
(
'
list_item
'
,
'
ShapeRectNew
'
);
const
listItem
=
this
.
g_cartoon
.
createCartoonElement
(
'
list_item
'
,
'
ShapeRectNew
'
);
// 设置固定高度为
8
00
// 设置固定高度为
6
00
const
listHeight
=
600
;
const
listHeight
=
600
;
// 每列最多2个子节点
// 每列最多2个子节点
const
maxItemsPerColumn
=
2
;
const
maxItemsPerColumn
=
2
;
// 子节点数量
const
totalItems
=
20
;
// 计算需要的列数
// 计算需要的列数
const
columnsNeeded
=
Math
.
ceil
(
totalItems
/
maxItemsPerColumn
);
const
columnsNeeded
=
Math
.
ceil
(
totalItems
/
maxItemsPerColumn
);
// 每个子节点的宽度和高度
// 每个子节点的宽度和高度
...
@@ -516,7 +519,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -516,7 +519,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 初始化list_item - 将锚点设置为左侧 (0, 0.5)
// 初始化list_item - 将锚点设置为左侧 (0, 0.5)
listItem
.
ref
.
init
(
null
,
0
,
0.5
);
listItem
.
ref
.
init
(
null
,
0
,
0.5
);
listItem
.
ref
.
x
=
0
;
//listWidth / 2; // 设置初始位置,使列表居中显示
listItem
.
ref
.
x
=
0
;
listItem
.
ref
.
y
=
this
.
g_canvasHeight
/
2
+
100
;
listItem
.
ref
.
y
=
this
.
g_canvasHeight
/
2
+
100
;
listItem
.
ref
.
fillColor
=
'
rgba(231, 193, 193, 0.5)
'
;
listItem
.
ref
.
fillColor
=
'
rgba(231, 193, 193, 0.5)
'
;
// 设置list_item的宽高
// 设置list_item的宽高
...
@@ -531,6 +534,8 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -531,6 +534,8 @@ export class PlayComponent implements OnInit, OnDestroy {
// 创建子节点
// 创建子节点
for
(
let
i
=
0
;
i
<
totalItems
;
i
++
)
{
for
(
let
i
=
0
;
i
<
totalItems
;
i
++
)
{
const
questionData
=
questions
[
i
];
// 计算当前子节点所在的列和行
// 计算当前子节点所在的列和行
const
column
=
Math
.
floor
(
i
/
maxItemsPerColumn
);
const
column
=
Math
.
floor
(
i
/
maxItemsPerColumn
);
const
row
=
i
%
maxItemsPerColumn
;
const
row
=
i
%
maxItemsPerColumn
;
...
@@ -543,6 +548,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -543,6 +548,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 存储数据索引和选中状态
// 存储数据索引和选中状态
itemNode
.
ref
.
dataIndex
=
i
;
itemNode
.
ref
.
dataIndex
=
i
;
itemNode
.
ref
.
isSelected
=
false
;
itemNode
.
ref
.
isSelected
=
false
;
itemNode
.
ref
.
data
=
questionData
;
// 存储问题数据
// 计算子节点位置 - 基于左锚点的坐标计算
// 计算子节点位置 - 基于左锚点的坐标计算
// X坐标:从左到右排列,考虑间距,基于listItem的左边界
// X坐标:从左到右排列,考虑间距,基于listItem的左边界
...
@@ -555,19 +561,29 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -555,19 +561,29 @@ export class PlayComponent implements OnInit, OnDestroy {
itemNode
.
ref
.
y
=
itemY
;
itemNode
.
ref
.
y
=
itemY
;
itemNode
.
ref
.
scaleX
=
itemWidth
/
itemNode
.
ref
.
width
;
itemNode
.
ref
.
scaleX
=
itemWidth
/
itemNode
.
ref
.
width
;
itemNode
.
ref
.
scaleY
=
itemHeight
/
itemNode
.
ref
.
height
;
itemNode
.
ref
.
scaleY
=
itemHeight
/
itemNode
.
ref
.
height
;
// 创建图片元素显示question的image
// 为每个itemNode添加序号文字子节点
if
(
questionData
.
image
)
{
const
textElement
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_text_
${
i
}
`
,
'
Label
'
);
const
imageElement
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_image_
${
i
}
`
,
'
MySprite
'
);
// 设置文字内容为对应的序号(从1开始)
const
img
=
this
.
g_cartoon
.
images
.
get
(
questionData
.
image
)
textElement
.
ref
.
text
=
(
i
+
1
).
toString
();
this
.
g_cartoon
.
preloadImage
(
questionData
.
image
).
then
((
img
:
any
)
=>
{
// 设置字号为80,颜色为黑色
// 图片加载完成后初始化sprite
textElement
.
ref
.
fontSize
=
80
*
this
.
g_mapScale
;
imageElement
.
ref
.
init
(
img
);
textElement
.
ref
.
fontColor
=
'
#000000
'
;
// 设置图片位置居中
// 设置文字位置与itemNode相同
imageElement
.
ref
.
x
=
0
;
textElement
.
ref
.
x
=
0
//itemX;
imageElement
.
ref
.
y
=
0
;
textElement
.
ref
.
y
=
0
//itemY;
// 根据背景卡片尺寸调整图片大小,保持适当的边距
// 设置文本对齐方式为居中
const
padding
=
20
;
// 边距
textElement
.
ref
.
textAlign
=
'
center
'
;
const
maxWidth
=
itemWidth
-
padding
*
2
;
const
maxHeight
=
itemHeight
-
padding
*
2
;
const
scaleX
=
maxWidth
/
img
.
width
;
const
scaleY
=
maxHeight
/
img
.
height
;
const
scale
=
Math
.
min
(
scaleX
,
scaleY
);
// 保持宽高比
imageElement
.
ref
.
scaleX
=
scale
;
imageElement
.
ref
.
scaleY
=
scale
;
})
// 将图片元素添加到itemNode
itemNode
.
ref
.
addChild
(
imageElement
.
ref
);
}
// 添加选择标记(dui_hao图片)
// 添加选择标记(dui_hao图片)
const
selectMarkElement
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_select_
${
i
}
`
,
'
MySprite
'
);
const
selectMarkElement
=
this
.
g_cartoon
.
createCartoonElement
(
`list_item_select_
${
i
}
`
,
'
MySprite
'
);
...
@@ -591,8 +607,7 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -591,8 +607,7 @@ export class PlayComponent implements OnInit, OnDestroy {
}
}
};
};
// 渲染子节点、文字和选择标记
// 渲染子节点和选择标记
itemNode
.
ref
.
addChild
(
textElement
.
ref
);
itemNode
.
ref
.
addChild
(
selectMarkElement
.
ref
);
itemNode
.
ref
.
addChild
(
selectMarkElement
.
ref
);
listItem
.
ref
.
addChild
(
itemNode
.
ref
);
listItem
.
ref
.
addChild
(
itemNode
.
ref
);
}
}
...
@@ -1536,12 +1551,10 @@ export class PlayComponent implements OnInit, OnDestroy {
...
@@ -1536,12 +1551,10 @@ export class PlayComponent implements OnInit, OnDestroy {
// 初始化默认数据
// 初始化默认数据
// ----------------------------------
// ----------------------------------
initDefaultData
()
{
initDefaultData
()
{
if
(
Object
.
keys
(
this
.
g_formData
).
length
===
0
)
{
console
.
log
(
"
Init default form data
"
)
// console.log("Init default form data")
this
.
g_formData
=
defaultFormData
;
this
.
g_formData
=
defaultFormData
;
console
.
log
(
"
this.g_formData
"
,
this
.
g_formData
)
console
.
log
(
"
this.g_formData
"
,
this
.
g_formData
)
}
}
}
// ----------------------------------
// ----------------------------------
...
...
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