Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
飞
飞鹤小程序
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
FH
飞鹤小程序
Commits
004fd931
Commit
004fd931
authored
Nov 14, 2025
by
spc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed
parent
221e119b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
201 additions
and
5 deletions
+201
-5
XingmaLabPosterPage.vue
components/xingmaLab/XingmaLabPosterPage.vue
+117
-3
XingmaLabDetailPage.vue
pages/XingmaLabDetailPage/XingmaLabDetailPage.vue
+84
-2
No files found.
components/xingmaLab/XingmaLabPosterPage.vue
View file @
004fd931
...
...
@@ -134,12 +134,13 @@ const generateQrcodeFunc = async () => {
console
.
warn
(
'recordId 未传入,无法生成二维码'
)
return
}
console
.
warn
(
'recordId'
,
props
.
recordId
)
try
{
const
result
=
await
generateQRCode
({
scene
:
`id=
${
props
.
recordId
}
`
,
page
:
`pages/XingmaLabDetailPage/XingmaLabDetailPage`
,
envVersion
:
'
release'
//trial develop
envVersion
:
'
trial'
//trial develop release
})
if
(
result
&&
result
.
ok
&&
result
.
data
&&
result
.
data
.
qrCodeBase64
)
{
...
...
@@ -319,17 +320,26 @@ const handleDownload = async () => {
// 二维码位置:图片区域右下角,距离右边 22rpx,距离底部 26rpx
const
qrcodeX
=
imageBgX
+
imageBgW
-
qrcodeSize
-
(
22
/
750
)
*
screenWidth
const
qrcodeY
=
imageBgY
+
imageBgH
-
qrcodeSize
-
(
26
/
750
)
*
screenWidth
// 稍微缩小二维码尺寸以去除边框(缩小 8%,相当于去除 4% 的边框)
const
qrcodeDrawSize
=
qrcodeSize
*
0.92
const
qrcodeDrawX
=
qrcodeX
+
(
qrcodeSize
-
qrcodeDrawSize
)
/
2
const
qrcodeDrawY
=
qrcodeY
+
(
qrcodeSize
-
qrcodeDrawSize
)
/
2
console
.
log
(
'开始绘制二维码:'
,
{
qrcodeX
,
qrcodeY
,
qrcodeSize
,
qrcodeDrawSize
,
imageBgX
,
imageBgY
,
imageBgW
,
imageBgH
,
qrcodeImageUrl
:
qrcodeImageUrl
.
value
.
substring
(
0
,
50
)
+
'...'
})
await
drawImage
(
ctx
,
qrcodeImageUrl
.
value
,
qrcodeX
,
qrcodeY
,
qrcodeSize
,
qrcodeSize
)
// 绘制二维码,使用稍微缩小的尺寸以去除边框
await
drawQRCodeImage
(
ctx
,
qrcodeImageUrl
.
value
,
qrcodeDrawX
,
qrcodeDrawY
,
qrcodeDrawSize
,
qrcodeDrawSize
)
console
.
log
(
'二维码绘制完成'
)
}
else
{
console
.
warn
(
'二维码图片 URL 为空,无法绘制'
)
...
...
@@ -552,6 +562,110 @@ const calculateFitSize = (imageWidth, imageHeight, containerWidth, containerHeig
return
{
drawWidth
,
drawHeight
,
drawX
,
drawY
}
}
// 绘制二维码图片(去除边框)
const
drawQRCodeImage
=
(
ctx
,
src
,
x
,
y
,
w
,
h
)
=>
{
return
new
Promise
((
resolve
)
=>
{
// 获取图片路径(Base64 需要转换)
const
getImagePath
=
()
=>
{
if
(
src
.
startsWith
(
'data:image'
))
{
return
base64ToTempFilePath
(
src
)
}
else
{
return
Promise
.
resolve
(
src
)
}
}
getImagePath
().
then
((
imagePath
)
=>
{
// 获取图片信息
return
getImageInfo
(
imagePath
).
then
((
info
)
=>
{
// 二维码通常是正方形,如果图片有边框,计算裁剪区域
// 假设二维码图片可能有边框,尝试裁剪掉边缘部分
// 如果图片宽高比接近 1:1,可能是标准二维码,直接绘制
// 如果图片明显不是正方形,可能需要裁剪
const
isSquare
=
Math
.
abs
(
info
.
width
-
info
.
height
)
<
10
const
minSize
=
Math
.
min
(
info
.
width
,
info
.
height
)
// 如果图片是正方形且尺寸合理,直接绘制
if
(
isSquare
&&
minSize
>
200
)
{
if
(
imagePath
.
startsWith
(
'http'
))
{
uni
.
downloadFile
({
url
:
imagePath
,
success
:
(
res
)
=>
{
if
(
res
.
statusCode
===
200
)
{
ctx
.
drawImage
(
res
.
tempFilePath
,
x
,
y
,
w
,
h
)
resolve
()
}
else
{
console
.
warn
(
'二维码图片下载失败'
)
resolve
()
}
},
fail
:
()
=>
{
console
.
warn
(
'二维码图片下载失败'
)
resolve
()
}
})
}
else
{
ctx
.
drawImage
(
imagePath
,
x
,
y
,
w
,
h
)
resolve
()
}
}
else
{
// 图片可能有边框,尝试裁剪掉 5% 的边缘
// 注意:uni-app canvas 可能不支持 9 参数 drawImage
// 这里先尝试直接绘制,如果仍有边框问题,可能需要后端处理
if
(
imagePath
.
startsWith
(
'http'
))
{
uni
.
downloadFile
({
url
:
imagePath
,
success
:
(
res
)
=>
{
if
(
res
.
statusCode
===
200
)
{
// 直接绘制,让 canvas 自动处理
ctx
.
drawImage
(
res
.
tempFilePath
,
x
,
y
,
w
,
h
)
resolve
()
}
else
{
console
.
warn
(
'二维码图片下载失败'
)
resolve
()
}
},
fail
:
()
=>
{
console
.
warn
(
'二维码图片下载失败'
)
resolve
()
}
})
}
else
{
ctx
.
drawImage
(
imagePath
,
x
,
y
,
w
,
h
)
resolve
()
}
}
}).
catch
(()
=>
{
// 如果获取图片信息失败,直接绘制
if
(
imagePath
.
startsWith
(
'http'
))
{
uni
.
downloadFile
({
url
:
imagePath
,
success
:
(
res
)
=>
{
if
(
res
.
statusCode
===
200
)
{
ctx
.
drawImage
(
res
.
tempFilePath
,
x
,
y
,
w
,
h
)
resolve
()
}
else
{
console
.
warn
(
'二维码图片下载失败'
)
resolve
()
}
},
fail
:
()
=>
{
console
.
warn
(
'二维码图片下载失败'
)
resolve
()
}
})
}
else
{
ctx
.
drawImage
(
imagePath
,
x
,
y
,
w
,
h
)
resolve
()
}
})
}).
catch
((
err
)
=>
{
console
.
error
(
'二维码图片处理失败:'
,
err
)
resolve
()
// 即使失败也继续
})
})
}
// 绘制图片到 canvas(异步加载图片)
const
drawImage
=
(
ctx
,
src
,
x
,
y
,
w
,
h
,
fitMode
=
false
)
=>
{
return
new
Promise
((
resolve
)
=>
{
...
...
@@ -777,7 +891,6 @@ const drawImage = (ctx, src, x, y, w, h, fitMode = false) => {
height: 586rpx;
z-index: 1;
object-fit: contain;
margin: 26rpx;
box-sizing: border-box;
}
...
...
@@ -796,6 +909,7 @@ const drawImage = (ctx, src, x, y, w, h, fitMode = false) => {
color: #000000;
width: 450rpx;
height: 40rpx;
line-height: 40rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
...
...
pages/XingmaLabDetailPage/XingmaLabDetailPage.vue
View file @
004fd931
...
...
@@ -358,6 +358,43 @@
}
}
// 从 scene 参数中解析 id
const
parseIdFromScene
=
(
scene
)
=>
{
if
(
!
scene
||
typeof
scene
!==
'string'
)
{
return
''
}
try
{
// 先对 scene 字符串进行 URL 解码
const
decodedScene
=
decodeURIComponent
(
scene
)
// scene 格式可能是 "id=xxx" 或 "id=xxx&other=yyy"
const
params
=
decodedScene
.
split
(
'&'
)
for
(
const
param
of
params
)
{
const
[
key
,
value
]
=
param
.
split
(
'='
)
if
(
key
===
'id'
&&
value
)
{
// value 可能也需要解码(如果 value 本身也被编码了)
return
decodeURIComponent
(
value
)
}
}
}
catch
(
error
)
{
console
.
warn
(
'解析 scene 参数失败:'
,
error
)
// 如果解码失败,尝试直接解析原始 scene
const
params
=
scene
.
split
(
'&'
)
for
(
const
param
of
params
)
{
const
[
key
,
value
]
=
param
.
split
(
'='
)
if
(
key
===
'id'
&&
value
)
{
try
{
return
decodeURIComponent
(
value
)
}
catch
(
e
)
{
return
value
}
}
}
}
return
''
}
// 页面初始化逻辑
const
initPage
=
async
()
=>
{
console
.
log
(
'🔍 initPage:页面初始化逻辑'
);
...
...
@@ -379,11 +416,56 @@
// 调用 home 接口获取登录状态
await
homeStore
.
loadHomeInfo
()
// 获取页面跳转参数中的 id
和 index
// 获取页面跳转参数中的 id
const
pages
=
getCurrentPages
()
const
currentPage
=
pages
[
pages
.
length
-
1
]
console
.
log
(
'🔍 currentPage:'
,
currentPage
);
const
id
=
currentPage
.
options
?.
id
||
''
// 优先从 options.id 获取
let
id
=
currentPage
.
options
?.
id
||
''
// 如果 options.id 不存在,尝试从 scene 参数中解析
if
(
!
id
)
{
// 尝试从 currentPage.options.scene 获取
const
scene
=
currentPage
.
options
?.
scene
||
''
if
(
scene
)
{
id
=
parseIdFromScene
(
scene
)
console
.
log
(
'🔍 从 currentPage.options.scene 解析到 id:'
,
id
)
}
// 如果还是没有,尝试从 wx.getLaunchOptionsSync() 获取(扫码进入场景)
if
(
!
id
)
{
try
{
const
launchOptions
=
wx
.
getLaunchOptionsSync
()
if
(
launchOptions
&&
launchOptions
.
scene
)
{
// 如果是扫码场景(scene 值为 1047 或 1048),从 query 中获取 scene 参数
if
(
launchOptions
.
scene
===
1047
||
launchOptions
.
scene
===
1048
)
{
const
sceneParam
=
launchOptions
.
query
?.
scene
||
''
if
(
sceneParam
)
{
id
=
parseIdFromScene
(
sceneParam
)
console
.
log
(
'🔍 从 launchOptions.query.scene 解析到 id:'
,
id
)
}
}
}
}
catch
(
error
)
{
console
.
warn
(
'获取 launchOptions 失败:'
,
error
)
}
}
// 如果还是没有,尝试从 wx.getEnterOptionsSync() 获取
if
(
!
id
)
{
try
{
const
enterOptions
=
wx
.
getEnterOptionsSync
()
if
(
enterOptions
&&
enterOptions
.
query
&&
enterOptions
.
query
.
scene
)
{
id
=
parseIdFromScene
(
enterOptions
.
query
.
scene
)
console
.
log
(
'🔍 从 enterOptions.query.scene 解析到 id:'
,
id
)
}
}
catch
(
error
)
{
console
.
warn
(
'获取 enterOptions 失败:'
,
error
)
}
}
}
if
(
id
)
{
console
.
log
(
'🔍 获取到页面参数 id:'
,
id
)
recordId
.
value
=
id
// 立即保存ID,确保分享时能获取到
...
...
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