me.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <view>
  3. <view class="header">
  4. <view class="bg">
  5. <view class="box">
  6. <view class="box-hd" @click="login">
  7. <view v-if="islogin">
  8. <view class="avator">
  9. <img :src="userinfo.avatar">
  10. </view>
  11. <view class="phone-number">ID:{{userinfo.id}} 昵称:{{userinfo.nickname || '未设置昵称'}}</view>
  12. </view>
  13. <view v-else>
  14. <view class="avator">
  15. <img :src="avatarUrl">
  16. </view>
  17. <view class="phone-number" style="color: red;">请先点我登录</view>
  18. </view>
  19. </view>
  20. <view class="box-bd" @click="myNotice">
  21. <view class="item">
  22. <u-icon class="icon" name="volume-fill" size="25" color="#757575"></u-icon>
  23. <view class="text">我的通知</view>
  24. </view>
  25. <view class="item">
  26. <u-icon class="icon" name="star-fill" size="25" color="#757575"></u-icon>
  27. <view class="text">我的收藏</view>
  28. </view>
  29. <view class="item">
  30. <u-icon class="icon" name="server-fill" size="25" color="#757575"></u-icon>
  31. <view class="text">我的客服</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="list-content">
  38. <view class="list">
  39. <view class="li">
  40. <u-icon class="icon" name="coupon-fill" size="25" color="#757575"></u-icon>
  41. <view class="text">我的名片</view>
  42. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  43. </view>
  44. <view class="li " @click="changeSkin">
  45. <u-icon class="icon" name="grid-fill" size="25" color="#757575"></u-icon>
  46. <view class="text">主题切换</view>
  47. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  48. </view>
  49. <view class="li ">
  50. <u-icon class="icon" name="question-circle-fill" size="25" color="#757575"></u-icon>
  51. <view class="text">帮助中心</view>
  52. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  53. </view>
  54. <view class="li ">
  55. <u-icon class="icon" name="info-circle-fill" size="25" color="#757575"></u-icon>
  56. <view class="text">关于我们</view>
  57. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  58. </view>
  59. <view class="li ">
  60. <u-icon class="icon" name="email-fill" size="25" color="#757575"></u-icon>
  61. <view class="text">意见反馈</view>
  62. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  63. </view>
  64. <view class="li noborder">
  65. <u-icon class="icon" name="setting-fill" size="25" color="#757575"></u-icon>
  66. <view class="text">系统设置</view>
  67. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  68. </view>
  69. <view class="li noborder" @click="loginOut">
  70. <u-icon class="icon" name="setting-fill" size="25" color="#757575"></u-icon>
  71. <view class="text">注销登录</view>
  72. <u-icon class="icon" name="arrow-right" size="20" color="#757575"></u-icon>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="copyright">
  77. <text>AbuCoder版权所有</text>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import {
  83. setUserInfo,
  84. getUserInfo,
  85. setToken,
  86. getToken,
  87. removeUserInfo,
  88. removeToken
  89. } from '@/utils/auth';
  90. export default {
  91. data() {
  92. return {
  93. avatarUrl: 'https://portrait.gitee.com/uploads/avatars/user/354/1062657_rahman_1649233036.png!avatar60',
  94. userinfo: {},
  95. islogin:false,
  96. }
  97. },
  98. onShow() {
  99. console.log(getUserInfo())
  100. if(getUserInfo()!=undefined){
  101. this.islogin = true
  102. }
  103. this.userinfo = getUserInfo() || {};
  104. },
  105. methods: {
  106. login() {
  107. let that = this
  108. uni.login({
  109. provider: 'weixin',
  110. success: function(loginRes) {
  111. let form = {};
  112. form.code = loginRes.code; //用户code 注:用户的code每次登录都是随机的,所以不需要进行存储
  113. uni.showLoading({
  114. title: "登录中....",
  115. mask: true
  116. })
  117. that.request('wxlogin', form, 'POST').then(wxloginres => {
  118. console.log("wxloginres: ", wxloginres)
  119. if (wxloginres.code==200) {
  120. uni.hideLoading()
  121. setTimeout(function() {
  122. uni.hideLoading();
  123. }, 2000);
  124. setToken(wxloginres.data.openid)
  125. setUserInfo(wxloginres.data); //模拟存储用户信息
  126. //成功后进入头像与昵称修改页面
  127. uni.navigateTo({
  128. url: '/pages/me/userinfo'
  129. })
  130. } else {
  131. uni.showToast({
  132. icon: "none",
  133. title: "登录失败,请稍后试试!",
  134. duration: 2000
  135. })
  136. }
  137. })
  138. },
  139. fail(err) {
  140. console.log(err)
  141. }
  142. });
  143. },
  144. myNotice() {
  145. uni.navigateTo({
  146. url: './mynotice/mynotice'
  147. })
  148. },
  149. loginOut() {
  150. uni.showModal({
  151. title: '注销登录提示',
  152. content: '确定要注销登录吗?',
  153. cancelText: "取消", // 取消按钮的文字
  154. confirmText: "确认", // 确认按钮的文字
  155. confirmColor: '#f55850',
  156. success: (res) => {
  157. if (res.confirm) {
  158. console.log('comfirm') //点击确定之后执行的代码
  159. uni.$u.toast("注销登录成功,欢迎再来")
  160. removeUserInfo()
  161. removeToken()
  162. this.islogin=false
  163. } else {
  164. console.log('cancel') //点击取消之后执行的代码
  165. }
  166. }
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. page {
  174. background-color: #f1f1f1;
  175. font-size: 28rpx;
  176. }
  177. .header {
  178. background: #fff;
  179. height: 660rpx;
  180. padding-bottom: 110rpx;
  181. .bg {
  182. width: 100%;
  183. height: 490rpx;
  184. padding-top: 310rpx;
  185. background: linear-gradient(to bottom, rgb(1, 94, 234), rgb(0, 192, 250), rgb(255, 255, 255));
  186. }
  187. }
  188. .box {
  189. width: 650rpx;
  190. height: 300rpx;
  191. border-radius: 20rpx;
  192. margin: 0 auto;
  193. background: #fff;
  194. box-shadow: 0 5rpx 20rpx 0rpx rgba(0, 0, 150, .2);
  195. .box-hd {
  196. display: flex;
  197. flex-wrap: wrap;
  198. flex-direction: row;
  199. justify-content: center;
  200. margin-top: 15rpx;
  201. .avator {
  202. width: 160rpx;
  203. height: 160rpx;
  204. background: #fff;
  205. border: 5rpx solid #f1f1f1;
  206. border-radius: 50%;
  207. margin: 0 auto;
  208. margin-top: -80rpx;
  209. overflow: hidden;
  210. img {
  211. width: 100%;
  212. height: 100%;
  213. }
  214. }
  215. .phone-number {
  216. width: 100%;
  217. text-align: center;
  218. margin: 20rpx auto;
  219. }
  220. }
  221. .box-bd {
  222. display: flex;
  223. flex-wrap: nowrap;
  224. flex-direction: row;
  225. justify-content: center;
  226. .item {
  227. flex: 1 1 auto;
  228. display: flex;
  229. flex-wrap: wrap;
  230. flex-direction: row;
  231. justify-content: center;
  232. border-right: 1px solid #f1f1f1;
  233. margin: 15rpx 0;
  234. &:last-child {
  235. border: none;
  236. }
  237. .icon {
  238. width: 60rpx;
  239. height: 60rpx;
  240. img {
  241. width: 100%;
  242. height: 100%;
  243. }
  244. }
  245. .text {
  246. width: 100%;
  247. text-align: center;
  248. margin-top: 10rpx;
  249. }
  250. }
  251. }
  252. }
  253. .list-content {
  254. background: #fff;
  255. }
  256. .list {
  257. width: 100%;
  258. border-bottom: 15rpx solid #f1f1f1;
  259. background: #fff;
  260. &:last-child {
  261. border: none;
  262. }
  263. .li {
  264. width: 92%;
  265. height: 100rpx;
  266. padding: 0px 4%;
  267. border-bottom: 1px solid #f3f3f3;
  268. display: flex;
  269. align-items: center;
  270. margin: 0rpx auto;
  271. &.noborder {
  272. border-bottom: 0
  273. }
  274. .icon {
  275. flex-shrink: 0;
  276. width: 50rpx;
  277. height: 50rpx;
  278. image {
  279. width: 50rpx;
  280. height: 50rpx;
  281. }
  282. }
  283. .text {
  284. padding-left: 20rpx;
  285. width: 100%;
  286. color: #666;
  287. }
  288. .to {
  289. flex-shrink: 0;
  290. width: 40rpx;
  291. height: 40rpx;
  292. }
  293. }
  294. }
  295. .copyright {
  296. margin: 20rpx auto;
  297. width: 80%;
  298. height: 60rpx;
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. color: #9E9E9E;
  303. font-size: 26rpx;
  304. }
  305. </style>