profile.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <script setup>
  2. import { computed, onMounted, ref } from 'vue';
  3. import { onShow } from '@dcloudio/uni-app';
  4. import { useUserStore } from '@/stores/user';
  5. import { resolveUserAvatarUrl } from '@/utils/avatar';
  6. import ClientSkeleton from '@/components/client/client-skeleton.vue';
  7. import ClientImageLoader from '@/components/client/client-image-loader.vue';
  8. import { fetchServicePhone, dialServicePhone } from '@/utils/service-contact';
  9. // Store
  10. const userStore = useUserStore();
  11. const avatarDisplayUrl = computed(() => resolveUserAvatarUrl(userStore.userInfo?.avatarUrl, userStore.userInfo?.role));
  12. // 角色名称
  13. const roleName = computed(() => {
  14. switch (userStore.userRole) {
  15. case 'client':
  16. return '客户';
  17. case 'supplier':
  18. return '供应商';
  19. case 'deliver':
  20. return '配送员';
  21. default:
  22. return '用户';
  23. }
  24. });
  25. // 主题色(三端统一品牌绿)
  26. const brandHex = computed(() => '#0a9f6d');
  27. const userCardStyle = computed(() => ({ background: brandHex.value }));
  28. const servicePhone = ref('');
  29. const profileLoading = ref(true);
  30. async function loadServicePhone() {
  31. servicePhone.value = await fetchServicePhone();
  32. }
  33. async function onCallService() {
  34. const p = servicePhone.value || (await fetchServicePhone());
  35. servicePhone.value = p;
  36. dialServicePhone(p);
  37. }
  38. // 退出登录
  39. function handleLogout() {
  40. uni.showModal({
  41. title: '提示',
  42. content: '确定退出登录?',
  43. success: async (res) => {
  44. if (res.confirm) {
  45. await userStore.logout();
  46. }
  47. }
  48. });
  49. }
  50. onMounted(() => {
  51. if (!userStore.isLoggedIn) {
  52. uni.reLaunch({ url: '/pages/login/login' });
  53. profileLoading.value = false;
  54. return;
  55. }
  56. if (!userStore.isSupplier) {
  57. uni.showToast({ title: '您不是供应商用户', icon: 'none' });
  58. setTimeout(() => userStore.navigateToHome(), 1500);
  59. profileLoading.value = false;
  60. return;
  61. }
  62. (async () => {
  63. try {
  64. await loadServicePhone();
  65. }
  66. finally {
  67. profileLoading.value = false;
  68. }
  69. })();
  70. });
  71. onShow(() => {
  72. if (!userStore.isLoggedIn || !userStore.isSupplier)
  73. return;
  74. void loadServicePhone();
  75. });
  76. </script>
  77. <template>
  78. <view class="supplier-profile">
  79. <ClientSkeleton v-if="profileLoading" variant="hero-list" :rows="2" />
  80. <template v-else>
  81. <!-- 用户信息卡片 -->
  82. <view class="user-card" :style="userCardStyle">
  83. <view class="user-info">
  84. <view class="avatar">
  85. <ClientImageLoader class="avatar-img" :src="avatarDisplayUrl" mode="aspectFill" radius="50%" />
  86. </view>
  87. <view class="user-detail">
  88. <text class="user-name">{{ userStore.userInfo?.realName || '用户' }}</text>
  89. <text class="user-role">{{ roleName }}</text>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 功能菜单 -->
  94. <view class="menu-list">
  95. <view class="menu-item" @click="onCallService">
  96. <view class="menu-left">
  97. <view class="solid-icon menu-icon icon-phone"></view>
  98. <text class="menu-text">联系客服</text>
  99. </view>
  100. <text class="menu-arrow">›</text>
  101. </view>
  102. <view class="menu-item">
  103. <view class="menu-left">
  104. <view class="solid-icon menu-icon icon-phone"></view>
  105. <text class="menu-text">手机号</text>
  106. </view>
  107. <view class="menu-right">
  108. <text class="menu-value">{{ userStore.userInfo?.phone || '未绑定' }}</text>
  109. </view>
  110. </view>
  111. <view class="menu-item">
  112. <view class="menu-left">
  113. <view class="solid-icon menu-icon icon-region"></view>
  114. <text class="menu-text">所属区域</text>
  115. </view>
  116. <view class="menu-right">
  117. <text class="menu-value">{{ userStore.userInfo?.regionName || '未分配' }}</text>
  118. </view>
  119. </view>
  120. </view>
  121. <!-- 设置菜单 -->
  122. <view class="menu-list">
  123. <view class="menu-item">
  124. <view class="menu-left">
  125. <view class="solid-icon menu-icon icon-password"></view>
  126. <text class="menu-text">修改密码</text>
  127. </view>
  128. <text class="menu-arrow">›</text>
  129. </view>
  130. <view class="menu-item">
  131. <view class="menu-left">
  132. <view class="solid-icon menu-icon icon-notice"></view>
  133. <text class="menu-text">消息通知</text>
  134. </view>
  135. <text class="menu-arrow">›</text>
  136. </view>
  137. <view class="menu-item">
  138. <view class="menu-left">
  139. <view class="solid-icon menu-icon icon-about"></view>
  140. <text class="menu-text">关于我们</text>
  141. </view>
  142. <text class="menu-arrow">›</text>
  143. </view>
  144. </view>
  145. <!-- 退出登录 -->
  146. <view class="logout-btn" @click="handleLogout">
  147. <text>退出登录</text>
  148. </view>
  149. <!-- 版本信息 -->
  150. <view class="version-info">
  151. <text>V1.0.0</text>
  152. </view>
  153. </template>
  154. </view>
  155. </template>
  156. <style lang="scss" scoped>
  157. .supplier-profile {
  158. min-height: 100vh;
  159. background: #f3f7f5;
  160. padding-bottom: constant(safe-area-inset-bottom);
  161. padding-bottom: env(safe-area-inset-bottom);
  162. }
  163. // 用户信息卡片
  164. .user-card {
  165. padding: 56rpx 30rpx 44rpx;
  166. color: #ffffff;
  167. border-bottom-left-radius: 24px;
  168. border-bottom-right-radius: 24px;
  169. box-shadow: 0 8px 20px rgba(10, 159, 109, 0.1);
  170. .user-info {
  171. display: flex;
  172. align-items: center;
  173. .avatar {
  174. width: 120rpx;
  175. height: 120rpx;
  176. background: rgba(255, 255, 255, 0.2);
  177. border-radius: 60rpx;
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. margin-right: 24rpx;
  182. overflow: hidden;
  183. .avatar-img {
  184. width: 100%;
  185. height: 100%;
  186. }
  187. }
  188. .user-detail {
  189. display: flex;
  190. flex-direction: column;
  191. .user-name {
  192. font-size: 36rpx;
  193. font-weight: 500;
  194. margin-bottom: 8rpx;
  195. }
  196. .user-role {
  197. font-size: 24rpx;
  198. opacity: 0.8;
  199. }
  200. }
  201. }
  202. }
  203. // 菜单列表
  204. .menu-list {
  205. background: #ffffff;
  206. margin: 20rpx;
  207. border-radius: 14px;
  208. border: 1px solid #d9e9e1;
  209. overflow: hidden;
  210. .menu-item {
  211. display: flex;
  212. align-items: center;
  213. justify-content: space-between;
  214. padding: 30rpx;
  215. border-bottom: 1rpx solid #f5f5f5;
  216. &:last-child {
  217. border-bottom: none;
  218. }
  219. .menu-left {
  220. display: flex;
  221. align-items: center;
  222. .menu-icon {
  223. width: 44rpx;
  224. height: 44rpx;
  225. margin-right: 20rpx;
  226. }
  227. .emoji-icon {
  228. display: none;
  229. }
  230. .menu-text {
  231. font-size: 28rpx;
  232. color: #303133;
  233. }
  234. }
  235. .menu-right {
  236. .menu-value {
  237. font-size: 28rpx;
  238. color: #909399;
  239. }
  240. }
  241. .menu-right--phone {
  242. display: flex;
  243. align-items: center;
  244. justify-content: flex-end;
  245. gap: 12rpx;
  246. max-width: 62%;
  247. }
  248. .menu-arrow {
  249. font-size: 32rpx;
  250. color: #c0c4cc;
  251. }
  252. }
  253. }
  254. .solid-icon {
  255. position: relative;
  256. border-radius: 12rpx;
  257. flex-shrink: 0;
  258. }
  259. .solid-icon::before,
  260. .solid-icon::after {
  261. content: '';
  262. position: absolute;
  263. }
  264. .icon-phone {
  265. background: #0a9f6d;
  266. }
  267. .icon-phone::before {
  268. left: 12rpx;
  269. top: 6rpx;
  270. width: 20rpx;
  271. height: 32rpx;
  272. border-radius: 5rpx;
  273. border: 3rpx solid #ffffff;
  274. }
  275. .icon-phone::after {
  276. left: 20rpx;
  277. bottom: 8rpx;
  278. width: 4rpx;
  279. height: 4rpx;
  280. border-radius: 50%;
  281. background: #ffffff;
  282. }
  283. .icon-region {
  284. background: #0a9f6d;
  285. }
  286. .icon-region::before {
  287. left: 14rpx;
  288. top: 8rpx;
  289. width: 16rpx;
  290. height: 24rpx;
  291. border-radius: 10rpx;
  292. transform: rotate(45deg);
  293. background: #ffffff;
  294. }
  295. .icon-region::after {
  296. left: 22rpx;
  297. top: 18rpx;
  298. width: 6rpx;
  299. height: 6rpx;
  300. border-radius: 50%;
  301. background: #0a9f6d;
  302. }
  303. .icon-password {
  304. background: #ee0a24;
  305. }
  306. .icon-password::before {
  307. left: 10rpx;
  308. top: 20rpx;
  309. width: 24rpx;
  310. height: 16rpx;
  311. border-radius: 4rpx;
  312. background: #ffffff;
  313. }
  314. .icon-password::after {
  315. left: 14rpx;
  316. top: 10rpx;
  317. width: 16rpx;
  318. height: 12rpx;
  319. border: 3rpx solid #ffffff;
  320. border-bottom: 0;
  321. border-radius: 10rpx 10rpx 0 0;
  322. }
  323. .icon-notice {
  324. background: #0a9f6d;
  325. }
  326. .icon-notice::before {
  327. left: 12rpx;
  328. top: 9rpx;
  329. width: 20rpx;
  330. height: 18rpx;
  331. border-radius: 10rpx 10rpx 6rpx 6rpx;
  332. background: #ffffff;
  333. }
  334. .icon-notice::after {
  335. left: 18rpx;
  336. bottom: 7rpx;
  337. width: 8rpx;
  338. height: 4rpx;
  339. border-radius: 0 0 6rpx 6rpx;
  340. background: #ffffff;
  341. }
  342. .icon-about {
  343. background: #05a050;
  344. }
  345. .icon-about::before {
  346. content: 'i';
  347. left: 0;
  348. top: 3rpx;
  349. width: 100%;
  350. text-align: center;
  351. font-size: 30rpx;
  352. font-weight: 700;
  353. color: #ffffff;
  354. }
  355. // 退出登录
  356. .logout-btn {
  357. margin: 40rpx 20rpx;
  358. height: 88rpx;
  359. background: #ffffff;
  360. border-radius: 14px;
  361. border: 1px solid #d9e9e1;
  362. display: flex;
  363. align-items: center;
  364. justify-content: center;
  365. text {
  366. font-size: 28rpx;
  367. color: #0a9f6d;
  368. }
  369. }
  370. // 版本信息
  371. .version-info {
  372. text-align: center;
  373. padding: 30rpx;
  374. text {
  375. font-size: 24rpx;
  376. color: #c0c4cc;
  377. }
  378. }
  379. </style>