LoginPage.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="page-body">
  3. <view class="page-section">
  4. <view>请输入手机号</view>
  5. <view>
  6. <view>
  7. <input class="weui-input" @input="bindPhoneInput" type="number" placeholder="手机号"></input>
  8. </view>
  9. </view>
  10. </view>
  11. <view class="page-section">
  12. <view>请输入验证码</view>
  13. <view class="auth-code-container">
  14. <input @input="bindCodeInput" type="number" placeholder="验证码"></input>
  15. <button :disabled="phone.length !== 11" @tap="bindAuthCodeTap">获取验证码</button>
  16. </view>
  17. </view>
  18. <button :disabled="!(phone && code)" class="confirm-button" @tap="bindLoginTap">登录</button>
  19. </view>
  20. </template>
  21. <script>
  22. import wfc from "../../wfc/client/wfc";
  23. import wfcUIKit from "../../wfc/uikit/wfcUIKit";
  24. import Config from '../../config';
  25. import {getItem, setItem} from "../util/storageHelper";
  26. import ConnectionStatus from "../../wfc/client/connectionStatus";
  27. import appServerApi from "../../api/appServerApi";
  28. export default {
  29. name: 'LoginPage',
  30. data() {
  31. return {
  32. focus: false,
  33. phone: '',
  34. code: ''
  35. };
  36. },
  37. components: {},
  38. props: {},
  39. onShow() {
  40. console.log('login onShow');
  41. if((Config.APP_SERVER.indexOf('wildfirechat') >= 0 && Config.IM_SERVER_HOST.indexOf('wildfirechat') === -1)
  42. || (Config.APP_SERVER.indexOf('wildfirechat') === -1 && Config.IM_SERVER_HOST.indexOf('wildfirechat') >= 0)){
  43. console.error('!!!! 严重错误!!!! Config.APP_SERVER 和 Config.IM_SERVER_HOST要一起修改,不能一个用官方服务,一个用自己部署的服务');
  44. } else if(Config.IM_SERVER_HOST.indexOf(':') >= 0){
  45. console.error('!!!! 严重错误!!!! Config.IM_SERVER_HOST 不能包含端口,只需要 HOST 即可');
  46. } else if(Config.IM_SERVER_HOST.indexOf('http') >= 0){
  47. console.error('!!!! 严重错误!!!! Config.IM_SERVER_HOST 不能包含http,只需要 HOST 即可');
  48. }
  49. },
  50. methods: {
  51. bindPhoneInput: function (e) {
  52. this.phone = e.detail.value;
  53. },
  54. bindCodeInput: function (e) {
  55. this.code = e.detail.value;
  56. },
  57. bindLoginTap: function (e) {
  58. console.log(this.phone); // console.log(this.data.code)
  59. this.login(this.phone, this.code);
  60. },
  61. login(phone, code) {
  62. console.log('login', wfc.getClientId(), Config.getWFCPlatform());
  63. appServerApi.loginWithAuthCode(phone, code)
  64. .then(result => {
  65. console.log('login result', result);
  66. let userId = result.userId;
  67. let token = result.token;
  68. wfc.connect(userId, token);
  69. setItem('userId', userId);
  70. setItem('token', token)
  71. this.go2ConversationList();
  72. })
  73. .catch(r => {
  74. console.log('login failed', r)
  75. uni.showToast({
  76. title: r,
  77. icon: 'none',
  78. });
  79. });
  80. },
  81. bindAuthCodeTap: function (e) {
  82. console.log(this.phone);
  83. this.authCode(this.phone);
  84. },
  85. authCode(phone) {
  86. appServerApi.requestAuthCode(phone)
  87. .then(result => {
  88. uni.showToast({
  89. title: '发送验证码成功',
  90. icon: 'none',
  91. });
  92. })
  93. .catch(reason => {
  94. uni.showToast({
  95. title: reason,
  96. icon: 'none',
  97. });
  98. })
  99. },
  100. go2ConversationList() {
  101. uni.switchTab({
  102. url: '/pages/conversationList/ConversationListPage',
  103. success: () => {
  104. console.log('to conversation list success');
  105. },
  106. fail: e => {
  107. console.log('to conversation list error', e);
  108. },
  109. complete: () => {
  110. console.log('switch tab complete')
  111. }
  112. });
  113. }
  114. }
  115. };
  116. </script>
  117. <style>
  118. .page-body {
  119. padding: 20rpx;
  120. }
  121. .page-section {
  122. margin-top: 20rpx;
  123. }
  124. .auth-code-container {
  125. display: flex;
  126. flex-direction: row;
  127. align-items: center;
  128. justify-content: space-between;
  129. width: 100%;
  130. height: 50px;
  131. /*background-color: green;*/
  132. }
  133. .auth-code-container input {
  134. flex: 1;
  135. padding-right: 5px;
  136. }
  137. .auth-code-container button {
  138. /*background-color: red;*/
  139. font-size: 14px;
  140. }
  141. .confirm-button {
  142. margin-top: 20px;
  143. }
  144. /*.other-button-hover {*/
  145. /* background-color: #7497f1;*/
  146. /*}*/
  147. /*.button-hover {*/
  148. /* background-color: #4168e0;*/
  149. /*}*/
  150. </style>