tlogin.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view class="regbox" v-if="loginflag">
  3. <!-- <image :src="headimg" class="headimg flex0"></image> -->
  4. <image :src="lbg" class="navbg"></image>
  5. <image :src="fbg" class="fbg"></image>
  6. <view class="wymain">
  7. <view class="head">
  8. <view class="htit">你好,</view>
  9. <view class="htit">欢迎登录智慧社区平台</view>
  10. <view class="htxt" @click="getregister">还没有账号?<text>立即注册</text></view>
  11. </view>
  12. <view class="flex1" style="position: relative;">
  13. <!-- <view class="tab flexcc">
  14. <block v-for="(ite,idx) in tablist" :key="idx">
  15. <view v-if="ite.val!=1" class="tabtit" :class="tabidx==ite.val?'act':''" @click="getTab(ite.val)">
  16. {{ite.tit}}</view>
  17. </block>
  18. </view> -->
  19. <!-- 手机号登录 -->
  20. <view class="login-form-content">
  21. <block v-if="tabidx==1">
  22. <view class="input-item">
  23. <view class="login_tit">账号</view>
  24. <view class="login_box">
  25. <!-- <view class="login_boxl">+86</view> -->
  26. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入登录账号" maxlength="30" />
  27. </view>
  28. </view>
  29. <view class="input-item" >
  30. <view class="flexcj">
  31. <view class="login_tit">密码</view>
  32. <view class="login_jz" @click="jzflag=!jzflag">
  33. <image :src="pcicon" v-if="jzflag"></image>
  34. <image :src="pnicon" v-else></image>
  35. <view>记住密码</view>
  36. </view>
  37. </view>
  38. <view class="login_box">
  39. <uni-easyinput :inputBorder="false" type="password" v-model="loginForm.password" placeholder="请输入密码" />
  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" :class="tucode&&loginForm.username&&loginForm.password?'btn2':'btn'" @click="getLogin">登录</button>
  53. <button v-else type="primary" class=" rbtn " :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">+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 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" 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="pnicon" 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>
  91. <loading></loading>
  92. <!-- <view class="rtxt " @click="getregister">还没账号?去申请注册</view> -->
  93. <phone-btn :type="typeflag" @getPhoneNumber='getPhoneNumber' @getClose="getClose"></phone-btn>
  94. </view>
  95. </template>
  96. <script>
  97. import * as base64 from "base-64"
  98. import {getweChatLogin,getInfo,getweChatOpenid,getCodeImg,getCode,sendSmsCode} from "@/api/login.js"
  99. import {getUserProfile} from "@/api/system/user.js"
  100. import { getToken } from '@/utils/auth'
  101. import phoneBtn from "@/components/toptab/phonebtn.vue"
  102. import config from '@/config'
  103. export default {
  104. components:{
  105. phoneBtn
  106. },
  107. data(){
  108. return{
  109. lbg:require('@/static/images/mine/lbg.png'),
  110. fbg:require('@/static/images/mine/fbg.png'),
  111. headimg:require('@/static/logo.png'),
  112. checkimg:require('@/static/images/mine/lcicon.png'),
  113. ncheckimg:require('@/static/images/mine/lnicon.png'),
  114. rimg:require('@/static/images/mine/rimg.png'),
  115. pcicon:require('@/static/images/mine/pcicon.png'),
  116. pnicon:require('@/static/images/mine/pnicon.png'),
  117. checkflag:true,
  118. typeflag: false,
  119. loginflag:false,
  120. captchaEnabled: false,
  121. duancode:'',//短信验证码
  122. checkeye:false,
  123. tucode:'',
  124. codeUrl:'',
  125. time:'',
  126. timefalg:'',
  127. tabidx:1,
  128. tablist:[{tit:'密码登录',val:1},{tit:'验证码登录',val:2},],
  129. loginForm: {
  130. username: "",
  131. code: "",
  132. password:'',
  133. clientId:config.Clientid,
  134. clientKey:config.userType,
  135. },
  136. //sms
  137. voList:[],
  138. voindex:0,
  139. jzflag:false
  140. }
  141. },
  142. methods:{
  143. getTab(idx){
  144. this.tabidx=idx;
  145. },
  146. // 获取图形验证码
  147. getCode() {
  148. getCodeImg().then(res => {
  149. // 租户
  150. this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled
  151. if (this.captchaEnabled) {
  152. this.codeUrl = 'data:image/gif;base64,' + res.data.img
  153. this.loginForm.uuid = res.data.uuid
  154. }
  155. // 单个
  156. // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  157. // if (this.captchaEnabled) {
  158. // this.codeUrl = 'data:image/gif;base64,' + res.img
  159. // this.loginForm.uuid = res.uuid
  160. // }
  161. })
  162. },
  163. getForget(){
  164. this.$tab.navigateTo(`/mine/pages/pwd/forgetpwd`)
  165. },
  166. getregister(){
  167. this.$tab.redirectTo(`/mine/pages/register`)
  168. },
  169. getLogin(){
  170. if(this.tabidx==1){
  171. if(!this.loginForm.username||!this.loginForm.password||(!this.tucode&& this.captchaEnabled)){
  172. return
  173. }
  174. this.loginForm.code=this.tucode;
  175. this.loginForm.grantType='password';
  176. }else{
  177. 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}$/
  178. // 座机号
  179. if (this.loginForm.username && !regphone.test(this.loginForm.username)) {
  180. this.$toast("请输入正确的手机号")
  181. return
  182. }
  183. if(!this.loginForm.username||!this.duancode){
  184. return
  185. }
  186. this.loginForm.password='';
  187. this.loginForm.code=this.duancode;
  188. this.loginForm.grantType='sms';
  189. // this.loginForm.type=
  190. }
  191. // 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}$/;
  192. // if(!regphone.test(this.loginForm.username)){
  193. // this.$toast('请输入正确的手机号')
  194. // return
  195. // }
  196. // if(!this.checkflag){
  197. // this.$toast("请同意用户协议")
  198. // return
  199. // }
  200. console.log(this.loginForm)
  201. this.pwdLogin()
  202. },
  203. // 密码登录
  204. async pwdLogin() {
  205. var that=this;
  206. console.log(this.loginForm)
  207. // return
  208. this.$store.dispatch('Login', this.loginForm).then((res) => {
  209. // 判断是否记住密码
  210. if(that.jzflag){
  211. var newObj={
  212. username:that.loginForm.username,
  213. password:base64.encode(that.loginForm.password),
  214. captchaEnabled:that.captchaEnabled,
  215. }
  216. uni.setStorageSync('account', JSON.parse(JSON.stringify(newObj)))
  217. }else{
  218. uni.removeStorageSync('account')
  219. }
  220. this.$modal.closeLoading()
  221. this.$toast('登录成功')
  222. setTimeout(function(){
  223. that.loginSuccess()
  224. },1500)
  225. }).catch((error) => {
  226. setTimeout(function(){
  227. if (that.captchaEnabled&&that.tabidx==1) {
  228. that.getCode()
  229. }
  230. },1000)
  231. })
  232. },
  233. handlePrivacy(){
  234. this.$tab.navigateTo(`/pages/agreement`)
  235. },
  236. getClose() {
  237. this.typeflag = false
  238. },
  239. btns() {
  240. },
  241. // 获取短信验证码
  242. getsendCode(){
  243. var that=this;
  244. if (!this.loginForm.username ) {
  245. that.$toast("请输入手机号")
  246. return
  247. }
  248. 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}$/
  249. // 座机号
  250. let reg1=/^(0\d{2,3})-?(\d{7,8})$/
  251. if (this.loginForm.username && !regphone.test(this.loginForm.username)) {
  252. that.$toast("请输入正确的手机号")
  253. return
  254. }
  255. var params={
  256. phonenumber:this.loginForm.username,
  257. type:1,//1:登录 2:注册 3:修改密码
  258. }
  259. sendSmsCode(params).then(res=>{
  260. if (res.code == 200) {
  261. // 发送验证码
  262. that.$toast("发送成功")
  263. that.time=60;
  264. that.timefalg=true;
  265. that.setTimein()
  266. } else {
  267. that.$toast(res.msg)
  268. }
  269. })
  270. },
  271. // 验证码倒计时
  272. setTimein(){
  273. var that=this;
  274. clearInterval(that.timer)
  275. that.timer=setInterval(()=>{
  276. if(that.time<=1){
  277. that.timefalg=false;
  278. that.time=60;
  279. clearInterval(that.timer)
  280. }
  281. that.time=that.time-1;
  282. },1000)
  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. // 登录成功后,处理函数
  299. loginSuccess(result) {
  300. // 设置用户信息
  301. var that=this;
  302. this.$store.dispatch('GetInfo').then(res => {
  303. this.$tab.reLaunch('/pages/index/index')
  304. })
  305. },
  306. async getuserinfo(e) {
  307. // if(!this.checkflag){
  308. // this.$toast("请同意用户协议")
  309. // return
  310. // }
  311. // 判断是不是有学校
  312. const {iv,encryptedData} = e.detail
  313. const {nickName, avatarUrl, ...userInfo} = e.detail.userInfo
  314. // console.log(e.detail)
  315. try{
  316. uni.login({
  317. provider: 'weixin',
  318. success: (res) => {
  319. // 获取用户信息
  320. if(res.code){
  321. this.avatarUrl = avatarUrl
  322. this.nickName = nickName
  323. this.code = res.code
  324. this.userInfo =e.detail.userInfo
  325. uni.setStorageSync('userInfo', e.detail.userInfo)
  326. uni.setStorageSync('lcheckflag',true)
  327. this.typeflag=true;
  328. }
  329. }
  330. })
  331. } catch(e){
  332. //TODO handle the exception
  333. }
  334. },
  335. },
  336. onLoad: function(e) {
  337. this.tabidx=e.type;
  338. this.getCode()
  339. if (getToken()) {
  340. this.$tab.reLaunch('/pages/index/index')
  341. // 判断有什么角色
  342. } else {
  343. this.loginflag=true;
  344. // this.getCode()
  345. // if(uni.getStorageSync('lcheckflag')){
  346. // this.checkflag=true
  347. // }else{
  348. // this.checkflag=false
  349. // }
  350. if(this.tabidx==1){
  351. if(uni.getStorageSync('account')){
  352. var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('account')))
  353. this.loginForm.username=newObj.username;
  354. this.loginForm.password=base64.decode(newObj.password);
  355. this.jzflag=true;
  356. }
  357. }
  358. }
  359. },
  360. }
  361. </script>
  362. <style lang="scss" scoped>
  363. .navbg{width: 100%;height: 100vh;}
  364. .fbg{width: 100%;height: 750rpx;position: absolute;bottom: 0;left: 0;}
  365. .wymain{z-index: 2;position: relative;padding: 180rpx 60rpx;}
  366. .headimg{width: 136rpx;height: 136rpx;margin:0 auto 36rpx;}
  367. .head{margin-bottom: 64rpx;
  368. .htit{font-weight: bold;font-size: 48rpx;color: #0156FE;line-height: 60rpx;}
  369. .htxt{font-weight: 500;font-size: 24rpx;color: #666666;margin-top: 30rpx;
  370. text{color: #0156FE;}
  371. }
  372. }
  373. .mzimg{width: 100rpx;height: 44rpx;margin: 0 auto ;}
  374. .regbox /deep/ .uni-easyinput__content{background-color: transparent !important;}
  375. .regbox /deep/ .uni-easyinput__content-input{font-size: 30rpx !important;padding-left: 0 !important;line-height: 80rpx;height: 80rpx;}
  376. .regbox /deep/ .uni-input-placeholder{font-size: 30rpx !important;padding-left: 0 !important;color: #808080;}
  377. .rtxt{font-size: 30rpx;font-weight: 500;
  378. color: $com-cd3;text-align: center;}
  379. .bbcode{position: absolute;width: 100%;text-align: center;left: 0;bottom: -80rpx;font-size: 24rpx;color: #666666;}
  380. .lread{
  381. display: flex;align-items: flex-start;justify-content: center;
  382. .lreadl{padding-top: 4rpx;
  383. image{width: 22rpx;height: 22rpx;margin-right: 12rpx;}
  384. }
  385. .tit{font-size: 26rpx;font-weight: 500;color: #666666;
  386. text{color:#4888FA;padding: 0 6rpx;font-weight: 500;}
  387. }
  388. }
  389. .tab{
  390. .tabtit{font-size: 30rpx;font-weight: 500;color: #666666;padding: 0 24rpx;position: relative;
  391. &.act{color: $com-cd3;font-weight: bold;}
  392. &::before{content: '';position: absolute;left: 0;top: 50%;margin-top: -10rpx;width: 2rpx;height: 20rpx;background: #DADADA;}
  393. &:first-child::before{display: none;}
  394. }
  395. }
  396. .rbtn {height: 84rpx;margin: 120rpx 0 24rpx;font-weight: bold;font-size: 28rpx;color: #FFFFFF;line-height: 84rpx;
  397. &.btn{background: #9a9c9e;color: #ffffff;}
  398. &.btn2{background: $com-cd3;color: #ffffff;}
  399. }
  400. .login-form-content {
  401. margin: 0 auto;
  402. width: 100%;
  403. .input-item {
  404. // margin-bottom:48rpx;
  405. border-bottom: 2rpx solid #CDCDCD;
  406. padding: 40rpx 0 0rpx;
  407. .icon {
  408. font-size: 40rpx;
  409. margin-left: 10px;
  410. color: #999;
  411. }
  412. .login_tit{
  413. font-size: 30rpx;
  414. font-weight: bold;
  415. color: #343434;margin-bottom: 8rpx;
  416. }
  417. .login_box{display: flex;align-items: center;
  418. .rimgs{width: 18rpx;height: 30rpx;flex: 0 0 auto;margin-left: 20rpx;}
  419. }
  420. .input {
  421. width: 100%;
  422. font-size: 30rpx;
  423. height: 80rpx;
  424. line-height: 80rpx;
  425. }
  426. }
  427. .login-code {
  428. height: 38px;
  429. float: right;
  430. .login-code-img {
  431. height: 38px;
  432. position: absolute;
  433. margin-left: 10px;
  434. width: 200rpx;
  435. }
  436. }
  437. }
  438. // .image{width: 30rpx;height: 30rpx;margin-right: 14rpx;}
  439. .input_ye image{width: 34rpx;height: 18rpx;}
  440. .codess{font-size: 30rpx;color: $com-cd3;flex: 0 0 auto;min-width: 200rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  441. .codes{background: none;font-size: 30rpx;flex: 0 0 auto;width: 180rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  442. .login_box{display: flex;align-items: center;}
  443. .login_boxl{width:130rpx;font-size: 34rpx;color: #343434;border-right: 2rpx solid #CDCDCD;}
  444. .login_txt{text-align: right;flex: 0 0 auto; padding:0 24rpx;
  445. text{font-size: 30rpx;color:#666666;}
  446. }
  447. .line{width: 2rpx;height: 24rpx;background: #CDCDCD;margin: 0 10rpx;}
  448. .login_jz{display: flex;align-items: center;justify-content: flex-end;flex: 0 0 auto;
  449. image{width: 30rpx;height: 30rpx;margin-right: 12rpx;}
  450. view{color: #666666;font-size: 28rpx;}
  451. }
  452. // app
  453. </style>