phoneLogin.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="phonelogin">
  3. <u-navbar title-color="#FFFFFF" :custom-back="customBack" :bpay-bottom="false" back-icon-color="#FFFFFF"
  4. :background="{background: 'transparent' }" title="手机登录" class="phonelogin-unavbar" />
  5. <view class="phonelogin-title">
  6. <view>欢迎您!</view>
  7. <view>登录退役军人服务移动端</view>
  8. </view>
  9. <view class="phonelogin-content">
  10. <!-- <input class="u-border-bottom" type="number" maxlength="11" v-model="tel" placeholder="请输入手机号" /> -->
  11. <u-input class="u-border-bottom phonelogin-content-input" v-model="tel" type="number" maxlength="11"
  12. placeholder="请输入手机号" />
  13. <view class="u-text-center u-type-error u-m-t-20" v-if="telError">手机号输入错误</view>
  14. <button @tap="submit" :style="[inputStyle]" class="phonelogin-content-getcaptcha">获取验证码</button>
  15. <u-message-input v-if="show" :focus="true" :value="messageCode" @change="change" @finish="finish"
  16. mode="bottomLine" :maxlength="codelength" class="phonelogin-content-messageinput"></u-message-input>
  17. </view>
  18. <!-- <view class="u-text-center u-type-error" v-if="phoneError">手机号输入错误</view> -->
  19. <view class="phonelogin-captcha">
  20. <!-- <text v-if="show&&this.messageDisable==false" @tap="noCaptcha">收不到验证码点这里</text> -->
  21. <text v-if="messageShow">{{ second }}秒后可重新获取验证码</text>
  22. </view>
  23. <view class="phonelogin-pact" :class="messageShow?'phonelogin-msgpact':''">
  24. <view class="phonelogin-pact-hint u-text-center">
  25. 进入即代表同意
  26. <text class="link" @tap="jumpToPage(1)">《用户协议》</text>及
  27. <text class="link" @tap="jumpToPage(2)">《隐私协议》</text>
  28. </view>
  29. </view>
  30. <u-toast ref="uToast" />
  31. </view>
  32. </template>
  33. <script>
  34. import getUrlParams from "utils/getUrlParams.js";
  35. export default {
  36. data() {
  37. return {
  38. tel: '',
  39. messageCode: '',
  40. messageShow: false,
  41. messageDisable: false,
  42. codelength: 4,
  43. show: false,
  44. second: 60,
  45. toastMsg: '',
  46. toastUrl: '',
  47. toastType: '',
  48. accessToken: '',
  49. userId: '',
  50. telError: false,
  51. }
  52. },
  53. onShow() {
  54. // 判断是否登录 已登录直接跳转首页
  55. if (this.vuex_hasLogin) {
  56. uni.switchTab({
  57. url: '../index/index'
  58. })
  59. }
  60. },
  61. computed: {
  62. inputStyle() {
  63. let style = {};
  64. if (this.tel.length == 11 && this.messageDisable == false && this.$u.test.mobile(this.tel)) {
  65. style.color = "#fff";
  66. style.backgroundColor = '#5295F5';
  67. this.telError = false;
  68. } else if (this.tel.length == 11 && !this.$u.test.mobile(this.tel)) {
  69. this.telError = true;
  70. }
  71. return style;
  72. }
  73. },
  74. methods: {
  75. showToast() {
  76. this.$refs.uToast.show({
  77. title: this.toastMsg,
  78. type: this.toastType,
  79. url: this.toastUrl
  80. })
  81. },
  82. submit() {
  83. if (this.$u.test.mobile(this.tel) && this.messageDisable == false) {
  84. let that = this;
  85. this.$u.api.getPhoneLoginCode({
  86. mobile: this.tel
  87. })
  88. .then(res => {
  89. if (res.code == 200) {
  90. this.messageDisable = true;
  91. this.messageShow = true;
  92. this.show = true;
  93. let interval = setInterval(() => {
  94. that.second--;
  95. if (that.second <= 0) {
  96. that.messageDisable = false
  97. that.messageShow = false;
  98. if (that.messageCode.lenth != 4) {
  99. // this.messageError = true;
  100. }
  101. clearInterval(interval);
  102. that.second = 60;
  103. }
  104. }, 1000);
  105. this.accessToken = res.data.accessToken;
  106. this.$u.vuex('vuex_token', res.data.accessToken);
  107. this.userId = res.data.userId;
  108. } else {
  109. uni.showToast({
  110. title: res.msg,
  111. icon: 'none',
  112. duration: 2000
  113. });
  114. }
  115. }).catch(err => {
  116. this.toastMsg = err.code + ":" + err.msg;
  117. this.showToast();
  118. });
  119. }
  120. },
  121. // 收不到验证码选择时的选择
  122. // noCaptcha() {
  123. // uni.showActionSheet({
  124. // itemList: ['重新获取验证码', '接听语音验证码'],
  125. // success: function(res) {
  126. // },
  127. // fail: function(res) {
  128. // }
  129. // });
  130. // },
  131. // change事件侦听
  132. change(value) {
  133. // console.log('change', value);
  134. },
  135. // 输入完验证码最后一位执行
  136. finish(value) {
  137. let params = {
  138. accessToken: this.accessToken,
  139. userId: this.userId,
  140. code: value
  141. };
  142. this.$u.api.phoneLoginAuth(params)
  143. .then(res => {
  144. if (res.code == '200') {
  145. // console.log('finish res',res);
  146. this.$u.vuex('vuex_user', res.data);
  147. this.$u.vuex('vuex_hasLogin', true);
  148. this.veteEducCheck();
  149. // this.wechatLogin()
  150. } else {
  151. this.toastMsg = res.msg;
  152. this.showToast();
  153. }
  154. }).catch(err => {
  155. this.toastMsg = err.msg;
  156. this.showToast();
  157. });
  158. },
  159. veteEducCheck() {
  160. this.$u.api.getVeteEducCheck().then(res => {
  161. if (res.data != 9) {
  162. this.jumpIndex()
  163. // this.$u.route({
  164. // type: 'switchTab',
  165. // url: 'pages/index/index'
  166. // });
  167. } else {
  168. uni.navigateTo({
  169. url: '/pages/applyEducationCode/applyEducationCode'
  170. })
  171. }
  172. })
  173. },
  174. // 跳转到首页
  175. jumpIndex() {
  176. let ret = localStorage.getItem('backUrl')
  177. if (ret && ret.indexOf('phoneLogin') < 0) {
  178. // 截取url
  179. const pagesIndex = ret.indexOf('pages')
  180. let switchTabList = ['pages/index/index', 'pages/myCode/myCode', 'pages/mine/mine'];
  181. if (pagesIndex > (-1)) {
  182. const pageUrl = ret.slice(pagesIndex);
  183. if (switchTabList.includes(pageUrl)) {
  184. setTimeout(() => {
  185. uni.switchTab({
  186. url: '/' + pageUrl
  187. })
  188. }, 300)
  189. } else {
  190. setTimeout(() => {
  191. uni.navigateTo({
  192. url: '/' + pageUrl
  193. })
  194. }, 300)
  195. }
  196. } else {
  197. uni.switchTab({
  198. url: '../index/index'
  199. })
  200. }
  201. } else {
  202. uni.switchTab({
  203. url: '../index/index'
  204. })
  205. }
  206. },
  207. /**
  208. * 跳转页面
  209. * */
  210. jumpToPage(flag) {
  211. uni.navigateTo({
  212. url: "/pages/inbuild/inbuild",
  213. })
  214. },
  215. // tabbar 返回
  216. customBack() {
  217. this.$u.route({
  218. type: 'switchTab',
  219. url: 'pages/index/index'
  220. });
  221. }
  222. }
  223. };
  224. </script>
  225. <style lang="scss" scoped>
  226. .hide {
  227. display: none !important;
  228. }
  229. .phonelogin {
  230. width: 100%;
  231. height: 100vh;
  232. background-image: url(../../static/img/phonelogin-bg-png.png);
  233. background-repeat: no-repeat;
  234. background-size: cover;
  235. &-unavbar {
  236. ::v-deep .u-border-bottom:after {
  237. border-bottom-width: 0 !important;
  238. }
  239. }
  240. &-title {
  241. padding: 10% 4% 6%;
  242. font-family: PingFangSC-Light, PingFang SC;
  243. font-weight: 300;
  244. color: #FFFFFF;
  245. line-height: 98rpx;
  246. letter-spacing: 2rpx;
  247. view:first-child {
  248. font-size: 70rpx;
  249. }
  250. view:last-child {
  251. font-size: 56rpx;
  252. }
  253. }
  254. &-content {
  255. padding: 0 4%;
  256. &-input {
  257. ::v-deep {
  258. .uni-input-placeholder {
  259. text-align: center;
  260. font-size: 40rpx;
  261. font-family: PingFangSC-Heavy, PingFang SC;
  262. color: #FFFFFF !important;
  263. letter-spacing: 1px;
  264. line-height: 60rpx;
  265. opacity: 0.6;
  266. }
  267. .uni-input-input {
  268. text-align: center;
  269. font-size: 60rpx;
  270. font-family: PingFangSC-Heavy, PingFang SC;
  271. font-weight: 800;
  272. color: #FFFFFF;
  273. line-height: 83rpx;
  274. letter-spacing: 1px;
  275. }
  276. }
  277. &:after {
  278. top: 21rpx;
  279. }
  280. }
  281. &-getcaptcha {
  282. margin-top: 10%;
  283. color: $u-tips-color;
  284. border: none;
  285. padding: 14rpx 0;
  286. background-color: rgba(255, 255, 255, 0.5);
  287. border-radius: 55rpx;
  288. font-size: 40rpx;
  289. font-family: PingFangSC-Medium, PingFang SC;
  290. font-weight: 500;
  291. color: #6A5C52;
  292. line-height: 83rpx;
  293. &::after {
  294. border: none;
  295. }
  296. }
  297. &-messageinput {
  298. ::v-deep .u-char-item {
  299. color: #FFFFFF !important;
  300. .u-bottom-line,
  301. .u-placeholder-line {
  302. background: #FFFFFF !important;
  303. }
  304. }
  305. }
  306. }
  307. &-captcha {
  308. color: $u-type-warning;
  309. font-size: 30rpx;
  310. margin-top: 40rpx;
  311. text-align: center;
  312. }
  313. &-pact {
  314. width: 100%;
  315. &-hint {
  316. font-size: 28rpx;
  317. font-family: PingFangSC-Regular, PingFang SC;
  318. font-weight: 400;
  319. color: #FFFFFF;
  320. line-height: 83rpx;
  321. opacity: 0.7;
  322. .link {
  323. color: $u-type-warning;
  324. }
  325. }
  326. }
  327. }
  328. </style>