login.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <view class="regbox pregbox flexdc pr" v-if="loginflag" style="padding-top: 120rpx;">
  3. <image :src="headimg" class="headimg flex0"></image>
  4. <view class="flex1" style="position: relative;">
  5. <image :src="ldicon" class="mzimg flex0"></image>
  6. <!-- #ifdef APP-PLUS -->
  7. <!-- <view class="mb24 mt50">
  8. <view class="f25 c16 fw5 mb30 txc">133****0756</view>
  9. <view class="rbtn">本机号码一键登录</view>
  10. </view> -->
  11. <!-- #endif -->
  12. <!-- #ifdef MP-WEIXIN -->
  13. <!-- #endif -->
  14. <view class="tab flexcc">
  15. <block v-for="(ite,idx) in tablist" :key="idx">
  16. <view class="tabtit" :class="tabidx==ite.val?'act':''" @click="getTab(ite.val)">
  17. {{ite.tit}}</view>
  18. </block>
  19. </view>
  20. <!-- 手机号登录 -->
  21. <view class="login-form-content">
  22. <block v-if="tabidx==1">
  23. <view class="input-item">
  24. <view class="login_tit">账号</view>
  25. <view class="login_box">
  26. <view class="login_boxl" v-if="tabidx==2">+86</view>
  27. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  28. </view>
  29. </view>
  30. <view class="input-item" >
  31. <view class="flexcj">
  32. <view class="login_tit">密码</view>
  33. <view class="login_jz" @click="jzflag=!jzflag">
  34. <image :src="pcicon" v-if="jzflag"></image>
  35. <image :src="pnicon" v-else></image>
  36. <view>记住密码</view>
  37. </view>
  38. </view>
  39. <view class="login_box">
  40. <uni-easyinput :inputBorder="false" type="password" v-model="loginForm.password" placeholder="请输入密码" />
  41. <!-- <input v-if="checkeye" v-model="loginForm.password" type="text" class="input" placeholder="请输入密码" maxlength="20" />
  42. <input v-else v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" /> -->
  43. <view class="line flex0"></view>
  44. <view class="login_txt" @click="getForget"><text>忘记密码</text></view>
  45. </view>
  46. </view>
  47. <view class="input-item flex align-center" style="width: 60%;margin: 0px;margin-bottom: 24rpx;" v-if="captchaEnabled">
  48. <input v-model="tucode" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  49. <view class="login-code">
  50. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  51. </view >
  52. </view>
  53. <button v-if="captchaEnabled" type="primary" class=" rbtn mb24 mt50" :class="tucode&&loginForm.username&&loginForm.password?'btn2':'btn'" @click="getLogin">登录</button>
  54. <button v-else type="primary" class=" rbtn mb24 mt50" :class="loginForm.username&&loginForm.password?'btn2':'btn'" @click="getLogin">登录</button>
  55. </block>
  56. <block v-if="tabidx==2">
  57. <view class="input-item">
  58. <view class="login_tit">手机号码</view>
  59. <view class="login_box">
  60. <view class="login_boxl" v-if="tabidx==2">+86</view>
  61. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入手机号" maxlength="30" />
  62. </view>
  63. </view>
  64. <view class="input-item" style="margin-bottom: 24rpx;" >
  65. <view class="login_tit">验证码</view>
  66. <view style="display: flex;align-items: center;">
  67. <input v-model="duancode" type="code" class="input" placeholder="请输入短信验证码" maxlength="20" />
  68. <view v-if="timefalg" class="codes">重新发送{{time}}s</view>
  69. <view v-else class="codess" @click="getsendCode">发送验证码</view>
  70. </view>
  71. </view>
  72. <button v-if="tabidx==2" type="primary" class=" rbtn mb24 mt50" :class="loginForm.username&&duancode?'btn2':'btn'" @click="getLogin">登录</button>
  73. </block>
  74. </view>
  75. <!-- 微信登录 -->
  76. <!-- <block v-if="tabidx==1">
  77. <button type="primary" class="rbtn mb24 mt50" open-type="getUserInfo" @getuserinfo="getuserinfo" >
  78. <text class="btn-txt">快捷登录</text>
  79. </button>
  80. </block> -->
  81. <!-- 账号密码登录 -->
  82. <view class="lread" @click="checkflag=!checkflag">
  83. <view class="lreadl">
  84. <image :src="checkimg" v-if="checkflag"></image>
  85. <image :src="ncheckimg" v-else></image>
  86. </view>
  87. <view class="tit">登录即代表您已阅读并同意<text @click.stop="handlePrivacy">用户协议</text>及<text @click.stop="handlePrivacy">隐私政策</text></view>
  88. </view>
  89. <!-- <view class="bbcode">版本号:ZXY_YY_1.3</view> -->
  90. </view>
  91. <!-- <view class="loginb" @click="getTab(1)" v-if="tabidx==2">账号密码登录</view>
  92. <view class="loginb" @click="getTab(2)" v-if="tabidx==1">手机登录</view> -->
  93. <view class="rtxt mt26" @click="getregister">还没有账号?去注册</view>
  94. <phone-btn :type="typeflag" @getPhoneNumber='getPhoneNumber' @getClose="getClose"></phone-btn>
  95. </view>
  96. </template>
  97. <script>
  98. // #ifdef APP-PLUS
  99. // const jpushModule = uni.requireNativePlugin('JG-JPush')
  100. // #endif
  101. import * as base64 from "base-64"
  102. import {getweChatLogin,getInfo,getweChatOpenid,getCodeImg,getCode,sendSmsOnly} from "@/api/login.js"
  103. import {getUserProfile,updateUserProfile} from "@/api/system/user.js"
  104. import { getToken } from '@/utils/auth'
  105. import phoneBtn from "@/components/toptab/phonebtn.vue"
  106. import {getOcrH5Fn} from "@/api/mine/card.js"
  107. export default {
  108. components:{
  109. phoneBtn
  110. },
  111. data(){
  112. return{
  113. headimg:require('@/static/logo.png'),
  114. ldicon:require('@/static/images/mine/ldicon.png'),
  115. checkimg:require('@/static/images/mine/lcicon.png'),
  116. ncheckimg:require('@/static/images/mine/lnicon.png'),
  117. rimg:require('@/static/images/mine/rimg.png'),
  118. pcicon:require('@/static/images/mine/pcicon.png'),
  119. pnicon:require('@/static/images/mine/pnicon.png'),
  120. checkflag:true,
  121. typeflag: false,
  122. loginflag:false,
  123. captchaEnabled: false,
  124. duancode:'',//短信验证码
  125. checkeye:false,
  126. tucode:'',
  127. codeUrl:'',
  128. time:'',
  129. timefalg:'',
  130. tabidx:1,
  131. tablist:[{tit:'账号登录',val:1},{tit:'手机登录',val:2},],
  132. loginForm: {
  133. username: "",
  134. code: "",
  135. password:'',
  136. type:1,//1:账号密码 2:手机登录
  137. },
  138. voList:[],
  139. voindex:0,
  140. jzflag:true
  141. }
  142. },
  143. methods:{
  144. getTab(idx){
  145. this.tabidx=idx;
  146. this.loginForm.type=idx;
  147. },
  148. // 极光推送
  149. getJGtuifn(){
  150. var jpushModule = uni.requireNativePlugin("JG-JPush");
  151. jpushModule.setLoggerEnable(true);
  152. // 初始化函数
  153. jpushModule.initJPushService();
  154. jpushModule.addConnectEventListener(result=>{
  155. let connectEnable = result.connectEnable
  156. // console.log("jpush连接", connectEnable)
  157. })
  158. jpushModule.getRegistrationID(result => {
  159. // console.log("注册ID.....",result)
  160. var registerID = result.registerID;
  161. // console.log(registerID)
  162. if(getToken()){
  163. var params={
  164. jgId:registerID,
  165. }
  166. updateUserProfile(params).then(res=>{
  167. if(res.code==200){
  168. console.log(res,9)
  169. }
  170. })
  171. }
  172. })
  173. },
  174. // 获取图形验证码
  175. getCode() {
  176. getCodeImg().then(res => {
  177. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  178. if (this.captchaEnabled) {
  179. this.codeUrl = 'data:image/gif;base64,' + res.img
  180. this.loginForm.uuid = res.uuid
  181. }
  182. })
  183. },
  184. getForget(){
  185. this.$tab.navigateTo(`/pages/mine/pwd/forgetpwd`)
  186. },
  187. getregister(){
  188. this.$tab.navigateTo(`/pages/register`)
  189. // this.$tab.navigateTo(`/work/pages/prove/index`)
  190. // this.$tab.navigateTo(`/mine/pages/mine/auth`)
  191. },
  192. getLogin(){
  193. if(this.tabidx==1){
  194. if(!this.loginForm.username||!this.loginForm.password||(!this.tucode&& this.captchaEnabled)){
  195. return
  196. }
  197. this.loginForm.code=this.tucode;
  198. }else{
  199. let regphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  200. // 座机号
  201. if (this.loginForm.username && !regphone.test(this.loginForm.username)) {
  202. this.$toast("请输入正确的手机号")
  203. return
  204. }
  205. if(!this.loginForm.username||!this.duancode){
  206. return
  207. }
  208. this.loginForm.code=this.duancode;
  209. }
  210. this.pwdLogin()
  211. // if(!this.checkflag){
  212. // this.$toast("请同意用户协议")
  213. // return
  214. // }
  215. },
  216. // 密码登录
  217. async pwdLogin() {
  218. var that=this;
  219. this.$store.dispatch('Login', this.loginForm).then((res) => {
  220. // 判断是否记住密码
  221. if(this.tabidx==1){
  222. if(that.jzflag){
  223. var newObj={
  224. username:that.loginForm.username,
  225. password:base64.encode(that.loginForm.password),
  226. captchaEnabled:that.captchaEnabled,
  227. }
  228. uni.setStorageSync('account', JSON.parse(JSON.stringify(newObj)))
  229. }else{
  230. uni.removeStorageSync('account')
  231. }
  232. }
  233. this.$modal.closeLoading()
  234. this.$toast('登录成功')
  235. var certifyId= uni.getStorageSync('certifyId')||""
  236. if(certifyId){
  237. var params={
  238. certifyId:certifyId
  239. }
  240. getOcrH5Fn(params).then(resa=>{
  241. if(resa.code==200){
  242. uni.removeStorageSync('certifyId')
  243. that.loginSuccess()
  244. }
  245. })
  246. }else{
  247. setTimeout(function(){
  248. that.loginSuccess()
  249. },1500)
  250. }
  251. }).catch((error) => {
  252. setTimeout(function(){
  253. if (that.captchaEnabled&&that.tabidx==2) {
  254. that.getCode()
  255. }
  256. },1000)
  257. })
  258. },
  259. // 获取短信验证码
  260. getsendCode(){
  261. var that=this;
  262. if (!this.loginForm.username ) {
  263. that.$toast("请输入手机号")
  264. return
  265. }
  266. let regphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  267. // 座机号
  268. let reg1=/^(0\d{2,3})-?(\d{7,8})$/
  269. if (this.loginForm.username && !regphone.test(this.loginForm.username)) {
  270. that.$toast("请输入正确的手机号")
  271. return
  272. }
  273. var params={
  274. 'username':this.loginForm.username
  275. }
  276. // getSMS();
  277. // return
  278. sendSmsOnly(params).then(res=>{
  279. if (res.code == 200) {
  280. // 发送验证码
  281. that.$toast("发送成功")
  282. that.time=60;
  283. that.timefalg=true;
  284. that.setTimein()
  285. } else {
  286. that.$toast(res.msg)
  287. }
  288. })
  289. },
  290. // 验证码倒计时
  291. setTimein(){
  292. var that=this;
  293. clearInterval(that.timer)
  294. that.timer=setInterval(()=>{
  295. if(that.time<=1){
  296. that.timefalg=false;
  297. that.time=60;
  298. clearInterval(that.timer)
  299. }
  300. that.time=that.time-1;
  301. },1000)
  302. },
  303. handlePrivacy(){
  304. this.$tab.navigateTo(`/pages/agreement`)
  305. },
  306. getClose() {
  307. this.typeflag = false
  308. },
  309. btns() {
  310. },
  311. getPhoneNumber(data){
  312. var that=this;
  313. var params=data
  314. that.$store.dispatch('Login', params).then(() => {
  315. that.$modal.closeLoading()
  316. that.$toast('登录成功')
  317. that.typeflag=false;
  318. that.loginSuccess(data)
  319. }).catch(() => {
  320. // if (this.captchaEnabled) {
  321. // this.getCode()
  322. // }
  323. })
  324. },
  325. //获取推送ID
  326. getRegistrationID() {
  327. jpushModule.getRegistrationID(result => {
  328. let registerID = result.registerID
  329. console.log(registerID,7)
  330. var params={
  331. jgId:registerID,
  332. }
  333. updateUserProfile(params).then(res=>{
  334. if(res.code==200){
  335. console.log(res,9)
  336. }
  337. })
  338. })
  339. },
  340. // 登录成功后,处理函数
  341. loginSuccess(result) {
  342. // 设置用户信息
  343. var that=this;
  344. // #ifdef APP-PLUS
  345. this.getJGtuifn()
  346. // this.getRegistrationID()
  347. // #endif
  348. this.$store.dispatch('GetInfo').then(res => {
  349. this.$tab.reLaunch('/pages/index/index')
  350. // 判断有几个角色 进入选择页面
  351. // var roles=that.$store.state.user.roles;
  352. // var userroles=that.$store.state.user.userroles;
  353. // if(roles.length>0){
  354. // // 默认选择学校 老师 家长
  355. // var a,b,c,type;
  356. // if(roles.includes('school')){
  357. // type='school'
  358. // }else if(roles.includes('teacher')){
  359. // type='teacher'
  360. // }else if(roles.includes('parents')){
  361. // type='parents'
  362. // }else{
  363. // that.$tab.reLaunch('/pages/index/index')
  364. // return
  365. // }
  366. // Object.keys(userroles).some((key) => {
  367. // if (userroles[key].roleKey == ('' + type)) {
  368. // that.$store.dispatch('checkRole', userroles[key]).then(() => {
  369. // that.$tab.reLaunch('/pages/index/index')
  370. // }).catch(() => {
  371. // })
  372. // return true;
  373. // }
  374. // })
  375. // }else{
  376. // this.$tab.reLaunch('/pages/index/index')
  377. // }
  378. })
  379. },
  380. async getuserinfo(e) {
  381. // if(!this.checkflag){
  382. // this.$toast("请同意用户协议")
  383. // return
  384. // }
  385. // 判断是不是有学校
  386. const {iv,encryptedData} = e.detail
  387. const {nickName, avatarUrl, ...userInfo} = e.detail.userInfo
  388. // console.log(e.detail)
  389. try{
  390. uni.login({
  391. provider: 'weixin',
  392. success: (res) => {
  393. // 获取用户信息
  394. if(res.code){
  395. this.avatarUrl = avatarUrl
  396. this.nickName = nickName
  397. this.code = res.code
  398. this.userInfo =e.detail.userInfo
  399. uni.setStorageSync('userInfo', e.detail.userInfo)
  400. uni.setStorageSync('lcheckflag',true)
  401. this.typeflag=true;
  402. }
  403. }
  404. })
  405. } catch(e){
  406. //TODO handle the exception
  407. }
  408. },
  409. },
  410. onLoad: function() {
  411. this.getCode()
  412. if (getToken()) {
  413. this.$tab.reLaunch('/pages/index/index')
  414. // 判断有什么角色
  415. } else {
  416. this.loginflag=true;
  417. // this.getCode()
  418. // if(uni.getStorageSync('lcheckflag')){
  419. // this.checkflag=true
  420. // }else{
  421. // this.checkflag=false
  422. // }
  423. if(uni.getStorageSync('account')){
  424. var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('account')))
  425. this.loginForm.username=newObj.username;
  426. this.loginForm.password=base64.decode(newObj.password);
  427. this.jzflag=true;
  428. }
  429. }
  430. },
  431. }
  432. </script>
  433. <style lang="scss" scoped>
  434. .regbox /deep/ .uni-easyinput__content-input{font-size: 30rpx !important;padding-left: 0 !important;line-height: 80rpx;height: 80rpx;}
  435. .regbox /deep/ .uni-input-placeholder{font-size: 30rpx !important;padding-left: 0 !important;color: #808080;}
  436. .headimg{width: 200rpx;height: 200rpx;margin:0 auto 26rpx;}
  437. .mzimg{width: 100rpx;height: 44rpx;margin: 0 auto 40rpx;}
  438. .rtxt{font-size: 32rpx;font-weight: 500;
  439. color: $com-cd3;text-align: center;}
  440. .bbcode{position: absolute;width: 100%;text-align: center;left: 0;bottom: -80rpx;font-size: 24rpx;color: #666666;}
  441. .loginb{position: absolute;width: 100%;text-align: center;left: 0;bottom: 120rpx;font-size: 26rpx;color: #00A9F0;}
  442. .lread{
  443. display: flex;align-items: flex-start;justify-content: center;
  444. .lreadl{padding-top: 4rpx;
  445. image{width: 28rpx;height: 28rpx;margin-right: 14rpx;}
  446. }
  447. .tit{font-size: 26rpx;font-weight: 500;color: #666666;line-height: 40rpx;
  448. text{color:$com-cd3;text-decoration: underline;padding: 0 6rpx;}
  449. }
  450. }
  451. .tab{
  452. .tabtit{font-size: 32rpx;font-weight: 500;color: #666666;padding: 0 24rpx;position: relative;
  453. &.act{color: $com-cd3;font-weight: bold;}
  454. &::before{content: '';position: absolute;left: 0;top: 50%;margin-top: -10rpx;width: 2rpx;height: 20rpx;background: #DADADA;}
  455. &:first-child::before{display: none;}
  456. }
  457. }
  458. .rbtn {font-size: 30rpx;
  459. &.btn{background: #9a9c9e;color: #ffffff;}
  460. &.btn2{background: $com-cd3;color: #ffffff;}
  461. }
  462. .login-form-content {
  463. margin: 0 auto;
  464. width: 100%;
  465. .input-item {
  466. // margin-bottom:48rpx;
  467. border-bottom: 2rpx solid #CDCDCD;
  468. padding: 40rpx 0 0rpx;
  469. .icon {
  470. font-size: 40rpx;
  471. margin-left: 10px;
  472. color: #999;
  473. }
  474. .login_tit{
  475. font-size: 30rpx;
  476. font-weight: bold;
  477. color: #343434;margin-bottom: 20rpx;
  478. }
  479. .login_box{display: flex;align-items: center;
  480. .rimgs{width: 18rpx;height: 30rpx;flex: 0 0 auto;margin-left: 20rpx;}
  481. }
  482. .input {
  483. width: 100%;
  484. font-size: 30rpx;
  485. height: 84rpx;
  486. line-height: 84rpx;
  487. }
  488. }
  489. .login-code {
  490. height: 38px;
  491. float: right;
  492. .login-code-img {
  493. height: 38px;
  494. position: absolute;
  495. margin-left: 10px;
  496. width: 200rpx;
  497. }
  498. }
  499. }
  500. // .image{width: 32rpx;height: 32rpx;margin-right: 14rpx;}
  501. .input_ye image{width: 30rpx;height: 18rpx;}
  502. .codess{font-size: 30rpx;color: $com-cd3;flex: 0 0 auto;min-width: 200rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  503. .codes{background: none;font-size: 28rpx;flex: 0 0 auto;width: 180rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  504. .login_box{display: flex;align-items: center;}
  505. .login_boxl{width:100rpx;font-size: 30rpx;color: #343434;border-right: 2rpx solid #CDCDCD;margin-right: 40rpx;}
  506. .login_txt{text-align: right;flex: 0 0 auto; padding:0 24rpx;
  507. text{font-size: 30rrpx;color:$com-cd3;}
  508. }
  509. .line{width: 2rpx;height: 24rpx;background: #CDCDCD;margin: 0 10rpx;}
  510. .login_jz{display: flex;align-items: center;justify-content: flex-end;flex: 0 0 auto;
  511. image{width: 30rpx;height: 30rpx;margin-right: 12rpx;}
  512. view{color: #666666;font-size: 28rpx;}
  513. }
  514. // app
  515. </style>