index.vue 6.6 KB

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