index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <uv-navbar leftIcon="" title="我的" bg-color="#C6171E"></uv-navbar>
  3. <view class="w100 bg" style="background-color:#C6171E "></view>
  4. <!-- <image src="/static/user/user-bg.png" mode="widthFix" class="bg"/>-->
  5. <block>
  6. <view class="container" :style="containerStyle">
  7. <view class="header">
  8. <view class="flex-center">
  9. <image
  10. src="/static/user/round.png"
  11. mode="heightFix"
  12. style="width: 120rpx;height: 120rpx"/>
  13. </view>
  14. <view class="main">
  15. <image
  16. class="avatar"
  17. src='/static/iconfont/me.svg'>
  18. </image>
  19. <view class="phone fw-500">{{ user.mobilePhone }}</view>
  20. <view class="money-box">
  21. <view class="money" @click="toPage({path: '/pages-user/wallet/index'})">
  22. <view class="money-left">
  23. <uv-icon name="coupon" size="24" color="#C6171E"></uv-icon>
  24. <!-- <image src="/static/iconfont/chongzhi.svg" mode="widthFit" style="width: 40rpx;height: 40rpx"></image>-->
  25. <!-- <uv-icon name="red-packet" size="24" color="#C6171E"></uv-icon>-->
  26. <view style="font-size: 16px;margin-left: 10rpx;">钱包 | 充值</view>
  27. </view>
  28. <view class="money-right">
  29. <view class="money-right_balance"> ¥ {{ ((user.balance || 0) / 100).toFixed(2) }}</view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="body">
  36. <block v-for="(item, index) in menu" :key="index">
  37. <view
  38. class="menu-item"
  39. @click="toPage(item)">
  40. <view class="menu-item_left">
  41. <image :src="item.icon"></image>
  42. <view class="menu-item_left-title">{{ item.title }}</view>
  43. </view>
  44. <view class="menu-item_right">
  45. <uv-icon name="arrow-right" size="16"></uv-icon>
  46. </view>
  47. </view>
  48. </block>
  49. <view class="logout-btn" v-if="isLogin">
  50. <view class="mt20 logout-btn-wrap" type="error" @click="logoutUser">退出登录</view>
  51. </view>
  52. </view>
  53. </view>
  54. </block>
  55. <!-- <cover-view class="login_bar" v-if="!isLogin">
  56. <login-bar class="w100 text-center"></login-bar>
  57. </cover-view>-->
  58. <!-- <view class="logout-btn">
  59. <uv-button :custom-style="customStyle" type="error" @click="logoutUser">退出登录</uv-button>
  60. </view>-->
  61. <tab-bar :index="2"/>
  62. </template>
  63. <script setup lang="ts">
  64. import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
  65. import {computed, ref} from "vue";
  66. import TabBar from "@/components/tab-bar/index.vue";
  67. import LoginBar from "@/components/login-bar/index.vue";
  68. import {checkLogin, clearToken} from "@/utils/auth"
  69. import {get} from "@/utils/https";
  70. import {getServicePhone} from "@/utils/common";
  71. const containerStyle = ref({});
  72. const user = ref<any>({
  73. id: 0,
  74. avatar: "",
  75. mobilePhoneFormat: '',
  76. balance: 0,
  77. });
  78. const isLogin = ref(false)
  79. const service = ref("15012341234");
  80. const menu = ref([
  81. {
  82. title: "绑定车辆",
  83. path: "/pages-user/profile/index",
  84. icon: '/static/user/profile.png'
  85. },
  86. /* {
  87. title: "我的卡包",
  88. path: "/pages/coupon/index",
  89. icon: '/static/user/coupon.png'
  90. },*/
  91. {
  92. title: "我的订单",
  93. path: "/pages-order/list/index",
  94. icon: '/static/user/faq.png'
  95. },
  96. /* {
  97. title: "我的收藏",
  98. path: "/pages-user/fav/index",
  99. icon: '/static/user/fav.png'
  100. },*/
  101. {
  102. title: "联系我们",
  103. path: "/pages-user/contact/index",
  104. icon: '/static/user/contact.png'
  105. },
  106. {
  107. title: "洗车指导",
  108. path: "/pages-user/faq/index",
  109. icon: '/static/iconfont/default/guide.svg'
  110. },
  111. {
  112. title: "纠错上报",
  113. path: "/pages-user/feedback/index",
  114. icon: '/static/user/feedback.png'
  115. },
  116. ]);
  117. const toPage = (item: any) => {
  118. checkLogin().then(() => {
  119. let {title, path} = item;
  120. let servicePhone = getServicePhone();
  121. if (path.includes('contact')) {
  122. uni.makePhoneCall({
  123. phoneNumber: servicePhone,
  124. fail: (error) => {
  125. console.log(error)
  126. }
  127. });
  128. return;
  129. }
  130. uni.navigateTo({
  131. url: item.path,
  132. });
  133. }).catch(e => {
  134. console.error("handleMenuClick 校验,跳转登录页", e)
  135. uni.navigateTo({
  136. url: '/pages-user/login/index'
  137. })
  138. })
  139. };
  140. const loginListen = () => {
  141. }
  142. const logoutUser = () => {
  143. uni.showModal({
  144. title: "温馨提示",
  145. content: "确定退出登录吗?",
  146. confirmColor: "#C6171E",
  147. confirmText: "确定退出",
  148. cancelText: "手滑了",
  149. success: (res) => {
  150. if (res.confirm) {
  151. uni.showLoading({
  152. title: "退出中",
  153. });
  154. get(`/user/logout`).then(() => {
  155. uni.hideLoading();
  156. uni.showToast({
  157. icon: "success",
  158. title: "已退出",
  159. });
  160. getApp<any>().globalData.manualLogout = true;
  161. clearToken();
  162. setTimeout(() => {
  163. uni.exitMiniProgram()
  164. }, 1500);
  165. })
  166. }
  167. },
  168. });
  169. };
  170. onLoad(() => {
  171. uni.setNavigationBarTitle({title: '个人中心'})
  172. const bound = uni.getMenuButtonBoundingClientRect();
  173. containerStyle.value = {
  174. top: `${bound.bottom + 10}px`,
  175. };
  176. });
  177. const addListener = () => {
  178. uni.$on('login', function (data) {
  179. isLogin.value = data.isLogin;
  180. console.log("event>>>", data)
  181. if (data.isLogin) {
  182. user.value = getApp<any>().globalData.user;
  183. console.log("event1111>>>", user.value)
  184. }
  185. })
  186. uni.$on('logout', function (data) {
  187. isLogin.value = false;
  188. user.value = {}
  189. })
  190. }
  191. const removeListener = () => {
  192. uni.$off('logout');
  193. uni.$off('login');
  194. }
  195. onShow(() => {
  196. const userData = getApp<any>().globalData.user;
  197. if (userData && userData.id) {
  198. isLogin.value = true;
  199. user.value = userData;
  200. }
  201. // loginListen();
  202. addListener();
  203. });
  204. onHide(()=>{
  205. removeListener();
  206. })
  207. </script>
  208. <style lang="scss" scope>
  209. page{
  210. background-color: #fafafa;
  211. }
  212. .bg {
  213. position: absolute;
  214. left: 0;
  215. top: 0;
  216. width: 100%;
  217. height: 460rpx;
  218. }
  219. .container {
  220. position: absolute;
  221. left: 0;
  222. top: 0;
  223. height: calc(100vh - 250rpx);
  224. width: 100%;
  225. overflow-y: hidden;
  226. }
  227. .header {
  228. //height: 400rpx;
  229. width: 100%;
  230. flex-direction: column;
  231. .main {
  232. //height: 234rpx;
  233. //padding: 60rpx auto;
  234. background: rgba(254, 255, 255, 0.7);
  235. border-radius: 40rpx 40rpx 0 0;
  236. position: relative;
  237. text-align: center;
  238. z-index: 999;
  239. .avatar {
  240. position: absolute;
  241. left: 50%;
  242. transform: translateX(-50%);
  243. top: -90rpx;
  244. width: 110rpx;
  245. height: 110rpx;
  246. border: 2rpx solid #ffffff;
  247. //filter: drop-shadow(0px 4rpx 8rpx rgba(0, 24, 60, 0.1));
  248. background-size: cover;
  249. background-repeat: no-repeat;
  250. border-radius: 50%;
  251. }
  252. .phone {
  253. padding-top: 20rpx;
  254. //padding-top: 78rpx;
  255. color: #000;
  256. //padding: 30rpx auto;
  257. font-size: 40rpx;
  258. }
  259. .money-box{
  260. background: #EEB9BB;
  261. padding: 60rpx 20rpx;
  262. display: flex;
  263. justify-content: center;
  264. align-items: center;
  265. align-content: center;
  266. .money {
  267. //position: absolute;
  268. //left: 0;
  269. //bottom: 0;
  270. width: 600rpx;
  271. //height: 98rpx;
  272. background: #fff;
  273. border-radius: 120rpx;
  274. //margin: 130rpx auto 40rpx auto;
  275. //color: #000000;
  276. padding: 20rpx;
  277. font-size: 22px;
  278. display: flex;
  279. align-content: center;
  280. align-items: center;
  281. justify-content: space-between;
  282. &-left {
  283. opacity: 1;
  284. color: $uni-color-primary;
  285. display: inline-flex;
  286. align-items: flex-end;
  287. font-size: 22px;
  288. }
  289. &-right {
  290. font-size: 22px;
  291. opacity: 1;
  292. color: $uni-color-primary;
  293. display: inline-flex;
  294. align-items: flex-end;
  295. &_balance {
  296. padding-left: 5px;
  297. font-size: 26px;
  298. font-weight: 600;
  299. margin-right: 10px;
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. .body {
  307. width: 100%;
  308. background-color: #fff;
  309. //border-top: 1px solid $uni-color-primary;
  310. //padding: 0rpx 30rpx;
  311. .menu-item {
  312. display: inline-flex;
  313. justify-content: space-between;
  314. background-color: #fff;
  315. height: 90rpx;
  316. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  317. align-items: center;
  318. width: 100%;
  319. &_left {
  320. display: flex;
  321. align-items: center;
  322. align-content: center;
  323. margin-left: 20rpx;
  324. image {
  325. width: 42rpx;
  326. height: 42rpx;
  327. margin-right: 20rpx;
  328. }
  329. &-title {
  330. font-size: 13px;
  331. }
  332. }
  333. &_right {
  334. text-align: right;
  335. width: 60rpx;
  336. }
  337. &:last-child {
  338. border-bottom: none;
  339. }
  340. }
  341. }
  342. .logout-btn {
  343. width: calc(100vw - 60rpx);
  344. margin: 60rpx auto;
  345. &-wrap{
  346. height: 80rpx;
  347. border-radius: 40rpx;
  348. font-size: 28rpx;
  349. margin: 20px auto;
  350. width: 540rpx;
  351. text-align: center;
  352. background: #dd524d;
  353. color: white;
  354. display: flex;
  355. align-items: center;
  356. align-content: center;
  357. justify-content: center;
  358. }
  359. }
  360. </style>