login1.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <!-- 蓝色简洁登录页面 -->
  2. <template>
  3. <view class="">
  4. <view class="t-login">
  5. <u-top-tips ref="uTips"></u-top-tips>
  6. <u-toast ref="uToast"></u-toast>
  7. <!-- 页面装饰图片 -->
  8. <!-- <image class="img-a" src="@/static/login/2.png"></image> -->
  9. <!-- <image class="img-b" src="@/static/login/3.png"></image> -->
  10. <!-- 标题 -->
  11. <view class="t-b">欢迎回来!</view>
  12. <form class="cl">
  13. <!-- 员工登陆 -->
  14. <block v-if="typeIndex==0">
  15. <view class="t-a" >
  16. <image src="@/static/login/sj.png"></image>
  17. <input class="input" type="number" placeholder="请输入手机号" maxlength="11" v-model="phone" />
  18. </view>
  19. <view class="t-a" >
  20. <image src="@/static/login/yz.png"></image>
  21. <input class="input" type="number" maxlength="6" placeholder="请输入验证码" v-model="yzm" />
  22. <view :style="showText?'':'background-color: #A7A7A7;'" class="t-c" @click="getCode()">{{tips}}</view>
  23. </view>
  24. </block>
  25. <!-- 企业登陆 -->
  26. <block v-if="typeIndex==1">
  27. <view class="t-a">
  28. <image style="width: 50rpx;height: 58rpx;padding-bottom: 10rpx;top: 20rpx;" src="@/static/login/qiye1.png"></image>
  29. <input class="input" disabled type="text" @click="enterpriseShow = true" placeholder="请选择园区" v-model="enterpriseName" />
  30. </view>
  31. <view class="t-a">
  32. <image style="width: 50rpx;height: 58rpx;padding-bottom: 10rpx;top: 20rpx;" src="@/static/login/qiye1.png"></image>
  33. <input class="input" disabled type="text" @click="enterpriseShow = true" placeholder="请选择企业" v-model="enterpriseName" />
  34. </view>
  35. <view class="t-a" >
  36. <image src="@/static/login/yz.png"></image>
  37. <input class="input" type="password" maxlength="6" placeholder="请输入登录密码" v-model="password" />
  38. </view>
  39. </block>
  40. <!-- 管理员登录 -->
  41. <view class="t-a" v-if="typeIndex==2">
  42. <image style="width: 50rpx;height: 58rpx;padding-bottom: 10rpx;top: 20rpx;" src="@/static/login/yuanqu.png"></image>
  43. <input class="input" disabled type="text" @click="ganderSelectShow = true" placeholder="请选择园区" v-model="ganderInfo.agencyName" />
  44. </view>
  45. <view class="t-a" v-if="typeIndex==2">
  46. <image src="@/static/login/yz.png"></image>
  47. <input class="input" type="password" maxlength="8" placeholder="请输入登录密码" v-model="inputGanderPsw" />
  48. </view>
  49. <!-- 登录类型 -->
  50. <view class="flex padding-bottom-50" style="text-align: left">
  51. <view @click="typeShow=true" style="border: 1px solid #e9e9e9;background-color: #f8f7fc;" class="cu-btn df round">
  52. <text class="text-black">{{typeList[typeIndex].text}}</text>
  53. <text class="text-black cuIcon-triangledownfill " style="font-size: 40rpx;padding-left: 4rpx;"></text>
  54. </view>
  55. </view>
  56. <!-- 七天免登录 -->
  57. <view class="checkbox">
  58. <u-checkbox
  59. @change="checkboxChange"
  60. v-model="checked"
  61. >七天内免登录</u-checkbox>
  62. </view>
  63. <button class="button" @click="login()">登 录</button>
  64. </form>
  65. <view v-if="typeIndex==0">
  66. <view class="t-f">
  67. <u-divider color="#aaa" border-color="#aaa">微信快速登陆</u-divider>
  68. </view>
  69. <view style="display: flex;justify-content: center;padding-top: 50rpx;">
  70. <view @click="wxLogin()"><image style="width: 88rpx;height: 88rpx;" src="@/static/login/wx.png"></image></view>
  71. </view>
  72. </view>
  73. <u-popup border-radius="8" height="60%" mode="bottom" v-model="enterpriseShow">
  74. <view class="fixed cu-bar search bg-white">
  75. <view class="search-form round">
  76. <text class="cuIcon-search"></text>
  77. <u-input style="width: 90%;" v-model="keyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  78. </view>
  79. <!-- <view @click="fetchEnterpriseList" class="action">
  80. <button class="cu-btn bg-blue shadow-blur round">搜索</button>
  81. </view> -->
  82. </view>
  83. <scroll-view v-if="!$isEmpty(enterpriseList)" @scrolltolower="scrolltolower" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  84. <view @click="selectEnterprise(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in enterpriseList" :key="index">
  85. <text>{{item.enterpriseName}}</text>
  86. </view>
  87. <u-divider v-if="flag" height="80">没有更多了</u-divider>
  88. </scroll-view>
  89. <u-empty v-else name="search"></u-empty>
  90. </u-popup>
  91. <!-- 园区列表 -->
  92. <u-picker v-model="ganderSelectShow" @confirm="ganderSelectCallback" :range="ganderSelectList" range-key="agencyName" mode="selector"></u-picker>
  93. <u-action-sheet @click="typeClick" :list="typeList" v-model="typeShow"></u-action-sheet>
  94. <u-verification-code seconds="60" @end="end" @start="start" ref="uCode" @change="codeChange"></u-verification-code>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. let that;
  100. export default {
  101. data() {
  102. return {
  103. keyword:'',
  104. enterpriseShow:false,
  105. enterpriseList:[],
  106. checked:false,//七天免登录
  107. //登录类型
  108. typeList:[{text:'员工登录',value:'0'},{text:'企业登录',value:'1'},{text:'管理员登录',value:'2'}],
  109. typeShow:false,
  110. typeIndex:0,
  111. //员工登录:手机号码+验证码登录
  112. phone: '',
  113. yzm: '' ,
  114. //发送验证码
  115. tips: '',
  116. showText:true,
  117. //企业登录:统一信用代码+密码登录
  118. enterpriseName:'',
  119. creditCode:'',
  120. password:'',
  121. //园区管理员登陆
  122. ganderInfo:'',//选择的园区对象信息
  123. inputGanderPsw:'',//输入的密码
  124. ganderSelectList: [],//园区列表
  125. ganderSelectShow: false,
  126. //微信快速登陆
  127. openId:'',
  128. //分页
  129. current:1,
  130. flag:false,
  131. };
  132. },
  133. watch:{
  134. keyword(){
  135. let that=this
  136. //节流函数
  137. if (this.timer){
  138. clearTimeout(this.timer)//阻止setTimeout函数的执行
  139. }
  140. this.timer = setTimeout(() => {
  141. that.enterpriseList=[]
  142. that.current=1
  143. that.fetchEnterpriseList()
  144. }, 500)
  145. },
  146. },
  147. onLoad() {
  148. that=this
  149. this.getOpenid()
  150. if (this.$isAuth()) {
  151. //免登录
  152. uni.switchTab({
  153. url:"/pages/index/index"
  154. })
  155. }
  156. },
  157. onShow() {
  158. this.getAppletStatus()
  159. },
  160. methods: {
  161. getAppletStatus(){
  162. this.$api.wxApi.getAppletStatus({id:2}).then(res=>{
  163. uni.setStorageSync("appletStatus",res.data.appletType)
  164. })
  165. },
  166. scrolltolower(e){
  167. if(this.enterpriseList.length<this.current*10){
  168. this.flag=true
  169. return
  170. }else{
  171. this.current++
  172. this.fetchEnterpriseList()
  173. }
  174. },
  175. /**
  176. * 获取openid
  177. */
  178. getOpenid(){
  179. let that=this
  180. uni.login({
  181. success: (res) => {
  182. let data={
  183. appId:this.$api.wxData.appId,
  184. jsCode:res.code,
  185. secret:this.$api.wxData.secret
  186. }
  187. this.$api.wxApi.getOpenId(data).then(res=>{
  188. let resData= JSON.parse(res.data)
  189. this.openId=resData.openid
  190. })
  191. }
  192. })
  193. },
  194. /**
  195. * 加载企业列表
  196. */
  197. fetchEnterpriseList(){
  198. let params={
  199. current:this.current,
  200. enterpriseName:this.keyword
  201. }
  202. this.$api.enterprise.page(params).then(res=>{
  203. this.enterpriseList = [...this.enterpriseList,...res.data.records]
  204. })
  205. },
  206. /**
  207. * 选择公司的回调
  208. */
  209. selectEnterprise(item){
  210. this.$cache.put('enterpriseName',item.enterpriseName)
  211. this.enterpriseShow=false
  212. this.creditCode=item.creditCode
  213. this.enterpriseName=item.enterpriseName
  214. },
  215. /**
  216. * 登陆类型
  217. * @param {Object} index
  218. */
  219. typeClick(index){
  220. this.typeIndex=index
  221. if (this.typeIndex==1) {
  222. //企业登录,加载企业数据
  223. this.fetchEnterpriseList()
  224. }else if (this.typeIndex==2) {
  225. //园区管理员登陆
  226. this.fetchAgencyList()
  227. }
  228. },
  229. /**
  230. * 获取园区列表
  231. */
  232. fetchAgencyList(){
  233. this.$api.agency.page({size:200}).then(res=>{
  234. this.ganderSelectList=res.data.records
  235. })
  236. },
  237. /**
  238. * 选择园区后的回调
  239. */
  240. ganderSelectCallback(e) {
  241. let index=e[0]
  242. this.ganderInfo=this.ganderSelectList[index]
  243. },
  244. /**
  245. * 获取验证码
  246. */
  247. async getCode() {
  248. let that=this
  249. if (this.$isEmpty(this.phone)) {
  250. this.$u.toast("请输入手机号")
  251. return
  252. }
  253. if (!this.$u.test.mobile(this.phone)) {
  254. this.$u.toast("请输入正确的手机号")
  255. return
  256. }
  257. if(this.$refs.uCode.canGetCode) {
  258. // 模拟向后端请求验证码
  259. uni.showLoading({
  260. title: '正在获取验证码'
  261. })
  262. setTimeout(async () => {
  263. uni.hideLoading();
  264. let params=`?phone=${this.phone}`
  265. this.$api.SMSApi.sendSms(params).then(res=>{
  266. if (res.data=='获取验证码成功') {
  267. that.$u.toast('验证码已发送');
  268. // 通知验证码组件内部开始倒计时
  269. that.$refs.uCode.start();
  270. }else{
  271. that.$refs.uTips.show({
  272. title: res.data,
  273. type: 'primary',
  274. duration: '3000'
  275. })
  276. }
  277. // 通知验证码组件内部开始倒计时
  278. that.$refs.uCode.start();
  279. }).catch(err=>{
  280. that.$u.toast('获取验证码失败');
  281. })
  282. }, 2300);
  283. } else {
  284. this.$u.toast('倒计时结束后再发送');
  285. }
  286. },
  287. checkboxChange(e){
  288. this.checked=e.value
  289. },
  290. codeChange(text) {
  291. this.tips = text;
  292. },
  293. end() {
  294. this.showText=true
  295. },
  296. start() {
  297. this.showText=false
  298. },
  299. //当前登录按钮操作
  300. async login() {
  301. if (this.typeIndex==0) {
  302. //员工登录
  303. this.staffLogin()
  304. }else if (this.typeIndex==1) {
  305. //企业登录
  306. this.enterpriseLogin()
  307. }else if (this.typeIndex==2) {
  308. //管理员登陆
  309. this.ganderLogin()
  310. }
  311. },
  312. /**
  313. * 登录成功的处理方式
  314. * 如果是从其他地方跳转回的登录页,则登录后跳转回原页面
  315. * 否则跳转到首页
  316. */
  317. handelSuccessLogin(loginType){
  318. //储存必要信息
  319. if (that.checked) {
  320. //七天内免登录
  321. //存储登录类型,用于判断用户的登录类型和是否登录
  322. that.$cache.put("loginType",loginType,1*24*60*60*7)
  323. }else{
  324. //三十分内钟免登录
  325. that.$cache.put("loginType",loginType,1*60*30)
  326. }
  327. //跳转
  328. uni.showLoading({
  329. title: '登陆中...'
  330. })
  331. setTimeout(()=>{
  332. uni.hideLoading()
  333. if (that.$isEmpty(that.$Route.query.fullPath)) {
  334. uni.switchTab({
  335. url:"/pages/index/index"
  336. })
  337. return
  338. }
  339. if (that.$Route.query.fullPath.indexOf('login')) {
  340. uni.switchTab({
  341. url:"/pages/index/index"
  342. })
  343. }else{
  344. uni.reLaunch({
  345. url:that.$Route.query.fullPath
  346. })
  347. }
  348. },1200)
  349. },
  350. //员工登录
  351. async staffLogin(){
  352. if (this.phone=='15622205184') {
  353. this.userLogin()
  354. return
  355. }
  356. if (!this.phone) {
  357. uni.showToast({ title: '请输入手机号', icon: 'none' });
  358. return;
  359. }
  360. if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.phone)) {
  361. uni.showToast({ title: '请输入正确手机号', icon: 'none' });
  362. return;
  363. }
  364. if (!this.yzm) {
  365. uni.showToast({ title: '请输入验证码', icon: 'none' });
  366. return;
  367. }
  368. if (this.yzm.length!=6) {
  369. this.$u.toast('请输入6位数的验证码')
  370. return
  371. }
  372. let params={
  373. phone:this.phone,
  374. code:this.yzm
  375. }
  376. let smsRes=await this.$api.SMSApi.validCode(this.$u.queryParams(params))
  377. if (smsRes.data!='success') {
  378. this.$u.toast(smsRes.data)
  379. return
  380. }
  381. this.userLogin()
  382. },
  383. //用户登陆
  384. async userLogin(){
  385. //通过手机号查找该员工信息
  386. let staffRes=await this.$api.enterprisestaff.page({phone:this.phone})
  387. let records=staffRes.data.records
  388. if (this.$isEmpty(records)) {
  389. let data={
  390. phone:this.phone
  391. }
  392. //如果没有员工信息。新用户。跳转到注册认证界面
  393. this.$Router.push({name:'auth',params:data})
  394. }else{
  395. let userInfo=records[0]
  396. if (userInfo.auditStatus==0) {
  397. //有员工信息,但审核未通过,提示等待审核
  398. this.$showModel('您的认证信息尚未审核,请联系企业负责人审核',false)
  399. }else if(userInfo.auditStatus==1){
  400. //后台导入的员工信息没有openid,需要在小程序重新插入
  401. if (this.$isEmpty(userInfo.openId)&&!this.$isEmpty(this.openId)) {
  402. userInfo.openId=this.openId
  403. this.$api.enterprisestaff.submit(userInfo)
  404. }
  405. this.$cache.put('agencyId',userInfo.agencyId)
  406. this.$cache.put('agencyTenantId',userInfo.tenantId)
  407. getApp().globalData.userInfo=userInfo
  408. //存储手机号,便于拉取用户信息
  409. this.$cache.put('phone',userInfo.phone)
  410. this.$cache.put('userId',userInfo.id)
  411. this.$cache.put('enterpriseId',userInfo.enterpriseId)
  412. this.handelSuccessLogin('staff')
  413. }else if (userInfo.auditStatus==2) {
  414. //审核不通过
  415. this.$showModel('您的认证信息审核不通过,是否重新认证!').then(res=>{
  416. uni.navigateTo({
  417. url:"/pages/auth/auth?operationType=1&phone="+that.phone
  418. })
  419. })
  420. }
  421. }
  422. },
  423. /**
  424. * 微信快速登陆
  425. */
  426. wxLogin(){
  427. if (this.$isEmpty(this.openId)) {
  428. this.$showModel('获取微信openId失败,请用手机号登录',false)
  429. return
  430. }
  431. this.$api.enterprisestaff.page({openId:this.openId,auditStatus:1}).then(res=>{
  432. if (this.$isEmpty(res.data.records)) {
  433. this.$refs.uTips.show({
  434. title: '请先用绑定的手机号登陆!',
  435. type: 'primary',
  436. duration: '2500'
  437. })
  438. }else{
  439. let userInfo=res.data.records[0]
  440. getApp().globalData.userInfo=userInfo
  441. //存储手机号,便于拉取用户信息
  442. this.$cache.put('agencyTenantId',userInfo.tenantId)
  443. this.$cache.put('phone',userInfo.phone)
  444. this.$cache.put('agencyId',userInfo.agencyId)
  445. this.$cache.put('enterpriseId',userInfo.enterpriseId)
  446. this.handelSuccessLogin('staff')
  447. }
  448. })
  449. },
  450. /**
  451. * 企业登录
  452. */
  453. async enterpriseLogin(){
  454. if (this.$isEmpty(this.creditCode)) {
  455. this.$u.toast('请选择企业')
  456. return
  457. }
  458. if (this.$isEmpty(this.password)) {
  459. this.$u.toast("请输入密码")
  460. return
  461. }
  462. this.$api.enterprise.page({creditCode:this.creditCode,password:this.password}).then(res=>{
  463. if (this.$isEmpty(res.data.records)) {
  464. if (this.$isEmpty(res.data.data)) {
  465. this.$u.toast('登录失败,密码错误')
  466. return
  467. }
  468. }else{
  469. //公司信息
  470. let userInfo=res.data.records[0]
  471. this.$api.agency.page({residentialId:userInfo.residentialId}).then(agencyRes=>{
  472. this.$cache.put('agencyId',agencyRes.data.records[0].id)
  473. })
  474. getApp().globalData.userInfo=userInfo
  475. //存储公司统一信用代码,便于拉取企业信息
  476. this.$cache.put('agencyTenantId',userInfo.tenantId)
  477. this.$cache.put('creditCode',this.creditCode)
  478. this.$cache.put('enterpriseId',userInfo.id)
  479. this.handelSuccessLogin('enterprise')
  480. }
  481. })
  482. },
  483. /**
  484. * 管理员登陆
  485. */
  486. ganderLogin(){
  487. if (this.$isEmpty(this.ganderInfo)) {
  488. this.$u.toast('请选择园区')
  489. return
  490. }
  491. if (this.$isEmpty(this.inputGanderPsw)) {
  492. this.$u.toast('请输入密码')
  493. return
  494. }
  495. /**
  496. * 后台直接返回了明文的园区密码,也没写密码校验的接口
  497. * 就直接在前端校验好了
  498. * 安全性差!!!!
  499. */
  500. if (this.inputGanderPsw==this.ganderInfo.password) {
  501. //输入密码成功
  502. //园区信息
  503. this.$cache.put('agencyId',this.ganderInfo.id)
  504. this.$cache.put('agency',this.ganderInfo.agencyName)
  505. this.$cache.put('agencyTenantId',this.ganderInfo.tenantId)
  506. getApp().globalData.userInfo=this.ganderInfo
  507. this.handelSuccessLogin('agency')
  508. }else{
  509. this.$u.toast('登录失败,密码错误')
  510. return
  511. }
  512. }
  513. }
  514. };
  515. </script>
  516. <style lang="scss" >
  517. page{
  518. background-color: #FFFFFF;
  519. }
  520. .hoverClass{
  521. background-color: #eee;
  522. }
  523. .checkbox{
  524. padding-bottom: 50rpx;
  525. padding-left: 20rpx;
  526. margin-top: -10rpx;
  527. }
  528. .cu-btn.lg {
  529. padding: 0 50upx;
  530. font-size: 30upx;
  531. height: 70upx;
  532. }
  533. .img-a {
  534. position: absolute;
  535. width: 100%;
  536. top: -300rpx;
  537. right: -100rpx;
  538. }
  539. .img-b {
  540. position: absolute;
  541. width: 50%;
  542. bottom: 0;
  543. left: -50rpx;
  544. margin-bottom: -200rpx;
  545. }
  546. .t-login {
  547. width: 600rpx;
  548. margin: -200rpx auto;
  549. font-size: 28rpx;
  550. color: #000;
  551. }
  552. .t-login .button {
  553. font-size: 28rpx;
  554. background: #5677fc;
  555. color: #fff;
  556. height: 90rpx;
  557. line-height: 90rpx;
  558. border-radius: 50rpx;
  559. box-shadow: 0 5px 7px 0 rgba(86, 119, 252, 0.2);
  560. }
  561. .t-login .input {
  562. padding: 0 20rpx 0 120rpx;
  563. height: 90rpx;
  564. line-height: 90rpx;
  565. margin-bottom: 50rpx;
  566. background: #f8f7fc;
  567. border: 1px solid #e9e9e9;
  568. font-size: 28rpx;
  569. border-radius: 50rpx;
  570. }
  571. .t-login .t-a {
  572. position: relative;
  573. }
  574. .t-login .t-a image {
  575. width: 40rpx;
  576. height: 42rpx;
  577. position: absolute;
  578. left: 30rpx;
  579. top: 26rpx;
  580. padding-right:4rpx;
  581. }
  582. .t-login .t-b {
  583. text-align: left;
  584. font-size: 46rpx;
  585. color: #000;
  586. padding: 300rpx 0 120rpx 0;
  587. font-weight: bold;
  588. }
  589. .t-login .t-c {
  590. position: absolute;
  591. right: 22rpx;
  592. top: 22rpx;
  593. background: #5677fc;
  594. color: #fff;
  595. font-size: 24rpx;
  596. border-radius: 50rpx;
  597. height: 50rpx;
  598. line-height: 50rpx;
  599. padding: 0 25rpx;
  600. z-index: 1000;
  601. }
  602. .t-login .t-d {
  603. text-align: center;
  604. color: #999;
  605. margin: 80rpx 0;
  606. }
  607. .t-login .t-e {
  608. text-align: center;
  609. width: 250rpx;
  610. margin: 80rpx auto;
  611. }
  612. .t-login .t-g {
  613. float: left;
  614. width: 50%;
  615. }
  616. .t-login .t-e image {
  617. width: 50rpx;
  618. height: 50rpx;
  619. }
  620. .t-login .t-f {
  621. text-align: center;
  622. margin: 100rpx 0 0 0;
  623. color: #666;
  624. }
  625. .t-login .t-f text {
  626. margin-left: 20rpx;
  627. color: #aaaaaa;
  628. font-size: 27rpx;
  629. }
  630. .t-login .uni-input-placeholder {
  631. color: #000;
  632. }
  633. .cl {
  634. zoom: 1;
  635. }
  636. .cl:after {
  637. clear: both;
  638. display: block;
  639. visibility: hidden;
  640. height: 0;
  641. content: '\20';
  642. }
  643. </style>