phoneLogin.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. console.log(this.vuex_hasLogin)
  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. // style.backgroundColor = this.$u.color['warning'];
  69. }else if(this.tel.length==11&&!this.$u.test.mobile(this.tel)){
  70. this.telError = true;
  71. }
  72. return style;
  73. }
  74. },
  75. methods: {
  76. showToast() {
  77. this.$refs.uToast.show({
  78. title: this.toastMsg,
  79. type: this.toastType,
  80. url: this.toastUrl
  81. })
  82. },
  83. submit() {
  84. if(this.$u.test.mobile(this.tel)&&this.messageDisable==false) {
  85. let that = this;
  86. this.$u.api.getPhoneLoginCode({mobile:this.tel})
  87. .then(res =>{
  88. if(res.code == 200){
  89. this.messageDisable = true;
  90. this.messageShow = true;
  91. this.show = true;
  92. let interval = setInterval(() => {
  93. that.second--;
  94. if (that.second <= 0) {
  95. that.messageDisable=false
  96. that.messageShow = false;
  97. if (that.messageCode.lenth != 4) {
  98. // this.messageError = true;
  99. }
  100. clearInterval(interval);
  101. that.second=60;
  102. }
  103. }, 1000);
  104. this.accessToken = res.data.accessToken;
  105. this.$u.vuex('vuex_token', res.data.accessToken);
  106. this.userId = res.data.userId;
  107. }else{
  108. uni.showToast({
  109. title: res.msg,
  110. icon:'none',
  111. duration: 2000
  112. });
  113. }
  114. }).catch(err=>{
  115. this.toastMsg = err.code + ":" + err.msg;
  116. this.showToast();
  117. });
  118. }
  119. },
  120. // 收不到验证码选择时的选择
  121. // noCaptcha() {
  122. // uni.showActionSheet({
  123. // itemList: ['重新获取验证码', '接听语音验证码'],
  124. // success: function(res) {
  125. // },
  126. // fail: function(res) {
  127. // }
  128. // });
  129. // },
  130. // change事件侦听
  131. change(value) {
  132. // console.log('change', value);
  133. },
  134. // 输入完验证码最后一位执行
  135. finish(value) {
  136. let params = {
  137. accessToken:this.accessToken,
  138. userId:this.userId,
  139. code:value
  140. };
  141. this.$u.api.phoneLoginAuth(params)
  142. .then(res =>{
  143. if(res.code=='200'){
  144. // console.log('finish res',res);
  145. this.$u.vuex('vuex_user', res.data);
  146. this.$u.vuex('vuex_hasLogin', true);
  147. this.veteEducCheck();
  148. // this.wechatLogin()
  149. }else{
  150. this.toastMsg = res.msg;
  151. this.showToast();
  152. }
  153. }).catch(err=>{
  154. this.toastMsg = err.msg;
  155. this.showToast();
  156. });
  157. },
  158. veteEducCheck(){
  159. this.$u.api.getVeteEducCheck().then(res=>{
  160. if(res.data!=9){
  161. this.jumpIndex();
  162. }else{
  163. uni.navigateTo({
  164. url: '/pages/authentication/authentication'
  165. })
  166. }
  167. })
  168. },
  169. // 跳转到首页
  170. jumpIndex() {
  171. let ret = localStorage.getItem('backUrl')
  172. if (ret && ret.indexOf('phoneLogin') < 0) {
  173. // 截取url
  174. const pagesIndex = ret.indexOf('pages')
  175. let switchTabList = ['/pages/index/index','pages/center/center','pages/mine/mine'];
  176. if (pagesIndex > (-1)) {
  177. const pageUrl = ret.slice(pagesIndex)
  178. if(switchTabList.includes(pageUrl)){
  179. setTimeout(() => {
  180. uni.switchTab({
  181. url: '/' + pageUrl
  182. })
  183. }, 100)
  184. }else{
  185. setTimeout(() => {
  186. uni.navigateTo({
  187. url: '/' + pageUrl
  188. })
  189. }, 100)
  190. }
  191. } else {
  192. uni.switchTab({
  193. url: '../index/index'
  194. })
  195. }
  196. } else {
  197. uni.switchTab({
  198. url: '../index/index'
  199. })
  200. }
  201. },
  202. /**
  203. * 跳转页面
  204. * */
  205. jumpToPage(flag){
  206. uni.navigateTo({
  207. url: "/pages/inbuild/inbuild",
  208. // url: "/pages/privacyPolicy/privacyPolicy?termsType=" + flag,
  209. })
  210. },
  211. // tabbar 返回
  212. customBack() {
  213. this.$u.route({
  214. type: 'switchTab',
  215. url: 'pages/index/index'
  216. });
  217. }
  218. }
  219. };
  220. </script>
  221. <style lang="scss" scoped>
  222. .hide{display: none!important;}
  223. .phonelogin{
  224. width: 100%;
  225. height: 100vh;
  226. background-image: url(../../static/img/phonelogin-bg-png.png);
  227. background-repeat: no-repeat;
  228. background-size: cover;
  229. &-unavbar{
  230. ::v-deep .u-border-bottom:after {
  231. border-bottom-width: 0 !important;
  232. }
  233. }
  234. &-title{
  235. padding: 10% 4% 6%;
  236. font-family: PingFangSC-Light, PingFang SC;
  237. font-weight: 300;
  238. color: #FFFFFF;
  239. line-height: 98rpx;
  240. letter-spacing: 2rpx;
  241. view:first-child{
  242. font-size: 70rpx;
  243. }
  244. view:last-child{
  245. font-size: 56rpx;
  246. }
  247. }
  248. &-content{
  249. padding: 0 4%;
  250. &-input{
  251. ::v-deep {
  252. .uni-input-placeholder {
  253. text-align: center;
  254. font-size: 40rpx;
  255. font-family: PingFangSC-Heavy, PingFang SC;
  256. color: #FFFFFF !important;
  257. letter-spacing: 1px;
  258. line-height: 60rpx;
  259. opacity: 0.6;
  260. }
  261. .uni-input-input{
  262. text-align: center;
  263. font-size: 60rpx;
  264. font-family: PingFangSC-Heavy, PingFang SC;
  265. font-weight: 800;
  266. color: #FFFFFF;
  267. line-height: 83rpx;
  268. letter-spacing: 1px;
  269. }
  270. }
  271. &:after {
  272. top: 21rpx;
  273. }
  274. }
  275. &-getcaptcha{
  276. margin-top: 10%;
  277. color: $u-tips-color;
  278. border: none;
  279. padding: 14rpx 0;
  280. background-color: rgba(255, 255, 255, 0.5);
  281. border-radius: 55rpx;
  282. font-size: 40rpx;
  283. font-family: PingFangSC-Medium, PingFang SC;
  284. font-weight: 500;
  285. color: #6A5C52;
  286. line-height: 83rpx;
  287. &::after {
  288. border: none;
  289. }
  290. }
  291. &-messageinput{
  292. ::v-deep .u-char-item{
  293. color: #FFFFFF !important;
  294. .u-bottom-line, .u-placeholder-line{
  295. background: #FFFFFF !important;
  296. }
  297. }
  298. }
  299. }
  300. &-captcha{
  301. color: $u-type-warning;
  302. font-size: 30rpx;
  303. margin-top: 40rpx;
  304. text-align: center;
  305. }
  306. &-pact{
  307. width: 100%;
  308. &-hint{
  309. font-size: 28rpx;
  310. font-family: PingFangSC-Regular, PingFang SC;
  311. font-weight: 400;
  312. color: #FFFFFF;
  313. line-height: 83rpx;
  314. opacity: 0.7;
  315. .link {
  316. color: $u-type-warning;
  317. }
  318. }
  319. }
  320. }
  321. </style>