index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 permision from "@/js_sdk/wa-permission/permission.js"
  49. import {
  50. mapState,
  51. mapMutations
  52. } from 'vuex'
  53. import {
  54. request
  55. } from '../../common/request/request'
  56. require("promise.prototype.finally").shim()
  57. export default {
  58. data() {
  59. return {
  60. tel: '',
  61. code: '',
  62. codeText: '',
  63. pact: false,
  64. loading: false,
  65. codeLoading: false,
  66. SystemInfo: '',
  67. networkType: ''
  68. }
  69. },
  70. computed: {
  71. ...mapState(['hasLogin'])
  72. },
  73. created() {
  74. uni.getSystemInfo({
  75. success: (res) => {
  76. this.SystemInfo = res
  77. }
  78. });
  79. uni.getNetworkType({
  80. success: (res) => {
  81. this.networkType = res.networkType
  82. }
  83. });
  84. uni.getLocation({
  85. success:res=>{
  86. },
  87. fail:err=>{
  88. if(this.SystemInfo.platform=="ios"){
  89. this.judgeIosPermission()
  90. }else{
  91. this.requestAndroidPermission()
  92. }
  93. }
  94. });
  95. uni.$on('loginphone',data=>{
  96. this.tel=data
  97. })
  98. },
  99. methods: {
  100. ...mapMutations(['login']),
  101. judgeIosPermission() {
  102. let result = permision.judgeIosPermission('location')
  103. if (!result) {
  104. uni.showModal({
  105. title: "温馨提示",
  106. content: "为了更好地为您服务,请开启定位权限,请问是否同意??",
  107. cancelText: "不同意",
  108. confirmText: "同意",
  109. success: res => {
  110. if (res.confirm) {
  111. plus.runtime.openURL("app-settings://");
  112. }
  113. }
  114. })
  115. }
  116. },
  117. async requestAndroidPermission() {
  118. let result = await permision.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
  119. },
  120. toUser(provider) {
  121. this.login(provider);
  122. if (this.hasLogin) {
  123. this.$u.route({
  124. url: 'pages/home/index',
  125. type: 'switchTab',
  126. })
  127. } else {
  128. uni.navigateBack();
  129. }
  130. },
  131. submit() {
  132. if (this.$u.test.mobile(this.tel)) {
  133. this.loading = true
  134. request({
  135. url: '/sailun/appLogin/storeLogin',
  136. method: 'post',
  137. data: {
  138. "account": "",
  139. "loginType": "1",
  140. "mobileCode": this.code,
  141. "password": "",
  142. "phoneNumber": this.tel,
  143. "osType": this.SystemInfo.platform,
  144. "osVersion": this.SystemInfo.system,
  145. "phoneBrand": this.SystemInfo.brand,
  146. "phoneModel": this.SystemInfo.model,
  147. "appVersion": "1.00",
  148. "networkType": this.networkType,
  149. }
  150. }).then(res => {
  151. if (res.data.code == 0) {
  152. this.toUser(res.data.data)
  153. uni.$emit('login', {
  154. msg: '登录成功'
  155. })
  156. } else {
  157. this.$u.toast(res.data.msg);
  158. }
  159. }).catch(err => {
  160. console.log(err)
  161. this.$u.toast('登录失败');
  162. }).finally(() => {
  163. this.loading = false
  164. })
  165. }
  166. },
  167. inregister() {
  168. this.$u.route({
  169. url: 'pages/login/register',
  170. })
  171. },
  172. codeChange(text) {
  173. this.codeText = text;
  174. },
  175. getCode() {
  176. if (this.tel) {
  177. this.codeLoading = true
  178. request({
  179. url: '/sailun/appStoreBasicInfo/sendCode',
  180. method: 'post',
  181. data: {
  182. "phoneNumber": this.tel,
  183. "opreaType": "1"
  184. },
  185. }).then(res => {
  186. console.log(res)
  187. if (res.data.code == 0) {
  188. if (this.$refs.uCode.canGetCode) {
  189. this.$refs.uCode.start();
  190. } else {
  191. this.$u.toast('倒计时结束后再发送');
  192. }
  193. }
  194. if (res.data.code == 500) {
  195. this.$u.toast(res.data.msg);
  196. }
  197. }).catch(err => {
  198. console.log(err)
  199. }).finally(() => {
  200. this.codeLoading = false
  201. })
  202. } else {
  203. this.$u.toast('请输入手机号');
  204. }
  205. },
  206. }
  207. };
  208. </script>
  209. <style lang="scss" scoped>
  210. .status_bar {
  211. height: var(--status-bar-height);
  212. width: 100%;
  213. background-color: #0095FF;
  214. }
  215. .content {
  216. position: relative;
  217. top: -350rpx;
  218. }
  219. .foot {
  220. position: fixed;
  221. bottom: 10rpx;
  222. width: 100%;
  223. }
  224. </style>