You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

442 lines
9.7 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="goTo('/pages/message/message')">
  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="goTo('/pages/verify/verify')">
  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 goTo = (url) => {
  133. uni.navigateTo({ url })
  134. }
  135. const goMyInfo = () => {
  136. if (!isAuthed.value) {
  137. uni.showToast({ title: '请先完成实名认证', icon: 'none' })
  138. return
  139. }
  140. uni.navigateTo({ url: '/pages/myinfo/myinfo' })
  141. }
  142. const goChangePhone = () => {
  143. if (!isAuthed.value) {
  144. uni.showToast({ title: '请先完成实名认证', icon: 'none' })
  145. return
  146. }
  147. uni.navigateTo({ url: '/pages/change-phone/change-phone' })
  148. }
  149. const goLogin = () => {
  150. uni.navigateTo({ url: '/pages/login/index' })
  151. }
  152. const goRejectDetail = () => {
  153. uni.navigateTo({ url: '/pages/myinfo/myinfo' })
  154. }
  155. const changeAvatar = () => {
  156. uni.chooseImage({
  157. count: 1,
  158. sizeType: ['compressed'],
  159. sourceType: ['album', 'camera'],
  160. success: async (chooseRes) => {
  161. let filePath = chooseRes.tempFilePaths[0]
  162. // 小程序端使用 cropImage 裁剪
  163. // #ifdef MP-WEIXIN
  164. try {
  165. const cropRes = await new Promise((resolve, reject) => {
  166. wx.cropImage({
  167. src: filePath,
  168. cropScale: '1:1',
  169. success: resolve,
  170. fail: reject
  171. })
  172. })
  173. filePath = cropRes.tempFilePath
  174. } catch (e) {
  175. // 用户取消裁剪
  176. return
  177. }
  178. // #endif
  179. try {
  180. uni.showLoading({ title: '上传中...' })
  181. const uploadRes = await upload('/api/mp/upload', { filePath, name: 'file' })
  182. if (!uploadRes.data?.url) throw { msg: '上传失败' }
  183. const avatarUrl = uploadRes.data.url
  184. await post('/api/mp/updateAvatar', { avatar: avatarUrl })
  185. if (userInfo.value) {
  186. userInfo.value.avatar = avatarUrl
  187. setUserInfo(userInfo.value)
  188. }
  189. uni.showToast({ title: '头像已更新', icon: 'success' })
  190. } catch (e) {
  191. if (e?.msg) uni.showToast({ title: e.msg, icon: 'none' })
  192. } finally {
  193. uni.hideLoading()
  194. }
  195. }
  196. })
  197. }
  198. const handleLogout = () => {
  199. uni.showModal({
  200. title: '提示',
  201. content: '确定退出登录吗?',
  202. success: (res) => {
  203. if (res.confirm) {
  204. clearAll()
  205. userInfo.value = null
  206. isLoggedIn.value = false
  207. uni.showToast({ title: '已退出', icon: 'success' })
  208. }
  209. }
  210. })
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .page {
  215. min-height: 100vh;
  216. background: #f4f4f5;
  217. }
  218. .profile-header {
  219. position: relative;
  220. padding: 220rpx 40rpx 60rpx;
  221. overflow: hidden;
  222. }
  223. .header-bg {
  224. position: absolute;
  225. top: 0;
  226. left: 0;
  227. width: 100%;
  228. height: 100%;
  229. z-index: 0;
  230. }
  231. .user-row {
  232. display: flex;
  233. align-items: center;
  234. gap: 28rpx;
  235. position: relative;
  236. z-index: 1;
  237. }
  238. .avatar-wrap {
  239. position: relative;
  240. width: 120rpx;
  241. height: 120rpx;
  242. flex-shrink: 0;
  243. }
  244. .avatar {
  245. width: 120rpx;
  246. height: 120rpx;
  247. border-radius: 50%;
  248. background: rgba(255, 255, 255, 0.3);
  249. }
  250. .camera-icon {
  251. position: absolute;
  252. right: -4rpx;
  253. bottom: -4rpx;
  254. width: 40rpx;
  255. height: 40rpx;
  256. background: #fff;
  257. border-radius: 50%;
  258. font-size: 22rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
  263. }
  264. .info {
  265. .name {
  266. font-size: 40rpx;
  267. font-weight: 600;
  268. color: #fff;
  269. }
  270. .patient-no {
  271. font-size: 24rpx;
  272. color: rgba(255, 255, 255, 0.6);
  273. margin-top: 8rpx;
  274. }
  275. }
  276. .menu-section {
  277. margin: 24rpx 32rpx;
  278. background: #fff;
  279. border-radius: 8rpx;
  280. overflow: hidden;
  281. border: 1rpx solid #ebeef5;
  282. &:first-of-type {
  283. margin-top: -32rpx;
  284. position: relative;
  285. z-index: 1;
  286. }
  287. }
  288. .reject-tip {
  289. display: flex;
  290. align-items: center;
  291. margin: 0 32rpx;
  292. margin-top: 24rpx;
  293. margin-bottom: 24rpx;
  294. padding: 24rpx 28rpx;
  295. background: #fff2f0;
  296. border: 1rpx solid #ffccc7;
  297. border-radius: 8rpx;
  298. position: relative;
  299. z-index: 1;
  300. .reject-text {
  301. flex: 1;
  302. font-size: 26rpx;
  303. color: #f5222d;
  304. margin-left: 16rpx;
  305. line-height: 1.5;
  306. }
  307. }
  308. .reject-tip + .menu-section {
  309. margin-top: 0;
  310. }
  311. .menu-section.no-overlap {
  312. margin-top: 0 !important;
  313. }
  314. .menu-item {
  315. display: flex;
  316. align-items: center;
  317. padding: 28rpx 32rpx;
  318. border-bottom: 1rpx solid #ebeef5;
  319. &:last-child {
  320. border-bottom: none;
  321. }
  322. &:active {
  323. background: #f5f7fa;
  324. }
  325. .menu-icon {
  326. width: 40rpx;
  327. height: 40rpx;
  328. margin-right: 24rpx;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. }
  333. .text {
  334. flex: 1;
  335. font-size: 30rpx;
  336. color: #303133;
  337. }
  338. .extra {
  339. font-size: 26rpx;
  340. color: #909399;
  341. margin-right: 16rpx;
  342. &.link {
  343. color: #0e63e3;
  344. }
  345. &.authed {
  346. color: #67c23a;
  347. }
  348. &.pending {
  349. color: #fa8c16;
  350. }
  351. &.rejected {
  352. color: #f5222d;
  353. }
  354. &.draft {
  355. color: #909399;
  356. }
  357. }
  358. }
  359. .login-btn {
  360. margin: 48rpx 32rpx;
  361. height: 80rpx;
  362. line-height: 80rpx;
  363. background: #fff;
  364. border: 2rpx solid #0e63e3;
  365. color: #0e63e3;
  366. border-radius: 8rpx;
  367. font-size: 30rpx;
  368. &::after {
  369. border: none;
  370. }
  371. &:active {
  372. background: #e8f0fe;
  373. }
  374. }
  375. .logout-btn {
  376. margin: 48rpx 32rpx;
  377. height: 80rpx;
  378. line-height: 80rpx;
  379. background: #fff;
  380. border: 2rpx solid #e6e6e6;
  381. color: #909399;
  382. border-radius: 8rpx;
  383. font-size: 30rpx;
  384. &::after {
  385. border: none;
  386. }
  387. &:active {
  388. background: #f5f5f5;
  389. }
  390. }
  391. </style>