数据分析ui补充完善,接入数据库
This commit is contained in:
@@ -19,16 +19,25 @@ export async function ensureUserProfile(sessionUser: UTSJSONObject): Promise<Use
|
||||
return null
|
||||
}
|
||||
|
||||
// 检查用户是否已存在
|
||||
// 检查用户是否已存在(ak_users 通过 auth_id 关联 auth.users.id)
|
||||
const checkRes = await supabase.from('ak_users')
|
||||
.select('*', {})
|
||||
.eq('id', userId)
|
||||
.eq('auth_id', userId)
|
||||
.single()
|
||||
.execute()
|
||||
|
||||
console.log('ensureUserProfile check ak_users:', {
|
||||
status: checkRes.status,
|
||||
hasData: checkRes.data != null,
|
||||
hasError: (checkRes as any).error != null,
|
||||
error: (checkRes as any).error
|
||||
})
|
||||
|
||||
if (checkRes.status >= 200 && checkRes.status < 300 && checkRes.data != null) {
|
||||
// 用户已存在,返回现有资料
|
||||
const existingUser = checkRes.data as UTSJSONObject
|
||||
// 用户已存在,返回现有资料(H5 下 checkRes.data 可能是 plain object,不一定是 UTSJSONObject)
|
||||
const existingUser = (typeof (checkRes.data as any).getString === 'function')
|
||||
? (checkRes.data as UTSJSONObject)
|
||||
: new UTSJSONObject(checkRes.data as any)
|
||||
return {
|
||||
id: existingUser.getString('id') ?? '',
|
||||
username: existingUser.getString('username') ?? '',
|
||||
@@ -58,8 +67,17 @@ export async function ensureUserProfile(sessionUser: UTSJSONObject): Promise<Use
|
||||
.single()
|
||||
.execute()
|
||||
|
||||
console.log('ensureUserProfile insert ak_users:', {
|
||||
status: insertRes.status,
|
||||
hasData: insertRes.data != null,
|
||||
hasError: (insertRes as any).error != null,
|
||||
error: (insertRes as any).error
|
||||
})
|
||||
|
||||
if (insertRes.status >= 200 && insertRes.status < 300 && insertRes.data != null) {
|
||||
const newUser = insertRes.data as UTSJSONObject
|
||||
const newUser = (typeof (insertRes.data as any).getString === 'function')
|
||||
? (insertRes.data as UTSJSONObject)
|
||||
: new UTSJSONObject(insertRes.data as any)
|
||||
return {
|
||||
id: newUser.getString('id') ?? '',
|
||||
username: newUser.getString('username') ?? '',
|
||||
|
||||
@@ -173,3 +173,29 @@ export function setClipboard(text: string): void {
|
||||
// #endif
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间,显示为相对时间(如:刚刚,几小时前)
|
||||
* @param dateStr ISO 格式的日期字符串
|
||||
* @returns 格式化后的相对时间字符串
|
||||
*/
|
||||
export function formatTime(dateStr: string): string {
|
||||
if (!dateStr) return ''
|
||||
try {
|
||||
const date = new Date(dateStr)
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - date.getTime()
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
||||
|
||||
if (hours < 1) {
|
||||
return '刚刚'
|
||||
} else if (hours < 24) {
|
||||
return `${hours}小时前`
|
||||
} else {
|
||||
return `${Math.floor(hours / 24)}天前`
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('formatTime error:', e)
|
||||
return dateStr.replace('T', ' ').split('.')[0]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user