61 lines
1.5 KiB
Vue
61 lines
1.5 KiB
Vue
<template>
|
|
<view v-if="showSwitch" 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, onMounted } from 'vue';
|
|
import sheep from '@/sheep';
|
|
|
|
const appStore = sheep.$store('app');
|
|
const userStore = sheep.$store('user');
|
|
|
|
const label = computed(() => (appStore.bizMode === 'merchant' ? '商户' : '用户'));
|
|
const showSwitch = computed(() => Number(userStore?.userInfo?.storeId || 0) > 0);
|
|
|
|
onMounted(() => {
|
|
if (!userStore?.isLogin) return;
|
|
if (showSwitch.value) return;
|
|
userStore.getInfo();
|
|
});
|
|
|
|
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>
|