login.vue 14 KB

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