WMS_PDA/pages/home/edit-quick-actions.vue

628 lines
15 KiB
Vue

<template>
<view class="all-functions-page">
<view class="status_bar"></view>
<view class="page-header">
<view class="back-btn" @click="goBack">
<u-icon name="arrow-left" size="18" color="#333"></u-icon>
</view>
<text class="header-title">全部功能</text>
<view class="edit-common-btn" :class="{ active: isEditMode }" @click="onEditCommon">
<u-icon :name="isEditMode ? 'checkmark-circle-fill' : 'edit-pen'" size="14" :color="isEditMode ? '#19be6b' : '#2979ff'"></u-icon>
<text class="edit-common-text">{{ isEditMode ? '完成' : '编辑常用' }}</text>
</view>
</view>
<view class="search-bar">
<view class="search-input-wrap">
<u-icon name="search" size="18" color="#999"></u-icon>
<input
class="search-input"
v-model="searchKeyword"
placeholder="输入关键字搜索功能"
placeholder-class="search-placeholder"
/>
</view>
</view>
<view class="content-area">
<scroll-view v-if="allActions.length > 0" class="left-nav" scroll-y :scroll-into-view="leftNavTargetId" scroll-with-animation>
<view class="nav-item" :class="{ active: activeParent === '全部' }" @click="onClickAllParent">
全部
</view>
<view
v-for="(group, index) in leftParentList"
:key="group.key"
:id="`parent-${index}`"
class="nav-item parent-nav-item"
:class="{ active: activeParent === group.key }"
@click="onClickParent(group)"
>
{{ group.key }}
</view>
</scroll-view>
<scroll-view class="page-scroll" scroll-y>
<view v-if="allActions.length === 0" class="empty-state">
<text class="empty-text">暂无可用功能</text>
</view>
<view v-else-if="displayGroups.length > 0" class="group-list">
<view v-for="group in displayGroups" :key="group.key" class="group-section">
<view v-if="activeParent === '全部'" class="group-title">{{ group.key }}</view>
<view class="function-grid">
<view
v-for="(item, index) in group.items"
:key="item.id || index"
class="function-item"
:class="{ selected: isEditMode && isSelected(item) }"
@click="onFunctionClick(item)"
>
<view v-if="isEditMode" class="select-mark">
<u-icon :name="isSelected(item) ? 'checkmark-circle-fill' : 'checkmark-circle'" size="18" :color="isSelected(item) ? '#2979ff' : '#c0c4cc'"></u-icon>
</view>
<view class="item-icon-box" :style="{ background: item.color + '15' }">
<u-icon :name="item.icon || 'grid'" size="24" :color="item.color"></u-icon>
</view>
<text class="item-name">{{ item.name }}</text>
</view>
</view>
</view>
</view>
<view v-else class="empty-state">
<text class="empty-text">未找到相关功能</text>
</view>
</scroll-view>
<view v-if="allActions.length > 0" class="right-initial-nav">
<view
v-for="nav in initialNavList"
:key="nav"
class="initial-item"
:class="{ active: nav === activeNav }"
@click="handleInitialNavClick(nav)"
>
{{ nav }}
</view>
</view>
</view>
</view>
</template>
<script>
import { pinyin } from 'pinyin-pro'
export default {
data() {
return {
allGroups: [],
allActions: [],
searchKeyword: '',
activeNav: '全部',
activeParent: '全部',
leftNavTargetId: '',
isEditMode: false,
selectedKeys: [],
FIXED_MENU_KEY: 'fixed_home_menus'
}
},
computed: {
filteredGroups() {
const keyword = (this.searchKeyword || '').trim().toLowerCase();
if (!keyword) {
return this.allGroups;
}
return this.allGroups
.map(group => {
const groupMatch = (group.key || '').toLowerCase().includes(keyword);
const items = groupMatch
? group.items
: group.items.filter(item => (item.name || '').toLowerCase().includes(keyword));
return {
...group,
items
};
})
.filter(group => group.items.length > 0);
},
groupedActions() {
return [...this.filteredGroups]
.map(group => ({
...group,
items: [...group.items].sort((first, second) =>
(first.name || '').localeCompare(second.name || '', 'zh-Hans-CN-u-co-pinyin')
)
}))
.sort((first, second) => {
if (first.initial === '#') return 1;
if (second.initial === '#') return -1;
if (first.initial !== second.initial) {
return first.initial.localeCompare(second.initial);
}
return (first.key || '').localeCompare(second.key || '', 'zh-Hans-CN-u-co-pinyin');
});
},
initialNavList() {
return [...new Set(this.groupedActions.map(group => group.initial))];
},
leftParentList() {
return this.groupedActions;
},
displayGroups() {
if (this.activeParent !== '全部') {
return this.groupedActions.filter(group => group.key === this.activeParent);
}
if (this.activeNav !== '全部') {
return this.groupedActions.filter(group => group.initial === this.activeNav);
}
return this.groupedActions;
}
},
async onLoad() {
await this.loadAllActions();
},
methods: {
async loadAllActions() {
let user = null;
try {
user = await this.$store.dispatch('getUserInfo');
} catch (error) {
console.error('获取用户信息失败,使用本地缓存菜单:', error);
user = this.$store.getters.user || {};
}
const menus = (user && (user.menus || user.permissions)) || [];
console.log('用户信息接口菜单列表:', menus);
const colorPool = [
'#FF6B6B', '#4ECDC4', '#FFD166', '#06D6A0', '#118AB2',
'#EF476F', '#26547C', '#7209B7', '#3A86FF', '#FB5607', '#8338EC'
];
const validGroups = menus
.map(parent => {
const parentName = parent?.meta?.title || parent?.name || parent?.title || '未分类';
const items = (parent?.children || [])
.filter(menu =>
menu &&
menu.component &&
menu.component !== 'Layout' &&
menu.meta &&
menu.meta.title
)
.map(menu => ({
id: menu.id || menu.menuId || menu.component || menu.meta?.title || '',
name: menu.meta?.title || '未命名菜单',
component: menu.component || '',
icon: menu.meta?.icon || '',
color: colorPool[Math.floor(Math.random() * colorPool.length)],
parentName
}));
return {
key: parentName,
initial: this.getInitial(parentName),
items
};
})
.filter(group => group.items.length > 0);
this.allGroups = validGroups;
this.allActions = validGroups.flatMap(group => group.items);
if (!validGroups.some(group => group.key === this.activeParent)) {
this.activeParent = '全部';
}
await this.loadSelectedCommonMenus();
},
async handleInitialNavClick(nav) {
this.activeNav = nav;
if (nav === '全部') {
this.activeParent = '全部';
this.leftNavTargetId = '';
return;
}
this.activeParent = '全部';
await this.$nextTick();
const targetIndex = this.leftParentList.findIndex(group => group.initial === nav);
if (targetIndex > -1) {
this.activeParent = this.leftParentList[targetIndex].key;
this.leftNavTargetId = `parent-${targetIndex}`;
setTimeout(() => {
this.leftNavTargetId = '';
}, 350);
} else {
this.activeParent = '全部';
this.leftNavTargetId = '';
}
},
getMenuKey(item) {
return String(item?.id || item?.component || item?.name || '');
},
async loadSelectedCommonMenus() {
const saved = await this.$store.dispatch('setting/getValue', this.FIXED_MENU_KEY) || [];
const savedKeys = new Set((saved || []).map(item => this.getMenuKey(item)));
this.selectedKeys = this.allActions
.filter(item => savedKeys.has(this.getMenuKey(item)))
.map(item => this.getMenuKey(item));
},
isSelected(item) {
return this.selectedKeys.includes(this.getMenuKey(item));
},
onFunctionClick(item) {
if (!this.isEditMode) {
this.toPath(item);
return;
}
const key = this.getMenuKey(item);
const index = this.selectedKeys.indexOf(key);
if (index > -1) {
this.selectedKeys.splice(index, 1);
return;
}
if (this.selectedKeys.length >= 24) {
uni.showToast({
title: '最多选择24个常用功能',
icon: 'none'
});
return;
}
this.selectedKeys.push(key);
},
async onEditCommon() {
if (!this.isEditMode) {
await this.loadSelectedCommonMenus();
this.isEditMode = true;
return;
}
const selectedMenus = this.allActions.filter(item => this.selectedKeys.includes(this.getMenuKey(item)));
await this.$store.dispatch('setting/setValue', {
key: this.FIXED_MENU_KEY,
value: selectedMenus
});
this.isEditMode = false;
uni.showToast({
title: '常用功能已保存',
icon: 'success'
});
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 300);
},
onClickAllParent() {
this.activeParent = '全部';
this.activeNav = '全部';
},
onClickParent(group) {
this.activeParent = group.key;
this.activeNav = group.initial || '全部';
},
toPath(item) {
const menuName = String(item?.name || '').trim();
const isGoodsQuery = menuName === '商品查询' || (menuName.includes('商品') && menuName.includes('查询'));
const isOrderPicking = menuName === '订单拣货' || (menuName.includes('订单') && menuName.includes('拣货'));
const isScatterWaveStrategy = menuName === '散单波次策略' || (menuName.includes('散单') && menuName.includes('波次'));
const rawPath = item?.component || item?.path || '';
const normalizedPath = rawPath ? (rawPath.startsWith('/') ? rawPath : `/${rawPath}`) : '';
const isRelocation = menuName === '移库作业' || normalizedPath === '/pages/work/storage/relocation';
if (isRelocation) {
uni.showToast({
title: '该功能只支持在商品查询页面使用!',
icon: 'none',
duration: 2500
});
return;
}
const targetPath = isGoodsQuery
? '/pages/work/product/query'
: (isOrderPicking
? '/pages/work/order/picking'
: (isScatterWaveStrategy ? '/pages/work/order/scatter-wave-strategy' : normalizedPath));
if (!targetPath) {
uni.showToast({
title: '功能暂未开放',
icon: 'none'
});
return;
}
this.$tools.routerTo(targetPath);
},
goBack() {
uni.navigateBack({
delta: 1
});
},
getInitial(name) {
const firstChar = ((name || '').trim()[0] || '').toUpperCase();
if (!firstChar) {
return '#';
}
if (/^[A-Z]$/.test(firstChar)) {
return firstChar;
}
const initial = pinyin(firstChar, {
pattern: 'first',
toneType: 'none',
type: 'array'
})?.[0]?.toUpperCase() || '#';
return /^[A-Z]$/.test(initial) ? initial : '#';
}
}
}
</script>
<style lang="scss" scoped>
.all-functions-page {
display: flex;
flex-direction: column;
height: 100vh;
background: #f8f9fa;
}
.page-header {
position: relative;
padding: 20rpx;
background: #fff;
border-bottom: 1rpx solid #f0f0f0;
display: flex;
align-items: center;
justify-content: center;
.back-btn {
position: absolute;
left: 20rpx;
width: 56rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
}
.header-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.edit-common-btn {
position: absolute;
right: 20rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 24rpx;
color: #2979ff;
padding: 0 8rpx;
.edit-common-text {
margin-left: 6rpx;
font-size: 24rpx;
line-height: 1;
}
&.active {
color: #19be6b;
}
}
}
.content-area {
flex: 1;
display: flex;
min-height: 0;
position: relative;
}
.left-nav {
width: 132rpx;
background: #fff;
border-right: 1rpx solid #f0f0f0;
padding: 12rpx 8rpx;
.nav-item {
position: relative;
min-height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 10rpx;
font-size: 22rpx;
color: #666;
background: #f4f5f7;
border-radius: 10rpx;
padding: 8rpx;
text-align: center;
transition: all 0.2s ease;
&.active {
color: #2979ff;
background: #eaf2ff;
font-weight: 600;
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
&::before {
content: '';
position: absolute;
left: 0;
top: 10rpx;
bottom: 10rpx;
width: 6rpx;
background: #2979ff;
border-radius: 0 6rpx 6rpx 0;
}
}
}
.parent-nav-item {
font-size: 20rpx;
line-height: 1.3;
word-break: break-all;
}
}
.page-scroll {
flex: 1;
min-width: 0;
}
.right-initial-nav {
position: absolute;
right: 8rpx;
top: 50%;
transform: translateY(-50%);
z-index: 2;
display: flex;
flex-direction: column;
align-items: center;
background: transparent;
border-radius: 16rpx;
padding: 4rpx 3rpx;
.initial-item {
position: relative;
min-width: 26rpx;
height: 26rpx;
line-height: 26rpx;
text-align: center;
font-size: 16rpx;
color: #666;
border-radius: 6rpx;
&::before {
content: '';
position: absolute;
left: -8rpx;
right: -8rpx;
top: -6rpx;
bottom: -6rpx;
}
&.active {
color: #2979ff;
background: #eaf2ff;
}
}
}
.search-bar {
padding: 16rpx 20rpx;
background: #fff;
border-bottom: 1rpx solid #f0f0f0;
.search-input-wrap {
height: 72rpx;
background: #f4f5f7;
border-radius: 10rpx;
padding: 0 20rpx;
display: flex;
align-items: center;
}
.search-input {
flex: 1;
height: 72rpx;
padding-left: 12rpx;
font-size: 26rpx;
color: #333;
}
.search-placeholder {
font-size: 26rpx;
color: #999;
}
}
.group-list {
padding: 0 52rpx 20rpx 20rpx;
.group-section {
.group-title {
font-size: 26rpx;
font-weight: 600;
color: #666;
padding: 18rpx 4rpx 10rpx;
}
}
}
.function-grid {
display: grid;
grid-template-columns: repeat(1, 1fr);
gap: 16rpx;
padding: 0;
}
.function-item {
height: 128rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
background: #fff;
border-radius: 12rpx;
padding: 0 12rpx;
position: relative;
&.selected {
border: 2rpx solid #2979ff;
}
.select-mark {
position: absolute;
top: 8rpx;
right: 8rpx;
}
.item-icon-box {
width: 68rpx;
height: 68rpx;
border-radius: 14rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12rpx;
flex-shrink: 0;
}
.item-name {
font-size: 22rpx;
color: #333;
text-align: left;
padding: 0;
line-height: 1.3;
flex: 1;
word-break: break-all;
}
}
.empty-state {
padding: 120rpx 0;
display: flex;
justify-content: center;
.empty-text {
font-size: 28rpx;
color: #999;
}
}
</style>