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
afe547eb
Commit
afe547eb
authored
Aug 28, 2025
by
spc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
publish
parent
60653d20
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
251 additions
and
92 deletions
+251
-92
xingmaLab.js
api/xingmaLab.js
+13
-5
XingmaLabPublishPage.less
pages/XingmaLabPublishPage/XingmaLabPublishPage.less
+20
-0
XingmaLabPublishPage.vue
pages/XingmaLabPublishPage/XingmaLabPublishPage.vue
+218
-87
No files found.
api/xingmaLab.js
View file @
afe547eb
...
...
@@ -23,10 +23,18 @@ export const fetchFavoriteList = (pageNum, pageSize) => api.get('/c/lab/favorite
* 我的藏品
* @returns
*/
export
const
fetchRecordMyrecords
=
(
pageNum
,
pageSize
)
=>
api
.
get
(
'/c/lab/record/myRecords'
,{
pageNum
:
pageNum
,
pageSize
:
pageSize
});
export
const
fetchRecordMyrecords
=
(
pageNum
,
pageSize
)
=>
api
.
get
(
'/c/lab/record/myRecords'
,
{
pageNum
:
pageNum
,
pageSize
:
pageSize
})
export
const
fetchRecordIndex
=
()
=>
api
.
get
(
'/c/lab/home'
)
export
const
fetchRecordPublish
=
(
data
)
=>
api
.
post
(
'/c/lab/record/create'
,
data
)
export
const
fetchRecordDetail
=
(
data
)
=>
api
.
get
(
'/c/lab/record/detail'
,
data
)
export
const
fetchFavoriteAdd
=
(
data
)
=>
api
.
get
(
'/c/lab/favorite/add'
,
data
)
export
const
fetch
RecordIndex
=
()
=>
api
.
get
(
'/c/lab/home'
);
export
const
fetch
FavoriteRemove
=
(
data
)
=>
api
.
get
(
'/c/lab/favorite/remove'
,
data
)
pages/XingmaLabPublishPage/XingmaLabPublishPage.less
View file @
afe547eb
...
...
@@ -638,3 +638,23 @@
}
}
}
// 调试信息样式
.debug-info {
position: absolute;
top: 20rpx;
right: 20rpx;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 20rpx;
border-radius: 10rpx;
font-size: 24rpx;
z-index: 100;
max-width: 300rpx;
.debug-text {
display: block;
margin-bottom: 10rpx;
line-height: 1.4;
}
}
pages/XingmaLabPublishPage/XingmaLabPublishPage.vue
View file @
afe547eb
...
...
@@ -118,12 +118,18 @@ import { ref, onMounted, computed } from 'vue'
import
{
xingmaLabConfig
,
getImageUrl
,
getRandomSuccessMessage
}
from
'./config.js'
import
Xingmalabconfirmpop
from
'@/components/xingmaLab/Xingmalabconfirmpop.vue'
import
Xingmalabnotimepop
from
'@/components/xingmaLab/Xingmalabnotimepop.vue'
import
{
useXingmaLabStore
}
from
'@/stores/xingmaLab.js'
import
{
uploadImage
}
from
'@/api/common.js'
import
{
fetchRecordPublish
}
from
'@/api/xingmaLab.js'
// 组件名称
defineOptions
({
name
:
'XingmaLabPublishPage'
})
// 使用 store
const
xingmaLabStore
=
useXingmaLabStore
()
// 响应式数据
const
currentState
=
ref
(
xingmaLabConfig
.
states
.
NOSEL
)
// nosel, sel, suc
const
publishNumber
=
ref
(
'123456789'
)
...
...
@@ -149,18 +155,55 @@ const hasContent = computed(() => {
return
uploadedImage
.
value
&&
description
.
value
.
trim
()
})
// 计算属性
// 计算属性
- 根据 store 中的信息判断
const
isFirstTimePublish
=
computed
(()
=>
{
// 检查用户是否首次发布(这里需要根据实际业务逻辑判断)
// 可以通过本地存储或用户信息来判断
const
hasPublished
=
uni
.
getStorageSync
(
'hasPublished'
)
return
!
hasPublished
// 通过头像昵称判断是否为首次发布
// 如果没有头像昵称信息,则为首次发布
return
!
hasUserInfo
.
value
})
const
hasUserInfo
=
computed
(()
=>
{
// 检查用户是否已有头像昵称信息
const
userInfo
=
uni
.
getStorageSync
(
'userInfo'
)
return
userInfo
&&
userInfo
.
avatarUrl
&&
userInfo
.
nickName
// 只检查 store 中的 xingmaInfo
const
{
xingmaInfo
}
=
xingmaLabStore
console
.
log
(
'🔍 hasUserInfo 检查:'
,
{
xingmaInfo
,
avatar
:
xingmaInfo
?.
avatar
,
nickname
:
xingmaInfo
?.
nickname
,
avatarType
:
typeof
xingmaInfo
?.
avatar
,
nicknameType
:
typeof
xingmaInfo
?.
nickname
})
if
(
xingmaInfo
&&
xingmaInfo
.
avatar
&&
xingmaInfo
.
nickname
)
{
console
.
log
(
'✅ Store 中有头像昵称信息'
)
return
true
}
return
false
})
const
canPublish
=
computed
(()
=>
{
// 根据 store 中的 remainingPublishCount 判断是否还有发布次数
const
{
xingmaInfo
}
=
xingmaLabStore
if
(
!
xingmaInfo
)
return
false
const
{
remainingPublishCount
,
isReachedLimit
}
=
xingmaInfo
return
remainingPublishCount
>
0
&&
!
isReachedLimit
})
const
publishCountInfo
=
computed
(()
=>
{
const
{
xingmaInfo
}
=
xingmaLabStore
if
(
!
xingmaInfo
)
{
return
{
current
:
0
,
max
:
0
,
remaining
:
0
}
}
const
{
currentMonthPublishCount
,
maxPublishCount
,
remainingPublishCount
}
=
xingmaInfo
return
{
current
:
currentMonthPublishCount
,
max
:
maxPublishCount
,
remaining
:
remainingPublishCount
}
})
// 图片上传处理
...
...
@@ -174,10 +217,6 @@ const handleImageUpload = () => {
success
:
(
res
)
=>
{
const
tempFilePath
=
res
.
tempFilePaths
[
0
]
// 检查文件大小
uni
.
getFileInfo
({
filePath
:
tempFilePath
,
...
...
@@ -202,8 +241,9 @@ const handleImageUpload = () => {
return
}
// 上传图片
uploadImageFunc
(
tempFilePath
)
// 保存临时文件路径,等待发布时上传
uploadedImage
.
value
=
tempFilePath
console
.
log
(
'🖼️ 图片已选择,等待发布时上传:'
,
tempFilePath
)
},
fail
:
()
=>
{
uni
.
showToast
({
...
...
@@ -222,31 +262,38 @@ const handleImageUpload = () => {
// 上传图片到服务器
const
uploadImageFunc
=
async
(
tempFilePath
)
=>
{
isUploading
.
value
=
true
uni
.
showLoading
({
title
:
'上传中...'
,
mask
:
true
})
console
.
log
(
tempFilePath
)
const
fs
=
uni
.
getFileSystemManager
();
console
.
log
(
fs
)
const
base64
=
"data:image/jpeg;base64,"
+
fs
.
readFileSync
(
tempFilePath
,
"base64"
);
const
uploadRes
=
await
uploadImage
(
base64
);
if
(
uploadRes
.
success
)
{
uploadedImage
.
value
=
tempFilePath
try
{
console
.
log
(
'📤 开始上传图片:'
,
tempFilePath
)
const
fs
=
uni
.
getFileSystemManager
();
const
base64
=
"data:image/jpeg;base64,"
+
fs
.
readFileSync
(
tempFilePath
,
"base64"
);
const
uploadRes
=
await
uploadImage
(
base64
);
if
(
uploadRes
.
success
)
{
// 保存接口返回的url,用于发布
const
uploadedUrl
=
uploadRes
.
data
?.
url
isUploading
.
value
=
false
uni
.
hideLoading
()
console
.
log
(
'✅ 图片上传成功,url:'
,
uploadedUrl
)
return
uploadedUrl
}
else
{
throw
new
Error
(
uploadRes
.
message
||
'图片上传失败'
)
}
}
catch
(
error
)
{
isUploading
.
value
=
false
uni
.
hideLoading
()
console
.
error
(
'❌ 图片上传失败:'
,
error
)
uni
.
showToast
({
title
:
'图片上传成功'
,
icon
:
'none'
})
}
else
{
uni
.
showToast
({
title
:
uploadRes
.
message
,
title
:
error
.
message
||
'图片上传失败'
,
icon
:
"none"
,
});
throw
error
}
}
// 文案输入处理
...
...
@@ -266,23 +313,27 @@ const handleDescriptionInput = (e) => {
// 发布按钮点击处理
const
handlePublishBtnClick
=
async
()
=>
{
console
.
log
(
'点击发布按钮'
,
isFirstTimePublish
.
value
,
hasUserInfo
.
value
)
console
.
log
(
'点击发布按钮'
,
{
isFirstTimePublish
:
isFirstTimePublish
.
value
,
hasUserInfo
:
hasUserInfo
.
value
,
canPublish
:
canPublish
.
value
,
publishCountInfo
:
publishCountInfo
.
value
})
// 检查是否首次发布且需要授权
// if (isFirstTimePublish.value && !hasUserInfo.value) {
// 重置临时用户信息
tempUserInfo
.
value
=
{
avatarUrl
:
''
,
nickName
:
''
if
(
isFirstTimePublish
.
value
&&
!
hasUserInfo
.
value
)
{
// 重置临时用户信息
tempUserInfo
.
value
=
{
avatarUrl
:
''
,
nickName
:
''
}
// 显示用户信息授权弹窗
userInfoPopup
.
value
.
open
()
return
}
// 显示用户信息授权弹窗
userInfoPopup
.
value
.
open
()
return
// }
// 检查发布次数限制
const
canPublish
=
await
checkPublishLimit
()
if
(
!
canPublish
)
{
if
(
!
canPublish
.
value
)
{
// 显示无次数弹窗
showNoTimePopup
.
value
=
true
return
...
...
@@ -304,14 +355,6 @@ const onNicknameInput = (e) => {
tempUserInfo
.
value
.
nickName
=
e
.
detail
.
value
}
// 使用其他头像和昵称
const
handleUseOtherInfo
=
()
=>
{
// 这里可以添加自定义头像昵称的逻辑
uni
.
showToast
({
title
:
'可以使用自定义头像昵称'
,
icon
:
'none'
})
}
// 拒绝授权
const
handleRejectAuth
=
()
=>
{
...
...
@@ -332,23 +375,17 @@ const handleAllowAuth = () => {
return
}
// 保存用户信息
uni
.
setStorageSync
(
'userInfo'
,
{
avatarUrl
:
tempUserInfo
.
value
.
avatarUrl
,
nickName
:
tempUserInfo
.
value
.
nickName
})
// 关闭授权弹窗
userInfoPopup
.
value
.
close
()
// 检查发布次数限制
// 检查发布次数限制
并显示确认弹窗
checkPublishLimitAndShowConfirm
()
}
// 检查发布次数限制并显示确认弹窗
const
checkPublishLimitAndShowConfirm
=
async
()
=>
{
const
canPublish
=
await
checkPublishLimit
()
if
(
!
canPublish
)
{
const
checkPublishLimitAndShowConfirm
=
()
=>
{
// 直接使用计算属性判断
if
(
!
canPublish
.
value
)
{
// 显示无次数弹窗
showNoTimePopup
.
value
=
true
return
...
...
@@ -368,11 +405,26 @@ const handleConfirmPublish = async () => {
showConfirmPopup
.
value
=
false
try
{
console
.
log
(
'🚀 开始发布,当前状态:'
,
{
isFirstTimePublish
:
isFirstTimePublish
.
value
,
hasUserInfo
:
hasUserInfo
.
value
,
imgUrl
:
uploadedImage
.
value
,
content
:
description
.
value
})
// 执行发布
await
performPublish
()
// 标记用户已发布过
uni
.
setStorageSync
(
'hasPublished'
,
true
)
// 如果是首次授权发布成功,记录日志
if
(
isFirstTimePublish
.
value
)
{
console
.
log
(
'✅ 首次授权发布成功,用户信息:'
,
{
avatar
:
tempUserInfo
.
value
.
avatarUrl
,
nickname
:
tempUserInfo
.
value
.
nickName
})
}
// 发布成功后重新获取最新信息(如果需要的话)
// await xingmaLabStore.loadXingmaInfo()
// 切换到成功状态
currentState
.
value
=
config
.
states
.
SUC
...
...
@@ -391,34 +443,100 @@ const handleConfirmPublish = async () => {
// 无次数弹窗按钮点击处理
const
handleNoTimeButtonClick
=
()
=>
{
showNoTimePopup
.
value
=
false
// 显示更详细的发布次数信息
const
{
current
,
max
,
remaining
}
=
publishCountInfo
.
value
uni
.
showToast
({
title
:
'发布次数已用完,请明天再试'
,
icon
:
'none'
title
:
`本月已发布
${
current
}
次,剩余
${
remaining
}
次`
,
icon
:
'none'
,
duration
:
3000
})
}
//
检查发布次数限制
const
checkPublishLimit
=
async
()
=>
{
// 这里应该调用后端接口检查发布次数
// 暂时返回true作为示例,实际使用时应该根据后端返回结果判断
return
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
// 模拟检查结果,这里可以改为实际的接口调用
const
hasRemainingCount
=
Math
.
random
()
>
0.3
// 70% 概率有剩余次数
resolve
(
hasRemainingCount
)
},
500
)
})
}
//
移除不再需要的 checkPublishLimit 函数
//
const checkPublishLimit = async () => {
//
// 这里应该调用后端接口检查发布次数
//
// 暂时返回true作为示例,实际使用时应该根据后端返回结果判断
//
return new Promise((resolve) => {
//
setTimeout(() => {
//
// 模拟检查结果,这里可以改为实际的接口调用
//
const hasRemainingCount = Math.random() > 0.3 // 70% 概率有剩余次数
//
resolve(hasRemainingCount)
//
}, 500)
//
})
//
}
// 执行发布
const
performPublish
=
async
()
=>
{
// 这里应该调用后端发布接口
return
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
console
.
log
(
'发布成功'
)
resolve
()
},
1000
)
})
try
{
// 调用实际的发布接口
const
params
=
{
imgUrl
:
uploadedImage
.
value
,
// 初始时是临时文件路径,将在下面上传
content
:
description
.
value
}
// 上传内容图片
if
(
uploadedImage
.
value
)
{
try
{
const
uploadedUrl
=
await
uploadImageFunc
(
uploadedImage
.
value
)
params
.
imgUrl
=
uploadedUrl
console
.
log
(
'✅ 内容图片上传成功,更新 imgUrl:'
,
uploadedUrl
)
}
catch
(
uploadError
)
{
console
.
error
(
'❌ 内容图片上传失败:'
,
uploadError
)
throw
new
Error
(
'内容图片上传失败,请重试'
)
}
}
// 如果是首次授权,需要传递nickname和avatar
if
(
isFirstTimePublish
.
value
)
{
// 直接从临时用户信息中读取,不存储到本地
console
.
log
(
'🔍 检查临时用户信息:'
,
tempUserInfo
.
value
);
if
(
tempUserInfo
.
value
&&
tempUserInfo
.
value
.
avatarUrl
&&
tempUserInfo
.
value
.
nickName
)
{
params
.
nickname
=
tempUserInfo
.
value
.
nickName
// 上传头像到服务器,使用返回的URL
try
{
console
.
log
(
'🖼️ 开始上传头像:'
,
tempUserInfo
.
value
.
avatarUrl
)
// 将临时文件路径转换为base64
const
fs
=
uni
.
getFileSystemManager
()
const
avatarBase64
=
"data:image/jpeg;base64,"
+
fs
.
readFileSync
(
tempUserInfo
.
value
.
avatarUrl
,
"base64"
)
const
avatarUploadRes
=
await
uploadImage
(
avatarBase64
)
if
(
avatarUploadRes
.
success
)
{
params
.
avatar
=
avatarUploadRes
.
data
?.
url
console
.
log
(
'✅ 头像上传成功,avatar URL:'
,
params
.
avatar
)
}
else
{
throw
new
Error
(
avatarUploadRes
.
message
||
'头像上传失败'
)
}
}
catch
(
avatarError
)
{
console
.
error
(
'❌ 头像上传失败:'
,
avatarError
)
throw
new
Error
(
'头像上传失败,请重试'
)
}
}
else
{
console
.
warn
(
'⚠️ 临时用户信息不完整,无法上传头像:'
,
tempUserInfo
.
value
);
}
}
console
.
log
(
'🚀 发布参数:'
,
params
)
// 使用 fetchRecordPublish 调用发布接口
const
result
=
await
fetchRecordPublish
(
params
)
console
.
log
(
'📤 发布接口返回:'
,
result
)
if
(
result
.
success
)
{
console
.
log
(
'✅ 发布成功'
)
return
result
}
else
{
throw
new
Error
(
result
.
message
||
'发布失败'
)
}
}
catch
(
error
)
{
console
.
error
(
'❌ 发布失败:'
,
error
)
throw
error
}
}
// 生成发布编号
...
...
@@ -433,8 +551,21 @@ const handleSuccessBtnClick = () => {
}
// 生命周期
onMounted
(()
=>
{
onMounted
(
async
()
=>
{
console
.
log
(
'星妈实验室发布页面已加载'
)
// 获取最新的星妈实验室信息
await
xingmaLabStore
.
loadXingmaInfo
()
// 调试信息:查看加载后的数据状态
console
.
log
(
'🚀 页面加载完成后的状态:'
,
{
xingmaInfo
:
xingmaLabStore
.
xingmaInfo
,
hasUserInfo
:
hasUserInfo
.
value
,
isFirstTimePublish
:
isFirstTimePublish
.
value
,
canPublish
:
canPublish
.
value
,
publishCountInfo
:
publishCountInfo
.
value
})
// 生成随机成功文案
successMessage
.
value
=
getRandomSuccessMessage
()
})
...
...
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