index.vue 5.7 KB

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