index.vue 3.4 KB

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