- 新增 stock.warehouse.search 接口并在收货详情中切换为仓库维度搜索 - 优化用户菜单路径校验,兼容 component/path 及前导斜杠、.vue 后缀 - 首页与全部功能页对商品查询菜单统一跳转到 /pages/work/product/query - pages.json 注册商品查询页面路由
676 lines
16 KiB
Vue
676 lines
16 KiB
Vue
<template>
|
||
<view class="pda-home">
|
||
<view class="status_bar">
|
||
</view>
|
||
<view class="compact-header">
|
||
<!-- 主体切换 -->
|
||
<view class="org-switcher">
|
||
<view class="org-info" @click="showStoreSelector">
|
||
<text class="org-name">{{ userInfo.store_name || '选择主体' }}</text>
|
||
<text class="org-id">{{ userInfo.employees_name || '---' }}</text>
|
||
</view>
|
||
<u-icon @click="showStoreSelector" name="arrow-down" size="16" color="#666" v-if="userInfo.employees && userInfo.employees.length > 1"></u-icon>
|
||
<view class="news-wrapper" @click="toNewsPage">
|
||
<u-notice-bar :text="newsList[0]" mode="horizontal" bg-color="transparent" color="#666"
|
||
:font-size="12" :padding="0" :radius="0" :volume-icon="false" :more-icon="false" :speed="60"
|
||
:height="30" :autoplay="true"></u-notice-bar>
|
||
</view>
|
||
|
||
</view>
|
||
|
||
<!-- 消息区域 -->
|
||
<view class="header-actions">
|
||
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 主内容区 -->
|
||
<scroll-view class="main-scroll" scroll-y :scroll-top="scrollTop" :show-scrollbar="false">
|
||
<!-- 快捷入口区域 -->
|
||
<view class="quick-section">
|
||
<view class="section-title-bar">
|
||
<view class="title-left">
|
||
<text class="section-title">常用功能</text>
|
||
</view>
|
||
<view class="title-right">
|
||
<u-icon name="grid" color="#2979ff" size="20"></u-icon>
|
||
<text class="edit-btn" @click="toEditPage">全部功能</text>
|
||
<text class="divider">|</text>
|
||
<text class="page-indicator">{{ currentPage }}/{{ totalPages }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 3行4列的快捷入口网格 -->
|
||
<view class="quick-grid-container">
|
||
<!-- 上一页按钮 -->
|
||
<view class="nav-arrow left-arrow" @click="prevPage" :class="{ disabled: currentPage === 1 }">
|
||
<u-icon name="arrow-left" size="20" color="#666"></u-icon>
|
||
</view>
|
||
|
||
<!-- 网格内容 -->
|
||
<view class="quick-grid-wrapper">
|
||
<!-- 空状态提示 -->
|
||
<view class="empty-state" v-if="!isLoading && quickActions.length === 0">
|
||
<u-icon name="grid" size="80" color="#ccc"></u-icon>
|
||
<text class="empty-text">暂无可用功能</text>
|
||
<text class="empty-hint">请联系仓库管理员检查授权</text>
|
||
</view>
|
||
<swiper v-else class="quick-swiper" :current="currentPage - 1" @change="onSwiperChange"
|
||
:duration="300">
|
||
|
||
|
||
<swiper-item v-for="(pageItems, pageIndex) in paginatedActions" :key="pageIndex">
|
||
<view class="grid-page">
|
||
<!-- 3行4列布局,共12个 -->
|
||
<view class="grid-item" v-for="(item, index) in pageItems" :key="index"
|
||
@click="toPath(item)">
|
||
<view class="item-icon-box" :style="{ background: item.color + '15' }">
|
||
<u-icon :name="item.icon" size="26" :color="item.color"></u-icon>
|
||
</view>
|
||
<text class="item-name">{{ item.name }}</text>
|
||
<u-badge v-if="item.badge && item.badge > 0" :count="item.badge" size="mini"
|
||
type="error" :offset="[-3, 3]" class="item-badge"></u-badge>
|
||
</view>
|
||
|
||
<!-- 填充空白项 -->
|
||
<view v-for="n in (12 - pageItems.length)" :key="'empty-' + n"
|
||
class="grid-item empty-item"></view>
|
||
</view>
|
||
</swiper-item>
|
||
</swiper>
|
||
</view>
|
||
|
||
<!-- 下一页按钮 -->
|
||
<view class="nav-arrow right-arrow" @click="nextPage"
|
||
:class="{ disabled: currentPage === totalPages }">
|
||
<u-icon name="arrow-right" size="20" color="#666"></u-icon>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 分页指示器 -->
|
||
<view class="pagination-dots">
|
||
<view v-for="n in totalPages" :key="n" class="pagination-dot"
|
||
:class="{ active: n === currentPage }"></view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 加载状态 -->
|
||
<view class="loading-state" v-if="isLoading">
|
||
<text class="loading-text">加载中...</text>
|
||
</view>
|
||
|
||
</scroll-view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
isLoading: true,
|
||
currentPage: 1,
|
||
scrollTop: 0,
|
||
userInfo: {},
|
||
newsList: [
|
||
'欢迎使用PDA仓库管理系统',
|
||
'请及时处理待办任务',
|
||
'祝您工作愉快'
|
||
],
|
||
unreadCount: 0,
|
||
quickActions: [],
|
||
pageSize: 12,
|
||
FIXED_MENU_KEY: 'fixed_home_menus'
|
||
}
|
||
},
|
||
|
||
computed: {
|
||
// 分页后的快捷入口
|
||
paginatedActions() {
|
||
const pages = [];
|
||
for (let i = 0; i < this.quickActions.length; i += this.pageSize) {
|
||
pages.push(this.quickActions.slice(i, i + this.pageSize));
|
||
}
|
||
return pages;
|
||
},
|
||
|
||
totalPages() {
|
||
return Math.ceil(this.quickActions.length / this.pageSize) || 1;
|
||
}
|
||
},
|
||
|
||
async onLoad() {
|
||
await this.loadUserInfo();
|
||
},
|
||
|
||
onShow() {
|
||
this.loadUserInfo();
|
||
},
|
||
|
||
methods: {
|
||
async loadUserInfo() {
|
||
// 等待用户信息加载
|
||
await new Promise(resolve => setTimeout(resolve, 100));
|
||
|
||
if (!this.$store.getters.user) {
|
||
console.log('等待用户信息...');
|
||
setTimeout(() => this.loadUserInfo(), 100);
|
||
return;
|
||
}
|
||
|
||
const userData = this.$store.getters.user;
|
||
if (userData) {
|
||
this.isLoading = false;
|
||
this.userInfo = userData;
|
||
await this.refreshQuickActions();
|
||
}
|
||
},
|
||
|
||
// 刷新快捷入口
|
||
async refreshQuickActions() {
|
||
this.isLoading = true;
|
||
|
||
try {
|
||
// 1. 获取用户当前可用的菜单
|
||
const userMenus = this.getUserMenus();
|
||
const latestActions = this.processMenus(userMenus, null);
|
||
|
||
// 2. 从Vuex获取已固定的菜单
|
||
const savedFixedMenus = await this.$store.dispatch('setting/getValue', this.FIXED_MENU_KEY) || [];
|
||
const hasSavedConfig = Array.isArray(savedFixedMenus);
|
||
|
||
// 3. 如果存在已保存的常用配置(包括空数组),优先按配置展示
|
||
if (hasSavedConfig) {
|
||
const validFixedMenus = this.validateAndFilterMenus(savedFixedMenus, latestActions);
|
||
console.log('按已保存常用菜单展示:', validFixedMenus);
|
||
this.quickActions = validFixedMenus;
|
||
return;
|
||
}
|
||
|
||
// 4. 如果没有有效的固定菜单,检查用户菜单
|
||
if (userMenus && userMenus.length > 0) {
|
||
console.log('从用户菜单生成快捷入口:', userMenus);
|
||
// 根据用户菜单生成快捷入口
|
||
this.quickActions = this.processMenus(userMenus, 24);
|
||
} else {
|
||
// 5. 如果还是没有菜单,返回空数组
|
||
console.log('用户没有可用菜单');
|
||
this.quickActions = [];
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('刷新快捷入口失败:', error);
|
||
this.quickActions = [];
|
||
} finally {
|
||
this.isLoading = false;
|
||
}
|
||
},
|
||
|
||
// 辅助方法:验证和过滤菜单权限
|
||
validateAndFilterMenus(fixedMenus, latestActions) {
|
||
if (!Array.isArray(fixedMenus) || !Array.isArray(latestActions)) return [];
|
||
|
||
const actionMap = new Map();
|
||
latestActions.forEach(action => {
|
||
actionMap.set(this.getMenuKey(action), action);
|
||
});
|
||
|
||
return fixedMenus
|
||
.map(fixedMenu => {
|
||
const matched = actionMap.get(this.getMenuKey(fixedMenu));
|
||
if (!matched) return null;
|
||
return {
|
||
...matched,
|
||
...fixedMenu,
|
||
name: matched.name,
|
||
path: matched.path,
|
||
component: matched.component,
|
||
icon: matched.icon || fixedMenu.icon,
|
||
id: matched.id || fixedMenu.id
|
||
};
|
||
})
|
||
.filter(Boolean);
|
||
},
|
||
|
||
getMenuKey(menu) {
|
||
return String(
|
||
menu?.component ||
|
||
menu?.path ||
|
||
menu?.id ||
|
||
menu?.menuId ||
|
||
menu?.name ||
|
||
''
|
||
);
|
||
},
|
||
|
||
// 获取用户菜单
|
||
getUserMenus() {
|
||
const user = this.$store.getters.user;
|
||
if (!user) return [];
|
||
|
||
// 从用户信息中获取菜单
|
||
return user.menus || user.permissions || [];
|
||
},
|
||
|
||
// 处理菜单数据
|
||
processMenus(menus, limit = 24) {
|
||
// 1. 展平所有子菜单(使用 flatMap 替代 map + filter)
|
||
const allChildren = menus.flatMap(item =>
|
||
item.children || [] // 确保 children 存在,否则返回空数组
|
||
);
|
||
|
||
// 2. 过滤有效菜单并限制数量
|
||
let validMenus = allChildren.filter(menu =>
|
||
menu &&
|
||
menu.component &&
|
||
menu.component !== 'Layout' &&
|
||
menu.meta &&
|
||
menu.meta.title
|
||
);
|
||
|
||
if (typeof limit === 'number' && limit > 0) {
|
||
validMenus = validMenus.slice(0, limit); // 默认最多显示24个
|
||
}
|
||
|
||
// 3. 生成随机颜色的函数
|
||
const generateRandomColor = () => {
|
||
const colorPool = [
|
||
'#FF6B6B', '#4ECDC4', '#FFD166', '#06D6A0', '#118AB2',
|
||
'#EF476F', '#26547C', '#FFD166', '#06D6A0', '#118AB2',
|
||
'#7209B7', '#3A86FF', '#FB5607', '#8338EC', '#3A86FF'
|
||
];
|
||
return colorPool[Math.floor(Math.random() * colorPool.length)];
|
||
};
|
||
|
||
// 4. 转换为目标格式
|
||
return validMenus.map(menu => {
|
||
return {
|
||
id: menu.id || menu.menuId || menu.component || menu.path || menu.meta?.title || '',
|
||
name: menu.meta?.title || '未命名菜单',
|
||
path: menu.path || '',
|
||
component: menu.component || '',
|
||
permissions: menu.permissions || [],
|
||
icon: menu.meta?.icon || '',
|
||
color: generateRandomColor(), // 随机颜色
|
||
isFixed: true // 标记为已固定
|
||
};
|
||
});
|
||
},
|
||
showStoreSelector() {
|
||
if (!this.userInfo.employees || this.userInfo.employees.length <= 1) {
|
||
return;
|
||
}
|
||
|
||
// 提取店铺名称列表
|
||
const storeList = this.userInfo.employees.map(emp => emp.store_name);
|
||
|
||
uni.showActionSheet({
|
||
itemList: storeList,
|
||
success: (res) => {
|
||
const selectedIndex = res.tapIndex;
|
||
if (selectedIndex >= 0 && selectedIndex < this.userInfo.employees.length) {
|
||
const selectedEmployee = this.userInfo.employees[selectedIndex];
|
||
this.handleStoreSwitch(selectedEmployee);
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
console.log('用户取消选择', err);
|
||
}
|
||
});
|
||
},
|
||
|
||
async handleStoreSwitch(selectedEmployee) {
|
||
try {
|
||
// 显示加载中
|
||
uni.showLoading({
|
||
title: '切换中...',
|
||
mask: true
|
||
});
|
||
const result = await this.$store.dispatch('changeEmployee', selectedEmployee.id);
|
||
this.loadUserInfo();
|
||
|
||
} catch (error) {
|
||
uni.hideLoading();
|
||
}
|
||
},
|
||
|
||
toPath(item) {
|
||
const menuName = String(item?.name || '').trim();
|
||
const isGoodsQuery = menuName === '商品查询' || (menuName.includes('商品') && menuName.includes('查询'));
|
||
const rawPath = item?.component || item?.path || '';
|
||
const targetPath = isGoodsQuery
|
||
? '/pages/work/product/query'
|
||
: (rawPath ? (rawPath.startsWith('/') ? rawPath : `/${rawPath}`) : '');
|
||
|
||
if (!targetPath) {
|
||
uni.showToast({
|
||
title: '功能暂未开放',
|
||
icon: 'none',
|
||
duration: 1500
|
||
});
|
||
return;
|
||
}
|
||
|
||
uni.navigateTo({
|
||
url: targetPath,
|
||
animationType: 'slide-in-right'
|
||
});
|
||
},
|
||
|
||
toMessagePage() {
|
||
uni.navigateTo({
|
||
url: '/pages/message/index'
|
||
});
|
||
},
|
||
|
||
toNewsPage() {
|
||
uni.switchTab({
|
||
url: '/pages/oa/index'
|
||
});
|
||
},
|
||
|
||
toEditPage() {
|
||
uni.navigateTo({
|
||
url: '/pages/home/edit-quick-actions'
|
||
});
|
||
},
|
||
|
||
prevPage() {
|
||
if (this.currentPage > 1) {
|
||
this.currentPage--;
|
||
}
|
||
},
|
||
|
||
nextPage() {
|
||
if (this.currentPage < this.totalPages) {
|
||
this.currentPage++;
|
||
}
|
||
},
|
||
|
||
onSwiperChange(e) {
|
||
this.currentPage = e.detail.current + 1;
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.pda-home {
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: #f8f9fa;
|
||
}
|
||
|
||
// 紧凑型头部
|
||
.compact-header {
|
||
padding:0 20rpx;
|
||
background: white;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
|
||
.org-switcher {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-bottom: 6px;
|
||
|
||
.org-icon {
|
||
margin-right: 15rpx;
|
||
}
|
||
|
||
.org-info {
|
||
flex: 1;
|
||
|
||
.org-name {
|
||
font-size: 28rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
display: block;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.org-id {
|
||
font-size: 22rpx;
|
||
color: #909399;
|
||
display: block;
|
||
}
|
||
}
|
||
}
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
|
||
.news-wrapper {
|
||
flex: 1;
|
||
margin-right: 20rpx;
|
||
overflow: hidden;
|
||
|
||
::v-deep .u-notice-bar {
|
||
height: 30rpx !important;
|
||
line-height: 30rpx !important;
|
||
}
|
||
}
|
||
|
||
.message-bell {
|
||
position: relative;
|
||
width: 60rpx;
|
||
height: 60rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border-radius: 50%;
|
||
|
||
&:active {
|
||
background: #f0f0f0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 主滚动区域
|
||
.main-scroll {
|
||
flex: 1;
|
||
overflow: hidden;
|
||
}
|
||
|
||
// 快捷入口区域
|
||
.quick-section {
|
||
padding: 20rpx 20rpx 30rpx;
|
||
background: white;
|
||
margin: 20rpx;
|
||
border-radius: 16rpx;
|
||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||
|
||
.section-title-bar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 25rpx;
|
||
padding-bottom: 15rpx;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
|
||
.title-left {
|
||
display: flex;
|
||
align-items: center;
|
||
|
||
.section-title {
|
||
font-size: 32rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
margin-left: 10rpx;
|
||
}
|
||
}
|
||
|
||
.title-right {
|
||
display: flex;
|
||
align-items: center;
|
||
|
||
.edit-btn {
|
||
font-size: 24rpx;
|
||
color: #2979ff;
|
||
padding: 6rpx 12rpx;
|
||
border-radius: 6rpx;
|
||
|
||
&:active {
|
||
background: #f0f7ff;
|
||
}
|
||
}
|
||
|
||
.divider {
|
||
color: #e0e0e0;
|
||
margin: 0 15rpx;
|
||
}
|
||
|
||
.page-indicator {
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 网格容器
|
||
.quick-grid-container {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-bottom: 20rpx;
|
||
|
||
.nav-arrow {
|
||
width: 20rpx;
|
||
height: 60rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border-radius: 50%;
|
||
background: #f8f9fa;
|
||
|
||
&:active:not(.disabled) {
|
||
background: #e9ecef;
|
||
}
|
||
|
||
&.disabled {
|
||
opacity: 0.3;
|
||
}
|
||
}
|
||
|
||
.quick-grid-wrapper {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
|
||
.quick-swiper {
|
||
width: 100%;
|
||
height: 540rpx; // 3行 × 180rpx
|
||
}
|
||
|
||
.grid-page {
|
||
display: grid;
|
||
grid-template-columns: repeat(4, 1fr);
|
||
grid-template-rows: repeat(3, 1fr);
|
||
gap: 10rpx;
|
||
padding: 0 10rpx;
|
||
|
||
.grid-item {
|
||
height: 170rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
position: relative;
|
||
border-radius: 12rpx;
|
||
|
||
.item-icon-box {
|
||
width: 100rpx;
|
||
height: 100rpx;
|
||
border-radius: 20rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
margin-bottom: 12rpx;
|
||
}
|
||
|
||
.item-name {
|
||
font-size: 30rpx;
|
||
font-weight: bold;
|
||
color: #333;
|
||
text-align: center;
|
||
line-height: 1.3;
|
||
padding: 0 5rpx;
|
||
}
|
||
|
||
.item-badge {
|
||
position: absolute;
|
||
top: 10rpx;
|
||
right: 10rpx;
|
||
}
|
||
|
||
&:active {
|
||
background: #f8f9fa;
|
||
}
|
||
|
||
&.empty-item {
|
||
opacity: 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 分页指示器
|
||
.pagination-dots {
|
||
display: flex;
|
||
justify-content: center;
|
||
margin-top: 20rpx;
|
||
|
||
.pagination-dot {
|
||
width: 10rpx;
|
||
height: 10rpx;
|
||
border-radius: 50%;
|
||
background: #e0e0e0;
|
||
margin: 0 6rpx;
|
||
|
||
&.active {
|
||
background: #2979ff;
|
||
width: 30rpx;
|
||
border-radius: 5rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 加载状态
|
||
.loading-state {
|
||
padding: 100rpx 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
|
||
.loading-text {
|
||
margin-top: 20rpx;
|
||
color: #909399;
|
||
font-size: 24rpx;
|
||
}
|
||
}
|
||
|
||
// 空状态提示
|
||
.empty-state {
|
||
padding: 80rpx 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
|
||
.empty-text {
|
||
display: block;
|
||
font-size: 32rpx;
|
||
color: #999;
|
||
margin-top: 30rpx;
|
||
margin-bottom: 15rpx;
|
||
}
|
||
|
||
.empty-hint {
|
||
display: block;
|
||
font-size: 26rpx;
|
||
color: #ccc;
|
||
}
|
||
}
|
||
</style> |