index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="list" v-for="(item, index) in list" :key="index" @click="toCommon(item.route)">
  5. <view class="left">
  6. <text class="title">{{item.title}}</text>
  7. </view>
  8. <view class="right">
  9. <text class="iconfont icon-dayuhao"></text>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="two">
  14. <button class="button" type="primary" @click="toExit">退出登录</button>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. user: {},
  23. list: [{
  24. title: '账号详情',
  25. route: 'pagesMy/account/info'
  26. },
  27. {
  28. title: '修改密码',
  29. route: 'pagesMy/account/update'
  30. }
  31. ]
  32. }
  33. },
  34. async onLoad() {
  35. const that = this;
  36. await that.searchToken();
  37. },
  38. methods: {
  39. async searchToken() {
  40. const that = this;
  41. uni.getStorage({
  42. key: 'token',
  43. success: function(res) {
  44. that.$set(that, `user`, res.data);
  45. },
  46. fail: function(err) {
  47. uni.showToast({
  48. title: err.errmsg,
  49. icon: 'error',
  50. duration: 2000
  51. });
  52. }
  53. })
  54. },
  55. // 公共跳转
  56. toCommon(e) {
  57. const that = this;
  58. if (that.user && that.user._id) {
  59. uni.navigateTo({
  60. url: `/${e}`
  61. })
  62. } else {
  63. uni.navigateTo({
  64. url: `/pages/login/index`
  65. })
  66. }
  67. },
  68. // 退出登录
  69. toExit() {
  70. uni.removeStorage({
  71. key: 'token',
  72. success: function(res) {
  73. let url = `/pages/index/index`;
  74. uni.reLaunch({
  75. url
  76. })
  77. }
  78. });
  79. },
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .content {
  85. display: flex;
  86. flex-direction: column;
  87. padding: 2vw;
  88. }
  89. .one {
  90. .list {
  91. margin: 2vw 0 0 0;
  92. background-color: var(--f1Color);
  93. display: flex;
  94. justify-content: space-between;
  95. padding: 3vw;
  96. border-bottom: 1px solid var(--f9Color);
  97. .left {
  98. display: flex;
  99. align-items: center;
  100. font-size: var(--font12Size);
  101. .title {
  102. display: inline-block;
  103. font-size: var(--font12Size);
  104. }
  105. }
  106. .right {
  107. display: flex;
  108. align-items: center;
  109. font-size: var(--font12Size);
  110. color: var(--f99Color);
  111. }
  112. }
  113. }
  114. .two {
  115. margin: 2vw 0 0 0;
  116. background-color: var(--f1Color);
  117. .button {
  118. background-color: var(--f3CColor);
  119. color: var(--mainColor);
  120. font-size: var(--font14Size);
  121. }
  122. }
  123. </style>