my.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="my__main">
  3. <!-- 背景 -->
  4. <view class="my__main-top">
  5. </view>
  6. <view class="top-content">
  7. <image class="top-content-img" src="../../static/card.png" mode=""></image>
  8. <view class="top-content-main">
  9. <view class="content-main-id">
  10. <p>{{userInfo.userType==0? '巡更员':'管理员'}}</p>
  11. </view>
  12. <view v-if="!userInfo" class="content-main-text1">
  13. 请先登录~
  14. </view>
  15. <view v-else class="content-main-text2">
  16. <view class="main-text2-1">
  17. {{userInfo.idName}}
  18. </view>
  19. <view class="main-text2-2">
  20. {{userInfo.username}}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view v-if="userInfo" class="my__main-content-box">
  26. <view v-if="userInfo.userType==0" class="my__main-content">
  27. <u-cell-group :border="false">
  28. <u-cell :border="false" title="签到打卡" isLink url="/pages/home/home"></u-cell>
  29. </u-cell-group>
  30. </view>
  31. <view v-else class="my__main-content">
  32. <u-cell-group :border="false">
  33. <u-cell title="签到打卡" isLink url="/pages/home/home"></u-cell>
  34. <u-cell :border="false" title="更新巡更点信息" isLink url="/pages/my/myRenew/myRenew"></u-cell>
  35. </u-cell-group>
  36. </view>
  37. </view>
  38. <view :class="{ 'my__main-btn': true, 'mine-bgc': userInfo }">
  39. <button class="btn-1" v-if="userInfo" @click="loginOut">
  40. 退出登录
  41. </button>
  42. <button class="btn-1" v-else @click="goLogin">
  43. 登录
  44. </button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. getUserInfo,
  51. } from '@/api/login.js'
  52. export default {
  53. data() {
  54. return {
  55. userInfo: null
  56. };
  57. },
  58. methods: {
  59. loginOut() {
  60. uni.showModal({
  61. title: '提示',
  62. content: '确定退出吗?',
  63. success: res => {
  64. if (res.confirm) {
  65. uni.showToast({
  66. title: '操作成功',
  67. icon: 'none',
  68. duration: 800,
  69. mask: true,
  70. success: () => {
  71. setTimeout(() => {
  72. uni.removeStorageSync('userInfo'); // 移除本地的信息
  73. uni.removeStorageSync('token')
  74. uni.clearStorageSync()
  75. uni.navigateTo({
  76. url: '/pages/login/index',
  77. })
  78. }, 800)
  79. }
  80. })
  81. }
  82. }
  83. })
  84. },
  85. goLogin() {
  86. uni.navigateTo({
  87. url: '/pages/login/index',
  88. });
  89. },
  90. // 获取信息
  91. checkUserInfo() {
  92. getUserInfo().then(res => {
  93. uni.setStorageSync('userInfo', res.data)
  94. // this.userInfo = res.data
  95. this.userInfo.userType = res.data.userType
  96. }).catch(err => {});
  97. },
  98. },
  99. onShow() {
  100. this.checkUserInfo()
  101. // const userInfo = uni.getStorageSync("userInfo");
  102. // this.userInfo = userInfo
  103. },
  104. onLoad() {
  105. // this.checkUserInfo()
  106. const userInfo = uni.getStorageSync("userInfo");
  107. this.userInfo = userInfo
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .my__main {
  113. position: relative;
  114. width: 100%;
  115. height: 100%;
  116. // 背景
  117. .my__main-top {
  118. height: 140px;
  119. background: #3D8EFE;
  120. border-bottom-left-radius: 8%;
  121. border-bottom-right-radius: 8%;
  122. }
  123. .top-content {
  124. margin-top: -70px;
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. width: 100%;
  129. height: 150px;
  130. margin-bottom: 10px;
  131. .top-content-img {
  132. width: 100%;
  133. height: 100%;
  134. object-fit: cover;
  135. }
  136. .top-content-main {
  137. width: 96%;
  138. height: 135px;
  139. position: fixed;
  140. top: 75px;
  141. display: flex;
  142. align-items: center;
  143. justify-content: center;
  144. .content-main-id {
  145. position: fixed;
  146. left: 9px;
  147. top: 75px;
  148. background-color: #fff;
  149. border-radius: 16px 6px;
  150. padding: 3px 16px;
  151. color: #3E8AFF;
  152. font-weight: 500;
  153. font-size: 13px;
  154. }
  155. .content-main-text1 {
  156. text-align: center;
  157. font-size: 20px;
  158. font-weight: 700;
  159. color: #fff;
  160. }
  161. .content-main-text2 {
  162. color: #fff;
  163. text-align: center;
  164. .main-text2-1 {
  165. line-height: 36px;
  166. font-weight: 700;
  167. font-size: 24px;
  168. }
  169. .main-text2-2 {
  170. line-height: 27px;
  171. font-weight: 500;
  172. font-size: 18px;
  173. }
  174. }
  175. }
  176. }
  177. .my__main-content-box {
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. width: 100%;
  182. // height: 100px;
  183. margin-bottom: 15px;
  184. .my__main-content {
  185. width: 95%;
  186. border-radius: 10px;
  187. display: flex;
  188. align-items: center;
  189. background-color: #fff;
  190. .my__main-content-item {
  191. height: 90px;
  192. }
  193. }
  194. }
  195. .my__main-btn .btn-1 {
  196. background-color: #4065FB;
  197. color: #fff;
  198. // height: 48px;
  199. // line-height: 48px;
  200. width: 95%;
  201. border-radius: 10px;
  202. border: none !important;
  203. }
  204. .mine-bgc .btn-1 {
  205. border: none !important;
  206. background-color: #fff;
  207. color: #333;
  208. }
  209. }
  210. ::v-deep .u-cell__body {
  211. padding: 15px 15px !important;
  212. }
  213. ::v-deep .u-line {
  214. width: 93% !important;
  215. margin-left: 13px !important;
  216. }
  217. </style>