feat(supervisor): allow revoke binding
This commit is contained in:
@@ -148,3 +148,7 @@ export function getSupervisorOverview() {
|
|||||||
export function getSupervisorStatus() {
|
export function getSupervisorStatus() {
|
||||||
return request.request({ url: '/supervisor/status', method: 'GET', baseUrl: BASE_URL_V2 })
|
return request.request({ url: '/supervisor/status', method: 'GET', baseUrl: BASE_URL_V2 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function revokeSupervisorBinding(owner_uid, supervisor_uid) {
|
||||||
|
return request.request({ url: '/supervisor/revoke', method: 'POST', data: { owner_uid, supervisor_uid }, baseUrl: BASE_URL_V2 })
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,6 +57,9 @@
|
|||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
<text class="status">今日:{{ statusText(item.home?.daily_status?.status) }}</text>
|
<text class="status">今日:{{ statusText(item.home?.daily_status?.status) }}</text>
|
||||||
|
<view class="row-actions">
|
||||||
|
<button class="mini-btn" @tap.stop="confirmRevoke(item)">解除监督</button>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -92,9 +95,11 @@
|
|||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { onShow } from '@dcloudio/uni-app'
|
import { onShow } from '@dcloudio/uni-app'
|
||||||
import { useLogin } from '@/hooks/useLogin'
|
import { useLogin } from '@/hooks/useLogin'
|
||||||
import { createSupervisorInvite, getSupervisorOverview, getSupervisorStatus } from '@/api/smoke'
|
import { useUserStore } from '@/stores/user'
|
||||||
|
import { createSupervisorInvite, getSupervisorOverview, getSupervisorStatus, revokeSupervisorBinding } from '@/api/smoke'
|
||||||
|
|
||||||
const { waitForLogin } = useLogin()
|
const { waitForLogin } = useLogin()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const inviteLoading = ref(false)
|
const inviteLoading = ref(false)
|
||||||
@@ -163,6 +168,40 @@ function gotoBindPage() {
|
|||||||
uni.navigateTo({ url: '/pages/supervisor/bind' })
|
uni.navigateTo({ url: '/pages/supervisor/bind' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function confirmRevoke(item) {
|
||||||
|
const ownerUID = item?.owner?.user_id
|
||||||
|
if (!ownerUID) return
|
||||||
|
uni.showModal({
|
||||||
|
title: '解除监督',
|
||||||
|
content: '解除后你将无法再查看对方的戒烟概览。确定要解除吗?',
|
||||||
|
confirmText: '解除',
|
||||||
|
confirmColor: '#b91c1c',
|
||||||
|
success: async (res) => {
|
||||||
|
if (!res.confirm) return
|
||||||
|
await doRevoke(ownerUID)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doRevoke(ownerUID) {
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
const myUID = Number(userStore.user?.id)
|
||||||
|
if (!myUID) {
|
||||||
|
uni.showToast({ title: '登录信息缺失', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await revokeSupervisorBinding(ownerUID, myUID)
|
||||||
|
uni.showToast({ title: '已解除', icon: 'success' })
|
||||||
|
await refreshAll()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('revoke error:', e)
|
||||||
|
uni.showToast({ title: '解除失败', icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function generateInvite() {
|
async function generateInvite() {
|
||||||
if (inviteLoading.value) return
|
if (inviteLoading.value) return
|
||||||
inviteLoading.value = true
|
inviteLoading.value = true
|
||||||
@@ -407,6 +446,24 @@ onShow(async () => {
|
|||||||
color: #64748b;
|
color: #64748b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.row-actions {
|
||||||
|
margin-top: 12rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mini-btn {
|
||||||
|
height: 56rpx;
|
||||||
|
line-height: 56rpx;
|
||||||
|
padding: 0 18rpx;
|
||||||
|
border-radius: 14rpx;
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1rpx solid rgba(185, 28, 28, 0.28);
|
||||||
|
color: #b91c1c;
|
||||||
|
font-size: 22rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
margin-top: 20rpx;
|
margin-top: 20rpx;
|
||||||
padding-bottom: 20rpx;
|
padding-bottom: 20rpx;
|
||||||
@@ -435,4 +492,3 @@ onShow(async () => {
|
|||||||
border: 1rpx solid rgba(15, 118, 110, 0.25);
|
border: 1rpx solid rgba(15, 118, 110, 0.25);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user