index.vue 5.8 KB

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