完成consumer端同步
This commit is contained in:
@@ -206,9 +206,10 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onBackPress } from '@dcloudio/uni-app'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { goToLogin } from '@/utils/utils.uts'
|
||||
|
||||
// 拦截返回事件,强制跳转到个人中心页
|
||||
onBackPress((options) => {
|
||||
onBackPress((_options): boolean => {
|
||||
// 无论是什么触发的返回(系统返回键或导航栏返回按钮),都跳转到profile
|
||||
// 注意:onBackPress 只能在 page 中使用,component 中无效
|
||||
uni.switchTab({
|
||||
@@ -328,6 +329,13 @@ const goToProfile = () => {
|
||||
|
||||
// 跳转到地址管理
|
||||
const goToAddressList = () => {
|
||||
const userId = userInfo.value.id != null && userInfo.value.id !== ''
|
||||
? userInfo.value.id
|
||||
: ((uni.getStorageSync('user_id') as string | null) ?? '')
|
||||
if (userId === '') {
|
||||
goToLogin('/pages/mall/consumer/address-list')
|
||||
return
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/consumer/address-list'
|
||||
})
|
||||
@@ -484,6 +492,13 @@ const checkUpdate = () => {
|
||||
|
||||
// 联系客服
|
||||
const contactService = () => {
|
||||
const userId = userInfo.value.id != null && userInfo.value.id !== ''
|
||||
? userInfo.value.id
|
||||
: ((uni.getStorageSync('user_id') as string | null) ?? '')
|
||||
if (userId === '') {
|
||||
goToLogin('/pages/mall/consumer/settings')
|
||||
return
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: '/pages/mall/consumer/chat'
|
||||
})
|
||||
@@ -505,6 +520,74 @@ const rateApp = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const doLogout = (): void => {
|
||||
uni.showLoading({
|
||||
title: '正在退出...'
|
||||
})
|
||||
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('access_token')
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '已退出登录',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const getStoredUserId = (): string => {
|
||||
if (userInfo.value.id != null && userInfo.value.id !== '') {
|
||||
return userInfo.value.id
|
||||
}
|
||||
const storageId = uni.getStorageSync('user_id')
|
||||
if (storageId != null) {
|
||||
return storageId as string
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const doDeleteAccount = (): void => {
|
||||
uni.showLoading({
|
||||
title: '注销中...'
|
||||
})
|
||||
|
||||
const userId = getStoredUserId()
|
||||
if (userId != '') {
|
||||
const updateObj: UTSJSONObject = new UTSJSONObject()
|
||||
updateObj.set('status', 3)
|
||||
supa
|
||||
.from('ml_user_profiles')
|
||||
.update(updateObj)
|
||||
.eq('user_id', userId)
|
||||
.execute()
|
||||
}
|
||||
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('access_token')
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '账号已注销',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
const logout = () => {
|
||||
uni.showModal({
|
||||
@@ -512,26 +595,7 @@ const logout = () => {
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({
|
||||
title: '正在退出...'
|
||||
})
|
||||
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('access_token')
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '已退出登录',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1000)
|
||||
doLogout()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -544,42 +608,7 @@ const deleteAccount = () => {
|
||||
confirmColor: '#ff4757',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({
|
||||
title: '注销中...'
|
||||
})
|
||||
|
||||
let userId: string | null = userInfo.value.id
|
||||
if (userId == null || userId === '') {
|
||||
const storageId = uni.getStorageSync('user_id')
|
||||
userId = (storageId != null) ? storageId as string : null
|
||||
}
|
||||
|
||||
if (userId != null) {
|
||||
const updateObj: UTSJSONObject = new UTSJSONObject()
|
||||
updateObj.set('status', 3)
|
||||
supa
|
||||
.from('ml_user_profiles')
|
||||
.update(updateObj)
|
||||
.eq('user_id', userId)
|
||||
.execute()
|
||||
}
|
||||
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('user_id')
|
||||
uni.removeStorageSync('access_token')
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '账号已注销',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login'
|
||||
})
|
||||
}, 1500)
|
||||
doDeleteAccount()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user