index.vue 7.8 KB

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