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

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