移动端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

login.vue 8.7 KiB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="app-container">
  3. <div class="focus-logo">
  4. <img src="@/assets/images/login-logo.png" />
  5. <p class="describe">登录页</p>
  6. </div>
  7. <div class="login-main">
  8. <ul class="head_nav clear">
  9. <li @click="isSmsLogin = false" :class="{ active: !isSmsLogin }">
  10. 账号登录
  11. </li>
  12. <li @click="isSmsLogin = true" :class="{ active: isSmsLogin }">
  13. 验证码登录
  14. </li>
  15. </ul>
  16. <div class="form_main">
  17. <van-form @submit="handleLogin">
  18. <div v-show="!isSmsLogin">
  19. <van-field
  20. v-model="formData.username"
  21. name="username"
  22. label="用户名"
  23. placeholder="用户名"
  24. />
  25. <van-field
  26. v-model="formData.password"
  27. type="password"
  28. name="password"
  29. label="密码"
  30. placeholder="密码"
  31. />
  32. <van-field
  33. v-model="formData.code"
  34. center
  35. clearable
  36. label="验证码"
  37. placeholder="图形验证码"
  38. >
  39. <template #button>
  40. <img class="code-img" :src="codeUrl" @click="getCode" />
  41. </template>
  42. </van-field>
  43. </div>
  44. <div v-show="isSmsLogin">
  45. <van-field
  46. v-model="formData.mobile"
  47. label="手机号"
  48. placeholder="请输入手机号码"
  49. />
  50. <van-field
  51. v-model="formData.smsCode"
  52. center
  53. clearable
  54. label="短信验证码"
  55. placeholder="请输入短信验证码"
  56. >
  57. <template #button>
  58. <van-button
  59. size="small"
  60. type="primary"
  61. @click.native.prevent="getSmsCode"
  62. >{{
  63. computeTime > 0 ? `(${computeTime}s)已发送` : "获取验证码"
  64. }}</van-button
  65. >
  66. </template>
  67. </van-field>
  68. </div>
  69. <div class="form-submit">
  70. <van-button
  71. round
  72. block
  73. type="info"
  74. native-type="submit"
  75. :loading="loading"
  76. >登录</van-button
  77. >
  78. </div>
  79. </van-form>
  80. </div>
  81. </div>
  82. <div class="reveal-modal-con">
  83. <div class="dd_txt">
  84. <router-link to="/register">注册账户</router-link>
  85. </div>
  86. <div class="other-login">
  87. <p class="desc">—— 更多登录方式 ——</p>
  88. <p class="icon-other-logins">
  89. <router-link class="wx" to="/"></router-link>
  90. <router-link class="rlsb" to="/"></router-link>
  91. </p>
  92. </div>
  93. </div>
  94. </div>
  95. </template>
  96. <script>
  97. import { getCodeImg, getSmsCode } from "@/api/login";
  98. import Cookies from "js-cookie";
  99. //引用wx sdk
  100. import wx from "weixin-js-sdk";
  101. export default {
  102. name: "login",
  103. data() {
  104. return {
  105. formData: {
  106. username: "admin", //账号
  107. password: "admin123", //密码
  108. // username:'',
  109. // password:'',
  110. code: null, //图片验证码
  111. uuid: null, //识别uuid
  112. mobile: null, //手机号
  113. smsCode: null, //短信验证码
  114. },
  115. loading: false,
  116. codeUrl: "", //验证码
  117. isSmsLogin: false, //是否手机验证码
  118. computeTime: 0,
  119. };
  120. },
  121. created() {
  122. this.getCode();
  123. //调用微信公众号方法
  124. // wx.config({
  125. // debug: true, // 开启调试模式,
  126. // appId: res.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
  127. // timestamp: res.timestamp, // 必填,生成签名的时间戳
  128. // nonceStr: res.nonceStr, // 必填,生成签名的随机串
  129. // signature: res.signature,// 必填,签名,见附录1
  130. // jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  131. // });
  132. //分享要用encodeURIComponent()方法
  133. },
  134. methods: {
  135. getCode() {
  136. getCodeImg().then((res) => {
  137. this.formData.uuid = res.uuid;
  138. this.codeUrl = "data:image/gif;base64," + res.img;
  139. });
  140. },
  141. getSmsCode() {
  142. if (!this.computeTime) {
  143. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  144. if (!myreg.test(this.formData.mobile)) {
  145. this.$dialog.alert({
  146. message: '手机号格式不正确',
  147. });
  148. return false;
  149. }
  150. getSmsCode(this.formData.mobile).then((res) => {
  151. if (res.code === 200) {
  152. this.$dialog.alert({
  153. message: '验证码已发送',
  154. });
  155. this.loginForm.uuid = res.uuid;
  156. this.computeTime = 60;
  157. this.timer = setInterval(() => {
  158. this.computeTime--;
  159. if (this.computeTime <= 0) {
  160. clearInterval(this.timer);
  161. }
  162. }, 1000);
  163. }
  164. });
  165. }
  166. },
  167. handleLogin(values) {
  168. if (this.isSmsLogin) {
  169. //短信登录
  170. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  171. if (!myreg.test(this.formData.mobile)) {
  172. this.$dialog.alert({
  173. message: '手机号格式不正确',
  174. });
  175. return false;
  176. } else if (this.formData.smsCode == "") {
  177. this.$dialog.alert({
  178. message: '短信验证码不能为空',
  179. });
  180. return false;
  181. }
  182. this.loading = true;
  183. this.$store
  184. .dispatch("SmsLogin", this.formData)
  185. .then(() => {
  186. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  187. })
  188. .catch(() => {
  189. this.loading = false;
  190. });
  191. } else {
  192. //账号密码登录
  193. if (this.formData.username == "") {
  194. this.$dialog.alert({
  195. message: '账号不能为空',
  196. });
  197. return false;
  198. } else if (this.formData.password == "") {
  199. this.$dialog.alert({
  200. message: '密码不能为空',
  201. });
  202. return false;
  203. } else if (this.formData.code == "") {
  204. this.$dialog.alert({
  205. message: '图片验证码不能为空',
  206. });
  207. return false;
  208. }
  209. this.$store
  210. .dispatch("Login", this.formData)
  211. .then(() => {
  212. this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  213. })
  214. .catch(() => {
  215. this.loading = false;
  216. this.getCode();
  217. });
  218. }
  219. },
  220. },
  221. };
  222. </script>
  223. <!-- Add "scoped" attribute to limit CSS to this component only -->
  224. <style scoped lang="scss">
  225. .app-container {
  226. .focus-logo {
  227. width: 310px;
  228. margin: 0 auto 40px;
  229. padding-top: 60px;
  230. img {
  231. width: 100%;
  232. }
  233. .describe{
  234. text-align: center;
  235. font-size: 34px;
  236. padding:10px 0 0;
  237. color: #666;
  238. }
  239. }
  240. .login-main{
  241. width: 95%;
  242. margin: 0 auto;
  243. background: #fff;
  244. border-radius: 20px;
  245. overflow: hidden;
  246. border: 1px solid #ddd;
  247. padding-bottom:40px;
  248. }
  249. .head_nav {
  250. li {
  251. width: 50%;
  252. float: left;
  253. height: 90px;
  254. line-height: 90px;
  255. text-align: center;
  256. font-size: 30px;
  257. border-bottom: 2px solid #ddd;
  258. &.active {
  259. background: #fff;
  260. border-bottom: 2px solid #fff;
  261. color: #2386ee;
  262. }
  263. &:last-child {
  264. border-left: 2px solid #ddd;
  265. }
  266. }
  267. background: #f5f5f5;
  268. }
  269. .form_main {
  270. padding-top: 20px;
  271. .form-submit {
  272. margin: 40px 40px 0;
  273. }
  274. .code-img {
  275. width: 220px;
  276. }
  277. }
  278. .reveal-modal-con {
  279. margin: 30px 40px 0;
  280. .dd_txt {
  281. text-align: center;
  282. font-size: 28px;
  283. a {
  284. color: #666;
  285. }
  286. }
  287. .other-login {
  288. text-align: center;
  289. .desc {
  290. font-family: PingFangSC-Regular;
  291. font-size: 24px;
  292. color: #666;
  293. letter-spacing: 0;
  294. line-height: 30px;
  295. height: 30px;
  296. margin-top: 40px;
  297. opacity: 0.7;
  298. }
  299. .icon-other-logins {
  300. margin-top: 26px;
  301. a {
  302. &.wx {
  303. background-image: url("~@/assets/images/icon/wx.svg");
  304. }
  305. &.rlsb {
  306. background-image: url("~@/assets/images/icon/rlsb.svg");
  307. }
  308. position: relative;
  309. display: inline-block;
  310. margin: 0 12px;
  311. width: 60px;
  312. height: 60px;
  313. // border-radius: 50%;
  314. text-indent: -9999px;
  315. background-size: 100% 100%;
  316. background-repeat: no-repeat;
  317. background-position: left top;
  318. }
  319. }
  320. }
  321. }
  322. }
  323. </style>