文件
Henglianshutong/uniapp/pages/index/user.vue

83 行
2.0 KiB
Vue

<template>
<s-layout
title="我的"
tabbar="/pages/index/user"
navbar="custom"
:bgStyle="template.style?.background"
:navbarStyle="template.style?.navbar"
onShareAppMessage
:showFloatButton="true"
>
<s-block v-for="(item, index) in layoutBlocks" :key="index" :styles="item.style">
<s-block-item :type="item.type" :data="item.data" :styles="item.style" />
</s-block>
</s-layout>
</template>
<script setup>
import { computed } from 'vue';
import { onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
import sheep from '@/sheep';
// 隐藏原生tabBar
uni.hideTabBar({
fail: () => {},
});
const template = computed(() => sheep.$store('app').template.user);
const isLogin = computed(() => sheep.$store('user').isLogin);
const defaultWalletStyle = {
background: {
type: 'color',
bgImage: '',
bgColor: '#FFFFFF',
},
marginLeft: 10,
marginRight: 10,
marginTop: 0,
marginBottom: 8,
borderRadiusTop: 8,
borderRadiusBottom: 8,
padding: 0,
};
const layoutBlocks = computed(() => {
const list = template.value?.data || [];
if (!Array.isArray(list) || list.length === 0) return list;
const hasWallet = list.some((item) => item.type === 'walletCard');
if (hasWallet) return list;
const blocks = [...list];
const userCardIndex = blocks.findIndex((item) => item.type === 'userCard');
const walletBlock = {
type: 'walletCard',
data: {},
style: defaultWalletStyle,
};
if (userCardIndex !== -1) {
blocks.splice(userCardIndex + 1, 0, walletBlock);
} else {
blocks.unshift(walletBlock);
}
return blocks;
});
onShow(() => {
sheep.$store('user').updateUserData();
});
onPullDownRefresh(() => {
sheep.$store('user').updateUserData();
setTimeout(function () {
uni.stopPullDownRefresh();
}, 800);
});
onPageScroll(() => {});
</script>
<style></style>