phoneLogin.vue 8.3 KB

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