refactor(app): 优化代码结构和功能
- 移除多处 console.log 语句,清理无用代码 - 在消息组件中添加 info 类型配置并实现 info 消息显示功能 - 优化 WebSocket 消息处理逻辑,提高代码可读性
This commit is contained in:
parent
c86e449d52
commit
a791248752
BIN
app/components/x-message/images/info.png
Normal file
BIN
app/components/x-message/images/info.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 932 B |
@ -3,6 +3,7 @@
|
|||||||
import error from '../images/error.png'
|
import error from '../images/error.png'
|
||||||
import success from '../images/success.png'
|
import success from '../images/success.png'
|
||||||
import warning from '../images/warning.png'
|
import warning from '../images/warning.png'
|
||||||
|
import info from '../images/info.png'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
type: {
|
type: {
|
||||||
@ -40,6 +41,11 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const typeConfig = {
|
const typeConfig = {
|
||||||
|
info: {
|
||||||
|
imgSrc: info,
|
||||||
|
borderColor: '#C6DFFB',
|
||||||
|
bgColor: '#ECF5FE',
|
||||||
|
},
|
||||||
success: {
|
success: {
|
||||||
imgSrc: success,
|
imgSrc: success,
|
||||||
borderColor: '#C5E7D5',
|
borderColor: '#C5E7D5',
|
||||||
|
@ -28,12 +28,25 @@ const message = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
info(options, duration = 2000) {
|
||||||
|
if (process.client) {
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
this.show({ type: 'info', message: options, duration })
|
||||||
|
} else {
|
||||||
|
this.show({
|
||||||
|
type: 'error',
|
||||||
|
...options,
|
||||||
|
duration
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
warning(options, duration = 2000) {
|
warning(options, duration = 2000) {
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
this.show({ type: 'warning', message: options, duration })
|
this.show({ type: 'warning', message: options, duration })
|
||||||
} else {
|
} else {
|
||||||
console.log('options',options)
|
|
||||||
this.show({
|
this.show({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
...options,
|
...options,
|
||||||
|
@ -8,7 +8,7 @@ const initData=async ()=>{
|
|||||||
const res=await userArtwork({uuid})
|
const res=await userArtwork({uuid})
|
||||||
if (res.status===0){
|
if (res.status===0){
|
||||||
detail.value=res.data
|
detail.value=res.data
|
||||||
console.log('detail.value',detail.value)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initData()
|
initData()
|
||||||
|
@ -37,7 +37,6 @@ const close = () => emit('update:show', false);
|
|||||||
const openShow=(item)=>{
|
const openShow=(item)=>{
|
||||||
showDetailInfo.value=item
|
showDetailInfo.value=item
|
||||||
showDetail.value=true
|
showDetail.value=true
|
||||||
|
|
||||||
}
|
}
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
pageRef.value.page++
|
pageRef.value.page++
|
||||||
|
@ -85,7 +85,7 @@ watch(()=>{
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
const goBuy=async ()=>{
|
const goBuy=async ()=>{
|
||||||
console.log('auctionData',auctionData.value)
|
|
||||||
const res= await artworkBuy({
|
const res= await artworkBuy({
|
||||||
auctionArtworkUuid:auctionData.value?.artwork?.uuid,
|
auctionArtworkUuid:auctionData.value?.artwork?.uuid,
|
||||||
buyMoney:String(auctionData.value?.nowAuctionPrice?.nextPrice??0)
|
buyMoney:String(auctionData.value?.nowAuctionPrice?.nextPrice??0)
|
||||||
|
@ -24,7 +24,7 @@ export const liveStore = createGlobalState(() => {
|
|||||||
ws.send({ type: 'chat', content: 'Hello!' })*/
|
ws.send({ type: 'chat', content: 'Hello!' })*/
|
||||||
// 监听消息
|
// 监听消息
|
||||||
onMessage((data) => {
|
onMessage((data) => {
|
||||||
console.log('收到消息:', data)
|
|
||||||
auctionData.value = data
|
auctionData.value = data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,10 @@ export class WebSocketClient {
|
|||||||
},
|
},
|
||||||
onMessage: (callback: (data: any) => void) => {
|
onMessage: (callback: (data: any) => void) => {
|
||||||
this.socket!.onmessage = (event) => {
|
this.socket!.onmessage = (event) => {
|
||||||
console.log('event',event)
|
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(event.data)
|
const data = JSON.parse(event.data)
|
||||||
console.log('data',data)
|
|
||||||
callback(data)
|
callback(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('解析消息失败:', error)
|
console.error('解析消息失败:', error)
|
||||||
|
Loading…
Reference in New Issue
Block a user