consumer模块完成度95%,实现数据库多端注册登录,优化安卓端小程序bug
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { supabaseService } from '@/utils/supabaseService.uts'
|
||||
|
||||
type MessageType = {
|
||||
@@ -60,31 +61,14 @@ const message = ref<MessageType>({
|
||||
|
||||
const extraInfo = ref<ExtraInfoItem[]>([])
|
||||
|
||||
const loadMessage = async (id: string) => {
|
||||
try {
|
||||
const notifications = await supabaseService.getUserNotifications(null)
|
||||
const found = notifications.find(n => n.id === id)
|
||||
|
||||
if (found != null) {
|
||||
message.value = {
|
||||
id: found.id,
|
||||
type: found.type,
|
||||
title: found.title,
|
||||
content: found.content,
|
||||
icon_url: found.icon_url,
|
||||
link_url: found.link_url,
|
||||
extra_data: found.extra_data,
|
||||
created_at: found.created_at
|
||||
}
|
||||
|
||||
// 解析extra_data
|
||||
if (found.extra_data != null) {
|
||||
parseExtraData(found.extra_data)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载消息失败:', e)
|
||||
}
|
||||
const formatLabel = (key: string): string => {
|
||||
if (key === 'share_code') return '分享码'
|
||||
if (key === 'product_name') return '商品名称'
|
||||
if (key === 'reward_amount') return '奖励金额'
|
||||
if (key === 'order_no') return '订单号'
|
||||
if (key === 'buyer_name') return '购买者'
|
||||
if (key === 'quantity') return '数量'
|
||||
return key
|
||||
}
|
||||
|
||||
const parseExtraData = (data: any) => {
|
||||
@@ -93,21 +77,29 @@ const parseExtraData = (data: any) => {
|
||||
if (data == null) return
|
||||
|
||||
try {
|
||||
let dataObj: any = data
|
||||
let dataObj: UTSJSONObject | null = null
|
||||
if (typeof data === 'string') {
|
||||
dataObj = JSON.parse(data)
|
||||
const parsed = JSON.parse(data as string)
|
||||
if (parsed != null) {
|
||||
dataObj = parsed as UTSJSONObject
|
||||
}
|
||||
} else if (data instanceof UTSJSONObject) {
|
||||
dataObj = data
|
||||
} else {
|
||||
dataObj = JSON.parse(JSON.stringify(data)) as UTSJSONObject
|
||||
}
|
||||
|
||||
if (typeof dataObj === 'object') {
|
||||
const keys = Object.keys(dataObj)
|
||||
if (dataObj != null) {
|
||||
const keys = UTSJSONObject.keys(dataObj)
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i]
|
||||
const value = dataObj[key]
|
||||
const key = keys[i] as string
|
||||
const value = dataObj.get(key)
|
||||
if (value != null) {
|
||||
extraInfo.value.push({
|
||||
const item: ExtraInfoItem = {
|
||||
label: formatLabel(key),
|
||||
value: String(value)
|
||||
})
|
||||
value: `${value}`
|
||||
}
|
||||
extraInfo.value.push(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,16 +108,32 @@ const parseExtraData = (data: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const formatLabel = (key: string): string => {
|
||||
const labelMap: Record<string, string> = {
|
||||
'share_code': '分享码',
|
||||
'product_name': '商品名称',
|
||||
'reward_amount': '奖励金额',
|
||||
'order_no': '订单号',
|
||||
'buyer_name': '购买者',
|
||||
'quantity': '数量'
|
||||
const loadMessage = async (id: string) => {
|
||||
try {
|
||||
const notifications = await supabaseService.getUserNotifications(null)
|
||||
const found = notifications.find(n => n.id === id)
|
||||
|
||||
if (found != null) {
|
||||
const extraData = found.extra_data
|
||||
const msg: MessageType = {
|
||||
id: found.id,
|
||||
type: found.type,
|
||||
title: found.title,
|
||||
content: found.content,
|
||||
icon_url: found.icon_url,
|
||||
link_url: found.link_url,
|
||||
extra_data: extraData,
|
||||
created_at: found.created_at ?? ''
|
||||
}
|
||||
message.value = msg
|
||||
|
||||
if (extraData != null) {
|
||||
parseExtraData(extraData)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载消息失败:', e)
|
||||
}
|
||||
return labelMap[key] ?? key
|
||||
}
|
||||
|
||||
const formatTime = (timeStr: string): string => {
|
||||
@@ -155,13 +163,11 @@ const goToLink = () => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const pages = getCurrentPages()
|
||||
if (pages.length > 0) {
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const options = (currentPage as any).options
|
||||
if (options != null && options.id != null) {
|
||||
loadMessage(options.id as string)
|
||||
onLoad((options) => {
|
||||
if (options != null) {
|
||||
const idVal = options['id']
|
||||
if (idVal != null) {
|
||||
loadMessage(idVal as string)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user