移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

424 lines
12 KiB

  1. <template>
  2. <div class="app-container" :style="{height:height+'px'}">
  3. <van-nav-bar
  4. title="登录"
  5. left-arrow
  6. fixed
  7. placeholder
  8. @click-left="onClickLeft"
  9. />
  10. <div class="title">
  11. <p class="title_one">PROPERTY RIGHT</p>
  12. <p class="title_two">TRANSACTION</p>
  13. <p class="title_three">农村产权交易平台</p>
  14. </div>
  15. <div class="login-main">
  16. <ul class="head_nav clear">
  17. <li @click="isSmsLogin = false" :class="{ active: !isSmsLogin }">
  18. 账号登录
  19. </li>
  20. <li @click="isSmsLogin = true" :class="{ active: isSmsLogin }">
  21. 验证码登录
  22. </li>
  23. </ul>
  24. <div class="form_main">
  25. <van-form @submit="handleLogin">
  26. <div v-show="!isSmsLogin">
  27. <van-field
  28. v-model="formData.username"
  29. name="username"
  30. label="用户名"
  31. placeholder="用户名"
  32. />
  33. <van-field
  34. v-model="formData.password"
  35. type="password"
  36. name="password"
  37. label="密码"
  38. placeholder="密码"
  39. />
  40. <van-field
  41. v-model="code"
  42. center
  43. clearable
  44. label="验证码"
  45. placeholder="图形验证码"
  46. >
  47. <template #button>
  48. <img class="code-img" :src="codeUrl" @click="getCode" />
  49. </template>
  50. </van-field>
  51. <van-checkbox style="float: left;margin-top:10px;margin-left:20px;" v-model="formData.rememberMe" shape="square">{{showMessage ? "记住手机号" : "记住密码"}}</van-checkbox>
  52. <!-- <p style="float: right;margin-top:10px;margin-right:20px;color:#1D6FE9 ">忘记密码</p>-->
  53. <div class="clear"></div>
  54. </div>
  55. <div v-show="isSmsLogin">
  56. <van-field
  57. v-model="formData.mobile"
  58. label="手机号"
  59. placeholder="请输入手机号码"
  60. />
  61. <van-field
  62. v-model="mobileCode"
  63. center
  64. clearable
  65. label="验证码"
  66. placeholder="图形验证码"
  67. >
  68. <template #button>
  69. <img class="code-img" :src="codeUrlPhone" @click="getCodePhone" />
  70. </template>
  71. </van-field>
  72. <van-field
  73. v-model="formData.smsCode"
  74. center
  75. clearable
  76. label="短信验证码"
  77. placeholder="请输入短信验证码"
  78. >
  79. <template #button>
  80. <van-button
  81. size="small"
  82. type="primary"
  83. native-type="button"
  84. @click="getSmsCode"
  85. >{{
  86. computeTime > 0 ? `(${computeTime}s)已发送` : "获取验证码"
  87. }}</van-button
  88. >
  89. </template>
  90. </van-field>
  91. </div>
  92. <div class="form-submit">
  93. <van-button
  94. round
  95. block
  96. type="info"
  97. native-type="submit"
  98. :loading="loading"
  99. >登录</van-button
  100. >
  101. </div>
  102. </van-form>
  103. </div>
  104. </div>
  105. <div class="reveal-modal-con">
  106. <div class="dd_txt">
  107. <router-link to="register/index">注册账户</router-link>
  108. </div>
  109. <!-- <div class="other-login">-->
  110. <!-- <p class="desc">—— 更多登录方式 ——</p>-->
  111. <!-- <p class="icon-other-logins">-->
  112. <!-- <router-link class="wx" to="/"></router-link>-->
  113. <!-- <router-link class="rlsb" to="/"></router-link>-->
  114. <!-- </p>-->
  115. <!-- </div>-->
  116. </div>
  117. </div>
  118. </template>
  119. <script>
  120. import { getCodeImg, getSmsCode } from "@/api/login";
  121. import Cookies from "js-cookie";
  122. import { encrypt, decrypt } from "../utils/jsencrypt";
  123. //引用wx sdk
  124. import wx from "weixin-js-sdk";
  125. export default {
  126. name: "login",
  127. data() {
  128. return {
  129. showMessage:false,
  130. formData: {
  131. // username: "admin", //账号
  132. // password: "admin123", //密码
  133. username:'',
  134. password:'',
  135. code: null, //图片验证码
  136. uuid: null, //识别uuid
  137. mobile: null, //手机号
  138. smsCode: null, //短信验证码
  139. rememberMe:false
  140. },
  141. loading: false,
  142. codeUrl: "", //验证码
  143. codeUrlPhone: "", //验证码
  144. mobileCode:null,
  145. code:null,
  146. isSmsLogin: false, //是否手机验证码
  147. computeTime: 0,
  148. height:0,
  149. uuid:'',
  150. uuidPhone:'',
  151. };
  152. },
  153. created() {
  154. this.getCode();
  155. this.getCodePhone();
  156. this.height = document.body.clientHeight
  157. this.getCookie();
  158. //调用微信公众号方法
  159. // wx.config({
  160. // debug: true, // 开启调试模式,
  161. // appId: res.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
  162. // timestamp: res.timestamp, // 必填,生成签名的时间戳
  163. // nonceStr: res.nonceStr, // 必填,生成签名的随机串
  164. // signature: res.signature,// 必填,签名,见附录1
  165. // jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  166. // });
  167. //分享要用encodeURIComponent()方法
  168. },
  169. methods: {
  170. getCode() {
  171. getCodeImg().then((res) => {
  172. this.uuid = res.uuid;
  173. this.codeUrl = "data:image/gif;base64," + res.img;
  174. });
  175. },
  176. getCodePhone() {
  177. getCodeImg().then((res) => {
  178. this.uuidPhone = res.uuid;
  179. this.codeUrlPhone = "data:image/gif;base64," + res.img;
  180. });
  181. },
  182. getCookie() {
  183. const username = Cookies.get("username");
  184. const password = Cookies.get("password");
  185. const rememberMe = Cookies.get("rememberMe");
  186. this.formData = {
  187. username: username === undefined ? this.formData.username : username,
  188. password:
  189. password === undefined ? this.formData.password : decrypt(password),
  190. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  191. };
  192. },
  193. getSmsCode() {
  194. console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
  195. if (!this.computeTime) {
  196. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  197. if (!myreg.test(this.formData.mobile)) {
  198. this.$dialog.alert({
  199. message: '手机号格式不正确',
  200. });
  201. return false;
  202. }
  203. getSmsCode(this.formData.mobile,this.mobileCode,this.formData.uuid).then((res) => {
  204. if (res.code === 200) {
  205. this.$dialog.alert({
  206. message: '验证码已发送',
  207. });
  208. this.formData.uuid = res.uuid;
  209. this.computeTime = 60;
  210. this.timer = setInterval(() => {
  211. this.computeTime--;
  212. if (this.computeTime <= 0) {
  213. clearInterval(this.timer);
  214. }
  215. }, 1000);
  216. }
  217. });
  218. }
  219. },
  220. handleLogin(values) {
  221. console.log(this.isSmsLogin)
  222. if (this.isSmsLogin==true) {
  223. //短信登录
  224. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  225. if (!myreg.test(this.formData.mobile)) {
  226. this.$dialog.alert({
  227. message: '手机号格式不正确',
  228. });
  229. return false;
  230. } else if (this.formData.smsCode == "") {
  231. this.$dialog.alert({
  232. message: '短信验证码不能为空',
  233. });
  234. return false;
  235. } else if (this.mobileCode == "") {
  236. this.$dialog.alert({
  237. message: '验证码不能为空',
  238. });
  239. return false;
  240. }
  241. this.loading = true;
  242. this.formData.code = this.mobileCode;
  243. this.formData.uuid = this.uuidPhone
  244. this.$store
  245. .dispatch("SmsLogin", this.formData)
  246. .then(() => {
  247. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  248. })
  249. .catch(() => {
  250. this.loading = false;
  251. });
  252. } else {
  253. if (this.formData.rememberMe) {
  254. Cookies.set("username", this.formData.username, { expires: 30 });
  255. Cookies.set("password", encrypt(this.formData.password), { expires: 30 });
  256. Cookies.set("rememberMe", this.formData.rememberMe, { expires: 30 });
  257. } else {
  258. Cookies.remove("username");
  259. Cookies.remove("password");
  260. Cookies.remove("rememberMe");
  261. }
  262. //账号密码登录
  263. if (this.formData.username == "") {
  264. this.$dialog.alert({
  265. message: '账号不能为空',
  266. });
  267. return false;
  268. } else if (this.formData.password == "") {
  269. this.$dialog.alert({
  270. message: '密码不能为空',
  271. });
  272. return false;
  273. } else if (this.code == "") {
  274. this.$dialog.alert({
  275. message: '图片验证码不能为空',
  276. });
  277. return false;
  278. }
  279. this.formData.code = this.code;
  280. this.formData.uuid = this.uuid;
  281. this.$store
  282. .dispatch("Login", this.formData)
  283. .then(() => {
  284. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  285. })
  286. .catch(() => {
  287. this.loading = false;
  288. this.getCode();
  289. });
  290. }
  291. },
  292. },
  293. };
  294. </script>
  295. <!-- Add "scoped" attribute to limit CSS to this component only -->
  296. <style scoped lang="scss">
  297. .title{
  298. padding-top: 20%;
  299. width: 88%;
  300. margin: 0 auto;
  301. }
  302. .title_one{
  303. color: #666666;
  304. font-size: 0.4rem;
  305. }
  306. .title_two{
  307. color: #007e72;
  308. font-size: 0.6rem;
  309. }
  310. .title_three{
  311. color: #FFF;
  312. font-size: 0.8rem;
  313. }
  314. .app-container {
  315. background: url("../../static/images/index/registerBg.png") no-repeat;
  316. background-size: 100% 100%;
  317. width: 100%;
  318. height: 100%;
  319. .focus-logo {
  320. width: 310px;
  321. margin: 0 auto 40px;
  322. padding-top: 60px;
  323. img {
  324. width: 100%;
  325. }
  326. .describe{
  327. text-align: center;
  328. font-size: 34px;
  329. padding:10px 0 0;
  330. color: #666;
  331. }
  332. }
  333. .login-main{
  334. width: 95%;
  335. margin: 0 auto;
  336. background: #fff;
  337. border-radius: 20px;
  338. overflow: hidden;
  339. border: 1px solid #ddd;
  340. padding-bottom:40px;
  341. margin-top: 0.4rem;
  342. }
  343. .head_nav {
  344. li {
  345. width: 50%;
  346. float: left;
  347. height: 90px;
  348. line-height: 90px;
  349. text-align: center;
  350. font-size: 30px;
  351. border-bottom: 2px solid #ddd;
  352. &.active {
  353. background: #fff;
  354. border-bottom: 2px solid #fff;
  355. color: #2386ee;
  356. }
  357. &:last-child {
  358. border-left: 2px solid #ddd;
  359. }
  360. }
  361. background: #f5f5f5;
  362. }
  363. .form_main {
  364. padding-top: 20px;
  365. .form-submit {
  366. margin: 40px 40px 0;
  367. }
  368. .code-img {
  369. width: 220px;
  370. }
  371. }
  372. .reveal-modal-con {
  373. margin: 30px 40px 0;
  374. .dd_txt {
  375. text-align: center;
  376. font-size: 28px;
  377. a {
  378. color: #FFF;
  379. }
  380. }
  381. .other-login {
  382. text-align: center;
  383. .desc {
  384. font-family: PingFangSC-Regular;
  385. font-size: 24px;
  386. color: #666;
  387. letter-spacing: 0;
  388. line-height: 30px;
  389. height: 30px;
  390. margin-top: 40px;
  391. opacity: 0.7;
  392. }
  393. .icon-other-logins {
  394. margin-top: 26px;
  395. a {
  396. &.wx {
  397. background-image: url("~@/assets/images/icon/wx.svg");
  398. }
  399. &.rlsb {
  400. background-image: url("~@/assets/images/icon/rlsb.svg");
  401. }
  402. position: relative;
  403. display: inline-block;
  404. margin: 0 12px;
  405. width: 60px;
  406. height: 60px;
  407. // border-radius: 50%;
  408. text-indent: -9999px;
  409. background-size: 100% 100%;
  410. background-repeat: no-repeat;
  411. background-position: left top;
  412. }
  413. }
  414. }
  415. }
  416. }
  417. </style>