index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view v-if="isUp">
  3. <view class="mobile-bg" v-if="isShow" @click="close"></view>
  4. <view class="mobile-mask animated" :class="{slideInUp:isUp}" :style="{position:isPos?'fixed':'static'}">
  5. <view class="input-item">
  6. <input type="text" v-model="account" placeholder="输入手机号" />
  7. </view>
  8. <view class="input-item">
  9. <input type="text" v-model="codeNum" placeholder="输入验证码" />
  10. <button class="code" :disabled="disabled" @click="code">{{text}}</button>
  11. </view>
  12. <view class="sub_btn" @click="loginBtn">{{(!userInfo.phone && isLogin) || (userInfo.phone && isLogin)?'立即绑定':'立即登录'}}</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. const app = getApp();
  18. import sendVerifyCode from "@/mixins/SendVerifyCode";
  19. import {mapGetters} from "vuex";
  20. import * as AuthApi from "@/api/member/auth";
  21. import * as UserApi from "@/api/member/user";
  22. import * as BrokerageAPI from '@/api/trade/brokerage.js'
  23. import { iosBinding } from '@/api/public';
  24. const BACK_URL = "login_back_url";
  25. export default {
  26. name: 'login_mobile',
  27. computed: mapGetters(['userInfo','isLogin']),
  28. props: {
  29. isUp: {
  30. type: Boolean,
  31. default: false,
  32. },
  33. authKey: {
  34. type: String,
  35. default: '',
  36. },
  37. socialCode: {
  38. type: String,
  39. default: '',
  40. },
  41. socialState: {
  42. type: String,
  43. default: '',
  44. },
  45. isShow: {
  46. type: Boolean,
  47. default: true
  48. },
  49. isPos: {
  50. type: Boolean,
  51. default: true
  52. },
  53. appleShow: {
  54. type: String,
  55. default: ''
  56. },
  57. platform: {
  58. type: String,
  59. default: '',
  60. }
  61. },
  62. data() {
  63. return {
  64. account: '',
  65. codeNum: '',
  66. isApp: 0
  67. }
  68. },
  69. mixins: [sendVerifyCode],
  70. methods: {
  71. // 获取验证码
  72. async code() {
  73. if (!this.account) {
  74. return this.$util.Tips({
  75. title: '请填写手机号码'
  76. });
  77. }
  78. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.account)) {
  79. return this.$util.Tips({
  80. title: '请输入正确的手机号码'
  81. });
  82. }
  83. await AuthApi.sendSmsCode(this.account, 1)
  84. .then(res => {
  85. this.$util.Tips({title:res.message});
  86. this.sendCode();
  87. })
  88. .catch(err => {
  89. return this.$util.Tips({
  90. title: err
  91. });
  92. });
  93. },
  94. close() {
  95. this.$emit('close', false)
  96. },
  97. // 登录
  98. loginBtn() {
  99. if (!this.account) {
  100. return this.$util.Tips({
  101. title: '请填写手机号码'
  102. });
  103. }
  104. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.account)) {
  105. return this.$util.Tips({
  106. title: '请输入正确的手机号码'
  107. });
  108. }
  109. if (!this.codeNum) return this.$util.Tips({
  110. title: '请填写验证码'
  111. });
  112. if (!/^[\w\d]+$/i.test(this.codeNum)) {
  113. return this.$util.Tips({
  114. title: '请输入正确的验证码'
  115. });
  116. }
  117. uni.showLoading({
  118. title: !this.userInfo.phone && this.isLogin?'正在绑定中':'正在登录中'
  119. });
  120. if (!this.userInfo.phone && this.isLogin) {
  121. // TODO 芋艿:不晓得它要搞啥哈???
  122. iosBinding({
  123. captcha: this.codeNum,
  124. phone: this.account
  125. }).then(res => {
  126. this.$util.Tips({
  127. title: '绑定手机号成功',
  128. icon: 'success'
  129. }, {
  130. tab: 3
  131. })
  132. this.isApp = 1;
  133. this.getUserInfo();
  134. }).catch(error => {
  135. uni.hideLoading()
  136. this.$util.Tips({
  137. title: error
  138. })
  139. })
  140. } else {
  141. AuthApi.smsLogin({
  142. mobile: this.account,
  143. code: this.codeNum,
  144. socialType: 31,
  145. socialCode: this.socialCode,
  146. socialState: this.socialState
  147. }).then(res => {
  148. // TODO 芋艿:refreshToken 机制
  149. let data = res.data;
  150. this.$store.commit("LOGIN", {
  151. 'token': res.data.accessToken
  152. });
  153. this.getUserInfo(data);
  154. this.bindBrokerUser();
  155. }).catch(error => {
  156. uni.hideLoading()
  157. this.$util.Tips({
  158. title: error
  159. })
  160. })
  161. }
  162. },
  163. /**
  164. * 获取个人用户信息
  165. */
  166. getUserInfo: function(data) {
  167. this.$store.commit("SETUID", data.userId);
  168. this.$store.commit("OPENID", data.openid);
  169. UserApi.getUserInfo().then(res => {
  170. uni.hideLoading();
  171. this.$store.commit("UPDATE_USERINFO", res.data);
  172. // 调回登录前页面
  173. // #ifdef MP
  174. this.$util.Tips({
  175. title: '登录成功',
  176. icon: 'success'
  177. }, {
  178. tab: 3
  179. })
  180. this.close()
  181. // #endif
  182. // #ifdef H5
  183. this.$emit('wechatPhone', true)
  184. // #endif
  185. });
  186. },
  187. bindBrokerUser() {
  188. const spread = this.$Cache.get("spread");
  189. if (spread > 0) {
  190. BrokerageAPI.bindBrokerageUser(spread)
  191. }
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="stylus" scoped>
  197. .mobile-bg {
  198. position: fixed;
  199. left: 0;
  200. top: 0;
  201. width: 100%;
  202. height: 100%;
  203. background: rgba(0, 0, 0, 0.5);
  204. }
  205. .isPos {
  206. position: static;
  207. }
  208. .mobile-mask {
  209. z-index: 20;
  210. // position: fixed;
  211. left: 0;
  212. bottom: 0;
  213. width: 100%;
  214. padding: 67rpx 30rpx;
  215. background: #fff;
  216. .input-item {
  217. display: flex;
  218. justify-content: space-between;
  219. width: 100%;
  220. height: 86rpx;
  221. margin-bottom: 38rpx;
  222. input {
  223. flex: 1;
  224. display: block;
  225. height: 100%;
  226. padding-left: 40rpx;
  227. border-radius: 43rpx;
  228. border: 1px solid #DCDCDC;
  229. }
  230. .code {
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. width: 220rpx;
  235. height: 86rpx;
  236. margin-left: 30rpx;
  237. background: rgba(233, 51, 35, 0.05);
  238. font-size: 28rpx;
  239. color: $theme-color;
  240. border-radius: 43rpx;
  241. &[disabled] {
  242. background: rgba(0, 0, 0, 0.05);
  243. color: #999;
  244. }
  245. }
  246. }
  247. .sub_btn {
  248. width: 690rpx;
  249. height: 86rpx;
  250. line-height: 86rpx;
  251. margin-top: 60rpx;
  252. background: #E93323;
  253. border-radius: 43rpx;
  254. color: #fff;
  255. font-size: 28rpx;
  256. text-align: center;
  257. }
  258. }
  259. .animated {
  260. animation-duration: .4s
  261. }
  262. </style>