feat: 添加商户端页面
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
<template>
|
||||
<view class="tabbar-wrap">
|
||||
<view class="tabbar safe-bottom">
|
||||
<view class="tabbar-inner">
|
||||
<view
|
||||
v-for="item in items"
|
||||
:key="item.pagePath"
|
||||
class="tabbar-item flex1 flex-center flex-column"
|
||||
:class="{ 'tabbar-item--mid': item.isMid }"
|
||||
@tap.stop="onTap(item)"
|
||||
>
|
||||
<view class="iconBox" :class="{ iconBoxMid: item.isMid }">
|
||||
<uni-icons
|
||||
:type="item.icon"
|
||||
:size="item.isMid ? 30 : 24"
|
||||
:color="isActive(item) ? activeColor : normalColor"
|
||||
/>
|
||||
</view>
|
||||
<view class="text" :class="{ textActive: isActive(item), textMid: item.isMid }">
|
||||
{{ item.text }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="props.placeholder" class="tabbar-placeholder safe-bottom"></view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
|
||||
const props = defineProps({
|
||||
path: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
placeholder: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const normalColor = '#666';
|
||||
const activeColor = '#2556EC';
|
||||
|
||||
const currentPath = ref('');
|
||||
|
||||
const normalizePath = (p) => {
|
||||
if (!p) return '';
|
||||
return p.startsWith('/') ? p : `/${p}`;
|
||||
};
|
||||
|
||||
const updateCurrentPath = () => {
|
||||
const pages = getCurrentPages?.() || [];
|
||||
const current = pages[pages.length - 1];
|
||||
const route = current?.route || '';
|
||||
currentPath.value = normalizePath(route);
|
||||
};
|
||||
|
||||
const hideNativeTabBar = () => {
|
||||
try {
|
||||
uni.hideTabBar({
|
||||
fail: () => {},
|
||||
});
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
onShow(() => {
|
||||
hideNativeTabBar();
|
||||
updateCurrentPath();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.path,
|
||||
(val) => {
|
||||
if (val) currentPath.value = normalizePath(val);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const items = computed(() => [
|
||||
{
|
||||
pagePath: '/pages/merchant/pickupList',
|
||||
text: '提货清单',
|
||||
icon: 'list',
|
||||
},
|
||||
{
|
||||
pagePath: '/pages/merchant/scanVerify',
|
||||
text: '扫码核销',
|
||||
icon: 'scan',
|
||||
isMid: true,
|
||||
},
|
||||
{
|
||||
pagePath: '/pages/merchant/storeManage',
|
||||
text: '网店管理',
|
||||
icon: 'shop',
|
||||
},
|
||||
]);
|
||||
|
||||
const isActive = (item) => {
|
||||
return normalizePath(item.pagePath) === normalizePath(currentPath.value);
|
||||
};
|
||||
|
||||
const onTap = (item) => {
|
||||
if (isActive(item)) return;
|
||||
hideNativeTabBar();
|
||||
uni.reLaunch({
|
||||
url: item.pagePath,
|
||||
fail: () => {
|
||||
uni.navigateTo({ url: item.pagePath });
|
||||
},
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.tabbar-wrap {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tabbar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 14rpx 24rpx;
|
||||
box-sizing: border-box;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.tabbar-inner {
|
||||
width: 100%;
|
||||
height: 110rpx;
|
||||
border-radius: 30rpx;
|
||||
background: rgba(255, 255, 255, 0.98);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 16rpx;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 16rpx 40rpx rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.tabbar-item {
|
||||
height: 110rpx;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.iconBox {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.iconBoxMid {
|
||||
width: 76rpx;
|
||||
height: 76rpx;
|
||||
border-radius: 22rpx;
|
||||
background: rgba(37, 86, 236, 0.12);
|
||||
}
|
||||
|
||||
.text {
|
||||
margin-top: 6rpx;
|
||||
font-size: 22rpx;
|
||||
color: #666;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.textActive {
|
||||
color: #2556ec;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.textMid {
|
||||
font-size: 20rpx;
|
||||
}
|
||||
|
||||
.tabbar-placeholder {
|
||||
height: calc(110rpx + 28rpx);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,52 @@
|
||||
<template>
|
||||
<view class="mode-switch" @tap.stop="open">
|
||||
<view class="mode-switch__text">{{ label }}</view>
|
||||
<uni-icons type="bottom" size="14" color="#333" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import sheep from '@/sheep';
|
||||
|
||||
const appStore = sheep.$store('app');
|
||||
|
||||
const label = computed(() => (appStore.bizMode === 'merchant' ? '商户' : '用户'));
|
||||
|
||||
const setMode = (mode) => {
|
||||
const next = mode === 'merchant' ? 'merchant' : 'user';
|
||||
if (appStore.bizMode === next) return;
|
||||
appStore.setBizMode(next);
|
||||
const url = next === 'merchant' ? '/pages/merchant/pickupList' : '/pages/index/index';
|
||||
uni.reLaunch({ url });
|
||||
};
|
||||
|
||||
const open = () => {
|
||||
uni.showActionSheet({
|
||||
itemList: ['用户', '商户'],
|
||||
success: ({ tapIndex }) => {
|
||||
setMode(tapIndex === 1 ? 'merchant' : 'user');
|
||||
},
|
||||
fail: () => {},
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.mode-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding: 10rpx 18rpx;
|
||||
border-radius: 100rpx;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.mode-switch__text {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
margin-right: 8rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user