mine.vue 11 KB

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