This commit is contained in:
2025-09-27 22:57:59 +08:00
parent 8a458ff0a4
commit ed26244cdb
12585 changed files with 1914308 additions and 3474 deletions

View File

@@ -1,21 +1,25 @@
<template>
<view class="me">
<view v-if="!isLoggedIn" class="card login">
<view class="login-title">登录/注册以同步数据</view>
<button class="login-btn" type="primary" @click="goLogin">登录</button>
<button class="login-btn minor" @click="goRegister">注册</button>
</view>
<view class="card user">
<image class="avatar" :src="avatarUrl" mode="aspectFill" @error="onAvatarError" />
<view class="card user" v-if="isLoggedIn">
<image class="avatar" :src="avatarDisplay" mode="aspectFill" @error="onAvatarError" />
<view class="meta">
<text class="name">{{ shopName }}</text>
<text class="phone">{{ mobileDisplay }}</text>
<text class="phone">{{ emailDisplay }}</text>
<text class="role">老板</text>
</view>
</view>
<view v-else class="card user guest">
<image class="avatar" src="/static/icons/icons8-login-50.png" mode="aspectFill" />
<view class="meta">
<text class="name">未登录</text>
<text class="phone">登录后同步数据</text>
<text class="role">访客</text>
</view>
<button class="login-entry" @click="goLogin">登录</button>
</view>
<!-- VIP 卡片置于会员与订单分组上方 -->
<view class="card vip" :class="{ active: vipIsVip }">
<view v-if="isLoggedIn" class="card vip" :class="{ active: vipIsVip }">
<view class="vip-row">
<text class="vip-badge">{{ vipIsVip ? 'VIP' : '非VIP' }}</text>
<text class="vip-title">会员状态</text>
@@ -35,7 +39,11 @@
<view class="group">
<view class="group-title">会员与订单</view>
<view class="cell" @click="goVip">
<text>VIP会员</text>
<view class="cell-left">
<text>VIP会员</text>
<text v-if="vipIsVip" class="vip-tag">已开通</text>
<text v-else class="vip-tag pending">待开通</text>
</view>
<text class="arrow"></text>
</view>
<view class="cell" @click="goMyOrders">
@@ -44,42 +52,16 @@
</view>
</view>
<view class="group">
<view class="group-title">基础管理</view>
<view class="cell" @click="goSupplier">
<text>供应商管理</text>
<text class="arrow"></text>
</view>
<view class="cell" @click="goCustomer">
<text>客户管理</text>
<text class="arrow"></text>
</view>
<view class="cell" @click="goCustomerQuote">
<text>客户报价</text>
<text class="arrow"></text>
</view>
<view class="cell" @click="goShop">
<text>店铺管理</text>
<text class="arrow"></text>
</view>
</view>
<view class="group">
<view class="group-title">设置中心</view>
<view class="cell" @click="editProfile">
<text>账号与安全</text>
<text class="desc">修改头像姓名密码</text>
<text class="arrow"></text>
</view>
<view class="cell" @click="goProductSettings">
<text>商品设置</text>
<text class="arrow"></text>
</view>
<view class="cell" @click="goSystemParams">
<text>系统参数</text>
<text class="desc">低价提示默认收款单行折扣等</text>
<text class="desc">修改头像姓名密码电话</text>
<text class="arrow"></text>
</view>
<view class="cell" @click="goAbout">
<text>关于与协议</text>
<text class="arrow"></text>
@@ -93,79 +75,158 @@
<script>
import { get } from '../../common/http.js'
import { API_BASE_URL } from '../../common/config.js'
function normalizeAvatar(url) {
if (!url) return '/static/icons/icons8-mitt-24.png'
const s = String(url)
if (/^https?:\/\//i.test(s)) return s
if (!API_BASE_URL) return s
if (s.startsWith('/')) return `${API_BASE_URL}${s}`
return `${API_BASE_URL}/${s}`
}
export default {
data() {
return {
avatarUrl: '/static/logo.png',
shopName: '未登录',
mobile: '',
pendingJsCode: '',
logging: false,
vipIsVip: false,
vipStart: '',
vipEnd: ''
}
},
onShow() {
this.fetchProfile()
this.loadVipFromStorage()
try {
if (uni.getStorageSync('TOKEN')) {
// 已登录时刷新资料并隐藏登录卡片
this.$forceUpdate && this.$forceUpdate()
}
} catch(e) {}
},
computed: {
isLoggedIn() { try { return !!uni.getStorageSync('TOKEN') } catch(e){ return false } },
mobileDisplay() {
const m = String(this.mobile || '')
return m.length === 11 ? m.slice(0,3) + '****' + m.slice(7) : (m || '未绑定手机号')
},
vipStartDisplay() { return this.formatDisplay(this.vipStart) },
vipEndDisplay() { return this.formatDisplay(this.vipEnd) }
},
methods: {
data() {
return {
avatarUrl: '/static/icons/icons8-mitt-24.png',
shopName: '未登录',
mobile: '',
pendingJsCode: '',
logging: false,
vipIsVip: false,
vipStart: '',
vipEnd: ''
}
},
onShow() {
this.fetchProfile()
this.loadVip()
try {
if (uni.getStorageSync('TOKEN')) {
// 已登录时刷新资料并隐藏登录卡片
this.$forceUpdate && this.$forceUpdate()
}
} catch(e) {}
},
computed: {
isLoggedIn() { try { return !!uni.getStorageSync('TOKEN') } catch(e){ return false } },
avatarDisplay() { return normalizeAvatar(this.avatarUrl) },
emailDisplay() {
if (!this.isLoggedIn) return ''
const e = String(uni.getStorageSync('USER_EMAIL') || '')
if (!e) return '未绑定邮箱'
const at = e.indexOf('@')
if (at > 1) {
const name = e.slice(0, at)
const domain = e.slice(at)
return (name.length <= 2 ? name[0] + '*' : name.slice(0,2) + '***') + domain
}
return e
},
vipStartDisplay() { return this.formatDisplay(this.vipStart) },
vipEndDisplay() { return this.formatDisplay(this.vipEnd) }
},
methods: {
// 登录相关方法已移除
async fetchProfile() {
// 未登录则不触发任何用户/店铺接口,也不加载本地用户字段
const hasToken = (() => { try { return !!uni.getStorageSync('TOKEN') } catch(e){ return false } })()
if (!hasToken) {
this.shopName = '未登录'
this.avatarUrl = '/static/logo.png'
this.mobile = ''
return
}
// 已登录:拉取概览以确认在线状态,并回填本地用户信息
try { await get('/api/dashboard/overview') } catch(e) {}
try {
const storeName = uni.getStorageSync('SHOP_NAME') || ''
const avatar = uni.getStorageSync('USER_AVATAR') || ''
const phone = uni.getStorageSync('USER_MOBILE') || ''
if (storeName) this.shopName = storeName
if (avatar) this.avatarUrl = avatar
this.mobile = phone
} catch(e) {}
},
loadVipFromStorage() {
try {
const isVip = String(uni.getStorageSync('USER_VIP_IS_VIP') || 'false').toLowerCase() === 'true'
const start = uni.getStorageSync('USER_VIP_START') || ''
const end = uni.getStorageSync('USER_VIP_END') || ''
this.vipIsVip = isVip
this.vipStart = start
this.vipEnd = end
} catch(e) {}
},
formatDisplay(value) {
if (!value) return '-'
const s = String(value)
// 简单规范化:只保留到分钟
const m = s.match(/^(\d{4}-\d{2}-\d{2})([ T](\d{2}:\d{2}))/)
if (m) return `${m[1]} ${m[3]}`
return s
},
async fetchProfile() {
const hasToken = (() => { try { return !!uni.getStorageSync('TOKEN') } catch(e){ return false } })()
if (!hasToken) {
this.shopName = '未登录'
this.avatarUrl = '/static/icons/icons8-mitt-24.png'
this.mobile = ''
return
}
try {
const profile = await get('/api/user/me')
const latestAvatar = profile?.avatarUrl || ''
if (latestAvatar) {
const bust = `${latestAvatar}${latestAvatar.includes('?') ? '&' : '?'}t=${Date.now()}`
this.avatarUrl = bust
try {
uni.setStorageSync('USER_AVATAR_RAW', latestAvatar)
uni.setStorageSync('USER_AVATAR', latestAvatar)
} catch(_){}
} else {
const cached = uni.getStorageSync('USER_AVATAR') || ''
this.avatarUrl = cached || '/static/icons/icons8-mitt-24.png'
}
const storeName = profile?.name || uni.getStorageSync('SHOP_NAME') || '未命名店铺'
this.shopName = storeName
const phone = profile?.phone || uni.getStorageSync('USER_MOBILE') || ''
this.mobile = phone
} catch(e) {
try {
const storeName = uni.getStorageSync('SHOP_NAME') || ''
const avatar = uni.getStorageSync('USER_AVATAR') || ''
const phone = uni.getStorageSync('USER_MOBILE') || ''
if (storeName) this.shopName = storeName
if (avatar) this.avatarUrl = avatar
this.mobile = phone
} catch(_){}
}
},
async loadVip() {
try {
const hasToken = (() => { try { return !!uni.getStorageSync('TOKEN') } catch(e){ return false } })()
if (!hasToken) {
// 未登录:不读取本地缓存,直接复位为默认值并隐藏卡片(由 v-if 控制)
this.vipIsVip = false
this.vipStart = ''
this.vipEnd = ''
return
}
const data = await get('/api/vip/status')
const active = !!data?.isVip
this.vipIsVip = active
this.vipEnd = data?.expireAt || ''
// 根据结束时间动态计算开始时间(固定退 1 个月)
let computedStart = ''
const exp = this.vipEnd
if (exp) {
const m = String(exp).match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/)
if (m) {
const y = Number(m[1])
const mo = Number(m[2]) - 1
const da = Number(m[3])
const hh = Number(m[4] || '0')
const mm = Number(m[5] || '0')
const ss = Number(m[6] || '0')
const startDate = new Date(y, mo - 1, da, hh, mm, ss)
const y2 = startDate.getFullYear()
const m2 = (startDate.getMonth() + 1).toString().padStart(2, '0')
const d2 = startDate.getDate().toString().padStart(2, '0')
const h2 = startDate.getHours().toString().padStart(2, '0')
const i2 = startDate.getMinutes().toString().padStart(2, '0')
computedStart = `${y2}-${m2}-${d2} ${h2}:${i2}`
}
}
// 写入到本地与内存
this.vipStart = computedStart
// 同步到本地,便于其他页面读取
try {
uni.setStorageSync('USER_VIP_IS_VIP', String(active))
uni.setStorageSync('USER_VIP_END', this.vipEnd)
if (this.vipStart) uni.setStorageSync('USER_VIP_START', this.vipStart); else uni.removeStorageSync('USER_VIP_START')
} catch(_) {}
} catch(e) {
// 网络异常回退到缓存
try {
const isVip = String(uni.getStorageSync('USER_VIP_IS_VIP') || 'false').toLowerCase() === 'true'
this.vipIsVip = isVip
this.vipStart = uni.getStorageSync('USER_VIP_START') || ''
this.vipEnd = uni.getStorageSync('USER_VIP_END') || ''
} catch(_) {}
}
},
formatDisplay(value) {
if (!value) return '-'
const s = String(value)
// 简单规范化:只保留到分钟
const m = s.match(/^(\d{4}-\d{2}-\d{2})([ T](\d{2}:\d{2}))/)
if (m) return `${m[1]} ${m[3]}`
return s
},
startLogin() {
if (this.logging) return
this.logging = true
@@ -194,7 +255,6 @@ export default {
}, fail: () => { this.logging = false; uni.showToast({ title: '微信登录失败', icon: 'none' }) } })
},
goLogin(){ uni.navigateTo({ url: '/pages/auth/login' }) },
goRegister(){ uni.navigateTo({ url: '/pages/auth/register' }) },
onGetPhoneNumber(e) {
if (this.logging) return
this.logging = true
@@ -208,17 +268,11 @@ export default {
},
goSmsLogin(){ uni.navigateTo({ url: '/pages/my/sms-login' }) },
onAvatarError() {
this.avatarUrl = '/static/logo.png'
this.avatarUrl = '/static/icons/icons8-mitt-24.png'
},
goVip() { uni.navigateTo({ url: '/pages/my/vip' }) },
goMyOrders() { uni.switchTab({ url: '/pages/detail/index' }) },
goSupplier() { uni.navigateTo({ url: '/pages/supplier/select' }) },
goCustomer() { uni.navigateTo({ url: '/pages/customer/select' }) },
goCustomerQuote() { uni.showToast({ title: '客户报价(开发中)', icon: 'none' }) },
goShop() { uni.showToast({ title: '店铺管理(开发中)', icon: 'none' }) },
editProfile() { uni.showToast({ title: '账号与安全(开发中)', icon: 'none' }) },
goProductSettings() { uni.navigateTo({ url: '/pages/product/settings' }) },
goSystemParams() { uni.showToast({ title: '系统参数(开发中)', icon: 'none' }) },
goMyOrders() { uni.navigateTo({ url: '/pages/my/orders' }) },
editProfile() { uni.navigateTo({ url: '/pages/my/security' }) },
goAbout() { uni.navigateTo({ url: '/pages/my/about' }) },
logout() {
try {
@@ -228,9 +282,14 @@ export default {
uni.removeStorageSync('DEFAULT_USER_ID')
uni.setStorageSync('ENABLE_DEFAULT_USER', 'false')
uni.removeStorageSync('USER_AVATAR')
uni.removeStorageSync('USER_AVATAR_RAW')
uni.removeStorageSync('USER_NAME')
uni.removeStorageSync('USER_MOBILE')
uni.removeStorageSync('USER_EMAIL')
uni.removeStorageSync('SHOP_NAME')
uni.removeStorageSync('USER_VIP_IS_VIP')
uni.removeStorageSync('USER_VIP_START')
uni.removeStorageSync('USER_VIP_END')
uni.showToast({ title: '已清理本地信息', icon: 'none' })
setTimeout(() => { uni.reLaunch({ url: '/pages/index/index' }) }, 300)
} catch(e) { uni.reLaunch({ url: '/pages/index/index' }) }
@@ -247,6 +306,9 @@ export default {
.login-btn.minor { background: $uni-bg-color-hover; color: $uni-text-color; }
.hint { font-size: 22rpx; color: $uni-text-color-grey; }
.card.user { display: flex; gap: 18rpx; padding: 22rpx; background: $uni-bg-color-grey; border-radius: 16rpx; box-shadow: 0 6rpx 16rpx rgba(0,0,0,0.16); align-items: center; }
.card.user.guest { justify-content: space-between; }
.card.user.guest .meta { flex: 1; }
.card.user.guest .login-entry { padding: 12rpx 30rpx; border-radius: 999rpx; background: $uni-color-primary; color: #fff; font-size: 28rpx; font-weight: 600; }
.avatar { width: 120rpx; height: 120rpx; border-radius: 60rpx; background: $uni-bg-color-hover; }
.meta { display: flex; flex-direction: column; gap: 6rpx; }
.name { font-size: 34rpx; font-weight: 700; color: $uni-text-color; }
@@ -266,7 +328,10 @@ export default {
.group { margin-top: 24rpx; background: $uni-bg-color-grey; border-radius: 16rpx; overflow: hidden; }
.group-title { padding: 18rpx 22rpx; font-size: 26rpx; color: $uni-text-color-grey; background: $uni-bg-color-hover; }
.cell { display: flex; align-items: center; padding: 26rpx 22rpx; border-top: 1rpx solid $uni-border-color; color: $uni-text-color; }
.cell { display: flex; align-items: center; padding: 26rpx 22rpx; border-top: 1rpx solid $uni-border-color; color: $uni-text-color; gap: 18rpx; }
.cell-left { display:flex; align-items:center; gap: 14rpx; }
.vip-tag { padding: 4rpx 12rpx; border-radius: 999rpx; background: rgba(76,141,255,0.15); color: $uni-color-primary; font-size: 22rpx; }
.vip-tag.pending { background: rgba(76,141,255,0.06); color: #99a2b3; }
.cell .desc { margin-left: auto; margin-right: 8rpx; font-size: 22rpx; color: $uni-text-color-grey; }
.cell .arrow { margin-left: auto; color: #99a2b3; }
.cell.danger { color: #dd524d; justify-content: center; font-weight: 700; }