選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

488 行
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. uni.showToast({ title: '已退出', icon: 'success' })
  245. }
  246. }
  247. })
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .page {
  252. min-height: 100vh;
  253. background: #f4f4f5;
  254. }
  255. .profile-header {
  256. position: relative;
  257. padding: 220rpx 40rpx 60rpx;
  258. overflow: hidden;
  259. /* #ifdef H5 */
  260. padding-top: 120rpx;
  261. /* #endif */
  262. }
  263. .header-bg {
  264. position: absolute;
  265. top: 0;
  266. left: 0;
  267. width: 100%;
  268. height: 100%;
  269. z-index: 0;
  270. }
  271. .user-row {
  272. display: flex;
  273. align-items: center;
  274. gap: 28rpx;
  275. position: relative;
  276. z-index: 1;
  277. }
  278. .avatar-wrap {
  279. position: relative;
  280. width: 120rpx;
  281. height: 120rpx;
  282. flex-shrink: 0;
  283. }
  284. .avatar {
  285. width: 120rpx;
  286. height: 120rpx;
  287. border-radius: 50%;
  288. background: rgba(255, 255, 255, 0.3);
  289. }
  290. .camera-icon {
  291. position: absolute;
  292. right: -4rpx;
  293. bottom: -4rpx;
  294. width: 40rpx;
  295. height: 40rpx;
  296. background: #fff;
  297. border-radius: 50%;
  298. font-size: 22rpx;
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
  303. }
  304. .info {
  305. .name {
  306. font-size: 40rpx;
  307. font-weight: 600;
  308. color: #fff;
  309. }
  310. .patient-no {
  311. font-size: 24rpx;
  312. color: rgba(255, 255, 255, 0.6);
  313. margin-top: 8rpx;
  314. }
  315. }
  316. .menu-section {
  317. margin: 24rpx 32rpx;
  318. background: #fff;
  319. border-radius: 8rpx;
  320. overflow: hidden;
  321. border: 1rpx solid #ebeef5;
  322. &:first-of-type {
  323. margin-top: -32rpx;
  324. position: relative;
  325. z-index: 1;
  326. }
  327. }
  328. .reject-tip {
  329. display: flex;
  330. align-items: center;
  331. margin: 0 32rpx;
  332. margin-top: 24rpx;
  333. margin-bottom: 24rpx;
  334. padding: 24rpx 28rpx;
  335. background: #fff2f0;
  336. border: 1rpx solid #ffccc7;
  337. border-radius: 8rpx;
  338. position: relative;
  339. z-index: 1;
  340. .reject-text {
  341. flex: 1;
  342. font-size: 26rpx;
  343. color: #f5222d;
  344. margin-left: 16rpx;
  345. line-height: 1.5;
  346. }
  347. }
  348. .reject-tip + .menu-section {
  349. margin-top: 0;
  350. }
  351. .menu-section.no-overlap {
  352. margin-top: 0 !important;
  353. }
  354. .menu-item {
  355. display: flex;
  356. align-items: center;
  357. padding: 28rpx 32rpx;
  358. border-bottom: 1rpx solid #ebeef5;
  359. &:last-child {
  360. border-bottom: none;
  361. }
  362. &:active {
  363. background: #f5f7fa;
  364. }
  365. .menu-icon {
  366. width: 40rpx;
  367. height: 40rpx;
  368. margin-right: 24rpx;
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. }
  373. .text {
  374. flex: 1;
  375. font-size: 30rpx;
  376. color: #303133;
  377. }
  378. .extra {
  379. font-size: 26rpx;
  380. color: #909399;
  381. margin-right: 16rpx;
  382. &.link {
  383. color: #0e63e3;
  384. }
  385. &.authed {
  386. color: #67c23a;
  387. }
  388. &.pending {
  389. color: #fa8c16;
  390. }
  391. &.rejected {
  392. color: #f5222d;
  393. }
  394. &.draft {
  395. color: #909399;
  396. }
  397. }
  398. }
  399. .login-btn {
  400. margin: 48rpx 32rpx;
  401. height: 80rpx;
  402. line-height: 80rpx;
  403. background: #fff;
  404. border: 2rpx solid #0e63e3;
  405. color: #0e63e3;
  406. border-radius: 8rpx;
  407. font-size: 30rpx;
  408. &::after {
  409. border: none;
  410. }
  411. &:active {
  412. background: #e8f0fe;
  413. }
  414. }
  415. .logout-btn {
  416. margin: 48rpx 32rpx;
  417. height: 80rpx;
  418. line-height: 80rpx;
  419. background: #fff;
  420. border: 2rpx solid #e6e6e6;
  421. color: #909399;
  422. border-radius: 8rpx;
  423. font-size: 30rpx;
  424. &::after {
  425. border: none;
  426. }
  427. &:active {
  428. background: #f5f5f5;
  429. }
  430. }
  431. </style>