Files
yunzerwebsiteallinone/uniapp/components/sub/SubFunctions.vue
T
2026-11-16 17:22:50 +08:00

317 lines
6.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="page" :class="{ embedded }">
<view v-if="!embedded" class="head" :style="headPad">
<text class="head-title">{{ sub.title }}</text>
</view>
<view class="body">
<view v-if="loadError" class="err-box" @tap="load(true)">
<FaIcon name="triangle-exclamation" color="#f04438" :size="18" />
<view class="err-body">
<text class="err-title">加载失败</text>
<text class="err-msg">{{ loadError }},点击重试</text>
</view>
</view>
<view v-else-if="groups.length === 0" class="empty-box">
<FaIcon name="table-cells" color="#c0c4cc" :size="30" />
<text class="empty-text">该子系统下暂无你可见的功能</text>
</view>
<view v-else class="group-list">
<view v-for="group in groups" :key="group.id" class="group-card">
<view class="group-head">
<text class="group-title">{{ group.title }}</text>
</view>
<view class="grid">
<view
v-for="item in group.items"
:key="item.id"
class="cell"
@tap="openMenu(item, item.title)"
>
<view class="fn-card" :class="{ locked: item.locked }">
<view
class="tint-icon fn-icon"
:class="item.locked ? 'tint-off' : 'tint-' + (item.tintIndex % 8)"
>
<FaIcon :name="item.icon || fallbackIcon" color="#ffffff" :size="20" />
</view>
<text class="fn-name">{{ item.title }}</text>
</view>
</view>
</view>
</view>
</view>
<view class="bottom-space" />
</view>
<AppTabbar v-if="!embedded" :group="slug" current="functions" />
</view>
</template>
<script setup>
import { computed, onMounted } from 'vue'
import { mpHeadPad } from '@/utils/mpHead.js'
const headPad = mpHeadPad()
import { onShow } from '@dcloudio/uni-app'
import { openMenu, WEB_RULES } from '@/utils/nav.js'
import { useSubsystem } from '@/utils/subsystem.js'
import AppTabbar from '@/components/AppTabbar.vue'
const props = defineProps({
slug: { type: String, required: true },
embedded: { type: Boolean, default: false }
})
const emit = defineEmits(['switch-tab', 'back'])
const { sub, loading, loadError, allMenus, load } = useSubsystem(props.slug)
const fallbackIcon = computed(() => {
const map = {
crm: 'handshake',
erp: 'boxes-stacked',
oa: 'clipboard-check',
cms: 'globe',
bianjiegongju: 'wrench'
}
return map[String(sub.module || '').toLowerCase()] || 'file-lines'
})
function isWebEntry(menu) {
if (!menu) return false
const title = String(menu.title || '')
const path = String(menu.path || '')
return WEB_RULES.some(kw => title.includes(kw) || path.includes(kw))
}
const groups = computed(() => {
const menus = allMenus.value
.filter(m => !isWebEntry(m))
.slice()
.sort((a, b) => (a.sort || 0) - (b.sort || 0))
const byId = {}
menus.forEach((m) => { byId[m.id] = m })
function groupNodeOf(m) {
const chain = [m]
let cur = m
let guard = 0
while (byId[cur.pid] && guard++ < 20) {
cur = byId[cur.pid]
chain.unshift(cur)
}
const top = chain[0]
if (top.pid === 0) {
if (chain.length >= 2) return chain[1]
return top.leaf === false ? null : top
}
return top
}
const groupMap = new Map()
menus.forEach((m) => {
const g = groupNodeOf(m)
if (!g) return
if (g.id === m.id) {
if (g.leaf === false && !groupMap.has(g.id)) {
groupMap.set(g.id, { id: g.id, title: g.title, sort: g.sort, items: [] })
}
return
}
if (!groupMap.has(g.id)) {
groupMap.set(g.id, { id: g.id, title: g.title, sort: g.sort, items: [] })
}
groupMap.get(g.id).items.push(m)
})
const list = []
groupMap.forEach((g) => {
if (g.items.length) list.push(g)
})
list.sort((a, b) => (a.sort || 0) - (b.sort || 0))
let colorIndex = 0
return list.map((group) => ({
...group,
items: group.items.map((item) => ({ ...item, tintIndex: colorIndex++ }))
}))
})
function goBackNav() {
if (props.embedded) {
emit('back')
return
}
uni.reLaunch({ url: '/pages/nav/nav' })
}
onMounted(() => {
load()
})
onShow(() => {
if (!loading.value) load()
})
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
@include page-shell;
&.embedded {
height: auto;
}
}
.head {
flex-shrink: 0;
padding: calc(var(--status-bar-height, 44px) + 20rpx) $page-padding-x 24rpx;
/* #ifdef MP-WEIXIN */
padding-top: calc(env(safe-area-inset-top, 25px) + 84rpx);
/* #endif */
background: $color-card;
box-shadow: $shadow-header;
}
.head-title {
display: block;
margin-top: 32rpx;
font-size: 36rpx;
font-weight: 600;
color: $color-text;
}
.body {
flex: 1;
min-height: 0;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
padding: 28rpx $page-padding-x 0;
}
.empty-box {
@include card;
padding: 80rpx 24rpx;
display: flex;
flex-direction: column;
align-items: center;
gap: 16rpx;
}
.empty-text {
font-size: 26rpx;
color: $color-text-muted;
}
.err-box {
display: flex;
align-items: center;
gap: 16rpx;
padding: 24rpx 22rpx;
background: #fef3f2;
border: 1rpx solid #fdd8d4;
border-radius: $radius-md;
}
.err-body {
flex: 1;
min-width: 0;
}
.err-title {
display: block;
font-size: 27rpx;
font-weight: 500;
color: $color-danger;
}
.err-msg {
display: block;
margin-top: 6rpx;
font-size: 22rpx;
color: #b42318;
word-break: break-all;
}
.group-card {
@include card;
padding: 24rpx 20rpx 8rpx;
& + & {
margin-top: 24rpx;
}
}
.group-head {
display: flex;
align-items: center;
gap: 12rpx;
padding: 0 4rpx 20rpx;
}
.group-title {
@include section-title;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.grid {
display: flex;
flex-wrap: wrap;
margin-right: -16rpx;
}
.cell {
width: 25%;
padding-right: 16rpx;
margin-bottom: 24rpx;
box-sizing: border-box;
}
.fn-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 12rpx;
transition: transform 0.15s ease;
&:active {
transform: scale(0.95);
}
}
.fn-icon {
@include tint-icon(84rpx, 24rpx);
}
.fn-name {
max-width: 100%;
font-size: 24rpx;
line-height: 1.3;
color: $color-text;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.fn-card.locked {
.fn-name {
color: $color-text-muted;
}
}
.bottom-space {
height: 32rpx;
}
</style>