index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="main">
  3. <view class="user" @click="go('info')">
  4. <image :src="user.avatarUrl ? user.avatarUrl : '../../static/favicon.png'" class="head"></image>
  5. <view class="con" v-if="user.id">
  6. <view class="nickName">微信用户</view>
  7. <view class="welcome">欢迎使用承揽时代</view>
  8. </view>
  9. <view class="con" v-else>
  10. <view class="nickName">你还没登录</view>
  11. <view class="welcome">欢迎使用承揽时代</view>
  12. </view>
  13. <view class="icon">&#xe62b;</view>
  14. </view>
  15. <view class="cmd">
  16. <view class="s_item" @click="go('auth')">
  17. <text class="icon ic">&#xe600;</text>
  18. <text class="title">我的认证</text>
  19. <text class="icon arrow">&#xe62b;</text>
  20. </view>
  21. <view class="s_item" @click="go('contract')">
  22. <text class="icon ic">&#xe6ed;</text>
  23. <text class="title">我的签约</text>
  24. <text class="icon arrow">&#xe62b;</text>
  25. </view>
  26. <view class="s_item" @click="go('company')">
  27. <text class="icon ic">&#xe623;</text>
  28. <text class="title">关联企业</text>
  29. <text class="icon arrow">&#xe62b;</text>
  30. </view>
  31. <view class="s_item" @click="go('packages')">
  32. <text class="icon ic">&#xe604;</text>
  33. <text class="title">我的承揽</text>
  34. <text class="icon arrow">&#xe62b;</text>
  35. </view>
  36. </view>
  37. <!-- <button class="btn exit" @click="exit()" v-if="user.id">退出登录</button> -->
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. ip: this.http.ip,
  45. user: {}
  46. };
  47. },
  48. onShow() {
  49. /* this.user = {
  50. token: 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImI0M2FmZjFmLWQ1YWMtNDk3Yi1hNDNiLTEwYTRiMmJmYmI4YiJ9.2IEItPPaVUBQw416MK9SA6OM_PE5WgcpvTdVf_-KJ8AQsI1J9PzMlRiA2ZCQT6gdHbY9l9wS1ZxQzdIxTx9PjQ'
  51. };
  52. uni.setStorageSync('user', this.user); */
  53. if (this.hasLogin()) {
  54. this.getUserInfo();
  55. }
  56. },
  57. methods: {
  58. getUserInfo() {
  59. this.http.request({
  60. url: '/app/user/info',
  61. success: (res) => {
  62. this.user = res.data.data;
  63. }
  64. });
  65. },
  66. go(url) {
  67. if (this.hasLogin()) {
  68. if (url == 'auth') {
  69. uni.navigateTo({ url: '/pages/auth/index' });
  70. }
  71. if (url == 'company' && this.user.isAuthentication === 1) {
  72. uni.navigateTo({ url: '/pages/company/index' });
  73. }
  74. if (url == 'packages' && this.user.isCompany > 0 && this.user.isContract == 1) {
  75. uni.switchTab({ url: '/pages/packages/index' });
  76. }
  77. if (url == 'contract' && this.user.isContract == 1) {
  78. this.look();
  79. }
  80. if (url == 'info') {
  81. uni.navigateTo({ url: '/pages/user/info' });
  82. }
  83. } else {
  84. uni.navigateTo({ url: '/pages/user/login' });
  85. }
  86. },
  87. //查看合同
  88. look() {
  89. uni.showLoading({ title: '正在打开合同...', mask: true });
  90. uni.downloadFile({
  91. url: this.user.isContract == 0 ? this.ip + this.contract.url : this.ip + '/app/contract/look',
  92. header: { Authorization: this.getUser().token },
  93. success: (res) => {
  94. uni.openDocument({
  95. filePath: res.tempFilePath,
  96. showMenu: true,
  97. success: (res) => {
  98. uni.hideLoading();
  99. }
  100. });
  101. },
  102. fail: (res) => {
  103. uni.hideLoading();
  104. }
  105. });
  106. },
  107. //退出登录
  108. exit(url) {
  109. uni.showModal({
  110. title: '提示',
  111. content: '确定退出登录?',
  112. success: (res) => {
  113. if (res.confirm) {
  114. this.http.request({
  115. url: this.http.urls.logout,
  116. success: (res) => {
  117. uni.removeStorageSync('user');
  118. uni.$emit('top');
  119. uni.switchTab({
  120. url: '/pages/index/index'
  121. });
  122. }
  123. });
  124. }
  125. }
  126. });
  127. }
  128. }
  129. };
  130. </script>
  131. <style lang="scss">
  132. .main {
  133. padding: 20px;
  134. }
  135. .user {
  136. overflow: hidden;
  137. image {
  138. float: left;
  139. width: 60px;
  140. height: 60px;
  141. border-radius: 50%;
  142. }
  143. .con {
  144. float: left;
  145. padding-left: 15px;
  146. .nickName {
  147. padding-top: 5px;
  148. }
  149. .welcome {
  150. font-size: 13px;
  151. padding-top: 5px;
  152. color: #989898;
  153. }
  154. }
  155. .icon {
  156. float: right;
  157. margin-top: 14px;
  158. }
  159. }
  160. .exit {
  161. margin-top: 20px;
  162. }
  163. </style>