index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="left">
  5. <u-avatar :text="formatName(user.name||user.nickname)" shape="square" fontSize="20"
  6. randomBgColor color-index="7"></u-avatar>
  7. </view>
  8. <view class="right" @tap="toLogin">
  9. <text v-if="user._id">{{user.name||user.nickname}}</text>
  10. <text v-else>点击登录</text>
  11. <u-icon :bold="true" color="#000" name="arrow-right" top="2px" size="18"></u-icon>
  12. </view>
  13. </view>
  14. <view class="two">
  15. <view class="list" v-for="(item, index) in $config.menuList" :key="index" @click="toCommon(item.route)">
  16. <view class="left">
  17. <view class="icon">
  18. <u-icon :name="item.icon" size="22"></u-icon>
  19. </view>
  20. <text class="title">{{item.title||'暂无'}}</text>
  21. </view>
  22. <view class="right">
  23. <u-icon name="arrow-right" size="20"></u-icon>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup lang="ts">
  30. import { getCurrentInstance, ref } from 'vue';
  31. //该依赖已内置不需要单独安装
  32. import { onShow, onLoad } from "@dcloudio/uni-app";
  33. // 请求接口
  34. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  35. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  36. // 基本信息
  37. const config = ref({});
  38. // 用户信息
  39. const user = ref({});
  40. onLoad(async () => {
  41. await searchConfig();
  42. await search();
  43. })
  44. onShow(() => {
  45. searchUser();
  46. })
  47. // 用户信息
  48. const searchUser = async () => {
  49. user.value = uni.getStorageSync('user');
  50. };
  51. // config信息
  52. const searchConfig = async () => {
  53. config.value = uni.getStorageSync('config');
  54. };
  55. // 查询
  56. const search = async () => {
  57. };
  58. // 登录
  59. const toLogin = () => {
  60. if (user.value._id) {
  61. uni.navigateTo({
  62. url: `/pagesMy/basic/index`
  63. })
  64. } else {
  65. uni.navigateTo({
  66. url: `/pagesHome/login/index`
  67. })
  68. }
  69. };
  70. // 公共跳转
  71. const toCommon = (e) => {
  72. if (user.value && user.value._id) {
  73. if (e) {
  74. uni.navigateTo({
  75. url: `/${e}`
  76. })
  77. } else {
  78. try {
  79. uni.clearStorage();
  80. uni.reLaunch({
  81. url: '/pages/index/index'
  82. })
  83. } catch (e) { }
  84. }
  85. } else {
  86. uni.navigateTo({
  87. url: `/pagesHome/login/index`
  88. })
  89. }
  90. };
  91. const formatName = (str) => {
  92. if (str) return str.substr(0, 1) + new Array(str.length).join('');
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. .content {
  97. display: flex;
  98. flex-direction: column;
  99. width: 100vw;
  100. height: 100vh;
  101. background-color: var(--f1Color);
  102. .one {
  103. display: flex;
  104. align-items: center;
  105. padding: 0 8vw;
  106. height: 25vh;
  107. background: linear-gradient(to bottom, #2979ff, #f1f1f1);
  108. .left {
  109. .image {
  110. width: 50px;
  111. height: 50px;
  112. border-radius: 50px;
  113. }
  114. }
  115. .right {
  116. display: flex;
  117. align-items: center;
  118. margin: 0 0 0 3vw;
  119. font-size: var(--font16Size);
  120. font-weight: bold;
  121. }
  122. }
  123. .two {
  124. display: flex;
  125. flex-direction: column;
  126. padding: 2vw;
  127. margin: 2vw;
  128. .list {
  129. display: flex;
  130. justify-content: space-between;
  131. padding: 4vw;
  132. margin: 0 0 2vw 0;
  133. border-bottom: 1px solid var(--f9Color);
  134. background-color: var(--mainColor);
  135. border-radius: 10px;
  136. .left {
  137. display: flex;
  138. align-items: center;
  139. .icon {
  140. padding: 0 1vw 0 0;
  141. }
  142. .title {
  143. display: inline-block;
  144. font-size: var(--font14Size);
  145. }
  146. }
  147. .right {
  148. font-size: var(--font12Size);
  149. color: var(--f99Color);
  150. }
  151. }
  152. }
  153. }
  154. </style>