index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view>
  3. <view class="status_bar">
  4. <!-- 这里是状态栏 -->
  5. </view>
  6. <u-image src="../../static/sailun/login_bg.png" mode="widthFix"></u-image>
  7. <view class="content">
  8. <u-card padding="50" :head-border-bottom="false" :show-head="false" :show-foot="false" :border="false" box-shadow="0px 1px 10px rgba(0,0,0,0.2)"
  9. border-radius="20" margin="50rpx">
  10. <view slot="body">
  11. <view style="margin-top: 20rpx;">
  12. <u-field v-model="tel" placeholder="请填写手机号" label-width="50">
  13. <u-icon slot="icon" name="account" size="36" color="#666666"></u-icon>
  14. </u-field>
  15. </view>
  16. <view style="margin-top: 30rpx;">
  17. <u-field v-model="code" placeholder="请填写验证码" label-width="50">
  18. <u-icon slot="icon" name="lock" size="36" color="#666666"></u-icon>
  19. <u-button size="mini" slot="right" type="primary" @click="getCode" shape="circle" :loading="codeLoading">{{codeText}}</u-button>
  20. </u-field>
  21. </view>
  22. <u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
  23. <view style="margin-top: 80rpx;">
  24. <u-button type="primary" :ripple="true" ripple-bg-color="#99d4ff" shape="circle" @tap="$u.debounce(submit, 2000,immediate = true)"
  25. :loading="loading">登录</u-button>
  26. </view>
  27. <view style="margin-top: 80rpx;display: flex;justify-content: center;">
  28. <view class="u-flex" @click="inregister">
  29. <view style="color: rgba(0,160,234,0.5)">
  30. 还没有账号?
  31. </view>
  32. <view style="color: #00A0EA">
  33. 立即注册
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </u-card>
  39. </view>
  40. <view class="foot">
  41. <view class="u-flex u-row-center u-col-center">
  42. <u-divider color="#0095FF" border-color="#0095FF" bg-color="#F4F4F4" fontSize="30">赛轮店管家</u-divider>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import {mapState,mapMutations} from 'vuex'
  49. import {
  50. request
  51. } from '../../common/request/request'
  52. require("promise.prototype.finally").shim()
  53. export default {
  54. data() {
  55. return {
  56. tel: '',
  57. code: '',
  58. codeText: '',
  59. pact: false,
  60. loading: false,
  61. codeLoading:false,
  62. SystemInfo:'',
  63. networkType:''
  64. }
  65. },
  66. computed: {
  67. ...mapState(['hasLogin'])
  68. },
  69. onLoad() {
  70. uni.getSystemInfo({
  71. success:(res)=>{
  72. this.SystemInfo=res
  73. }
  74. });
  75. uni.getNetworkType({
  76. success:(res)=>{
  77. this.networkType=res.networkType
  78. }
  79. });
  80. if(this.hasLogin){
  81. this.$u.route({
  82. url: 'pages/home/index',
  83. type: 'switchTab',
  84. })
  85. }
  86. },
  87. created() {
  88. },
  89. methods: {
  90. ...mapMutations(['login']),
  91. toUser(provider){
  92. this.login(provider);
  93. if(this.hasLogin){
  94. this.$u.route({
  95. url: 'pages/home/index',
  96. type: 'switchTab',
  97. })
  98. }else{
  99. uni.navigateBack();
  100. }
  101. },
  102. submit() {
  103. if (this.$u.test.mobile(this.tel)) {
  104. this.loading = true
  105. request({
  106. url: '/sailun/appLogin/storeLogin',
  107. method: 'post',
  108. data: {
  109. "account": "",
  110. "loginType": "1",
  111. "mobileCode": this.code,
  112. "password": "",
  113. "phoneNumber": this.tel,
  114. "osType":this.SystemInfo.platform,
  115. "osVersion":this.SystemInfo.system,
  116. "phoneBrand":this.SystemInfo.brand,
  117. "phoneModel":this.SystemInfo.model,
  118. "appVersion":"1.00",
  119. "networkType":this.networkType,
  120. }
  121. }).then(res => {
  122. if (res.data.code == 0) {
  123. console.log(res.data.data)
  124. this.toUser(res.data.data)
  125. uni.$emit('login', {
  126. msg: '登录成功'
  127. })
  128. }else {
  129. this.$refs.uToast.show({
  130. title: res.data.msg,
  131. })
  132. }
  133. }).catch(err => {
  134. console.log(err)
  135. this.$u.toast('登录失败');
  136. }).finally(() => {
  137. this.loading = false
  138. })
  139. }
  140. },
  141. inregister() {
  142. this.$u.route({
  143. url: 'pages/login/register',
  144. })
  145. },
  146. codeChange(text) {
  147. this.codeText = text;
  148. },
  149. getCode() {
  150. if (this.tel) {
  151. this.codeLoading=true
  152. request({
  153. url: '/sailun/appStoreBasicInfo/sendCode',
  154. method: 'post',
  155. data: {
  156. "phoneNumber": this.tel,
  157. "opreaType":"1"
  158. },
  159. }).then(res => {
  160. console.log(res)
  161. if (res.data.code == 0) {
  162. if (this.$refs.uCode.canGetCode) {
  163. this.$refs.uCode.start();
  164. } else {
  165. this.$u.toast('倒计时结束后再发送');
  166. }
  167. }
  168. if (res.data.code == 500) {
  169. this.$u.toast(res.data.msg);
  170. }
  171. }).catch(err => {
  172. console.log(err)
  173. }).finally(() => {
  174. this.codeLoading=false
  175. })
  176. } else {
  177. this.$u.toast('请输入手机号');
  178. }
  179. },
  180. }
  181. };
  182. </script>
  183. <style lang="scss" scoped>
  184. .status_bar {
  185. height: var(--status-bar-height);
  186. width: 100%;
  187. background-color: #0095FF;
  188. }
  189. .content {
  190. position: relative;
  191. top: -350rpx;
  192. }
  193. .foot {
  194. position: fixed;
  195. bottom: 10rpx;
  196. width: 100%;
  197. }
  198. </style>