index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="container">
  3. <view class="top">
  4. <image class="avatar"mode="aspectFill" :src="src"></image>
  5. <text v-if="role && role !== 'guest'" class="name">{{ userInfo.name}}</text>
  6. <button v-else type="default" :plain="true" style="border: none;" class="login" @click="register">注册</button>
  7. </view>
  8. <view class="main" v-if="role && role !== 'guest'">
  9. <uni-card>
  10. <uni-list :border="false">
  11. <uni-list-item :showExtraIcon="true" :extra-icon="extraIconList[0]" title="个人资料" link clickable @click="onClick(0)"></uni-list-item>
  12. </uni-list>
  13. </uni-card>
  14. <uni-card>
  15. <uni-list :border="false">
  16. <uni-list-item :showExtraIcon="true" :extra-icon="extraIconList[1]" title="家庭成员" link clickable @click="onClick(1)"></uni-list-item>
  17. </uni-list>
  18. </uni-card>
  19. <uni-card>
  20. <uni-list :border="false">
  21. <uni-list-item :showExtraIcon="true" :extra-icon="extraIconList[2]" title="问卷调查" link clickable @click="onClick(2)"></uni-list-item>
  22. </uni-list>
  23. </uni-card>
  24. <uni-card>
  25. <uni-list :border="false">
  26. <uni-list-item :showExtraIcon="true" :extra-icon="extraIconList[3]" title="我的积分" link clickable @click="onClick(3)"></uni-list-item>
  27. </uni-list>
  28. </uni-card>
  29. <!-- <uni-card>
  30. <uni-list :border="false">
  31. <uni-list-item :showExtraIcon="true" :extra-icon="extraIconList[4]" title="意见反馈" link clickable @click="onClick(4)"></uni-list-item>
  32. </uni-list>
  33. </uni-card> -->
  34. <!-- <uni-card class="logoutBox">
  35. <uni-list :border="false">
  36. <uni-list-item size="mini" class="logout" title="退出登录" clickable @click="onClick(4)"></uni-list-item>
  37. </uni-list>
  38. </uni-card> -->
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import request from '../../api/user.js';
  44. import requestLogin from '../../api/login.js';
  45. export default {
  46. data() {
  47. return {
  48. extraIconList: [
  49. {
  50. color: '#ff8319',
  51. size: '22',
  52. type: 'person'
  53. },
  54. {
  55. color: '#ebc200',
  56. size: '22',
  57. type: 'home'
  58. },
  59. {
  60. color: '#429ff6',
  61. size: '22',
  62. type: 'mail-open-filled'
  63. },
  64. {
  65. color: '#4cd964',
  66. size: '22',
  67. type: 'star-filled'
  68. },
  69. {
  70. color: '#e70000',
  71. size: '22',
  72. type: 'email-filled'
  73. }
  74. ],
  75. src: '',
  76. userInfo: {},
  77. role: ''
  78. }
  79. },
  80. async onShow() {
  81. this.role = uni.getStorageSync('role');
  82. if (this.role !== 'guest') {
  83. const userinfo = await request.getUser();
  84. uni.setStorageSync('userinfo', userinfo.data);
  85. this.userInfo = userinfo.data;
  86. }
  87. },
  88. async mounted() {
  89. const config = await requestLogin.getJson();
  90. const { avatar } = config.data;
  91. this.src = avatar;
  92. if (this.role == 'guest') {
  93. uni.navigateTo({
  94. url: '/pages/register/index'
  95. });
  96. return;
  97. }
  98. },
  99. methods: {
  100. register() {
  101. uni.navigateTo({
  102. url: '/pages/register/index'
  103. })
  104. },
  105. onClick(e) {
  106. console.log(e);
  107. if (e == 0) {
  108. uni.navigateTo({
  109. url: '/pages/user/index'
  110. })
  111. return;
  112. }
  113. if (e == 1) {
  114. this.illness();
  115. return;
  116. }
  117. if (e == 2) {
  118. uni.navigateTo({
  119. url: '/pages/questionnaire/index'
  120. })
  121. return;
  122. }
  123. if (e == 3) {
  124. uni.navigateTo({
  125. url: '/pages/integral/index'
  126. })
  127. return;
  128. }
  129. uni.showToast({
  130. title: '敬请期待',
  131. icon: 'error',
  132. duration: 2000,
  133. });
  134. },
  135. illness() {
  136. uni.navigateTo({
  137. url: '/pages/illness/receive'
  138. })
  139. },
  140. logOut() {
  141. uni.clearStorage();
  142. uni.redirectTo({
  143. url: '/pages/index/index'
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style>
  150. .container {
  151. width: 100%;
  152. }
  153. .top {
  154. height: 25vh;
  155. background-color: #cb0714;
  156. padding-top: 10px;
  157. position: relative;
  158. z-index: 1;
  159. }
  160. .avatar {
  161. width: 70px;
  162. height: 70px;
  163. border-radius: 50%;
  164. overflow: hidden;
  165. display: block;
  166. margin: 0 auto;
  167. }
  168. .name {
  169. color: #fff;
  170. width: 100%;
  171. text-align: center;
  172. display: block;
  173. margin: 10px 0;
  174. }
  175. .login {
  176. margin: 10px auto;
  177. color: #fff !important;
  178. padding: 0;
  179. line-height: 1em;
  180. }
  181. .main {
  182. width: 90%;
  183. display: block;
  184. margin: 0 auto;
  185. margin-top: -40px;
  186. position: relative;
  187. z-index: 2;
  188. }
  189. .logoutBox {
  190. display: block;
  191. margin-top: 50px;
  192. }
  193. .logout .uni-list-item__content-title {
  194. text-align: center;
  195. }
  196. </style>