移动端
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.
 
 

344 lines
11 KiB

  1. <template>
  2. <div class="home_wrapper">
  3. <div class="focus_head">
  4. </div>
  5. <div class="focus_info">
  6. <div class="icon"></div>
  7. <div class="title"></div>
  8. </div>
  9. <van-form @submit="handleLogin">
  10. <div class="login_from">
  11. <div class="flex_block">
  12. <div class="flex_input_main">
  13. <div class="icon_wrap user"></div>
  14. <div class="input_wrap">
  15. <input type="text" v-model="formData.username" class="ipt" placeholder="用户名"/>
  16. </div>
  17. </div>
  18. </div>
  19. <div class="flex_block">
  20. <div class="flex_input_main">
  21. <div class="icon_wrap password"></div>
  22. <div class="input_wrap">
  23. <input :type="show ? 'password' : 'text'" v-model="formData.password" class="ipt" maxlength="16" placeholder="密码"/>
  24. </div>
  25. <div :class="{'showHidden':true,'ico_hide':show}" @click="showPassword"></div>
  26. </div>
  27. </div>
  28. <div class="flex_block">
  29. <div class="flex_input_main valid">
  30. <div class="icon_wrap valid"></div>
  31. <div class="input_wrap">
  32. <input type="text" v-model="formData.code" class="ipt" maxlength="4" placeholder="请输入验证码"/>
  33. </div>
  34. </div>
  35. <div class="valid_main">
  36. <img :src="codeUrl" @click="getCode" />
  37. </div>
  38. </div>
  39. <van-checkbox v-model="formData.rememberMe" shape="square">记住密码</van-checkbox>
  40. </div>
  41. <div class="login_btn">
  42. <!-- <div class="btn" :loading="loading">登录</div>-->
  43. <van-button
  44. class="btn"
  45. round
  46. block
  47. type="info"
  48. native-type="submit"
  49. :loading="loading"
  50. >登录</van-button>
  51. </div>
  52. </van-form>
  53. </div>
  54. </template>
  55. <script>
  56. import { getCodeImg, getSmsCode } from "@/api/login";
  57. import Cookies from "js-cookie";
  58. import { encrypt, decrypt } from "../../utils/jsencrypt";
  59. //引用wx sdk
  60. import wx from "weixin-js-sdk";
  61. export default {
  62. name: "login",
  63. data() {
  64. return {
  65. formData: {
  66. username: "", //账号
  67. password: "", //密码
  68. // username:'',
  69. // password:'',
  70. code: null, //图片验证码
  71. uuid: null, //识别uuid
  72. mobile: null, //手机号
  73. smsCode: null, //短信验证码
  74. rememberMe:false
  75. },
  76. loading: false,
  77. codeUrl: "", //验证码
  78. isSmsLogin: false, //是否手机验证码
  79. computeTime: 0,
  80. height:0,
  81. show:true
  82. };
  83. },
  84. created() {
  85. this.getCode();
  86. this.height = document.body.clientHeight
  87. this.getCookie();
  88. //调用微信公众号方法
  89. // wx.config({
  90. // debug: true, // 开启调试模式,
  91. // appId: res.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
  92. // timestamp: res.timestamp, // 必填,生成签名的时间戳
  93. // nonceStr: res.nonceStr, // 必填,生成签名的随机串
  94. // signature: res.signature,// 必填,签名,见附录1
  95. // jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  96. // });
  97. //分享要用encodeURIComponent()方法
  98. },
  99. methods: {
  100. showPassword(){
  101. this.show = !this.show;
  102. },
  103. getCode() {
  104. getCodeImg().then((res) => {
  105. this.formData.uuid = res.uuid;
  106. this.codeUrl = "data:image/gif;base64," + res.img;
  107. });
  108. },
  109. getCookie() {
  110. const username = Cookies.get("username");
  111. const password = Cookies.get("password");
  112. const rememberMe = Cookies.get("rememberMe");
  113. this.formData = {
  114. username: username === undefined ? this.formData.username : username,
  115. password:
  116. password === undefined ? this.formData.password : decrypt(password),
  117. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  118. };
  119. },
  120. getSmsCode() {
  121. if (!this.computeTime) {
  122. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  123. if (!myreg.test(this.formData.mobile)) {
  124. this.$dialog.alert({
  125. message: '手机号格式不正确',
  126. });
  127. return false;
  128. }
  129. getSmsCode(this.formData.mobile).then((res) => {
  130. if (res.code === 200) {
  131. this.$dialog.alert({
  132. message: '验证码已发送',
  133. });
  134. this.loginForm.uuid = res.uuid;
  135. this.computeTime = 60;
  136. this.timer = setInterval(() => {
  137. this.computeTime--;
  138. if (this.computeTime <= 0) {
  139. clearInterval(this.timer);
  140. }
  141. }, 1000);
  142. }
  143. });
  144. }
  145. },
  146. handleLogin(values) {
  147. console.log(this.formData.username)
  148. console.log(this.formData.password)
  149. if (this.isSmsLogin) {
  150. //短信登录
  151. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  152. if (!myreg.test(this.formData.mobile)) {
  153. this.$dialog.alert({
  154. message: '手机号格式不正确',
  155. });
  156. return false;
  157. } else if (this.formData.smsCode == "") {
  158. this.$dialog.alert({
  159. message: '短信验证码不能为空',
  160. });
  161. return false;
  162. }
  163. this.loading = true;
  164. this.$store
  165. .dispatch("SmsLogin", this.formData)
  166. .then(() => {
  167. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  168. })
  169. .catch(() => {
  170. this.loading = false;
  171. });
  172. } else {
  173. if (this.formData.rememberMe) {
  174. Cookies.set("username", this.formData.username, { expires: 30 });
  175. Cookies.set("password", encrypt(this.formData.password), { expires: 30 });
  176. Cookies.set("rememberMe", this.formData.rememberMe, { expires: 30 });
  177. } else {
  178. Cookies.remove("username");
  179. Cookies.remove("password");
  180. Cookies.remove("rememberMe");
  181. }
  182. //账号密码登录
  183. if (this.formData.username == "") {
  184. this.$dialog.alert({
  185. message: '账号不能为空',
  186. });
  187. return false;
  188. } else if (this.formData.password == "") {
  189. this.$dialog.alert({
  190. message: '密码不能为空',
  191. });
  192. return false;
  193. } else if (this.formData.code == "") {
  194. this.$dialog.alert({
  195. message: '图片验证码不能为空',
  196. });
  197. return false;
  198. }
  199. this.$store
  200. .dispatch("Login", this.formData)
  201. .then(() => {
  202. this.$router.push({ name: 'sunVillageInfoIndex' || "/" }).catch(() => {});
  203. })
  204. .catch(() => {
  205. this.loading = false;
  206. this.getCode();
  207. });
  208. }
  209. },
  210. },
  211. };
  212. </script>
  213. <style scoped lang="scss">
  214. /deep/ .van-checkbox__label{
  215. color: #ffffff;
  216. }
  217. .home_wrapper{
  218. background: #f1f2f2;
  219. width: 100vw;
  220. min-height: 100vh;
  221. .focus_head{
  222. height: 450px;
  223. background: url('../../assets/images/sunVillage_info/login_head.png') no-repeat;
  224. background-size: 100% 100%;
  225. }
  226. .focus_info{
  227. margin-top: -74px;
  228. .icon{
  229. background: url('../../assets/images/sunVillage_info/login_head_t.png') no-repeat;
  230. background-size: 100% 100%;
  231. width: 145px;
  232. height: 148px;
  233. margin:0 auto;
  234. }
  235. .title{
  236. width: 284px;
  237. height: 52px;
  238. background: url('../../assets/images/sunVillage_info/login_head_nr.png') no-repeat;
  239. background-size: 100% 100%;
  240. margin:30px auto 0;
  241. }
  242. }
  243. .login_from{
  244. width: 676px;
  245. height: 450px;
  246. background: url('../../assets/images/sunVillage_info/login_main.png') no-repeat;
  247. background-size: 100% 100%;
  248. margin: 50px auto 0;
  249. padding:60px 50px 0;
  250. .flex_block{
  251. margin-bottom: 40px;
  252. display: flex;
  253. justify-content:space-between;
  254. .flex_input_main{
  255. position: relative;
  256. display: flex;
  257. flex: 1;
  258. align-items:center;
  259. background: rgba(255,255,255,0.7);
  260. border-radius: 62px;
  261. height: 62px;
  262. .icon_wrap{
  263. width: 35px;
  264. height: 35px;
  265. &.user{
  266. background: url('../../assets/images/sunVillage_info/login_icon_1.png') no-repeat;
  267. background-size: 100% 100%;
  268. margin-left: 30px;
  269. }
  270. &.password{
  271. background: url('../../assets/images/sunVillage_info/login_icon_2.png') no-repeat;
  272. background-size: 100% 100%;
  273. margin-left: 30px;
  274. }
  275. &.valid{
  276. background: url('../../assets/images/sunVillage_info/login_icon_3.png') no-repeat;
  277. background-size: 100% 100%;
  278. margin-left: 30px;
  279. }
  280. }
  281. .input_wrap{
  282. flex: 1;
  283. margin-left: 16px;
  284. padding-right: 30px;
  285. .ipt{
  286. width: 100%;
  287. height: 48px;
  288. background:transparent;
  289. font-size: 30px;
  290. color: #3f3d56;
  291. }
  292. }
  293. .showHidden{
  294. width: 32px;
  295. height: 32px;
  296. background: url('../../assets/images/sunVillage_info/login_icon_4.png') no-repeat;
  297. background-size: 100% 100%;
  298. position: absolute;
  299. right: 38px;
  300. cursor: pointer;
  301. &.ico_hide{
  302. background: url('../../assets/images/sunVillage_info/login_icon_5.png') no-repeat;
  303. background-size: 100% 100%;
  304. }
  305. }
  306. &.valid{
  307. flex:0 0 380px;
  308. }
  309. }
  310. .valid_main{
  311. width: 165px;
  312. height: 62px;
  313. border-radius: 30px;
  314. img{
  315. width: 100%;
  316. height: 100%;
  317. border-radius: 30px;
  318. }
  319. }
  320. }
  321. }
  322. .login_btn{
  323. padding-top: 80px;
  324. .btn{
  325. width: 315px;
  326. height: 70px;
  327. background:url('../../assets/images/sunVillage_info/login_btn.png') no-repeat;
  328. background-size: 100% 100%;
  329. margin:0 auto;
  330. font-size: 32px;
  331. color: #fff;
  332. line-height: 70px;
  333. text-align: center;
  334. border: none;
  335. }
  336. }
  337. }
  338. </style>