index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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="$t('login.mobile')" 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="$t('login.code')" label-width="50" maxlength="6">
  18. <u-icon slot="icon" name="lock" size="36" color="#666666"></u-icon>
  19. <u-button v-if="send=='zh'" size="mini" slot="right" type="primary" @click="getCode" shape="circle" :loading="codeLoading">{{codeText}}</u-button>
  20. <u-button v-else size="mini" slot="right" type="primary" @click="getCode" shape="circle" :loading="codeLoading">{{codeText}}</u-button>
  21. </u-field>
  22. </view>
  23. <view class="" v-if="send=='zh'">
  24. <u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
  25. </view>
  26. <u-verification-code v-else ref="uCode" @change="codeChange" start-text="Send" change-text="Reacquire in X S"
  27. end-text="Reacquire"></u-verification-code>
  28. <view style="margin-top: 80rpx;">
  29. <u-button type="primary" :ripple="true" ripple-bg-color="#99d4ff" shape="circle" @tap="$u.debounce(submit, 2000,immediate = true)"
  30. :loading="loading">{{$t("login.login")}}</u-button>
  31. </view>
  32. <view style="margin-top: 80rpx;display: flex;justify-content: center;">
  33. <view class="u-flex" @click="inregister">
  34. <view style="color: rgba(0,160,234,0.5)">
  35. {{$t("login.no")}}
  36. </view>
  37. <view style="color: #00A0EA">
  38. {{$t("login.sign")}}
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </u-card>
  44. </view>
  45. <view class="foot">
  46. <view class="u-flex u-row-center u-col-center">
  47. <u-divider color="#0095FF" border-color="#0095FF" bg-color="#F4F4F4" fontSize="30" @click="switchLang">{{$t("login.Lan")}}</u-divider>
  48. <!-- <u-divider color="#0095FF" border-color="#0095FF" bg-color="#F4F4F4" fontSize="30">赛轮集团</u-divider> -->
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import permision from "@/js_sdk/wa-permission/permission.js"
  55. import {
  56. mapState,
  57. mapMutations
  58. } from 'vuex'
  59. import {
  60. request
  61. } from '../../common/request/request'
  62. require("promise.prototype.finally").shim()
  63. export default {
  64. data() {
  65. return {
  66. tel: '',
  67. code: '',
  68. codeText: "",
  69. pact: false,
  70. loading: false,
  71. codeLoading: false,
  72. SystemInfo: '',
  73. networkType: '',
  74. version: '',
  75. send: '',
  76. }
  77. },
  78. computed: {
  79. ...mapState(['hasLogin'])
  80. },
  81. created() {
  82. uni.getSystemInfo({
  83. success: (res) => {
  84. this.SystemInfo = res
  85. }
  86. });
  87. uni.getNetworkType({
  88. success: (res) => {
  89. this.networkType = res.networkType
  90. }
  91. });
  92. // #ifdef APP-PLUS
  93. uni.getLocation({
  94. success: res => {},
  95. fail: err => {
  96. if (this.SystemInfo.platform == "ios") {
  97. this.judgeIosPermission()
  98. } else {
  99. this.requestAndroidPermission()
  100. }
  101. }
  102. });
  103. // #endif
  104. // #ifdef APP-PLUS
  105. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
  106. this.version = wgtinfo.version
  107. })
  108. // #endif
  109. uni.$on('loginphone', data => {
  110. this.tel = data
  111. })
  112. this.send = this.$i18n.locale
  113. console.log(this.send)
  114. },
  115. methods: {
  116. switchLang() {
  117. this.$i18n.locale = this.$i18n.locale == 'en' ? 'zh' : 'en';
  118. this.send = this.$i18n.locale
  119. uni.setStorage({
  120. key: "lang",
  121. data: this.$i18n.locale
  122. })
  123. },
  124. ...mapMutations(['login']),
  125. judgeIosPermission() {
  126. let result = permision.judgeIosPermission('location')
  127. if (!result) {
  128. uni.showModal({
  129. title: this.$t('login.locationtitle'),
  130. content: this.$t('login.locationcontent'),
  131. cancelText: this.$t('login.locationcancelText'),
  132. confirmText: this.$t('login.locationconfirmText'),
  133. success: res => {
  134. if (res.confirm) {
  135. plus.runtime.openURL("app-settings://");
  136. }
  137. }
  138. })
  139. }
  140. },
  141. async requestAndroidPermission() {
  142. let result = await permision.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
  143. },
  144. toUser(provider) {
  145. this.login(provider);
  146. if (this.hasLogin) {
  147. this.$u.route({
  148. url: 'pages/home/index',
  149. type: 'switchTab',
  150. })
  151. } else {
  152. uni.navigateBack();
  153. }
  154. },
  155. submit() {
  156. if (this.$u.test.mobile(this.tel)) {
  157. this.loading = true
  158. request({
  159. url: '/sailun/appLogin/storeLogin',
  160. method: 'post',
  161. data: {
  162. "account": "",
  163. "loginType": "1",
  164. "mobileCode": this.code,
  165. "password": "",
  166. "phoneNumber": this.tel,
  167. "osType": this.SystemInfo.platform,
  168. "osVersion": this.SystemInfo.system,
  169. "phoneBrand": this.SystemInfo.brand,
  170. "phoneModel": this.SystemInfo.model,
  171. "appVersion": this.version,
  172. "networkType": this.networkType,
  173. }
  174. }).then(res => {
  175. if (res.data.code == 0) {
  176. this.toUser(res.data.data)
  177. uni.$emit('login', {
  178. msg: this.$t('login.suclogin')
  179. })
  180. } else {
  181. this.$u.toast(res.data.msg);
  182. }
  183. }).catch(err => {
  184. this.$u.toast(this.$t('login.errlogin'));
  185. }).finally(() => {
  186. this.loading = false
  187. })
  188. }
  189. },
  190. inregister() {
  191. this.$u.route({
  192. url: 'pages/login/register',
  193. })
  194. },
  195. codeChange(text) {
  196. this.codeText = text;
  197. },
  198. getCode() {
  199. if (this.$u.test.mobile(this.tel)) {
  200. if (this.$refs.uCode.canGetCode) {
  201. this.codeLoading = true
  202. request({
  203. url: '/sailun/appStoreBasicInfo/sendCode',
  204. method: 'post',
  205. data: {
  206. "phoneNumber": this.tel,
  207. "opreaType": "1"
  208. },
  209. }).then(res => {
  210. if (res.data.code == 0) {
  211. this.$refs.uCode.start();
  212. }
  213. if (res.data.code == 500) {
  214. this.$u.toast(res.data.msg);
  215. }
  216. }).catch(err => {
  217. }).finally(() => {
  218. this.codeLoading = false
  219. })
  220. } else {
  221. this.$u.toast(this.$t('login.repeatcode'));
  222. }
  223. } else {
  224. this.$u.toast(this.$t('login.telcode'));
  225. }
  226. },
  227. }
  228. };
  229. </script>
  230. <style lang="scss" scoped>
  231. .status_bar {
  232. height: var(--status-bar-height);
  233. width: 100%;
  234. background-color: #0095FF;
  235. }
  236. .content {
  237. position: relative;
  238. top: -400rpx;
  239. }
  240. .foot {
  241. position: fixed;
  242. bottom: 10rpx;
  243. width: 100%;
  244. padding-bottom: 0;
  245. padding-bottom: constant(safe-area-inset-bottom);
  246. padding-bottom: env(safe-area-inset-bottom);
  247. }
  248. </style>