文件
Henglianshutong/uniapp/sheep/components/s-user-card/s-user-card.vue

431 行
12 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<!-- 页面 -->
<template>
<view class="ss-user-info-wrap ss-p-t-50">
<view class="ss-flex ss-col-center ss-row-between ss-m-b-20">
<!-- 已登录状态 -->
<view v-if="isLogin" class="left-box ss-flex ss-col-center ss-m-l-36">
<view class="avatar-box ss-m-r-24">
<image
class="avatar-img"
:src="sheep.$url.cdn(userInfo.avatar)"
mode="aspectFill"
@tap="sheep.$router.go('/pages/user/info')"
></image>
</view>
<view class="user-meta">
<view class="nickname-box ss-flex ss-col-center">
<view class="nick-name ss-m-r-20">{{ userInfo?.nickname || nickname }}</view>
</view>
<view
v-if="showIdentityBadges"
class="identity-row ss-flex ss-col-center ss-flex-wrap"
@tap="onBadgeTap"
>
<view v-if="hasTaster" class="identity-tag taster-tag">{{ roleNames.taster || '品酒师' }}</view>
<view v-if="makerLevelName" class="identity-tag maker-tag">{{ makerLevelName }}</view>
<view v-if="hasVenue" class="identity-tag venue-tag">{{ roleNames.venue || '酒道馆' }}</view>
<view v-if="hasCounty" class="identity-tag county-tag">{{ roleNames.county || '区县' }}</view>
<view v-if="hasPartner" class="identity-tag partner-tag">{{ roleNames.partner || '合伙股东' }}</view>
</view>
</view>
</view>
<!-- 未登录状态:微信小程序原生手机号快捷登录按钮 -->
<!-- #ifdef MP-WEIXIN -->
<button
v-else
class="ss-reset-button left-box ss-flex ss-col-center ss-m-l-36 unlogin-btn"
open-type="getPhoneNumber"
@getphonenumber="onQuickLogin"
>
<view class="avatar-box ss-m-r-24">
<image
class="avatar-img"
:src="sheep.$url.static('/assets/addons/shopro/uniapp/default_avatar.png')"
mode="aspectFill"
></image>
</view>
<view class="user-meta">
<view class="nickname-box ss-flex ss-col-center">
<view class="nick-name ss-m-r-20">点击登录</view>
</view>
<view class="quick-login-badge ss-flex ss-col-center">
<text class="cicon-wechat ss-m-r-8"></text>
<text class="quick-badge-text">手机号快捷登录</text>
</view>
</view>
</button>
<!-- #endif -->
<!-- 未登录状态:其他平台普通点击呼出弹窗 -->
<!-- #ifndef MP-WEIXIN -->
<view
v-else
class="left-box ss-flex ss-col-center ss-m-l-36"
@tap="showAuthModal()"
>
<view class="avatar-box ss-m-r-24">
<image
class="avatar-img"
:src="sheep.$url.static('/assets/addons/shopro/uniapp/default_avatar.png')"
mode="aspectFill"
></image>
</view>
<view class="user-meta">
<view class="nickname-box ss-flex ss-col-center">
<view class="nick-name ss-m-r-20">{{ nickname }}</view>
</view>
</view>
</view>
<!-- #endif -->
<view class="right-box ss-m-r-52">
<button class="ss-reset-button" @tap="showShareModal">
<text class="sicon-qrcode"></text>
</button>
</view>
</view>
<view
class="bind-mobile-box ss-flex ss-row-between ss-col-center"
v-if="showBindMobile"
>
<view class="ss-flex">
<text class="cicon-mobile-o"></text>
<view class="mobile-title ss-m-l-20"> 点击绑定手机号确保账户安全 </view>
</view>
<!-- #ifdef MP-WEIXIN -->
<button
class="ss-reset-button bind-btn"
open-type="getPhoneNumber"
@getphonenumber="onBindPhoneNumber"
>
去绑定
</button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<button class="ss-reset-button bind-btn" @tap="onBind">去绑定</button>
<!-- #endif -->
</view>
</view>
</template>
<script setup>
/**
* 用户卡片
*
* @property {Number} leftSpace - 容器左间距
* @property {Number} rightSpace - 容器右间距
*
* @property {String} avatar - 头像
* @property {String} nickname - 昵称
* @property {String} vip - 等级
* @property {String} collectNum - 收藏数
* @property {String} likeNum - 点赞数
*
*
*/
import { computed } from 'vue';
import sheep from '@/sheep';
import { showShareModal, showAuthModal } from '@/sheep/hooks/useModal';
// 用户信息
const userInfo = computed(() => sheep.$store('user').userInfo);
// 是否登录
const isLogin = computed(() => sheep.$store('user').isLogin);
// 接收参数
const props = defineProps({
background: {
type: String,
default: '',
},
// 头像
avatar: {
type: String,
default: '',
},
nickname: {
type: String,
default: '请先登录',
},
vip: {
type: [String, Number],
default: '1',
},
collectNum: {
type: [String, Number],
default: '1',
},
likeNum: {
type: [String, Number],
default: '1',
},
});
const identities = computed(() =>
Array.isArray(userInfo.value?.identities) ? userInfo.value.identities : [],
);
const identityText = computed(() => userInfo.value?.identity_text || '');
const roleNames = computed(() => {
return userInfo.value?.custom_role_names || userInfo.value?.role_names || {};
});
const makerLevelName = computed(() => userInfo.value?.maker_level_name || '');
const hasVenue = computed(
() =>
identities.value.includes('venue') ||
identityText.value.includes('酒道馆') ||
(roleNames.value.venue && identityText.value.includes(roleNames.value.venue)),
);
const hasCounty = computed(
() =>
identities.value.includes('county') ||
identityText.value.includes('区县') ||
(roleNames.value.county && identityText.value.includes(roleNames.value.county)),
);
const hasPartner = computed(() => {
return (
Boolean(userInfo.value?.is_partner) ||
identities.value.includes('partner') ||
identityText.value.includes('合伙股东') ||
(roleNames.value.partner && identityText.value.includes(roleNames.value.partner))
);
});
const hasTaster = computed(() => {
if (makerLevelName.value) return false;
return (
identities.value.includes('taster') ||
identityText.value.includes('品酒师') ||
(roleNames.value.taster && identityText.value.includes(roleNames.value.taster))
);
});
const showIdentityBadges = computed(
() =>
hasTaster.value ||
!!makerLevelName.value ||
hasVenue.value ||
hasCounty.value ||
hasPartner.value,
);
const hasBoundMobile = computed(() => {
return Boolean(userInfo.value?.mobile || userInfo.value?.verification?.mobile);
});
const showBindMobile = computed(() => {
// 1. 未登录不展示
if (!isLogin.value) return false;
// 2. 存在已绑定手机号不展示
if (hasBoundMobile.value) return false;
// 3. 微信小程序环境:默认手机号快捷登录体系,不展示此冗余横幅
// #ifdef MP-WEIXIN
return false;
// #endif
// 4. 其他环境:受平台设置“绑定手机号”开关控制
return Boolean(sheep.$store('app').platform?.bind_mobile);
});
function onBind() {
showAuthModal('changeMobile');
}
// 微信小程序一键快捷绑定手机号
async function onBindPhoneNumber(e) {
if (e.detail?.errMsg !== 'getPhoneNumber:ok') {
showAuthModal('changeMobile');
return;
}
uni.showLoading({ title: '绑定中...', mask: true });
try {
const result = await sheep.$platform.useProvider('wechat').bindUserPhoneNumber(e.detail);
if (result) {
await sheep.$store('user').getInfo();
sheep.$helper.toast('绑定成功');
} else {
showAuthModal('changeMobile');
}
} catch (err) {
console.error('onBindPhoneNumber error', err);
showAuthModal('changeMobile');
} finally {
uni.hideLoading();
}
}
function onBadgeTap() {
if (!isLogin.value) {
showAuthModal();
return;
}
sheep.$router.go('/pages/commission/index');
}
// 微信小程序手机号一键快捷登录
async function onQuickLogin(e) {
if (e.detail?.errMsg !== 'getPhoneNumber:ok') {
showAuthModal();
return;
}
uni.showLoading({
title: '登录中...',
mask: true,
});
try {
const result = await sheep.$platform.useProvider('wechat').mobileLogin(e.detail);
if (result) {
await sheep.$store('user').loginAfter();
sheep.$helper.toast('登录成功');
} else {
sheep.$helper.toast('登录失败,请重试');
showAuthModal();
}
} catch (err) {
console.error('onQuickLogin error', err);
sheep.$helper.toast('登录异常,请稍后重试');
} finally {
uni.hideLoading();
}
}
</script>
<style lang="scss" scoped>
.ss-user-info-wrap {
box-sizing: border-box;
.unlogin-btn {
text-align: left;
background: transparent;
padding: 0;
line-height: normal;
}
.quick-login-badge {
display: inline-flex;
align-items: center;
margin-top: 8rpx;
padding: 4rpx 14rpx;
font-size: 20rpx;
line-height: 28rpx;
color: #07c160;
background: rgba(7, 193, 96, 0.1);
border-radius: 20rpx;
border: 1rpx solid rgba(7, 193, 96, 0.25);
.cicon-wechat {
font-size: 24rpx;
line-height: 1;
}
.quick-badge-text {
font-size: 20rpx;
font-weight: 500;
}
}
.avatar-box {
width: 100rpx;
height: 100rpx;
border-radius: 50%;
overflow: hidden;
.avatar-img {
width: 100%;
height: 100%;
}
}
.user-meta {
max-width: 430rpx;
}
.nick-name {
font-size: 34rpx;
font-weight: 400;
color: #333333;
line-height: normal;
}
.identity-row {
margin-top: 10rpx;
max-width: 430rpx;
}
.identity-tag {
font-size: 20rpx;
line-height: 32rpx;
padding: 0 12rpx;
border-radius: 16rpx;
margin: 0 8rpx 8rpx 0;
}
.taster-tag {
color: #8a5a2b;
background: #f3e4cd;
}
.partner-tag {
color: #ffffff;
background: #ff6000;
}
.maker-tag {
color: #692e04;
background: #ffd9a8;
}
.venue-tag,
.county-tag {
color: #ffffff;
background: #c48a3a;
}
.vip-img {
width: 30rpx;
height: 30rpx;
}
.sicon-qrcode {
font-size: 40rpx;
}
}
.bind-mobile-box {
width: 100%;
height: 84rpx;
padding: 0 34rpx 0 44rpx;
box-sizing: border-box;
background: #ffffff;
box-shadow: 0px -8rpx 9rpx 0px rgba(#e0e0e0, 0.3);
.cicon-mobile-o {
font-size: 30rpx;
color: #ff690d;
}
.mobile-title {
font-size: 24rpx;
font-weight: 500;
color: #ff690d;
}
.bind-btn {
width: 100rpx;
height: 50rpx;
background: #ff6100;
border-radius: 25rpx;
font-size: 24rpx;
font-weight: 500;
color: #ffffff;
}
}
</style>