您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

489 行
11 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 && 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 && userInfo.patient && userInfo.patient.patient_no" class="patient-no">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 v-if="!isAuthed" 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="goPrivacy">
  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 && userInfo.value.patient && userInfo.value.patient.auth_status === 1)
  93. const patientStatus = computed(() => {
  94. const p = userInfo.value && userInfo.value.patient
  95. if (!p) return null
  96. return p.status
  97. })
  98. const isRejected = computed(() => patientStatus.value === 2)
  99. const randomTag = () => {
  100. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  101. let s = ''
  102. for (let i = 0; i < 4; i++) s += chars.charAt(Math.floor(Math.random() * chars.length))
  103. return s
  104. }
  105. const _userTag = randomTag()
  106. const displayName = computed(() => {
  107. if (!isLoggedIn.value) return '点击登录'
  108. if (isAuthed.value && userInfo.value && userInfo.value.patient && userInfo.value.patient.name) return userInfo.value.patient.name
  109. return (userInfo.value && userInfo.value.nickname) || ('用户' + _userTag)
  110. })
  111. onShow(() => {
  112. isLoggedIn.value = !!getToken()
  113. userInfo.value = getUserInfo()
  114. if (isLoggedIn.value) {
  115. fetchUserInfo()
  116. fetchUnreadCount()
  117. } else {
  118. unreadCount.value = 0
  119. }
  120. })
  121. const fetchUserInfo = async () => {
  122. try {
  123. const res = await get('/api/mp/userinfo')
  124. userInfo.value = res.data
  125. setUserInfo(res.data)
  126. } catch (e) {
  127. if (e && e.code === 1009) {
  128. clearAll()
  129. userInfo.value = null
  130. }
  131. }
  132. }
  133. const fetchUnreadCount = async () => {
  134. try {
  135. const res = await get('/api/mp/unreadCount')
  136. unreadCount.value = (res.data && res.data.count) || 0
  137. } catch (e) {}
  138. }
  139. const checkLogin = () => {
  140. if (!isLoggedIn.value) {
  141. uni.showToast({ title: '请先登录', icon: 'none' })
  142. setTimeout(() => goLogin(), 1500)
  143. return false
  144. }
  145. return true
  146. }
  147. const checkAuth = () => {
  148. if (!checkLogin()) return false
  149. if (!isAuthed.value) {
  150. uni.showToast({ title: '请先完成实名认证', icon: 'none' })
  151. return false
  152. }
  153. return true
  154. }
  155. const goTo = (url) => {
  156. uni.navigateTo({ url })
  157. }
  158. const goPrivacy = () => {
  159. // #ifdef H5
  160. uni.navigateTo({ url: '/pages/content/content?key=privacy_policy_h5' })
  161. // #endif
  162. // #ifdef MP-WEIXIN
  163. uni.navigateTo({ url: '/pages/content/content?key=privacy_policy' })
  164. // #endif
  165. }
  166. const goMyInfo = () => {
  167. if (!checkAuth()) return
  168. uni.navigateTo({ url: '/pages/myinfo/myinfo' })
  169. }
  170. const goChangePhone = () => {
  171. if (!checkAuth()) return
  172. uni.navigateTo({ url: '/pages/change-phone/change-phone' })
  173. }
  174. const goMessage = () => {
  175. if (!checkLogin()) return
  176. uni.navigateTo({ url: '/pages/message/message' })
  177. }
  178. const goVerify = () => {
  179. if (!checkLogin()) return
  180. if (isAuthed.value) {
  181. uni.showToast({ title: '已认证', icon: 'none' })
  182. return
  183. }
  184. uni.navigateTo({ url: '/pages/verify/verify' })
  185. }
  186. const goLogin = () => {
  187. uni.navigateTo({ url: '/pages/login/index' })
  188. }
  189. const goRejectDetail = () => {
  190. uni.navigateTo({ url: '/pages/myinfo/myinfo' })
  191. }
  192. const changeAvatar = () => {
  193. uni.chooseImage({
  194. count: 1,
  195. sizeType: ['compressed'],
  196. sourceType: ['album', 'camera'],
  197. success: async (chooseRes) => {
  198. let filePath = chooseRes.tempFilePaths[0]
  199. // 小程序端使用 cropImage 裁剪
  200. // #ifdef MP-WEIXIN
  201. try {
  202. const cropRes = await new Promise((resolve, reject) => {
  203. wx.cropImage({
  204. src: filePath,
  205. cropScale: '1:1',
  206. success: resolve,
  207. fail: reject
  208. })
  209. })
  210. filePath = cropRes.tempFilePath
  211. } catch (e) {
  212. // 用户取消裁剪
  213. return
  214. }
  215. // #endif
  216. try {
  217. uni.showLoading({ title: '上传中...' })
  218. const uploadRes = await upload('/api/mp/upload', { filePath, name: 'file' })
  219. if (!(uploadRes.data && uploadRes.data.url)) throw { msg: '上传失败' }
  220. const avatarUrl = uploadRes.data.url
  221. await post('/api/mp/updateAvatar', { avatar: avatarUrl })
  222. if (userInfo.value) {
  223. userInfo.value.avatar = avatarUrl
  224. setUserInfo(userInfo.value)
  225. }
  226. uni.showToast({ title: '头像已更新', icon: 'success' })
  227. } catch (e) {
  228. if (e && e.msg) uni.showToast({ title: e.msg, icon: 'none' })
  229. } finally {
  230. uni.hideLoading()
  231. }
  232. }
  233. })
  234. }
  235. const handleLogout = () => {
  236. uni.showModal({
  237. title: '提示',
  238. content: '确定退出登录吗?',
  239. success: (res) => {
  240. if (res.confirm) {
  241. clearAll()
  242. userInfo.value = null
  243. isLoggedIn.value = false
  244. unreadCount.value = 0
  245. uni.showToast({ title: '已退出', icon: 'success' })
  246. }
  247. }
  248. })
  249. }
  250. </script>
  251. <style lang="scss" scoped>
  252. .page {
  253. min-height: 100vh;
  254. background: #f4f4f5;
  255. }
  256. .profile-header {
  257. position: relative;
  258. padding: 220rpx 40rpx 60rpx;
  259. overflow: hidden;
  260. /* #ifdef H5 */
  261. padding-top: 120rpx;
  262. /* #endif */
  263. }
  264. .header-bg {
  265. position: absolute;
  266. top: 0;
  267. left: 0;
  268. width: 100%;
  269. height: 100%;
  270. z-index: 0;
  271. }
  272. .user-row {
  273. display: flex;
  274. align-items: center;
  275. gap: 28rpx;
  276. position: relative;
  277. z-index: 1;
  278. }
  279. .avatar-wrap {
  280. position: relative;
  281. width: 120rpx;
  282. height: 120rpx;
  283. flex-shrink: 0;
  284. }
  285. .avatar {
  286. width: 120rpx;
  287. height: 120rpx;
  288. border-radius: 50%;
  289. background: rgba(255, 255, 255, 0.3);
  290. }
  291. .camera-icon {
  292. position: absolute;
  293. right: -4rpx;
  294. bottom: -4rpx;
  295. width: 40rpx;
  296. height: 40rpx;
  297. background: #fff;
  298. border-radius: 50%;
  299. font-size: 22rpx;
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
  304. }
  305. .info {
  306. .name {
  307. font-size: 40rpx;
  308. font-weight: 600;
  309. color: #fff;
  310. }
  311. .patient-no {
  312. font-size: 24rpx;
  313. color: rgba(255, 255, 255, 0.6);
  314. margin-top: 8rpx;
  315. }
  316. }
  317. .menu-section {
  318. margin: 24rpx 32rpx;
  319. background: #fff;
  320. border-radius: 8rpx;
  321. overflow: hidden;
  322. border: 1rpx solid #ebeef5;
  323. &:first-of-type {
  324. margin-top: -32rpx;
  325. position: relative;
  326. z-index: 1;
  327. }
  328. }
  329. .reject-tip {
  330. display: flex;
  331. align-items: center;
  332. margin: 0 32rpx;
  333. margin-top: 24rpx;
  334. margin-bottom: 24rpx;
  335. padding: 24rpx 28rpx;
  336. background: #fff2f0;
  337. border: 1rpx solid #ffccc7;
  338. border-radius: 8rpx;
  339. position: relative;
  340. z-index: 1;
  341. .reject-text {
  342. flex: 1;
  343. font-size: 26rpx;
  344. color: #f5222d;
  345. margin-left: 16rpx;
  346. line-height: 1.5;
  347. }
  348. }
  349. .reject-tip + .menu-section {
  350. margin-top: 0;
  351. }
  352. .menu-section.no-overlap {
  353. margin-top: 0 !important;
  354. }
  355. .menu-item {
  356. display: flex;
  357. align-items: center;
  358. padding: 28rpx 32rpx;
  359. border-bottom: 1rpx solid #ebeef5;
  360. &:last-child {
  361. border-bottom: none;
  362. }
  363. &:active {
  364. background: #f5f7fa;
  365. }
  366. .menu-icon {
  367. width: 40rpx;
  368. height: 40rpx;
  369. margin-right: 24rpx;
  370. display: flex;
  371. align-items: center;
  372. justify-content: center;
  373. }
  374. .text {
  375. flex: 1;
  376. font-size: 30rpx;
  377. color: #303133;
  378. }
  379. .extra {
  380. font-size: 26rpx;
  381. color: #909399;
  382. margin-right: 16rpx;
  383. &.link {
  384. color: #0e63e3;
  385. }
  386. &.authed {
  387. color: #67c23a;
  388. }
  389. &.pending {
  390. color: #fa8c16;
  391. }
  392. &.rejected {
  393. color: #f5222d;
  394. }
  395. &.draft {
  396. color: #909399;
  397. }
  398. }
  399. }
  400. .login-btn {
  401. margin: 48rpx 32rpx;
  402. height: 80rpx;
  403. line-height: 80rpx;
  404. background: #fff;
  405. border: 2rpx solid #0e63e3;
  406. color: #0e63e3;
  407. border-radius: 8rpx;
  408. font-size: 30rpx;
  409. &::after {
  410. border: none;
  411. }
  412. &:active {
  413. background: #e8f0fe;
  414. }
  415. }
  416. .logout-btn {
  417. margin: 48rpx 32rpx;
  418. height: 80rpx;
  419. line-height: 80rpx;
  420. background: #fff;
  421. border: 2rpx solid #e6e6e6;
  422. color: #909399;
  423. border-radius: 8rpx;
  424. font-size: 30rpx;
  425. &::after {
  426. border: none;
  427. }
  428. &:active {
  429. background: #f5f5f5;
  430. }
  431. }
  432. </style>