index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.$u.toast(res.data.msg);
  130. }
  131. }).catch(err => {
  132. console.log(err)
  133. this.$u.toast('登录失败');
  134. }).finally(() => {
  135. this.loading = false
  136. })
  137. }
  138. },
  139. inregister() {
  140. this.$u.route({
  141. url: 'pages/login/register',
  142. })
  143. },
  144. codeChange(text) {
  145. this.codeText = text;
  146. },
  147. getCode() {
  148. if (this.tel) {
  149. this.codeLoading=true
  150. request({
  151. url: '/sailun/appStoreBasicInfo/sendCode',
  152. method: 'post',
  153. data: {
  154. "phoneNumber": this.tel,
  155. "opreaType":"1"
  156. },
  157. }).then(res => {
  158. console.log(res)
  159. if (res.data.code == 0) {
  160. if (this.$refs.uCode.canGetCode) {
  161. this.$refs.uCode.start();
  162. } else {
  163. this.$u.toast('倒计时结束后再发送');
  164. }
  165. }
  166. if (res.data.code == 500) {
  167. this.$u.toast(res.data.msg);
  168. }
  169. }).catch(err => {
  170. console.log(err)
  171. }).finally(() => {
  172. this.codeLoading=false
  173. })
  174. } else {
  175. this.$u.toast('请输入手机号');
  176. }
  177. },
  178. }
  179. };
  180. </script>
  181. <style lang="scss" scoped>
  182. .status_bar {
  183. height: var(--status-bar-height);
  184. width: 100%;
  185. background-color: #0095FF;
  186. }
  187. .content {
  188. position: relative;
  189. top: -350rpx;
  190. }
  191. .foot {
  192. position: fixed;
  193. bottom: 10rpx;
  194. width: 100%;
  195. }
  196. </style>