index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="container main">
  3. <view class="one">
  4. <view class="one_1">
  5. <view v-if="user.id" class="top" @tap="toView">
  6. <view class="top_left">
  7. <text class="t-icon t-icon-yonghu1"></text>
  8. <text class="name">{{user.nick_name||'微信用户'}}</text>
  9. </view>
  10. <view class="top_right">
  11. <text class="t-icon t-icon-tiaozhuan"></text>
  12. </view>
  13. </view>
  14. <view v-else class="top" @tap="toLogin">
  15. <view class="top_left">
  16. <text class="t-icon t-icon-yonghu1"></text>
  17. <text class="name">登录/注册</text>
  18. </view>
  19. <view class="top_right">
  20. <text class="t-icon t-icon-tiaozhuan"></text>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="two">
  26. <view class="list" v-for="(item, index) in menuList" :key="index" @click="toCommon(item.route,item.type)">
  27. <view class="left">
  28. <text class="t-icon" :class="[item.icon]"></text>
  29. <text class="title">{{item.title||'暂无'}}</text>
  30. </view>
  31. <view class="right">
  32. <text class="t-icon t-icon-tiaozhuan"></text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. user: {},
  43. // 菜单
  44. menuList: []
  45. }
  46. },
  47. onShow: async function() {
  48. const that = this;
  49. await that.searchToken();
  50. await that.searchOther();
  51. },
  52. methods: {
  53. async searchToken() {
  54. const that = this;
  55. try {
  56. const res = uni.getStorageSync('token');
  57. if (res) {
  58. const user = that.$jwt(res);
  59. let arr;
  60. arr = await that.$api(`/user/${user.id}`, 'GET', {})
  61. if (arr.errcode == '0') {
  62. that.$set(that, `user`, arr.data)
  63. } else {
  64. uni.showToast({
  65. title: arr.errmsg,
  66. });
  67. }
  68. } else {
  69. that.$set(that, `user`, {});
  70. }
  71. } catch (e) {}
  72. },
  73. searchOther() {
  74. const that = this;
  75. let config = that.$config;
  76. let isShow = false
  77. if (that.user.id) {
  78. const hasCompetition = that.user.role.find((f) => f === 'Competition')
  79. if (hasCompetition) isShow = true
  80. }
  81. if (!isShow) config.menuList = config.menuList.filter((f) => f.title !== '我的赛事')
  82. that.$set(that, `menuList`, config.menuList);
  83. },
  84. // 登录或注册
  85. toLogin() {
  86. uni.navigateTo({
  87. url: `/pagesHome/login/index`
  88. })
  89. },
  90. // 查看用户信息
  91. toView() {
  92. uni.navigateTo({
  93. url: `/pagesMy/account/index`
  94. })
  95. },
  96. // 公共跳转
  97. toCommon(e, type) {
  98. const that = this;
  99. if (that.user && that.user.id || type == '1') {
  100. uni.navigateTo({
  101. url: `/${e}`
  102. })
  103. } else {
  104. uni.navigateTo({
  105. url: `/pagesHome/login/index`
  106. })
  107. }
  108. },
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .main {
  114. background-color: var(--footColor);
  115. .one {
  116. margin: 2vw;
  117. border-radius: 10px;
  118. background-color: var(--mainColor);
  119. .one_1 {
  120. padding: 4vw;
  121. .top {
  122. display: flex;
  123. justify-content: space-between;
  124. align-items: center;
  125. .top_left {
  126. display: flex;
  127. align-items: center;
  128. .name {
  129. margin: 0 2vw;
  130. font-size: var(--font16Size);
  131. }
  132. .t-icon {
  133. width: 70px !important;
  134. height: 70px !important;
  135. }
  136. }
  137. .top_right {
  138. .t-icon {
  139. width: var(--font14Size) !important;
  140. height: var(--font14Size) !important;
  141. color: var(--f99Color) !important;
  142. }
  143. }
  144. }
  145. }
  146. }
  147. .two {
  148. display: flex;
  149. flex-direction: column;
  150. padding: 2vw;
  151. margin: 0 2vw;
  152. border-radius: 10px;
  153. background-color: var(--mainColor);
  154. .list {
  155. display: flex;
  156. justify-content: space-between;
  157. padding: 3vw 2vw;
  158. border-bottom: 1px solid var(--f9Color);
  159. .left {
  160. display: flex;
  161. align-items: center;
  162. .title {
  163. margin: 0 0 0 5px;
  164. display: inline-block;
  165. font-size: var(--font14Size);
  166. }
  167. }
  168. .right {
  169. .t-icon {
  170. width: var(--font14Size) !important;
  171. height: var(--font14Size) !important;
  172. color: var(--f99Color) !important;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. </style>