phoneLogin.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. })
  116. }
  117. },
  118. // change事件侦听
  119. change(value) {
  120. // console.log('change', value);
  121. },
  122. // 输入完验证码最后一位执行
  123. finish(value) {
  124. let params = {
  125. accessToken: this.accessToken,
  126. userId: this.userId,
  127. code: value
  128. };
  129. this.$u.api.phoneLoginAuth(params)
  130. .then(res => {
  131. if (res.code == '200') {
  132. console.log('登录信息:', res);
  133. this.$u.vuex('vuex_user', res.data);
  134. this.$u.vuex('vuex_hasLogin', true);
  135. this.veteEducCheck();
  136. // this.wechatLogin()
  137. } else {
  138. this.toastMsg = res.msg;
  139. this.showToast();
  140. }
  141. }).catch(err => {
  142. this.toastMsg = err.msg;
  143. this.showToast();
  144. });
  145. },
  146. veteEducCheck() {
  147. this.$u.api.getVeteEducCheck().then(res => {
  148. if (res.data != 9) {
  149. this.jumpIndex()
  150. } else {
  151. uni.navigateTo({
  152. url: '/pages/applyEducationCode/applyEducationCode'
  153. })
  154. }
  155. })
  156. },
  157. // 跳转到首页
  158. jumpIndex() {
  159. let ret = localStorage.getItem('backUrl')
  160. if (ret && ret.indexOf('phoneLogin') < 0) {
  161. // 截取url
  162. const pagesIndex = ret.indexOf('pages')
  163. let switchTabList = ['pages/index/index', 'pages/myCode/myCode', 'pages/mine/mine'];
  164. if (pagesIndex > (-1)) {
  165. const pageUrl = ret.slice(pagesIndex);
  166. if (switchTabList.includes(pageUrl)) {
  167. setTimeout(() => {
  168. uni.switchTab({
  169. url: '/' + pageUrl
  170. })
  171. }, 300)
  172. } else {
  173. setTimeout(() => {
  174. uni.navigateTo({
  175. url: '/' + pageUrl
  176. })
  177. }, 300)
  178. }
  179. } else {
  180. uni.switchTab({
  181. url: '../index/index'
  182. })
  183. }
  184. } else {
  185. uni.switchTab({
  186. url: '../index/index'
  187. })
  188. }
  189. },
  190. /**
  191. * 跳转页面
  192. * */
  193. jumpToPage(flag) {
  194. uni.navigateTo({
  195. url: "/pages/inbuild/inbuild",
  196. })
  197. },
  198. // tabbar 返回
  199. customBack() {
  200. this.$u.route({
  201. type: 'switchTab',
  202. url: 'pages/index/index'
  203. });
  204. }
  205. }
  206. };
  207. </script>
  208. <style lang="scss" scoped>
  209. .hide {
  210. display: none !important;
  211. }
  212. .phonelogin {
  213. width: 100%;
  214. height: 100vh;
  215. background-image: url(../../static/img/phonelogin-bg-png.png);
  216. background-repeat: no-repeat;
  217. background-size: cover;
  218. &-unavbar {
  219. ::v-deep .u-border-bottom:after {
  220. border-bottom-width: 0 !important;
  221. }
  222. }
  223. &-title {
  224. padding: 10% 4% 6%;
  225. font-family: PingFangSC-Light, PingFang SC;
  226. font-weight: 300;
  227. color: #FFFFFF;
  228. line-height: 98rpx;
  229. letter-spacing: 2rpx;
  230. view:first-child {
  231. font-size: 70rpx;
  232. }
  233. view:last-child {
  234. font-size: 56rpx;
  235. }
  236. }
  237. &-content {
  238. padding: 0 4%;
  239. &-input {
  240. ::v-deep {
  241. .uni-input-placeholder {
  242. text-align: center;
  243. font-size: 40rpx;
  244. font-family: PingFangSC-Heavy, PingFang SC;
  245. color: #FFFFFF !important;
  246. letter-spacing: 1px;
  247. line-height: 60rpx;
  248. opacity: 0.6;
  249. }
  250. .uni-input-input {
  251. text-align: center;
  252. font-size: 60rpx;
  253. font-family: PingFangSC-Heavy, PingFang SC;
  254. font-weight: 800;
  255. color: #FFFFFF;
  256. line-height: 83rpx;
  257. letter-spacing: 1px;
  258. }
  259. }
  260. &:after {
  261. top: 21rpx;
  262. }
  263. }
  264. &-getcaptcha {
  265. margin-top: 10%;
  266. color: $u-tips-color;
  267. border: none;
  268. padding: 14rpx 0;
  269. background-color: rgba(255, 255, 255, 0.5);
  270. border-radius: 55rpx;
  271. font-size: 40rpx;
  272. font-family: PingFangSC-Medium, PingFang SC;
  273. font-weight: 500;
  274. color: #6A5C52;
  275. line-height: 83rpx;
  276. &::after {
  277. border: none;
  278. }
  279. }
  280. &-messageinput {
  281. ::v-deep .u-char-item {
  282. color: #FFFFFF !important;
  283. .u-bottom-line,
  284. .u-placeholder-line {
  285. background: #FFFFFF !important;
  286. }
  287. }
  288. }
  289. }
  290. &-captcha {
  291. color: $u-type-warning;
  292. font-size: 30rpx;
  293. margin-top: 40rpx;
  294. text-align: center;
  295. }
  296. &-pact {
  297. width: 100%;
  298. &-hint {
  299. font-size: 28rpx;
  300. font-family: PingFangSC-Regular, PingFang SC;
  301. font-weight: 400;
  302. color: #FFFFFF;
  303. line-height: 83rpx;
  304. opacity: 0.7;
  305. .link {
  306. color: $u-type-warning;
  307. }
  308. }
  309. }
  310. }
  311. </style>