index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="main">
  3. <view class="list" v-for="(item, index) in menuList" :key="index" @click="toCommon(item.route)">
  4. <view class="left">
  5. <text class="title">{{item.title||'暂无'}}</text>
  6. </view>
  7. <view class="right">
  8. <text class="t-icon t-icon-tiaozhuan"></text>
  9. </view>
  10. </view>
  11. <view class="button">
  12. <button type="warn" v-if="user&&user.id" @click="toLogin('1')">退出登录</button>
  13. <button type="warn" v-else @click="toLogin('2')">登录</button>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. components: {},
  20. data() {
  21. return {
  22. user: {},
  23. menuList: [{
  24. title: "账号信息",
  25. route: "pagesMy/account/basic",
  26. },
  27. {
  28. title: "修改密码",
  29. route: "pagesMy/account/password",
  30. }
  31. ],
  32. }
  33. },
  34. onLoad: async function(e) {
  35. const that = this;
  36. await that.searchToken();
  37. },
  38. methods: {
  39. // 用户信息
  40. searchToken() {
  41. const that = this;
  42. try {
  43. const res = uni.getStorageSync('token');
  44. if (res) {
  45. const user = that.$jwt(res);
  46. that.$set(that, `user`, user);
  47. }
  48. } catch (e) {}
  49. },
  50. // 公共跳转
  51. toCommon(e) {
  52. uni.navigateTo({
  53. url: `/${e}`
  54. })
  55. },
  56. // 登录或注销
  57. toLogin(type) {
  58. if (type == '1') {
  59. uni.showModal({
  60. title: '提示',
  61. content: '确定要退出登录?',
  62. success: function(res) {
  63. if (res.confirm) {
  64. try {
  65. uni.removeStorageSync('token');
  66. } catch (e) {}
  67. uni.navigateBack({
  68. delta: 1
  69. })
  70. } else if (res.cancel) {
  71. console.log('用户点击取消');
  72. }
  73. }
  74. });
  75. } else {
  76. uni.reLaunch({
  77. url: `/pagesHome/login/index`
  78. })
  79. }
  80. },
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .main {
  86. .list {
  87. display: flex;
  88. justify-content: space-between;
  89. padding: 3vw 2vw;
  90. border-bottom: 1px solid var(--f9Color);
  91. .left {
  92. display: flex;
  93. align-items: center;
  94. .title {
  95. margin: 0 0 0 5px;
  96. display: inline-block;
  97. font-size: var(--font14Size);
  98. }
  99. }
  100. .right {
  101. .t-icon {
  102. width: var(--font14Size) !important;
  103. height: var(--font14Size) !important;
  104. color: var(--f99Color) !important;
  105. }
  106. }
  107. }
  108. .button {
  109. margin: 3vw;
  110. text-align: center;
  111. .button {}
  112. }
  113. }
  114. </style>