feat(admin): 恢复原生登录与业务路由并移除预览顶栏
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<button
|
||||
v-if="!liveNative"
|
||||
class="admin-ui-toggle"
|
||||
type="button"
|
||||
data-admin-ui-toggle
|
||||
@@ -80,6 +81,7 @@ import MultipleTabs from './multiple-tabs.vue'
|
||||
import Refresh from './refresh.vue'
|
||||
import UserDropDown from './user-drop-down.vue'
|
||||
|
||||
const liveNative = import.meta.env.MODE === 'live-native'
|
||||
const appStore = useAppStore()
|
||||
const isMobile = computed(() => appStore.isMobile)
|
||||
const isCollapsed = computed(() => appStore.isCollapsed)
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
title="主题设置"
|
||||
>
|
||||
<div class="h-full flex flex-col">
|
||||
<div v-if="liveNative" class="setting-item mb-5 flex justify-between items-center">
|
||||
<span class="text-tx-secondary">界面样式</span>
|
||||
<el-radio-group v-model="interfaceStyle" size="small" aria-label="界面样式">
|
||||
<el-radio-button value="legacy">经典</el-radio-button>
|
||||
<el-radio-button value="v2">新版</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<div class="setting-item mb-5">
|
||||
<span class="text-tx-secondary">风格设置</span>
|
||||
<div v-if="settingStore.adminUi === 'v2'" class="art-menu-options" role="group" aria-label="菜单风格">
|
||||
@@ -102,7 +109,14 @@ import theme_dark from '@/assets/images/theme_black.png'
|
||||
import theme_light from '@/assets/images/theme_white.png'
|
||||
import useSettingStore, { artMainColors, useAdminDark } from '@/stores/modules/setting'
|
||||
|
||||
const liveNative = import.meta.env.MODE === 'live-native'
|
||||
const settingStore = useSettingStore()
|
||||
const interfaceStyle = computed({
|
||||
get: () => settingStore.adminUi,
|
||||
set(value: 'legacy' | 'v2') {
|
||||
if (value !== settingStore.adminUi) settingStore.toggleAdminUi()
|
||||
}
|
||||
})
|
||||
const predefineColors = computed(() => settingStore.adminUi === 'v2' ? artMainColors :
|
||||
['#409EFF', '#28C76F', '#EA5455', '#FF9F43', '#01CFE8', '#4A5DFF'])
|
||||
const artMenuThemes = [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<template v-if="!route.meta?.hidden">
|
||||
<app-link v-if="!hasShowChild" :to="`${routePath}?${queryStr}`">
|
||||
<app-link v-if="!hasShowChild" :to="menuTarget">
|
||||
<el-menu-item :index="routePath">
|
||||
<icon
|
||||
class="menu-item-icon"
|
||||
@@ -78,6 +78,10 @@ const queryStr = computed<string>(() => {
|
||||
return query
|
||||
}
|
||||
})
|
||||
const menuTarget = computed(() => {
|
||||
const q = String(queryStr.value || '').replace(/^\?/, '')
|
||||
return q ? `${props.routePath}${props.routePath.includes('?') ? '&' : '?'}${q}` : props.routePath
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.el-menu-item,
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'virtual:svg-icons-register'
|
||||
|
||||
import { createApp } from 'vue'
|
||||
|
||||
import { getConfig } from './api/app'
|
||||
import App from './App.vue'
|
||||
import install from './install'
|
||||
|
||||
@@ -12,11 +11,3 @@ const app = createApp(App)
|
||||
|
||||
app.use(install)
|
||||
app.mount('#app')
|
||||
|
||||
getConfig().then((res) => {
|
||||
console.log(
|
||||
`%c likeadmin %c v${res.version} `,
|
||||
'padding: 4px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #bbb; font-weight: bold;',
|
||||
'padding: 4px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #4A5DFF; font-weight: bold;'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -27,17 +27,34 @@ export function filterAsyncRoutes(routes: any[], firstRoute = true) {
|
||||
|
||||
// 创建一条路由记录
|
||||
export function createRouteRecord(route: any, firstRoute: boolean): RouteRecordRaw {
|
||||
const normalizedPath = normalizeMenuPath(route.paths)
|
||||
const remote = isExternal(route.paths)
|
||||
const rawPath = String(route.paths || '')
|
||||
const queryAt = remote ? -1 : rawPath.indexOf('?')
|
||||
const normalizedPath = normalizeMenuPath(queryAt < 0 ? rawPath : rawPath.slice(0, queryAt))
|
||||
let menuParams = route.params
|
||||
if (queryAt !== -1) {
|
||||
// Route patterns never contain the URL query. Some menu records store
|
||||
// it in paths instead of the separate params field. Keep an empty path
|
||||
// empty: it is a valid index child of the parent (e.g. 自录转化统计).
|
||||
const inline = Object.fromEntries(new URLSearchParams(rawPath.slice(queryAt + 1)))
|
||||
let extra: Record<string, unknown> = {}
|
||||
if (typeof menuParams === 'string' && menuParams) {
|
||||
if (menuParams.trim().startsWith('{')) {
|
||||
try { extra = JSON.parse(menuParams) ?? {} } catch { /* ignore malformed menu defaults */ }
|
||||
} else { extra = Object.fromEntries(new URLSearchParams(menuParams)) }
|
||||
}
|
||||
menuParams = JSON.stringify({ ...inline, ...extra })
|
||||
}
|
||||
//@ts-ignore
|
||||
const routeRecord: RouteRecordRaw = {
|
||||
path: isExternal(route.paths) ? route.paths : firstRoute ? `/${normalizedPath}` : normalizedPath,
|
||||
path: remote ? route.paths : firstRoute ? `/${normalizedPath}` : normalizedPath,
|
||||
name: Symbol(route.paths),
|
||||
meta: {
|
||||
hidden: !route.is_show,
|
||||
keepAlive: !!route.is_cache,
|
||||
title: route.name,
|
||||
perms: route.perms,
|
||||
query: route.params,
|
||||
query: menuParams,
|
||||
icon: route.icon,
|
||||
type: route.type,
|
||||
activeMenu: route.selected
|
||||
|
||||
@@ -32,7 +32,8 @@ const artDefaults = {
|
||||
function initialAppearance() {
|
||||
const root = document.documentElement
|
||||
const preview = root.dataset.adminUi === 'v2'
|
||||
const mode: AdminUi = preview || cache.get(APPEARANCE_KEY) === 'v2' ? 'v2' : 'legacy'
|
||||
const stored = cache.get(APPEARANCE_KEY)
|
||||
const mode: AdminUi = preview || stored === 'v2' || (stored !== 'legacy' && root.dataset.defaultAdminUi === 'v2') ? 'v2' : 'legacy'
|
||||
root.dataset.adminUi = mode
|
||||
return { preview, mode }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,12 @@
|
||||
根据安全策略,需绑定企业微信账号后方可使用管理后台
|
||||
</div>
|
||||
|
||||
<div v-if="wxWorkAutoAuth" class="text-center py-10">
|
||||
<div v-if="liveNative" class="text-center">
|
||||
<a class="el-button el-button--primary" href="https://admin.zhenyangtang.com.cn/admin/bind-work-wechat" target="_blank" rel="noopener noreferrer">在正式后台绑定企业微信 ↗</a>
|
||||
<p class="mt-3 text-sm">绑定完成后返回这里刷新,系统会重新核对账号状态。</p>
|
||||
<el-button class="mt-3" @click="recheckBinding">重新核对绑定状态</el-button>
|
||||
</div>
|
||||
<div v-else-if="wxWorkAutoAuth" class="text-center py-10">
|
||||
<el-icon class="is-loading mb-4" :size="40" color="var(--el-color-primary)">
|
||||
<Loading />
|
||||
</el-icon>
|
||||
@@ -78,6 +83,15 @@ function getOAuthQuery(): URLSearchParams {
|
||||
return merged
|
||||
}
|
||||
|
||||
const liveNative = import.meta.env.MODE === 'live-native'
|
||||
async function recheckBinding() {
|
||||
try {
|
||||
await userStore.getUserInfo()
|
||||
const flag = userStore.userInfo.need_bind_work_wechat
|
||||
if ([false,0,'0'].includes(flag)) await router.replace(userStore.isPaw === 0 ? '/change-password' : '/')
|
||||
else ElMessage.info('正式后台尚未确认绑定,请先完成企业微信绑定。')
|
||||
} catch { ElMessage.info('请重新登录以核对绑定状态。') }
|
||||
}
|
||||
const handleLogout = () => {
|
||||
userStore.logout()
|
||||
}
|
||||
@@ -140,6 +154,7 @@ const renderQr = async () => {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (liveNative) return // 绑定回调仅由已经登记的正式域名处理。
|
||||
// 与 axios 拦截器竞态:首屏若有请求先返回 10,可能在 onMounted 执行前就 router.replace 清掉 query;同步快照尽量早读
|
||||
let oauthCodeSnapshot = ''
|
||||
try {
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
<div class="flex-1 flex items-center justify-center">
|
||||
<div class="login-card flex rounded-md overflow-hidden">
|
||||
<div class="flex-1 h-full hidden md:inline-block">
|
||||
<div v-if="liveReadonly" class="live-login-note"><strong>正式数据 · 只读预览</strong><p>这是本机运行的甄养堂管理后台。账号密码由浏览器直接通过 HTTPS 提交到正式后台,本机服务只提供页面文件。</p><code>admin.zhenyangtang.com.cn</code><p>仅支持已开通的账号密码登录。企业微信、统一登录、首次改密和账号绑定请在正式站点完成。</p><a href="https://admin.zhenyangtang.com.cn/admin/" target="_blank" rel="noopener noreferrer">打开正式后台 ↗</a></div>
|
||||
<image-contain v-else :src="config.login_image" :width="400" height="100%" />
|
||||
<image-contain :src="config.login_image" :width="400" height="100%" />
|
||||
</div>
|
||||
<div
|
||||
class="login-form bg-body flex flex-col justify-center px-10 py-10 md:w-[420px] w-[380px] flex-none mx-auto"
|
||||
@@ -30,7 +29,6 @@
|
||||
|
||||
<!-- 账号密码登录 -->
|
||||
<template v-if="loginMode === 'account'">
|
||||
<p v-if="liveReadonly" class="live-login-destination">正式账号登录 · 仅查询<br><span>密码直发 admin.zhenyangtang.com.cn,不经本机代理。</span></p>
|
||||
<el-form ref="formRef" :model="formData" size="large" :rules="rules">
|
||||
<el-form-item prop="account">
|
||||
<el-input
|
||||
@@ -65,7 +63,7 @@
|
||||
v-model="formData.password"
|
||||
show-password
|
||||
placeholder="请输入密码"
|
||||
@keyup.enter="liveReadonly ? lockLogin() : handleLogin()"
|
||||
@keyup.enter="handleLogin"
|
||||
>
|
||||
<template #prepend>
|
||||
<icon name="el-icon-Lock" size="16" />
|
||||
@@ -73,7 +71,7 @@
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div v-if="!liveReadonly" class="mb-5">
|
||||
<div class="mb-5">
|
||||
<el-checkbox v-model="remAccount" label="记住账号"></el-checkbox>
|
||||
</div>
|
||||
<el-button type="primary" size="large" :loading="isLock" @click="lockLogin">
|
||||
@@ -83,7 +81,11 @@
|
||||
|
||||
<!-- 企业微信扫码登录(非企业微信内浏览器) -->
|
||||
<template v-if="loginMode === 'wxwork'">
|
||||
<div class="wxwork-qrcode-wrap">
|
||||
<div v-if="liveNative" class="wxwork-native-entry">
|
||||
<a class="el-button el-button--primary" :href="officialQrHref" target="_blank" rel="noopener noreferrer" referrerpolicy="no-referrer">企业微信扫码登录 ↗</a>
|
||||
<p>二维码在企业微信页面打开;扫码后进入正式后台。</p>
|
||||
</div>
|
||||
<div v-else class="wxwork-qrcode-wrap">
|
||||
<div v-if="wxWorkLoading" class="text-center py-10">
|
||||
<el-icon class="is-loading" :size="32" color="var(--el-color-primary)">
|
||||
<Loading />
|
||||
@@ -92,7 +94,7 @@
|
||||
</div>
|
||||
<div v-else id="wxwork_qrcode_container" class="wxwork-qrcode"></div>
|
||||
</div>
|
||||
<div class="text-center text-sm text-gray-400 mt-4">
|
||||
<div v-if="!liveNative" class="text-center text-sm text-gray-400 mt-4">
|
||||
请使用企业微信扫描二维码登录
|
||||
</div>
|
||||
</template>
|
||||
@@ -108,7 +110,7 @@
|
||||
<icon name="el-icon-ArrowRight" size="16" />
|
||||
</span>
|
||||
</el-button>
|
||||
<p class="iam-login-hint">使用统一身份平台账号登录</p>
|
||||
<p class="iam-login-hint">{{ liveNative ? '使用统一身份平台账号登录正式后台' : '使用统一身份平台账号登录' }}</p>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
@@ -133,7 +135,8 @@ import useUserStore from '@/stores/modules/user'
|
||||
import cache from '@/utils/cache'
|
||||
import { getIamConfig, getWorkWechatConfig } from '@/api/user'
|
||||
|
||||
const liveReadonly = import.meta.env.MODE === 'live-readonly'
|
||||
const liveNative = import.meta.env.MODE === 'live-native'
|
||||
const officialLogin = 'https://admin.zhenyangtang.com.cn/admin/login'
|
||||
const passwordRef = shallowRef<InputInstance>()
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const appStore = useAppStore()
|
||||
@@ -163,7 +166,7 @@ const loadIamConfig = async () => {
|
||||
try {
|
||||
const result = await getIamConfig()
|
||||
const url = new URL(result?.loginUrl || '', window.location.origin)
|
||||
if (result?.enabled === true && url.protocol === 'https:') {
|
||||
if (result?.enabled === true && url.protocol === 'https:' && (!liveNative || (url.origin === new URL(officialLogin).origin && url.pathname === '/adminapi/iam/start'))) {
|
||||
iamLoginUrl.value = url.href
|
||||
iamEnabled.value = true
|
||||
}
|
||||
@@ -174,7 +177,8 @@ const loadIamConfig = async () => {
|
||||
|
||||
const handleIamLogin = () => {
|
||||
if (iamEnabled.value && iamLoginUrl.value) {
|
||||
window.location.assign(iamLoginUrl.value)
|
||||
if (liveNative) window.open(iamLoginUrl.value, '_blank', 'noopener,noreferrer')
|
||||
else window.location.assign(iamLoginUrl.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,27 +227,29 @@ const wxWorkLoading = ref(false)
|
||||
const isInWxWork = () => /wxwork/i.test(navigator.userAgent)
|
||||
|
||||
const getRedirectUri = () => {
|
||||
if (liveNative) return officialLogin
|
||||
return window.location.origin + window.location.pathname
|
||||
}
|
||||
|
||||
// This origin is not a registered enterprise OAuth callback. A top-level
|
||||
// provider flow keeps codes/tickets at the original authorized production page.
|
||||
const officialQrHref = computed(() => {
|
||||
const {corp_id, agent_id} = wxWorkConfig.value
|
||||
if (!corp_id || !agent_id) return officialLogin
|
||||
const url = new URL('https://open.work.weixin.qq.com/wwopen/sso/qrConnect')
|
||||
url.search = new URLSearchParams({appid: corp_id, agentid: String(agent_id), redirect_uri: officialLogin, state: 'admin_login', lang: 'zh'}).toString()
|
||||
return url.href
|
||||
})
|
||||
|
||||
const handleEnter = () => {
|
||||
if (!formData.password) {
|
||||
return passwordRef.value?.focus()
|
||||
}
|
||||
if (liveReadonly) void lockLogin()
|
||||
else handleLogin()
|
||||
handleLogin()
|
||||
}
|
||||
|
||||
const handleLogin = async () => {
|
||||
await formRef.value?.validate()
|
||||
if (liveReadonly) {
|
||||
try {
|
||||
await userStore.login({account: formData.account.trim(), password: formData.password})
|
||||
await router.replace('/')
|
||||
} catch (e) { ElMessage.error(e instanceof Error ? e.message : '登录未完成') }
|
||||
finally { formData.password = '' }
|
||||
return
|
||||
}
|
||||
const result: any = await userStore.login(formData)
|
||||
const account = formData.account.trim()
|
||||
const others = rememberedAccounts.value.filter((saved) => saved !== account)
|
||||
@@ -336,7 +342,7 @@ const renderWxWorkQRCode = async () => {
|
||||
|
||||
// 切换到企业微信扫码时自动渲染
|
||||
watch(loginMode, (val) => {
|
||||
if (val === 'wxwork') {
|
||||
if (val === 'wxwork' && !liveNative) {
|
||||
nextTick(() => renderWxWorkQRCode())
|
||||
}
|
||||
})
|
||||
@@ -349,7 +355,6 @@ function selectRememberedAccount(account: string) {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (liveReadonly) return
|
||||
// 恢复记住账号
|
||||
const value = cache.get(ACCOUNT_KEY)
|
||||
const saved: unknown[] = Array.isArray(value?.accounts) ? value.accounts : value?.remember ? [value.account] : []
|
||||
@@ -363,11 +368,11 @@ onMounted(async () => {
|
||||
// 检查 URL 中是否有企业微信回调 code
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
void loadIamConfig()
|
||||
const hasIamCallback = urlParams.has('iam_ticket') || urlParams.has('iam_error')
|
||||
const hasIamCallback = !liveNative && (urlParams.has('iam_ticket') || urlParams.has('iam_error'))
|
||||
if (hasIamCallback) {
|
||||
await handleIamCallback(urlParams.get('iam_ticket'), urlParams.get('iam_error'))
|
||||
}
|
||||
const wxCode = hasIamCallback ? null : urlParams.get('code')
|
||||
const wxCode = hasIamCallback || liveNative ? null : urlParams.get('code')
|
||||
const wxState = urlParams.get('state')
|
||||
|
||||
if (wxCode && wxState === 'admin_login') {
|
||||
@@ -387,7 +392,7 @@ onMounted(async () => {
|
||||
wxWorkConfig.value = { corp_id: res.corp_id, agent_id: res.agent_id }
|
||||
|
||||
// 在企业微信内:自动跳转 OAuth 授权
|
||||
if (isInWxWork() && !hasIamCallback && !switchingAccount.value) {
|
||||
if (!liveNative && isInWxWork() && !hasIamCallback && !switchingAccount.value) {
|
||||
const redirectUri = encodeURIComponent(getRedirectUri())
|
||||
const authUrl =
|
||||
`https://open.weixin.qq.com/connect/oauth2/authorize` +
|
||||
@@ -495,6 +500,8 @@ onMounted(async () => {
|
||||
}
|
||||
}
|
||||
|
||||
.wxwork-native-entry { min-height: 145px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
|
||||
.wxwork-native-entry p { color: var(--el-text-color-secondary); font-size: 13px; }
|
||||
.wxwork-qrcode-wrap {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
@@ -514,7 +521,3 @@ onMounted(async () => {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
.live-login-note{width:330px;min-height:100%;padding:44px 32px;display:flex;flex-direction:column;justify-content:center;gap:17px;background:var(--el-color-primary-light-9);color:var(--el-text-color-regular);font-size:14px;line-height:1.75}.live-login-note strong{font-size:22px;color:var(--el-text-color-primary)}.live-login-note code,.live-login-note a{color:var(--el-color-primary)}.live-login-destination{font-size:14px;margin:0 0 18px}.live-login-destination span{font-size:12px;color:var(--el-text-color-secondary)}
|
||||
</style>
|
||||
|
||||
@@ -189,6 +189,10 @@ const getBindRedirectUri = () => {
|
||||
|
||||
// 打开绑定弹窗,渲染扫码
|
||||
const showBindDialog = async () => {
|
||||
if (import.meta.env.MODE === 'live-native') {
|
||||
window.open('https://admin.zhenyangtang.com.cn/admin/user/setting', '_blank', 'noopener,noreferrer')
|
||||
return
|
||||
}
|
||||
bindDialogVisible.value = true
|
||||
bindLoading.value = true
|
||||
|
||||
@@ -276,6 +280,7 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
// 检查是否是绑定回调
|
||||
if (import.meta.env.MODE === 'live-native') return // 本机不接收正式企微绑定回调。
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const bindCode = urlParams.get('code')
|
||||
const state = urlParams.get('state')
|
||||
|
||||
Reference in New Issue
Block a user