login.vue 16 KB

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