index.wpy 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <style lang="less">
  2. .login-box {
  3. padding-top: 40px;
  4. .avatar-wrapper {
  5. padding: 0px;
  6. width: 196rpx;
  7. height: 196rpx;
  8. border-radius: 50%;
  9. image {
  10. width: 196rpx;
  11. height: 196rpx;
  12. border-radius: 50%;
  13. }
  14. }
  15. .avatar-tip {
  16. text-align: center;
  17. font-family: PingFang SC;
  18. font-size: 28rpx;
  19. font-weight: 400;
  20. line-height: 44rpx;
  21. text-align: center;
  22. }
  23. .bind-btn-box {
  24. position: fixed;
  25. bottom: 228rpx;
  26. left: 50%;
  27. transform: translateX(-50%);
  28. .bind-btn {
  29. width: 548rpx;
  30. height: 100rpx;
  31. line-height: 100rpx;
  32. border-radius: 56rpx;
  33. background: rgba(61, 203, 204, 1);
  34. border: none;
  35. font-family: PingFang SC;
  36. font-size: 32rpx;
  37. font-weight: 400;
  38. letter-spacing: 0px;
  39. text-align: center;
  40. color: #fff;
  41. }
  42. .bind-btn-tip {
  43. //styleName: 14/常规;
  44. font-family: PingFang SC;
  45. padding-top: 32rpx;
  46. font-size: 28rpx;
  47. font-weight: 400;
  48. line-height: 44rpx;
  49. text-align: center;
  50. color: rgba(139, 148, 158, 1);
  51. }
  52. }
  53. .home-btn {
  54. margin-top: 240rpx;
  55. width: 548rpx;
  56. height: 100rpx;
  57. line-height: 100rpx;
  58. border-radius: 56rpx;
  59. border: 1px solid rgba(61, 203, 204, 1);
  60. }
  61. }
  62. </style>
  63. <template>
  64. <div class="login-box">
  65. <button class="avatar-wrapper"
  66. v-if="canIUseGetUserProfile"
  67. open-type="chooseAvatar"
  68. bind:chooseavatar="onChooseAvatar">
  69. <image class="avatar" src="{{avatarUrl}}"/>
  70. </button>
  71. <div class="avatar-tip" v-if="canIUseGetUserProfile">可点击获取头像</div>
  72. <div class="bind-btn-box">
  73. <button class="bind-btn"
  74. open-type="getPhoneNumber"
  75. bindgetphonenumber="phonenumberAuth"
  76. >微信手机号认证</button>
  77. <!-- @click="goBindTenant" -->
  78. <!-- bindgetphonenumber="phonenumberAuth" -->
  79. <div class="bind-btn-tip">确保是入职公司使用的手机号</div>
  80. </div>
  81. <button class="home-btn" @click="goHome">首页</button>
  82. </div>
  83. </template>
  84. <script>
  85. import wepy from '@wepy/core';
  86. import { mapState } from '@wepy/x';
  87. import store from '@/store';
  88. import config from '@/config';
  89. import { setAvatar, checkLoginNew, setUserInfoByAuth } from '@/service/user';
  90. import { getHttpPhoneNumber } from '@/api/user';
  91. let defaultAvatarUrl =
  92. config.h5StaticPath + '/page-bind-tenant/default_avatar.svg';
  93. wepy.page({
  94. store,
  95. config: {
  96. navigationBarTitleText: 'test'
  97. },
  98. data: {
  99. nicknameValue: '',
  100. avatarUrl: defaultAvatarUrl,
  101. msg: '测试数据',
  102. canIUseGetUserProfile: false,
  103. userInformation: wx.getStorageSync('userInformation')
  104. },
  105. onLoad() {
  106. if (wx.getUserProfile) {
  107. this.canIUseGetUserProfile = true;
  108. }
  109. },
  110. onShow() {
  111. // 过期重定向处理
  112. // checkLoginNew().then(res => {
  113. // if (res.data && res.data.isActivated == 1) {
  114. // this.goHome();
  115. // } else {
  116. // wx.navigateTo({
  117. // url: '/pages/index'
  118. // });
  119. // }
  120. // });
  121. },
  122. methods: {
  123. // 绑定租户
  124. bindTenant() {},
  125. onChooseAvatar(e) {
  126. this.avatarUrl = e.$wx.detail.avatarUrl;
  127. let avatarUrl = this.avatarUrl;
  128. let that = this;
  129. wx.getFileSystemManager().readFile({
  130. filePath: avatarUrl,
  131. encoding: 'base64',
  132. success: function(res) {
  133. console.log(res.data);
  134. that.avatarUrl = 'data:image/png;base64,' + res.data;
  135. setAvatar(that.avatarUrl);
  136. }
  137. });
  138. },
  139. getPageCompanyByPhone() {},
  140. goHome() {
  141. wx.navigateTo({
  142. url: '/packagesEnv/pages/home/index'
  143. });
  144. },
  145. // 手机号认证
  146. phonenumberAuth(e) {
  147. let detail = e.$wx.detail;
  148. let code = detail.code;
  149. // store.commit('setUserPhone', 13810794283);
  150. // this.goBindTenant();
  151. this.getHttpPhoneNumber(code);
  152. },
  153. // code 换取手机号
  154. getHttpPhoneNumber(code) {
  155. getHttpPhoneNumber(code).then(res => {
  156. let data = res.data || {};
  157. let phoneNumber = data.purePhoneNumber;
  158. if (phoneNumber) {
  159. store.commit('setUserPhone', phoneNumber);
  160. this.goBindTenant();
  161. }
  162. });
  163. },
  164. goBindTenant() {
  165. console.log('被点击了');
  166. wx.navigateTo({
  167. url: '/pages/bindTenant/index'
  168. });
  169. }
  170. },
  171. created() {}
  172. });
  173. </script>
  174. <config>
  175. {
  176. navigationBarTitleText: '首页',
  177. }
  178. </config>