No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

464 líneas
10 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 头部 -->
  4. <view class="profile-header">
  5. <image class="header-bg" src="https://cdn.csybhelp.com/images/cytx/profile-bg.jpg" mode="aspectFill" />
  6. <view class="user-row">
  7. <view class="avatar-wrap" @tap="isLoggedIn && changeAvatar()">
  8. <image class="avatar" :src="userInfo?.avatar || 'https://cdn.csybhelp.com/images/cytx/default-avatar.jpg'"
  9. mode="aspectFill" />
  10. <view v-if="isLoggedIn" class="camera-icon">
  11. <u-icon name="camera-fill" size="20" color="#666" />
  12. </view>
  13. </view>
  14. <view class="info" @tap="!isLoggedIn && goLogin()">
  15. <view class="name">{{ displayName }}</view>
  16. <view v-if="isLoggedIn && userInfo?.patient?.patient_no" class="patient-no">{{ userInfo.patient.patient_no }}</view>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 驳回提示 -->
  21. <view v-if="isRejected" class="reject-tip" @tap="goRejectDetail">
  22. <u-icon name="warning-fill" size="20" color="#fa8c16" />
  23. <text class="reject-text">您提交的资料未通过审核,请点击查看详情并重新提交。</text>
  24. <u-icon name="arrow-right" size="16" color="#f5222d" />
  25. </view>
  26. <!-- 菜单区域 -->
  27. <view class="menu-section" :class="{ 'no-overlap': isRejected }">
  28. <view class="menu-item" @tap="goMyInfo">
  29. <view class="menu-icon">
  30. <u-icon name="file-text-fill" size="20" color="#0e63e3" />
  31. </view>
  32. <text class="text">我的资料</text>
  33. <text v-if="patientStatus === -1" class="extra draft">待提交</text>
  34. <text v-else-if="patientStatus === 0" class="extra pending">待审核</text>
  35. <text v-else-if="patientStatus === 1" class="extra authed">已通过</text>
  36. <text v-else-if="patientStatus === 2" class="extra rejected">已驳回</text>
  37. <u-icon name="arrow-right" size="16" color="#c0c4cc" />
  38. </view>
  39. <view class="menu-item" @tap="goMessage">
  40. <view class="menu-icon">
  41. <u-icon name="chat-fill" size="20" color="#fa8c16" />
  42. </view>
  43. <text class="text">消息中心</text>
  44. <u-badge v-if="unreadCount > 0" :value="unreadCount" :max="99" type="error" />
  45. <u-icon name="arrow-right" size="16" color="#c0c4cc" />
  46. </view>
  47. <view class="menu-item" @tap="goVerify">
  48. <view class="menu-icon">
  49. <u-icon name="account-fill" size="20" color="#52c41a" />
  50. </view>
  51. <text class="text">实名认证</text>
  52. <text v-if="isAuthed" class="extra authed">已认证</text>
  53. <text v-else class="extra link">去认证</text>
  54. <u-icon name="arrow-right" size="16" color="#c0c4cc" />
  55. </view>
  56. </view>
  57. <view class="menu-section">
  58. <view class="menu-item" @tap="goChangePhone">
  59. <view class="menu-icon">
  60. <u-icon name="phone-fill" size="20" color="#0e63e3" />
  61. </view>
  62. <text class="text">修改手机号</text>
  63. <u-icon name="arrow-right" size="16" color="#c0c4cc" />
  64. </view>
  65. <view class="menu-item" @tap="goTo('/pages/content/content?key=privacy_policy')">
  66. <view class="menu-icon">
  67. <u-icon name="lock-fill" size="20" color="#909399" />
  68. </view>
  69. <text class="text">隐私协议</text>
  70. <u-icon name="arrow-right" size="16" color="#c0c4cc" />
  71. </view>
  72. <view class="menu-item" @tap="goTo('/pages/content/content?key=about_us')">
  73. <view class="menu-icon">
  74. <u-icon name="info-circle-fill" size="20" color="#909399" />
  75. </view>
  76. <text class="text">关于我们</text>
  77. <u-icon name="arrow-right" size="16" color="#c0c4cc" />
  78. </view>
  79. </view>
  80. <button v-if="isLoggedIn" class="logout-btn" @tap="handleLogout">退出登录</button>
  81. <button v-else class="login-btn" @tap="goLogin">去登录</button>
  82. </view>
  83. </template>
  84. <script setup>
  85. import { ref, computed } from 'vue'
  86. import { onShow } from '@dcloudio/uni-app'
  87. import { get, post, upload } from '@/utils/request.js'
  88. import { getToken, getUserInfo, setUserInfo, clearAll } from '@/utils/cache.js'
  89. const userInfo = ref(getUserInfo())
  90. const isLoggedIn = ref(!!getToken())
  91. const unreadCount = ref(0)
  92. const isAuthed = computed(() => userInfo.value?.patient?.auth_status === 1)
  93. const patientStatus = computed(() => {
  94. const p = userInfo.value?.patient
  95. if (!p) return null
  96. return p.status
  97. })
  98. const isRejected = computed(() => patientStatus.value === 2)
  99. const displayName = computed(() => {
  100. if (!isLoggedIn.value) return '点击登录'
  101. if (isAuthed.value && userInfo.value?.patient?.name) return userInfo.value.patient.name
  102. return userInfo.value?.nickname || '微信用户'
  103. })
  104. onShow(() => {
  105. isLoggedIn.value = !!getToken()
  106. userInfo.value = getUserInfo()
  107. if (isLoggedIn.value) {
  108. fetchUserInfo()
  109. fetchUnreadCount()
  110. } else {
  111. unreadCount.value = 0
  112. }
  113. })
  114. const fetchUserInfo = async () => {
  115. try {
  116. const res = await get('/api/mp/userinfo')
  117. userInfo.value = res.data
  118. setUserInfo(res.data)
  119. } catch (e) {
  120. if (e?.code === 1009) {
  121. clearAll()
  122. userInfo.value = null
  123. }
  124. }
  125. }
  126. const fetchUnreadCount = async () => {
  127. try {
  128. const res = await get('/api/mp/unreadCount')
  129. unreadCount.value = res.data?.count || 0
  130. } catch (e) {}
  131. }
  132. const checkLogin = () => {
  133. if (!isLoggedIn.value) {
  134. uni.showToast({ title: '请先登录', icon: 'none' })
  135. setTimeout(() => goLogin(), 1500)
  136. return false
  137. }
  138. return true
  139. }
  140. const checkAuth = () => {
  141. if (!checkLogin()) return false
  142. if (!isAuthed.value) {
  143. uni.showToast({ title: '请先完成实名认证', icon: 'none' })
  144. return false
  145. }
  146. return true
  147. }
  148. const goTo = (url) => {
  149. uni.navigateTo({ url })
  150. }
  151. const goMyInfo = () => {
  152. if (!checkAuth()) return
  153. uni.navigateTo({ url: '/pages/myinfo/myinfo' })
  154. }
  155. const goChangePhone = () => {
  156. if (!checkAuth()) return
  157. uni.navigateTo({ url: '/pages/change-phone/change-phone' })
  158. }
  159. const goMessage = () => {
  160. if (!checkLogin()) return
  161. uni.navigateTo({ url: '/pages/message/message' })
  162. }
  163. const goVerify = () => {
  164. if (!checkLogin()) return
  165. uni.navigateTo({ url: '/pages/verify/verify' })
  166. }
  167. const goLogin = () => {
  168. uni.navigateTo({ url: '/pages/login/index' })
  169. }
  170. const goRejectDetail = () => {
  171. uni.navigateTo({ url: '/pages/myinfo/myinfo' })
  172. }
  173. const changeAvatar = () => {
  174. uni.chooseImage({
  175. count: 1,
  176. sizeType: ['compressed'],
  177. sourceType: ['album', 'camera'],
  178. success: async (chooseRes) => {
  179. let filePath = chooseRes.tempFilePaths[0]
  180. // 小程序端使用 cropImage 裁剪
  181. // #ifdef MP-WEIXIN
  182. try {
  183. const cropRes = await new Promise((resolve, reject) => {
  184. wx.cropImage({
  185. src: filePath,
  186. cropScale: '1:1',
  187. success: resolve,
  188. fail: reject
  189. })
  190. })
  191. filePath = cropRes.tempFilePath
  192. } catch (e) {
  193. // 用户取消裁剪
  194. return
  195. }
  196. // #endif
  197. try {
  198. uni.showLoading({ title: '上传中...' })
  199. const uploadRes = await upload('/api/mp/upload', { filePath, name: 'file' })
  200. if (!uploadRes.data?.url) throw { msg: '上传失败' }
  201. const avatarUrl = uploadRes.data.url
  202. await post('/api/mp/updateAvatar', { avatar: avatarUrl })
  203. if (userInfo.value) {
  204. userInfo.value.avatar = avatarUrl
  205. setUserInfo(userInfo.value)
  206. }
  207. uni.showToast({ title: '头像已更新', icon: 'success' })
  208. } catch (e) {
  209. if (e?.msg) uni.showToast({ title: e.msg, icon: 'none' })
  210. } finally {
  211. uni.hideLoading()
  212. }
  213. }
  214. })
  215. }
  216. const handleLogout = () => {
  217. uni.showModal({
  218. title: '提示',
  219. content: '确定退出登录吗?',
  220. success: (res) => {
  221. if (res.confirm) {
  222. clearAll()
  223. userInfo.value = null
  224. isLoggedIn.value = false
  225. uni.showToast({ title: '已退出', icon: 'success' })
  226. }
  227. }
  228. })
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .page {
  233. min-height: 100vh;
  234. background: #f4f4f5;
  235. }
  236. .profile-header {
  237. position: relative;
  238. padding: 220rpx 40rpx 60rpx;
  239. overflow: hidden;
  240. }
  241. .header-bg {
  242. position: absolute;
  243. top: 0;
  244. left: 0;
  245. width: 100%;
  246. height: 100%;
  247. z-index: 0;
  248. }
  249. .user-row {
  250. display: flex;
  251. align-items: center;
  252. gap: 28rpx;
  253. position: relative;
  254. z-index: 1;
  255. }
  256. .avatar-wrap {
  257. position: relative;
  258. width: 120rpx;
  259. height: 120rpx;
  260. flex-shrink: 0;
  261. }
  262. .avatar {
  263. width: 120rpx;
  264. height: 120rpx;
  265. border-radius: 50%;
  266. background: rgba(255, 255, 255, 0.3);
  267. }
  268. .camera-icon {
  269. position: absolute;
  270. right: -4rpx;
  271. bottom: -4rpx;
  272. width: 40rpx;
  273. height: 40rpx;
  274. background: #fff;
  275. border-radius: 50%;
  276. font-size: 22rpx;
  277. display: flex;
  278. align-items: center;
  279. justify-content: center;
  280. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
  281. }
  282. .info {
  283. .name {
  284. font-size: 40rpx;
  285. font-weight: 600;
  286. color: #fff;
  287. }
  288. .patient-no {
  289. font-size: 24rpx;
  290. color: rgba(255, 255, 255, 0.6);
  291. margin-top: 8rpx;
  292. }
  293. }
  294. .menu-section {
  295. margin: 24rpx 32rpx;
  296. background: #fff;
  297. border-radius: 8rpx;
  298. overflow: hidden;
  299. border: 1rpx solid #ebeef5;
  300. &:first-of-type {
  301. margin-top: -32rpx;
  302. position: relative;
  303. z-index: 1;
  304. }
  305. }
  306. .reject-tip {
  307. display: flex;
  308. align-items: center;
  309. margin: 0 32rpx;
  310. margin-top: 24rpx;
  311. margin-bottom: 24rpx;
  312. padding: 24rpx 28rpx;
  313. background: #fff2f0;
  314. border: 1rpx solid #ffccc7;
  315. border-radius: 8rpx;
  316. position: relative;
  317. z-index: 1;
  318. .reject-text {
  319. flex: 1;
  320. font-size: 26rpx;
  321. color: #f5222d;
  322. margin-left: 16rpx;
  323. line-height: 1.5;
  324. }
  325. }
  326. .reject-tip + .menu-section {
  327. margin-top: 0;
  328. }
  329. .menu-section.no-overlap {
  330. margin-top: 0 !important;
  331. }
  332. .menu-item {
  333. display: flex;
  334. align-items: center;
  335. padding: 28rpx 32rpx;
  336. border-bottom: 1rpx solid #ebeef5;
  337. &:last-child {
  338. border-bottom: none;
  339. }
  340. &:active {
  341. background: #f5f7fa;
  342. }
  343. .menu-icon {
  344. width: 40rpx;
  345. height: 40rpx;
  346. margin-right: 24rpx;
  347. display: flex;
  348. align-items: center;
  349. justify-content: center;
  350. }
  351. .text {
  352. flex: 1;
  353. font-size: 30rpx;
  354. color: #303133;
  355. }
  356. .extra {
  357. font-size: 26rpx;
  358. color: #909399;
  359. margin-right: 16rpx;
  360. &.link {
  361. color: #0e63e3;
  362. }
  363. &.authed {
  364. color: #67c23a;
  365. }
  366. &.pending {
  367. color: #fa8c16;
  368. }
  369. &.rejected {
  370. color: #f5222d;
  371. }
  372. &.draft {
  373. color: #909399;
  374. }
  375. }
  376. }
  377. .login-btn {
  378. margin: 48rpx 32rpx;
  379. height: 80rpx;
  380. line-height: 80rpx;
  381. background: #fff;
  382. border: 2rpx solid #0e63e3;
  383. color: #0e63e3;
  384. border-radius: 8rpx;
  385. font-size: 30rpx;
  386. &::after {
  387. border: none;
  388. }
  389. &:active {
  390. background: #e8f0fe;
  391. }
  392. }
  393. .logout-btn {
  394. margin: 48rpx 32rpx;
  395. height: 80rpx;
  396. line-height: 80rpx;
  397. background: #fff;
  398. border: 2rpx solid #e6e6e6;
  399. color: #909399;
  400. border-radius: 8rpx;
  401. font-size: 30rpx;
  402. &::after {
  403. border: none;
  404. }
  405. &:active {
  406. background: #f5f5f5;
  407. }
  408. }
  409. </style>