login.vue 12 KB

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