25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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