mine.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <!-- pages/mine/mine.vue -->
  2. <template>
  3. <view class="mine-container">
  4. <!-- 顶部用户信息区域 -->
  5. <view class="user-header ">
  6. <headerInfo title="个人中心"></headerInfo>
  7. <view class="user-info-section">
  8. <view class="avatar-section">
  9. <u-avatar
  10. @click="toUser"
  11. size="144rpx"
  12. shape="circle"
  13. :src="userAvatar"
  14. mode="aspectFill"
  15. :show-level="false"
  16. default-url="/static/img/default-avatar.png"
  17. ></u-avatar>
  18. <!-- <image
  19. @click="toUser"
  20. :src="userAvatar"
  21. mode="aspectFill"
  22. class="avatar"
  23. ></image> -->
  24. <view class="user-text-info">
  25. <view class="user-name-section">
  26. <view v-if="isLoggedIn">
  27. <view class="name-section">
  28. <view class="user-name" @click="toUser">
  29. {{ displayName }}
  30. </view>
  31. <view class="department-badge" v-if="dept">
  32. {{dept}}
  33. </view>
  34. </view>
  35. <view class="user-account">
  36. 账号:{{ userAccount }}
  37. </view>
  38. </view>
  39. <!-- 修改点:去掉 open-type,改为点击跳转登录页 -->
  40. <button v-else
  41. class="login-button"
  42. @click="goToLogin"
  43. >
  44. 请点击登录
  45. </button>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 菜单功能区域(保持不变) -->
  52. <view class="menu-section">
  53. <view class="menu-card">
  54. <!-- 订单列表 -->
  55. <!-- <view class="menu-item" @click="toOrderList">
  56. <view class="menu-item-left">
  57. <image src="/static/img/mine/icon-mine-order.png" class="menu-icon"></image>
  58. <text class="menu-text">订单列表</text>
  59. </view>
  60. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  61. </view> -->
  62. <!-- 地址簿 -->
  63. <view class="menu-item" @click="toAddressBook">
  64. <view class="menu-item-left">
  65. <image src="/static/img/mine/icon-mine-address.png" class="menu-icon"></image>
  66. <text class="menu-text">地址簿</text>
  67. </view>
  68. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  69. </view>
  70. <!-- 到付月结码 -->
  71. <view class="menu-item" @click="toSettlementCode">
  72. <view class="menu-item-left">
  73. <image src="/static/img/mine/icon-mine-qr.png" class="menu-icon"></image>
  74. <text class="menu-text">到付月结码</text>
  75. </view>
  76. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  77. </view>
  78. <!-- 联系客服 -->
  79. <view class="menu-item" @click="makePhoneCall">
  80. <view class="menu-item-left">
  81. <image src="/static/img/mine/icon-mine-server.png" class="menu-icon"></image>
  82. <text class="menu-text">联系客服</text>
  83. </view>
  84. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  85. </view>
  86. <!-- 隐私政策 -->
  87. <view class="menu-item" @click="toPrivacyPolicy">
  88. <view class="menu-item-left">
  89. <image src="/static/img/mine/icon-mine-policy.png" class="menu-icon"></image>
  90. <text class="menu-text">用户协议</text>
  91. </view>
  92. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  93. </view>
  94. <!-- 隐私政策 -->
  95. <view class="menu-item" @click="toPrivacyPolicy1">
  96. <view class="menu-item-left">
  97. <image src="/static/img/mine/icon-mine-policy.png" class="menu-icon"></image>
  98. <text class="menu-text">隐私政策</text>
  99. </view>
  100. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  101. </view>
  102. <!-- 关于我们 -->
  103. <view class="menu-item" @click="toAboutUs">
  104. <view class="menu-item-left">
  105. <image src="/static/img/mine/icon-mine-about.png" class="menu-icon"></image>
  106. <text class="menu-text">关于我们</text>
  107. </view>
  108. <image src="/static/img/arrow-right.png" class="arrow-icon"></image>
  109. </view>
  110. <!-- 退出登录(仅登录后显示) -->
  111. <view
  112. class="menu-item logout-item"
  113. v-if="isLoggedIn"
  114. @click="userLogoutFn">
  115. <text class="menu-text logout-text">退出登录</text>
  116. </view>
  117. </view>
  118. </view>
  119. <!-- 加载提示 -->
  120. <u-loading-page :loading="pageLoading" bg-color="transparent"></u-loading-page>
  121. </view>
  122. </template>
  123. <script setup>
  124. import { ref, computed, onMounted } from "vue";
  125. import headerInfo from "@/components/headerInfo.vue";
  126. import { userLogout } from "@/api/user.js";
  127. import { getAdServicePhone } from "@/api/home.js";
  128. import { checkLoginShowModal } from "@/utils/util.js"; // 移除 quickLogin 导入
  129. import { onLoad, onShow, onShareAppMessage } from '@dcloudio/uni-app'
  130. import { useAppStore } from "@/stores/app";
  131. const appStore = useAppStore();
  132. // 响应式数据(移除了 isLogging, isProcessing)
  133. const pageLoading = ref(false);
  134. const phoneNumber = ref('');
  135. // 计算属性
  136. const isLoggedIn = computed(() => {
  137. return appStore.token;
  138. });
  139. const userAvatar = computed(() => {
  140. return appStore.userInfo?.avatar || '/static/img/default-avatar.png';
  141. });
  142. const displayName = computed(() => {
  143. return appStore.userInfo?.nickName || appStore.userInfo?.userName;
  144. });
  145. const dept = computed(() => {
  146. return appStore.userInfo?.dept?.deptName || "";
  147. });
  148. const userAccount = computed(() => {
  149. return appStore.userInfo?.userName || appStore.userInfo?.phonenumber || '';
  150. });
  151. onShareAppMessage((res) => {
  152. return appStore.onShareAppMessageObj;
  153. });
  154. onLoad(() => {
  155. getAdServicePhoneFn();
  156. checkUserStatus();
  157. });
  158. onShow(() => {
  159. if (appStore.token) {
  160. appStore.USERINFO();
  161. }
  162. });
  163. // 检查用户状态
  164. async function checkUserStatus() {
  165. if (appStore.token && !appStore.userName) {
  166. pageLoading.value = true;
  167. try {
  168. await appStore.USERINFO();
  169. } catch (error) {
  170. console.error('获取用户信息失败:', error);
  171. } finally {
  172. pageLoading.value = false;
  173. }
  174. }
  175. }
  176. // 获取客服电话
  177. function getAdServicePhoneFn() {
  178. getAdServicePhone({}).then(res => {
  179. phoneNumber.value = res.contact || '';
  180. }).catch(err => {
  181. console.log(err);
  182. });
  183. }
  184. // 跳转到登录页(新增)
  185. function goToLogin() {
  186. uni.navigateTo({
  187. url: '/pages/mine/login'
  188. });
  189. }
  190. // 跳转到用户信息页(保留原有逻辑)
  191. async function toUser() {
  192. // if (!await checkLoginShowModal()) return;
  193. // uni.navigateTo({ url: '/pages/user/user' });
  194. }
  195. // 跳转到订单列表
  196. async function toOrderList() {
  197. if (!await checkLoginShowModal()) return;
  198. uni.navigateTo({ url: '/pages/order/index' });
  199. }
  200. // 跳转到地址簿
  201. async function toAddressBook() {
  202. if (!await checkLoginShowModal()) return;
  203. uni.navigateTo({ url: '/pages/address/address_list' });
  204. }
  205. // 跳转到月结码
  206. async function toSettlementCode() {
  207. if (!await checkLoginShowModal()) return;
  208. uni.navigateTo({ url: '/pages/mine/settlementCode' });
  209. }
  210. // 跳转到隐私政策
  211. async function toPrivacyPolicy() {
  212. uni.navigateTo({
  213. url: '/pages/webView/webView?title=用户协议&url=' + encodeURIComponent('https://rjsd.mychery.com/user_agreement.html')
  214. });
  215. }
  216. // 跳转到隐私政策
  217. async function toPrivacyPolicy1() {
  218. uni.navigateTo({
  219. url: '/pages/webView/webView?title=隐私政策&url=' + encodeURIComponent('https://rjsd.mychery.com/privacy_policy.html')
  220. });
  221. }
  222. // 跳转到关于我们
  223. async function toAboutUs() {
  224. uni.navigateTo({ url: '/pages/about/index' });
  225. }
  226. // 拨打电话
  227. const makePhoneCall = () => {
  228. if (!phoneNumber.value) {
  229. uni.showToast({ title: '客服电话暂时无法接通', icon: 'none' });
  230. return;
  231. }
  232. uni.makePhoneCall({ phoneNumber: phoneNumber.value });
  233. };
  234. // 退出登录
  235. function userLogoutFn() {
  236. uni.showModal({
  237. title: '提示',
  238. content: '确认要退出登录吗?',
  239. success: function(res) {
  240. if (res.confirm) {
  241. appStore.LOGOUT();
  242. }
  243. }
  244. });
  245. }
  246. </script>
  247. <style lang="less" scoped>
  248. /* 样式优化:昵称和部门自适应布局,部门背景完整 */
  249. .mine-container {
  250. height: 100vh;
  251. background: linear-gradient(135deg, #CFE9FF 0%, #F5F7FA 50.86%);
  252. position: relative;
  253. .user-header {
  254. padding: 0rpx 24rpx;
  255. .user-info-section {
  256. margin-top: 32rpx;
  257. display: flex;
  258. flex-direction: column;
  259. gap: 20rpx;
  260. .avatar-section {
  261. display: flex;
  262. align-items: center;
  263. min-height: 144rpx;
  264. .avatar {
  265. width: 144rpx;
  266. height: 144rpx;
  267. border-radius: 50%;
  268. }
  269. .user-text-info {
  270. flex: 1;
  271. display: flex;
  272. flex-direction: column;
  273. justify-content: center;
  274. min-height: 144rpx;
  275. overflow: hidden; /* 防止内部内容溢出 */
  276. }
  277. .user-name-section {
  278. margin-left: 16rpx;
  279. min-height: 100rpx;
  280. display: flex;
  281. flex-direction: column;
  282. justify-content: center;
  283. width: 100%; /* 确保占满父容器宽度 */
  284. .name-section {
  285. display: flex;
  286. align-items: center;
  287. margin-bottom: 8rpx;
  288. width: 540rpx;
  289. overflow: hidden; /* 隐藏超出部分,避免影响布局 */
  290. }
  291. .user-name {
  292. min-width: 0; /* 允许截断 */
  293. font-weight: bold;
  294. font-size: 36rpx;
  295. color: #333333;
  296. white-space: nowrap;
  297. overflow: hidden;
  298. text-overflow: ellipsis;
  299. line-height: 1;
  300. }
  301. .login-button {
  302. background: transparent;
  303. font-size: 40rpx;
  304. font-weight: 600;
  305. color: #333;
  306. line-height: 56rpx;
  307. padding: 0;
  308. margin: 0;
  309. text-align: left;
  310. height: auto;
  311. min-height: 56rpx;
  312. display: flex;
  313. align-items: center;
  314. justify-content: flex-start;
  315. &::after {
  316. border: none;
  317. }
  318. }
  319. }
  320. .user-account {
  321. height: 44rpx;
  322. font-weight: 400;
  323. font-size: 28rpx;
  324. color: #333333;
  325. line-height: 44rpx;
  326. margin-top: 4rpx;
  327. }
  328. }
  329. .department-badge {
  330. background: #1B64F0;
  331. border-radius: 8rpx;
  332. font-size: 24rpx;
  333. color: #FFFFFF;
  334. text-align: center;
  335. margin-left: 8rpx;
  336. padding: 7rpx 16rpx;
  337. line-height: 1;
  338. white-space: nowrap;
  339. overflow: hidden;
  340. text-overflow: ellipsis;
  341. }
  342. }
  343. }
  344. .menu-section {
  345. padding: 0 20rpx;
  346. margin-top: 20rpx;
  347. .menu-card {
  348. overflow: hidden;
  349. }
  350. .menu-item {
  351. display: flex;
  352. align-items: center;
  353. justify-content: space-between;
  354. padding: 32rpx;
  355. background: #FFFFFF;
  356. border-radius: 24rpx;
  357. margin-bottom: 20rpx;
  358. min-height: 112rpx;
  359. .menu-item-left {
  360. display: flex;
  361. align-items: center;
  362. gap: 24rpx;
  363. flex: 1;
  364. }
  365. .menu-icon {
  366. width: 48rpx;
  367. height: 48rpx;
  368. flex-shrink: 0;
  369. }
  370. .menu-text {
  371. font-size: 32rpx;
  372. font-weight: 500;
  373. color: #333333;
  374. line-height: 45rpx;
  375. }
  376. .arrow-icon {
  377. width: 48rpx;
  378. height: 48rpx;
  379. opacity: 0.5;
  380. flex-shrink: 0;
  381. }
  382. &.logout-item {
  383. height: 88rpx;
  384. background: #FEEAEA;
  385. border-radius: 32rpx;
  386. display: flex;
  387. justify-content: center;
  388. align-items: center;
  389. .logout-text {
  390. font-weight: 400;
  391. font-size: 32rpx;
  392. color: #F52929;
  393. text-align: center;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. .menu-item {
  400. transition: all 0.3s ease;
  401. opacity: 1;
  402. &:active {
  403. background-color: rgba(66, 133, 244, 0.05);
  404. transform: translateX(8rpx);
  405. }
  406. &[disabled] {
  407. opacity: 0.6;
  408. pointer-events: none;
  409. }
  410. }
  411. .department-badge {
  412. transition: all 0.3s ease;
  413. &:active {
  414. transform: scale(0.95);
  415. }
  416. }
  417. @media (max-width: 375px) {
  418. .menu-section {
  419. padding: 0 20rpx !important;
  420. }
  421. .menu-card {
  422. padding: 0 20rpx !important;
  423. }
  424. .menu-text {
  425. font-size: 30rpx !important;
  426. }
  427. }
  428. view, text, image {
  429. will-change: auto;
  430. backface-visibility: hidden;
  431. -webkit-backface-visibility: hidden;
  432. }
  433. </style>