login.vue 13 KB

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