当前位置:   article > 正文

uni-app个人中心_uniapp仿微信app个人中心页面

uniapp仿微信app个人中心页面

个人中心页面

  1. <template>
  2. <view>
  3. <view class="u-m-t-20">
  4. <view class="center">
  5. <view class="u-m-t-12 u-m-l-60">
  6. <!-- <u-avatar :src="src" mode="circle" size="160"></u-avatar> -->
  7. <image :src="list.avatar" style="width: 180rpx; height: 180rpx; border-radius: 60px;"></image>
  8. </view>
  9. <!-- <image src=""></image> -->
  10. <view class="center-item">
  11. <!-- <view>昵称:{{list.nickName}}</view> -->
  12. <view>用户名:{{list.userName}}</view>
  13. <view>账户ID:{{list.userId}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="u-m-t-20">
  18. <u-cell-group>
  19. <u-cell-item icon="account" title="个人信息" @click="toBaseInfo"></u-cell-item>
  20. </u-cell-group>
  21. </view>
  22. <view class="u-m-t-20">
  23. <u-cell-group>
  24. <u-cell-item icon="bag" title="订单"></u-cell-item>
  25. <u-cell-item icon="reload" title="修改密码" @click="changePassword"></u-cell-item>
  26. <u-cell-item icon="kefu-ermai" title="意见反馈"></u-cell-item>
  27. </u-cell-group>
  28. </view>
  29. <view class="u-m-t-20">
  30. <u-cell-group>
  31. <!-- <u-cell-item icon="account" title="登录" @click="login"></u-cell-item> -->
  32. <u-cell-item icon="close" title="退出" @click="logout"></u-cell-item>
  33. </u-cell-group>
  34. </view>
  35. </view>
  36. </template>

  1. <script>
  2. import api from "../../request/api.js"
  3. export default {
  4. data() {
  5. return {
  6. src: '../../static/phone/105.webp',
  7. list:[]
  8. }
  9. },
  10. onLoad() {
  11. // this.getuser()
  12. this.login()
  13. /* 判断是否token */
  14. /* if(!uni.getStorageSync('token')){
  15. this.$u.toast('请登录')
  16. setTimeout(()=>{
  17. uni.navigateTo({
  18. url:'../auth/login'
  19. })
  20. },3000)
  21. } */
  22. },
  23. onShow() {
  24. this.getuser()
  25. },
  26. methods: {
  27. /* 个人信息 */
  28. toBaseInfo(){
  29. uni.navigateTo({
  30. url:'./baseInfo'
  31. })
  32. },
  33. async getuser(){
  34. const res=await api.Getuser()
  35. console.log(res)
  36. this.list = res.user
  37. },
  38. /* 修改密码 */
  39. changePassword(){
  40. uni.navigateTo({
  41. url:'./changePassword'
  42. })
  43. },
  44. /* 登录 */
  45. login(){
  46. if(!uni.getStorageSync('token')){
  47. this.$u.toast('请登录')
  48. setTimeout(()=>{
  49. uni.navigateTo({
  50. url:'../auth/login'
  51. })
  52. },3000)
  53. }
  54. },
  55. /* 退出登录 */
  56. async logout(){
  57. uni.removeStorageSync('token')
  58. this.$u.toast('退出登录')
  59. setTimeout(()=>{
  60. uni.switchTab({
  61. url:'../index/index'
  62. })
  63. },1500)
  64. }
  65. }
  66. }
  67. </script>

  1. <style lang="scss" scoped>
  2. page{
  3. background-color: #DCDFE6;
  4. }
  5. .center{
  6. background-color: #FFFFFF;
  7. display: flex;
  8. /* image{
  9. height: 70px;
  10. width: 70px;
  11. margin-top: 20rpx;
  12. // margin: 130rpx;
  13. } */
  14. .center-item{
  15. margin-top:60rpx;
  16. margin-left: 40rpx;
  17. }
  18. }
  19. </style>

登录页面

  1. <template>
  2. <view class="wrap">
  3. <view class="content">
  4. <view class="title">欢迎登录智慧城市</view>
  5. <input class="u-border-bottom" type="text" v-model="username" placeholder="请输入用户名" />
  6. <input class="u-border-bottom" type="password" v-model="password" placeholder="请输入密码" />
  7. <button @tap="submit" :style="[inputStyle]" class="getCaptcha">登录</button>
  8. <view class="alternative">
  9. <view class="password">找回密码</view>
  10. <view class="issue" @click="register">注册</view>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import api from '../../request/api.js'
  17. export default {
  18. data() {
  19. return {
  20. username: '',
  21. password: ''
  22. }
  23. },
  24. async onLoad() {
  25. },
  26. computed: {
  27. inputStyle() {
  28. let style = {};
  29. if(this.username && this.password) {
  30. style.color = "#fff";
  31. style.backgroundColor = this.$u.color['warning'];
  32. }
  33. return style;
  34. }
  35. },
  36. methods: {
  37. register(){
  38. uni.redirectTo({
  39. url:'./register'
  40. })
  41. },
  42. async submit() {
  43. if(!this.username || !this.password) return
  44. //处理登录用的参数
  45. const params = {
  46. username:this.username,
  47. password:this.password
  48. }
  49. //请求API,执行登录
  50. const res = await api.Login(params)
  51. uni.setStorageSync('token',res.token)
  52. setTimeout(()=>{
  53. uni.switchTab({
  54. url:'../center/center'
  55. })
  56. },1500)
  57. this.$u.toast('登录成功')
  58. }
  59. }
  60. };
  61. </script>
  62. <style lang="scss" scoped>
  63. .u-border-bottom{
  64. margin-bottom: 40rpx !important;
  65. }
  66. .wrap {
  67. font-size: 28rpx;
  68. .content {
  69. width: 600rpx;
  70. margin: 80rpx auto 0;
  71. .title {
  72. text-align: left;
  73. font-size: 60rpx;
  74. font-weight: 500;
  75. margin-bottom: 100rpx;
  76. }
  77. input {
  78. text-align: left;
  79. margin-bottom: 10rpx;
  80. padding-bottom: 6rpx;
  81. }
  82. .tips {
  83. color: $u-type-info;
  84. margin-bottom: 60rpx;
  85. margin-top: 8rpx;
  86. }
  87. .getCaptcha {
  88. background-color: rgb(253, 243, 208);
  89. color: $u-tips-color;
  90. border: none;
  91. font-size: 30rpx;
  92. padding: 12rpx 0;
  93. &::after {
  94. border: none;
  95. }
  96. }
  97. .alternative {
  98. color: $u-tips-color;
  99. display: flex;
  100. justify-content: space-between;
  101. margin-top: 30rpx;
  102. }
  103. }
  104. .buttom {
  105. .loginType {
  106. display: flex;
  107. padding: 350rpx 150rpx 150rpx 150rpx;
  108. justify-content:space-between;
  109. .item {
  110. display: flex;
  111. flex-direction: column;
  112. align-items: center;
  113. color: $u-content-color;
  114. font-size: 28rpx;
  115. }
  116. }
  117. .hint {
  118. padding: 20rpx 40rpx;
  119. font-size: 20rpx;
  120. color: $u-tips-color;
  121. .link {
  122. color: $u-type-warning;
  123. }
  124. }
  125. }
  126. }
  127. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/930240
推荐阅读
相关标签