tlogin.vue 13 KB

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