index.vue 4.6 KB

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