profile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <view class="profile-page client-theme">
  3. <view v-if="profileLoading" class="profile-loading-wrap">
  4. <ClientSkeleton variant="hero-list" :rows="2" />
  5. </view>
  6. <scroll-view v-else scroll-y class="profile-scroll" :show-scrollbar="true">
  7. <!-- 对齐 sanqiang-client-profile-ui-demo.html .header -->
  8. <view class="profile-header sq-hero-header sq-hero-header--compact sq-hero-header--client">
  9. <view class="profile-header-content">
  10. <view class="user-row">
  11. <view class="avatar">
  12. <ClientImageLoader class="avatar-img" :src="avatarDisplayUrl" mode="aspectFill" radius="50%" />
  13. </view>
  14. <view class="user-text">
  15. <text class="user-name">{{ userStore.userInfo?.realName || '用户' }}</text>
  16. <text class="user-sub">
  17. 叁强会员 · {{ userStore.userInfo?.regionName?.trim() || '客户' }}
  18. </text>
  19. </view>
  20. </view>
  21. <view class="user-stats">
  22. <view class="stat-item" hover-class="stat-item--pressed" :hover-stay-time="100" @click="goOrders">
  23. <text class="stat-value">{{ dashPending }}</text>
  24. <text class="stat-label">待支付</text>
  25. </view>
  26. <view class="stat-item" hover-class="stat-item--pressed" :hover-stay-time="100" @click="goOrders">
  27. <text class="stat-value">{{ dashDeliver }}</text>
  28. <text class="stat-label">配送中</text>
  29. </view>
  30. <view class="stat-item" hover-class="stat-item--pressed" :hover-stay-time="100" @click="goOrders">
  31. <text class="stat-value">{{ dashDone }}</text>
  32. <text class="stat-label">已完成</text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="profile-section">
  38. <view class="menu-card">
  39. <view
  40. v-for="(item, index) in menuItems"
  41. :key="index"
  42. class="menu-row"
  43. hover-class="menu-row--pressed"
  44. :hover-stay-time="100"
  45. @click="goToMenu(item.path)"
  46. >
  47. <view class="menu-left">
  48. <view class="menu-ico-wrap" :class="{ 'menu-ico-wrap--bg': item.withBg }">
  49. <image class="menu-ico-img" :src="item.icon" mode="aspectFit" />
  50. </view>
  51. <text class="menu-text">{{ item.text }}</text>
  52. </view>
  53. <text class="menu-arrow">›</text>
  54. </view>
  55. <view class="menu-row" hover-class="menu-row--pressed" :hover-stay-time="100" @click="goToMenu('__service__')">
  56. <view class="menu-left">
  57. <view class="menu-ico-wrap menu-ico-wrap--bg">
  58. <image class="menu-ico-img" :src="ICON_SERVICE" mode="aspectFit" />
  59. </view>
  60. <text class="menu-text">联系客服</text>
  61. </view>
  62. <image class="menu-arrow-icon" :src="ICON_OUTGOING_CALL" mode="aspectFit" />
  63. </view>
  64. </view>
  65. <view class="logout-btn" hover-class="logout-btn--pressed" :hover-stay-time="120" @click="handleLogout">
  66. <text>退出登录</text>
  67. </view>
  68. </view>
  69. </scroll-view>
  70. <!-- #ifdef H5 -->
  71. <ClientTabBar active="profile" />
  72. <!-- #endif -->
  73. <view
  74. v-if="showLogoutDialog"
  75. class="logout-dialog-mask"
  76. @click="closeLogoutDialog"
  77. @touchmove.stop.prevent
  78. >
  79. <view class="logout-dialog" @click.stop>
  80. <view class="logout-dialog-title">退出登录</view>
  81. <view class="logout-dialog-content">退出后需要重新登录,确认要退出当前账号吗?</view>
  82. <view class="logout-dialog-actions">
  83. <view class="logout-action logout-action-cancel" @click="closeLogoutDialog">取消</view>
  84. <view class="logout-action logout-action-confirm" @click="confirmLogout">
  85. {{ logoutSubmitting ? '退出中...' : '退出登录' }}
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <script setup>
  93. import { computed, onMounted, ref } from 'vue'
  94. import { onShow } from '@dcloudio/uni-app'
  95. import { useUserStore } from '@/stores/user'
  96. import { request, parseResponseJson } from '@/utils/request'
  97. import { API_URL } from '@/config/api'
  98. import { resolveUserAvatarUrl } from '@/utils/avatar'
  99. import { fetchServicePhone, dialServicePhone } from '@/utils/service-contact'
  100. import { staticAssetUrl } from '@/utils/staticAsset'
  101. import ClientTabBar from '@/components/client/client-tab-bar.vue'
  102. import ClientSkeleton from '@/components/client/client-skeleton.vue'
  103. import ClientImageLoader from '@/components/client/client-image-loader.vue'
  104. // Store
  105. const userStore = useUserStore()
  106. const avatarDisplayUrl = computed(() =>
  107. resolveUserAvatarUrl(userStore.userInfo?.avatarUrl, userStore.userInfo?.role)
  108. )
  109. const dashPending = ref(0)
  110. const dashDeliver = ref(0)
  111. const dashDone = ref(0)
  112. const servicePhone = ref('')
  113. const profileLoading = ref(true)
  114. const showLogoutDialog = ref(false)
  115. const logoutSubmitting = ref(false)
  116. const ICON_COORDINATE = staticAssetUrl('coordinate-1.svg')
  117. const ICON_PASSWORD = staticAssetUrl('images/修改密码.svg')
  118. const ICON_SERVICE = staticAssetUrl('images/客服.svg')
  119. const ICON_OUTGOING_CALL = staticAssetUrl('Outgoing-call.svg')
  120. // 由于 `tabBar` 页面不能使用 `uni.navigateTo`,这里对已配置的 tabbar 路由做个区分
  121. const tabBarPageSet = new Set([
  122. '/pages/client/home/home',
  123. '/pages/client/order/order',
  124. '/pages/client/cart/cart',
  125. '/pages/client/profile/profile'
  126. ])
  127. function goOrders() {
  128. uni.switchTab({ url: '/pages/client/order/order' })
  129. }
  130. async function loadServicePhone() {
  131. servicePhone.value = await fetchServicePhone()
  132. }
  133. async function onCallService() {
  134. const p = servicePhone.value || (await fetchServicePhone())
  135. servicePhone.value = p
  136. dialServicePhone(p)
  137. }
  138. async function loadDashboard() {
  139. try {
  140. const res = await request({ url: API_URL.CLIENT_DASHBOARD, method: 'GET' })
  141. const body = parseResponseJson(res)
  142. if (body.code === 200 && body.data) {
  143. dashPending.value = body.data.pendingPayment ?? 0
  144. dashDeliver.value = body.data.delivering ?? 0
  145. dashDone.value = body.data.completed ?? 0
  146. }
  147. } catch {
  148. // 忽略统计失败
  149. }
  150. }
  151. // 与 miniprogram/profile 对齐(功能路径不变)
  152. const menuItems = [
  153. { text: '收货地址管理', path: '/pages/client/address/address', icon: ICON_COORDINATE, withBg: true },
  154. { text: '修改密码', path: '/pages/supplier/settings/password', icon: ICON_PASSWORD, withBg: true },
  155. ]
  156. // 跳转到菜单
  157. function goToMenu(path) {
  158. if (path === '__service__') {
  159. void onCallService()
  160. return
  161. }
  162. if (path) {
  163. if (tabBarPageSet.has(path)) {
  164. uni.switchTab({ url: path })
  165. } else {
  166. uni.navigateTo({ url: path })
  167. }
  168. } else {
  169. uni.showToast({ title: '功能开发中', icon: 'none' })
  170. }
  171. }
  172. // 退出登录
  173. function handleLogout() {
  174. showLogoutDialog.value = true
  175. }
  176. function closeLogoutDialog() {
  177. if (logoutSubmitting.value) return
  178. showLogoutDialog.value = false
  179. }
  180. async function confirmLogout() {
  181. if (logoutSubmitting.value) return
  182. logoutSubmitting.value = true
  183. try {
  184. await userStore.logout()
  185. showLogoutDialog.value = false
  186. } finally {
  187. logoutSubmitting.value = false
  188. }
  189. }
  190. onMounted(() => {
  191. userStore.checkLoginStatus()
  192. if (!userStore.isLoggedIn) {
  193. uni.reLaunch({ url: '/pages/login/login' })
  194. return
  195. }
  196. if (!userStore.isClient) {
  197. uni.showToast({ title: '请使用客户账号登录', icon: 'none' })
  198. setTimeout(() => userStore.navigateToHome(), 1500)
  199. return
  200. }
  201. ;(async () => {
  202. try {
  203. await Promise.all([loadDashboard(), loadServicePhone()])
  204. } finally {
  205. profileLoading.value = false
  206. }
  207. })()
  208. })
  209. onShow(() => {
  210. userStore.checkLoginStatus()
  211. if (!userStore.isLoggedIn || !userStore.isClient) return
  212. loadDashboard()
  213. })
  214. </script>
  215. <style lang="scss" scoped>
  216. .profile-loading-wrap {
  217. flex: 1;
  218. min-height: 0;
  219. }
  220. .profile-page {
  221. height: 100%;
  222. min-height: 0;
  223. background: var(--c-bg);
  224. display: flex;
  225. flex-direction: column;
  226. box-sizing: border-box;
  227. }
  228. .profile-scroll {
  229. flex: 1;
  230. min-height: 0;
  231. height: 0;
  232. width: 100%;
  233. box-sizing: border-box;
  234. }
  235. /* 对齐 sanqiang-client-profile-ui-demo.html .header */
  236. .profile-header {
  237. color: #ffffff;
  238. overflow: hidden;
  239. }
  240. .profile-header-content {
  241. padding: 8rpx 0 16rpx 0;
  242. }
  243. .user-row {
  244. display: flex;
  245. align-items: center;
  246. gap: 24rpx;
  247. margin-bottom: 24rpx;
  248. }
  249. .avatar {
  250. width: 108rpx;
  251. height: 108rpx;
  252. border-radius: 50%;
  253. background: rgba(255, 255, 255, 0.22);
  254. overflow: hidden;
  255. flex-shrink: 0;
  256. .avatar-img {
  257. width: 100%;
  258. height: 100%;
  259. }
  260. }
  261. .user-text {
  262. flex: 1;
  263. min-width: 0;
  264. display: flex;
  265. flex-direction: column;
  266. gap: 6rpx;
  267. }
  268. .user-name {
  269. font-size: 36rpx;
  270. font-weight: 700;
  271. line-height: 1.25;
  272. }
  273. .user-sub {
  274. font-size: 24rpx;
  275. opacity: 0.9;
  276. line-height: 1.35;
  277. }
  278. .user-stats {
  279. display: grid;
  280. grid-template-columns: repeat(3, 1fr);
  281. gap: 16rpx;
  282. }
  283. .stat-item {
  284. background: rgba(255, 255, 255, 0.14);
  285. border: 1rpx solid rgba(255, 255, 255, 0.22);
  286. border-radius: 24rpx;
  287. padding: 20rpx 16rpx;
  288. text-align: center;
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. }
  293. .stat-value {
  294. display: block;
  295. font-size: 36rpx;
  296. font-weight: 700;
  297. line-height: 1.2;
  298. }
  299. .stat-label {
  300. display: block;
  301. margin-top: 6rpx;
  302. font-size: 22rpx;
  303. opacity: 0.95;
  304. }
  305. .stat-item--pressed {
  306. opacity: 0.9;
  307. }
  308. .profile-section {
  309. padding: 24rpx 32rpx calc(32rpx + env(safe-area-inset-bottom, 0px));
  310. box-sizing: border-box;
  311. }
  312. .menu-card {
  313. background: var(--c-card);
  314. border: 1rpx solid var(--c-border);
  315. border-radius: 28rpx;
  316. padding: 8rpx 20rpx;
  317. box-sizing: border-box;
  318. }
  319. .menu-row {
  320. min-height: 92rpx;
  321. display: flex;
  322. align-items: center;
  323. justify-content: space-between;
  324. border-bottom: 1rpx solid #edf5f1;
  325. box-sizing: border-box;
  326. &:last-child {
  327. border-bottom: none;
  328. }
  329. }
  330. .menu-left {
  331. display: flex;
  332. align-items: center;
  333. gap: 20rpx;
  334. min-width: 0;
  335. }
  336. .menu-ico-img {
  337. width: 36rpx;
  338. height: 36rpx;
  339. flex-shrink: 0;
  340. }
  341. .menu-ico-wrap {
  342. width: 52rpx;
  343. height: 52rpx;
  344. border-radius: 16rpx;
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. flex-shrink: 0;
  349. }
  350. .menu-ico-wrap--bg {
  351. background: #0a9f6d;
  352. }
  353. .menu-text {
  354. font-size: 28rpx;
  355. color: var(--c-text);
  356. }
  357. .menu-row--pressed {
  358. opacity: 0.88;
  359. }
  360. .menu-arrow {
  361. font-size: 28rpx;
  362. color: #9ba8a2;
  363. flex-shrink: 0;
  364. }
  365. .menu-arrow-icon {
  366. width: 34rpx;
  367. height: 34rpx;
  368. flex-shrink: 0;
  369. }
  370. .logout-btn {
  371. margin-top: 24rpx;
  372. min-height: 88rpx;
  373. border-radius: 44rpx;
  374. background: linear-gradient(145deg, var(--c-brand-green), var(--c-brand-green-2));
  375. display: flex;
  376. align-items: center;
  377. justify-content: center;
  378. box-shadow: inset 0 -1rpx 0 rgba(0, 0, 0, 0.1);
  379. text {
  380. font-size: 28rpx;
  381. color: #ffffff;
  382. font-weight: 600;
  383. }
  384. }
  385. .logout-btn--pressed {
  386. opacity: 0.9;
  387. }
  388. .logout-dialog-mask {
  389. position: fixed;
  390. inset: 0;
  391. background: rgba(15, 23, 42, 0.36);
  392. backdrop-filter: blur(2px);
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. padding: 0 48rpx;
  397. z-index: 1200;
  398. }
  399. .logout-dialog {
  400. width: 100%;
  401. max-width: 620rpx;
  402. border-radius: 28rpx;
  403. background: #ffffff;
  404. box-shadow: 0 16rpx 42rpx rgba(10, 159, 109, 0.18);
  405. padding: 34rpx 28rpx 24rpx;
  406. box-sizing: border-box;
  407. }
  408. .logout-dialog-title {
  409. font-size: 34rpx;
  410. font-weight: 700;
  411. color: var(--c-text);
  412. text-align: center;
  413. line-height: 1.3;
  414. }
  415. .logout-dialog-content {
  416. margin-top: 14rpx;
  417. font-size: 26rpx;
  418. line-height: 1.6;
  419. color: var(--c-muted);
  420. text-align: center;
  421. }
  422. .logout-dialog-actions {
  423. margin-top: 28rpx;
  424. display: grid;
  425. grid-template-columns: repeat(2, 1fr);
  426. column-gap: 16rpx;
  427. }
  428. .logout-action {
  429. min-height: 76rpx;
  430. border-radius: 999rpx;
  431. display: flex;
  432. align-items: center;
  433. justify-content: center;
  434. font-size: 28rpx;
  435. font-weight: 600;
  436. }
  437. .logout-action-cancel {
  438. background: #f4f7f6;
  439. color: #5b6b64;
  440. border: 1rpx solid #ddebe5;
  441. }
  442. .logout-action-confirm {
  443. background: linear-gradient(145deg, var(--c-brand-green), var(--c-brand-green-2));
  444. color: #ffffff;
  445. }
  446. </style>
  447. <style lang="scss">
  448. page {
  449. height: 100%;
  450. background-color: #f5f8f7;
  451. }
  452. </style>