更新若干

This commit is contained in:
hero920103 committed 2026-11-17 17:16:02 +08:00
1 parent 54c90072fb
commit 5682069553
59 files changed
+3813 -1617

No files matched your search

+126 -206
View File
@@ -7,7 +7,7 @@
<text class="head-title">工作台</text>
</view>
<view v-if="!guest" class="account-chip" @tap="goProfile"><FaIcon name="user" color="#3478f6" :size="15" /><text>{{ user.name || user.nickname || '未设置姓名' }}</text></view>
<button v-else class="account-chip account-chip-button" open-type="getPhoneNumber" @getphonenumber="onCardPhone($event)"><FaIcon name="user" color="#3478f6" :size="15" /><text>游客</text></button>
<view v-else class="account-chip" @tap="goLogin"><FaIcon name="user" color="#3478f6" :size="15" /><text>登录 / 注册</text></view>
</view>
<view v-if="!guest" class="tenant-switch" @tap="chooseTenant">
<view class="tenant-mark"><FaIcon name="building" color="#ffffff" :size="19" /></view>
@@ -32,26 +32,8 @@
</view>
<view v-else class="grid">
<!-- #ifdef MP-WEIXIN -->
<button
v-for="card in cards"
v-show="guest"
:key="'phone-' + (card.code || card.id)"
class="cell cell-button"
open-type="getPhoneNumber"
@getphonenumber="onCardPhone($event, card)"
>
<view class="portal-card" :class="{ locked: card.locked }">
<view class="tint-icon portal-icon" :class="card.tint">
<FaIcon :name="card.icon" color="#ffffff" :size="26" />
</view>
<text class="portal-name">{{ card.name }}</text>
</view>
</button>
<!-- #endif -->
<view
v-for="card in cards"
v-show="!guest || !isMp"
:key="card.code || card.id"
class="cell"
@tap="enter(card)"
@@ -61,6 +43,7 @@
<FaIcon :name="card.icon" color="#ffffff" :size="26" />
</view>
<text class="portal-name">{{ card.name }}</text>
<text v-if="card.locked" class="portal-lock-tag">登录后可体验</text>
</view>
</view>
</view>
@@ -115,6 +98,19 @@
</view>
</view>
</view>
<view v-if="guestLoginVisible" class="guest-login-mask" @tap="closeGuestLogin">
<view class="guest-login-card" @tap.stop>
<view class="guest-login-icon"><FaIcon name="lock" color="#2563eb" :size="24" /></view>
<text class="guest-login-title">{{ guestLoginTitle }}</text>
<text class="guest-login-desc">该功能需要登录企业账号后使用,您也可以继续以游客身份浏览公开功能。</text>
<button class="guest-login-btn" @tap="goLogin">
<FaIcon name="user" color="#ffffff" :size="18" />
<text>登录 / 注册</text>
</button>
<view class="guest-login-cancel" @tap="closeGuestLogin"><text>暂不登录</text></view>
</view>
</view>
</view>
</template>
@@ -127,36 +123,22 @@ import { onShow } from '@dcloudio/uni-app'
import { isLoggedIn, getTenants, getTid, setAuthTokens, setTenants, setTid, setTenantName, getUser, setUser } from '@/utils/auth.js'
import { switchTenant, loginByMiniapp } from '@/api/auth.js'
import { fetchHome, fetchPublicModules, fetchPublicMenus, clearHomeCache } from '@/api/workspace.js'
import { onboardingPhone, getOnboardingStatus } from '@/api/onboarding.js'
import { setPendingCard, takePendingCard } from '@/utils/onboarding.js'
import { getOnboardingStatus } from '@/api/onboarding.js'
import { openMenu } from '@/utils/nav.js'
import { getSubsystemByModule, goSubsystem } from '@/config/subsystems.js'
import { getGuestToken, setGuestToken, clearGuestToken } from '@/utils/guest.js'
import { guestMiniLogin, guestMerge } from '@/api/guest.js'
import { getGuestToken, clearGuestToken } from '@/utils/guest.js'
import { guestMerge } from '@/api/guest.js'
const guestAuthVisible = ref(false)
const guestAuthLoading = ref(false)
const guestAuthDismissed = ref(false)
const phoneBusy = ref(false)
let isMp = false
// #ifdef MP-WEIXIN
isMp = true
// #endif
const guestLoginVisible = ref(false)
const guestLoginTitle = ref('登录后可体验')
function canRequestGuestPhone() {
// #ifdef MP-WEIXIN
return true
// #endif
// eslint-disable-next-line no-unreachable
return false
function openGuestLogin(name) {
guestLoginTitle.value = name ? '「' + name + '」登录后可体验' : '登录后可体验'
guestLoginVisible.value = true
}
function maybeAskGuestAuth() {
if (!guest.value || getGuestToken() || guestAuthDismissed.value || !canRequestGuestPhone()) {
guestAuthVisible.value = false
return
}
guestAuthVisible.value = true
function closeGuestLogin() {
guestLoginVisible.value = false
}
function navUniLoginCode() {
@@ -169,58 +151,6 @@ function navUniLoginCode() {
})
}
async function onGuestPhone(e) {
const detail = (e && e.detail) || {}
if (String(detail.errMsg || '').indexOf('ok') === -1 || !detail.code) {
uni.showToast({ title: '未获取到手机号,请重试', icon: 'none' })
return
}
if (guestAuthLoading.value) return
guestAuthLoading.value = true
try {
const code = await navUniLoginCode()
let appid = ''
try {
appid = (uni.getAccountInfoSync().miniProgram || {}).appId || ''
} catch (err) {
appid = ''
}
const res = await guestMiniLogin({ code, phoneCode: detail.code, appid })
if (res && res.type === 'user') {
guestAuthVisible.value = false
await completeUserLogin(res)
return
}
if (!res || !res.token) throw new Error('未返回游客令牌')
setGuestToken(res.token)
guestAuthVisible.value = false
uni.showToast({ title: '验证成功,数据可保存了', icon: 'none' })
} catch (err) {
console.error('[nav] guest mini-login failed:', err)
uni.showToast({ title: (err && err.message) || '验证失败,请重试', icon: 'none' })
} finally {
guestAuthLoading.value = false
}
}
async function completeUserLogin(res) {
const list = Array.isArray(res.tenants) ? res.tenants : []
setAuthTokens(res.tokens || {})
if (res.need_choose_tenant && list.length > 1) {
askChooseTenant(list)
return
}
const t0 = list[0] || {}
setTenants(list)
if (t0.tid) {
setTid(t0.tid)
setTenantName(t0.tenant_name || '')
}
await mergeGuestIfAny()
await load(true)
uni.showToast({ title: '已登录,欢迎回来', icon: 'none' })
}
const tenantPickerVisible = ref(false)
const tenantPickerRequired = ref(false)
const tenantPickerMode = ref('login')
@@ -294,11 +224,6 @@ async function pickTenant(item) {
}
}
function skipGuestAuth() {
guestAuthDismissed.value = true
guestAuthVisible.value = false
}
async function mergeGuestIfAny() {
if (!getGuestToken()) return
try {
@@ -343,18 +268,19 @@ const leafMenus = computed(() => menus.value.filter((m) => m.leaf !== false && !
const cards = computed(() => {
if (guest.value) {
return publicModules.value.map((mod, index) => {
const code = String(mod.code || '').toLowerCase()
const needTenant = mod.require_login !== 0
return {
return publicModules.value.map((mod, index) => {
const code = String(mod.code || '').toLowerCase()
const needTenant = mod.require_login !== 0
const locked = needTenant
return {
id: mod.id,
code: mod.code,
path: mod.path || '',
name: mod.name || '未命名系统',
desc: mod.description || (needTenant ? '加入企业后可用' : '可直接使用'),
desc: locked ? '登录后可体验完整功能' : (mod.description || '可直接使用'),
icon: MODULE_ICONS[code] || 'cube',
tint: 'tint-' + (index % 8),
locked: false,
locked,
needTenant,
items: [],
total: 0
@@ -429,6 +355,11 @@ function goProfile() {
uni.navigateTo({ url: '/pages/profile/profile' })
}
function goLogin() {
closeGuestLogin()
uni.navigateTo({ url: '/pages/login/login' })
}
function chooseTenant() {
const list = tenants.value
if (list.length <= 1) { uni.showToast({ title: list.length ? '当前账号仅绑定一个企业' : '暂无可切换的企业', icon: 'none' })
@@ -438,49 +369,6 @@ function chooseTenant() {
openTenantPicker(list, 'switch', false)
}
async function onCardPhone(e, card = null) {
const detail = (e && e.detail) || {}
if (String(detail.errMsg || '').indexOf('ok') === -1 || !detail.code) {
uni.showToast({ title: '请先完成手机号验证才能使用', icon: 'none' })
return
}
if (phoneBusy.value) return
phoneBusy.value = true
uni.showLoading({ title: '验证中...', mask: true })
try {
const code = await navUniLoginCode()
let appid = ''
try {
appid = (uni.getAccountInfoSync().miniProgram || {}).appId || ''
} catch (err) {
appid = ''
}
if (card) setPendingCard(card)
const res = await onboardingPhone({ code, phoneCode: detail.code, appid })
if (res && res.need_register) {
uni.hideLoading()
uni.navigateTo({
url: '/pages/onboarding/register?token=' + encodeURIComponent(res.register_token || '') +
'&mobile_mask=' + encodeURIComponent(res.mobile_mask || '')
})
return
}
const ready = await silentLogin(code, detail.code)
if (!ready) return
await load(true)
if (card) {
await enter(card)
takePendingCard()
}
} catch (err) {
console.error('[nav] onboarding phone failed:', err)
uni.showToast({ title: (err && err.message) || '验证失败,请重试', icon: 'none' })
} finally {
uni.hideLoading()
phoneBusy.value = false
}
}
async function silentLogin(code, phoneCode) {
const res = await loginByMiniapp({ code, phoneCode })
if (!res || !res.tokens || !res.tokens.access_token) {
@@ -503,11 +391,20 @@ async function silentLogin(code, phoneCode) {
async function enter(card) {
if (card.locked) {
if (guest.value) {
openGuestLogin(card.name)
return
}
openMenu({ locked: true, title: card.name })
return
}
if (guest.value) {
uni.showToast({ title: '请先完成手机号验证', icon: 'none' })
if (goSubsystemByModule(card.code)) return
if (card.path) {
openMenu({ title: card.name, path: card.path, leaf: true }, card.name)
return
}
uni.showToast({ title: card.name + '暂未开放', icon: 'none' })
return
}
if (card.needTenant) {
@@ -554,10 +451,6 @@ onMounted(() => {
onShow(() => {
if (!loading.value) load()
const pending = takePendingCard()
if (pending && isLoggedIn()) {
setTimeout(() => enter(pending), 600)
}
})
</script>
@@ -770,64 +663,18 @@ onShow(() => {
color: $color-text-muted;
}
.cell-button {
display: block;
margin: 0 0 20rpx 0;
padding: 0 20rpx 0 0;
background: transparent;
border: none;
border-radius: 0;
line-height: normal;
text-align: left;
&::after {
border: none;
}
.portal-lock-tag {
padding: 4rpx 14rpx;
border-radius: 20rpx;
background: #eef2f8;
color: #8a9bb3;
font-size: 20rpx;
}
.bottom-space {
height: 48rpx;
}
.guest-auth-mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 99;
}
.guest-auth-full {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
border: none;
border-radius: 0;
background: transparent;
opacity: 0;
&::after {
border: none;
}
}
.guest-auth-later {
position: absolute;
left: 0;
right: 0;
bottom: 64rpx;
z-index: 100;
text-align: center;
font-size: 24rpx;
color: #94a3b8;
padding: 16rpx;
}
.tenant-picker-mask {
position: fixed;
left: 0;
@@ -995,4 +842,77 @@ onShow(() => {
font-size: 22rpx;
color: $color-text-muted;
}
.guest-login-mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 1200;
display: flex;
align-items: center;
justify-content: center;
padding: 0 60rpx;
background: rgba(15, 23, 42, .48);
}
.guest-login-card {
width: 100%;
max-width: 560rpx;
padding: 48rpx 40rpx 32rpx;
border-radius: 28rpx;
background: #ffffff;
box-shadow: 0 20rpx 60rpx rgba(15, 23, 42, .18);
display: flex;
flex-direction: column;
align-items: center;
}
.guest-login-icon {
width: 96rpx;
height: 96rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 28rpx;
background: #eaf2ff;
}
.guest-login-title {
margin-top: 24rpx;
font-size: 32rpx;
font-weight: 700;
color: #17345f;
text-align: center;
}
.guest-login-desc {
margin-top: 16rpx;
font-size: 24rpx;
line-height: 1.6;
color: #64748b;
text-align: center;
}
.guest-login-btn {
width: 100%;
height: 88rpx;
margin: 36rpx 0 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
border: none;
border-radius: $radius-full;
background: linear-gradient(135deg, #60a5fa, #2563eb);
color: #ffffff;
font-size: 28rpx;
font-weight: 600;
box-shadow: 0 10rpx 24rpx rgba(37, 99, 235, .22);
&::after { border: none; }
}
.guest-login-cancel {
margin-top: 20rpx;
padding: 16rpx;
font-size: 26rpx;
color: #8a9bb3;
}
</style>