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.
 
 
 
 
 

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