This commit is contained in:
@@ -234,6 +234,13 @@ export const authApi = {
|
||||
}
|
||||
}
|
||||
|
||||
export interface AgreementPending {
|
||||
pending: boolean | null
|
||||
currentVersions: Record<string, string>
|
||||
acceptedVersions: Record<string, string>
|
||||
pendingTypes: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: legalAgreementApi supports auth.ts by holding or executing the legal agreement api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
@@ -247,5 +254,13 @@ export const legalAgreementApi = {
|
||||
},
|
||||
getMyConsent: () => {
|
||||
return api.get<{ consentVersions: Record<string, string> }>('/user/agreement-consent/me')
|
||||
},
|
||||
getPending: () => {
|
||||
return api.get<AgreementPending>('/legal-agreement/pending')
|
||||
},
|
||||
accept: (clientType = 'WEB') => {
|
||||
return api.post<AgreementPending>('/legal-agreement/accept', null, {
|
||||
params: { clientType }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { IdType } from '@/utils/id'
|
||||
import { clearAdminSessionStorage } from '@/utils/admin-session'
|
||||
import { attachRequestSignature } from '@/utils/request-signature'
|
||||
import { isApiAuthFreePath } from './auth-free-paths'
|
||||
import { isAgreementPending } from '../utils/agreement-gate'
|
||||
import {
|
||||
getApiResponseMessage,
|
||||
isPermissionErrorMessage,
|
||||
@@ -77,6 +78,18 @@ const getStoredAccessToken = (isAdmin = false) => {
|
||||
: (localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))
|
||||
}
|
||||
|
||||
/**
|
||||
* 协议门禁接口在后台登录态下也需要使用管理员 token;其余沿用原有 admin 路径判断。
|
||||
*/
|
||||
const isAdminScopedUrl = (url?: string) => {
|
||||
if (!url) return false
|
||||
if (url.includes('/admin/') || url.includes('/order/admin/')) return true
|
||||
const hasAdminToken = Boolean(localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken'))
|
||||
return hasAdminToken && (url.includes('/legal-agreement/pending') || url.includes('/legal-agreement/accept'))
|
||||
}
|
||||
|
||||
const AGREEMENT_GATE_ALLOWLIST = ['/legal-agreement/', '/admin/auth/', '/user/logout', '/user/info']
|
||||
|
||||
/**
|
||||
* Purpose: getStoredRefreshToken supports index.ts by holding or executing the get stored refresh token page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
@@ -238,7 +251,11 @@ const handleTokenExpired = (isAdmin = false, failedToken: string | null = null)
|
||||
|
||||
api.interceptors.request.use(
|
||||
async config => {
|
||||
const isAdminRequest = config.url?.includes('/admin/') || config.url?.includes('/order/admin/')
|
||||
if (isAgreementPending() && !AGREEMENT_GATE_ALLOWLIST.some(path => config.url?.includes(path))) {
|
||||
return Promise.reject(new Error('请先阅读并同意最新版用户协议与隐私政策'))
|
||||
}
|
||||
|
||||
const isAdminRequest = isAdminScopedUrl(config.url)
|
||||
let token = isAdminRequest
|
||||
? (localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken'))
|
||||
: (localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken'))
|
||||
@@ -286,7 +303,7 @@ api.interceptors.response.use(
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
// 检查是否是后台管理的API请求
|
||||
const isAdminRequest = originalRequest.url?.includes('/admin/') || originalRequest.url?.includes('/order/admin/')
|
||||
const isAdminRequest = isAdminScopedUrl(originalRequest.url)
|
||||
const requestToken = getRequestToken(originalRequest)
|
||||
const isRealTokenExpired = isTokenExpiredResponse(error, requestToken)
|
||||
|
||||
|
||||
@@ -278,9 +278,13 @@ export const userApi = {
|
||||
/**
|
||||
* 后台管理员按预约/订单上下文单次取号,号码不入库、不缓存。
|
||||
*/
|
||||
dialCustomer: async (customerId: IdType, orderId: IdType): Promise<CustomerDialResult> => {
|
||||
return await api.post<CustomerDialResult>(`/manager/customers/${customerId}/dial`, null, {
|
||||
params: { orderId }
|
||||
dialCustomer: async (params: { customerId?: IdType; appointmentId?: IdType; orderId?: IdType }): Promise<CustomerDialResult> => {
|
||||
return await api.post<CustomerDialResult>('/manager/customers/dial', null, {
|
||||
params: {
|
||||
customerId: params.customerId || undefined,
|
||||
appointmentId: params.appointmentId || undefined,
|
||||
orderId: params.orderId || undefined
|
||||
}
|
||||
}) as unknown as CustomerDialResult
|
||||
},
|
||||
getUserInfo: async (): Promise<UserVO> => {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 协议同意门禁状态:登录后检测到未同意的新版本时置位,
|
||||
* 请求层据此拦截非协议类业务请求,避免用户绕过弹层继续操作。
|
||||
*/
|
||||
let agreementPending = false
|
||||
|
||||
export const setAgreementPending = (value: boolean) => {
|
||||
agreementPending = value
|
||||
}
|
||||
|
||||
export const isAgreementPending = () => agreementPending
|
||||
@@ -68,7 +68,7 @@
|
||||
<span>预约用户:{{ order.customerNickname || '用户' }}</span>
|
||||
<span v-if="order.customerPhoneMasked">联系电话:{{ order.customerPhoneMasked }}</span>
|
||||
<a-button
|
||||
v-if="order.customerPhoneMasked && order.userId"
|
||||
v-if="order.customerPhoneMasked"
|
||||
size="small"
|
||||
type="link"
|
||||
:loading="dialingOrderId === order.id"
|
||||
@@ -667,15 +667,18 @@ const confirmQuote = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 按订单上下文单次取号后发起拨号,号码不落库、不缓存。 */
|
||||
/** 按订单上下文单次取号后发起拨号,号码不落库、不缓存;散客无 userId 时仅用订单定位。 */
|
||||
const dialCustomer = async (order: any) => {
|
||||
if (!order?.userId || !order?.id) {
|
||||
if (!order?.id) {
|
||||
message.warning('缺少订单上下文,无法取号')
|
||||
return
|
||||
}
|
||||
dialingOrderId.value = order.id
|
||||
try {
|
||||
const result = await userApi.dialCustomer(order.userId, order.id)
|
||||
const result = await userApi.dialCustomer({
|
||||
customerId: order.userId || undefined,
|
||||
orderId: order.id
|
||||
})
|
||||
if (!result?.dialNumber) {
|
||||
throw new Error('未获取到可拨打号码')
|
||||
}
|
||||
|
||||
@@ -70,6 +70,25 @@
|
||||
</a-button>
|
||||
</div>
|
||||
</a-drawer>
|
||||
|
||||
<a-modal
|
||||
v-model:open="agreementModalOpen"
|
||||
title="用户协议与隐私政策已更新"
|
||||
:closable="false"
|
||||
:maskClosable="false"
|
||||
:keyboard="false"
|
||||
:footer="null"
|
||||
>
|
||||
<div class="agreement-gate">
|
||||
<p>新版本{{ agreementVersionText ? `(${agreementVersionText})` : '' }}已发布,请阅读并同意后继续使用后台。</p>
|
||||
<p class="agreement-gate__links">
|
||||
<a href="/legal/user-terms.html" target="_blank" rel="noopener">查看用户协议</a>
|
||||
<span> · </span>
|
||||
<a href="/legal/privacy-policy.html" target="_blank" rel="noopener">查看隐私政策</a>
|
||||
</p>
|
||||
<a-button type="primary" block :loading="agreementAccepting" @click="acceptAgreements">同意并继续</a-button>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -84,6 +103,8 @@ import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { completeAdminLogout } from '@/utils/admin-logout'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import { legalAgreementApi, type AgreementPending } from '@/api/auth'
|
||||
import { setAgreementPending } from '@/utils/agreement-gate'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -92,6 +113,9 @@ const collapsed = ref(false)
|
||||
const mobileDrawerOpen = ref(false)
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
const userInfo = ref<any>(null)
|
||||
const agreementModalOpen = ref(false)
|
||||
const agreementAccepting = ref(false)
|
||||
const agreementVersionText = ref('')
|
||||
const iconMap: Record<AdminNavIconKey, Component> = { home: HomeOutlined, user: UserOutlined, shop: HomeOutlined, security: SafetyCertificateOutlined, tool: ToolOutlined, team: TeamOutlined, dashboard: HomeOutlined, gift: HomeOutlined, message: HomeOutlined, tag: HomeOutlined, shopping: HomeOutlined, calendar: HomeOutlined }
|
||||
const menuItems = adminNavigationItems.map(item => ({ key: item.path, label: item.label, icon: iconMap[item.iconKey] }))
|
||||
|
||||
@@ -99,9 +123,43 @@ const handleMenuClick = ({ key }: { key: string | number }) => router.push(Strin
|
||||
const openMobileMenu = ({ key }: { key: string | number }) => { mobileDrawerOpen.value = false; router.push(String(key)) }
|
||||
const handleLogout = () => Modal.confirm({ title: '确认退出登录', content: '退出后需要重新登录后台。', okText: '确认', cancelText: '取消', onOk: async () => { await runWithGlobalLoading(() => completeAdminLogout(router)); message.success('已退出登录') } })
|
||||
|
||||
const checkAgreementGate = async () => {
|
||||
try {
|
||||
const result = await legalAgreementApi.getPending() as unknown as AgreementPending
|
||||
if (result?.pending) {
|
||||
agreementVersionText.value = result.currentVersions?.USER_TERMS || ''
|
||||
setAgreementPending(true)
|
||||
agreementModalOpen.value = true
|
||||
} else {
|
||||
setAgreementPending(false)
|
||||
}
|
||||
} catch (error) {
|
||||
// 查询失败不阻塞后台使用,协议接口仍由服务端登录态校验保护
|
||||
}
|
||||
}
|
||||
|
||||
const acceptAgreements = async () => {
|
||||
if (agreementAccepting.value) return
|
||||
agreementAccepting.value = true
|
||||
try {
|
||||
const result = await legalAgreementApi.accept('WEB') as unknown as AgreementPending
|
||||
if (result?.pending === true) {
|
||||
throw new Error('协议同意状态未更新,请稍后重试')
|
||||
}
|
||||
setAgreementPending(false)
|
||||
agreementModalOpen.value = false
|
||||
message.success('已同意最新版协议')
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '同意协议失败')
|
||||
} finally {
|
||||
agreementAccepting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => route.path, path => { selectedKeys.value = [path] }, { immediate: true })
|
||||
onMounted(() => {
|
||||
try { userInfo.value = JSON.parse(localStorage.getItem('adminUserInfo') || 'null') } catch { userInfo.value = null }
|
||||
checkAgreementGate()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -419,6 +477,22 @@ onMounted(() => {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.agreement-gate {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
color: #315650;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.agreement-gate p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.agreement-gate__links a {
|
||||
color: var(--theme-primary-action);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.header,
|
||||
.content {
|
||||
|
||||
Reference in New Issue
Block a user