forgetUser.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <login-content>
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <template v-if="!scanningLogin">
  5. <div class="zap-2dcode">
  6. <!-- <img class="zap-2dcode__text" src="../assets/images/code1_1.png" alt=""> -->
  7. <!-- <img class="zap-2dcode__img" src="../assets/images/code1_2.gif" alt="" @click="scanningLogin=true"> -->
  8. </div>
  9. <el-tabs v-model="activeName" class="zap-tabs" @tab-click="changeLoginType">
  10. <el-tab-pane label="找回密码" name="login_shortMessage">
  11. <el-form-item prop="phone" v-if="!passwordUpdate">
  12. <el-input v-model="loginForm.phone" type="text" auto-complete="off" placeholder="手机号" maxlength="11">
  13. <img slot="prefix" class="zap-login__icon" src="../assets/images/register/icon_mobile.png" alt="">
  14. </el-input>
  15. </el-form-item>
  16. <el-form-item prop="shortMessageCode" v-if="!passwordUpdate">
  17. <el-input v-model="loginForm.shortMessageCode" type="text" maxlength="" auto-complete="off" placeholder="请输入验证码" class="login-code-msg" id="" onkeydown="enterHandler(event)">
  18. <img slot="prefix" class="zap-login__icon" src="../assets/images/register/icon_verify.png" alt="">
  19. <el-button class="zap-code-button" slot="suffix" @click="sendMessage" :disabled="sendShortMessageBtn">{{codeBtnWord}}</el-button>
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item style="width:100%;" v-if="!passwordUpdate">
  23. <el-button :loading="loading" class="zap-button" size="medium" type="primary" @click.native.prevent="handleLogin">
  24. <span v-if="!loading">下 一 步</span>
  25. <span v-else>请 稍 后...</span>
  26. </el-button>
  27. </el-form-item>
  28. <el-form-item prop="password" v-if="passwordUpdate">
  29. <el-input v-model="loginForm.password" type="text" auto-complete="off" placeholder="密码" maxlength="20">
  30. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  31. </el-input>
  32. </el-form-item>
  33. <el-form-item prop="again" v-if="passwordUpdate">
  34. <el-input v-model="loginForm.again" type="text" auto-complete="off" placeholder="确认密码" maxlength="20">
  35. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  36. </el-input>
  37. </el-form-item>
  38. <el-form-item style="width:100%;" v-if="passwordUpdate">
  39. <el-button :loading="loading" class="zap-button" size="medium" type="primary" @click.native.prevent="handleUpdate">
  40. <span v-if="!loading">下 一 步</span>
  41. <span v-else>请 稍 后...</span>
  42. </el-button>
  43. </el-form-item>
  44. </el-tab-pane>
  45. </el-tabs>
  46. </template>
  47. </el-form>
  48. <!-- 密码登录验证码 -->
  49. <el-dialog
  50. title="验证码"
  51. :close-on-click-modal="false"
  52. :visible.sync="codeDialogVisible"
  53. width="30%">
  54. <el-row type="flex" style="padding: 20px;">
  55. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 53%;" @keyup.enter.native="handleLogin">
  56. <img slot="prefix" class="zap-login__icon" src="../assets/images/login/icon_verify.png" alt="">
  57. </el-input>
  58. <div class="login-code">
  59. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  60. </div>
  61. </el-row>
  62. <el-row slot="footer" class="zap-dialog-footer zap-dialog-footer--small">
  63. <el-button type="primary" @click="handleImgCodeSubmit">确 定</el-button>
  64. </el-row>
  65. </el-dialog>
  66. </login-content>
  67. </template>
  68. <script>
  69. import { getCodeImg, sendShortMessage, chooseCompanyLogin, forgetUser, updateUser} from "@/api/login";
  70. import { wxImg } from "@/api/system/weChat";
  71. import Cookies from "js-cookie";
  72. import { encrypt, decrypt } from "@/utils/jsencrypt";
  73. import wxlogin from 'vue-wxlogin'
  74. import LoginContent from "@/components/LoginContent/index.vue"
  75. export default {
  76. components: {
  77. wxlogin : wxlogin,
  78. LoginContent: LoginContent
  79. },
  80. name: "Login",
  81. data() {
  82. return {
  83. //默认背景图
  84. activeName: "login_shortMessage",
  85. baseImg: require('../assets/images/login/login_illustration.png'),
  86. BackgroundImg : require('../assets/images/login/login_illustration.png'),
  87. scanningLogin: false, // 是否扫码登陆
  88. logo: '',
  89. // baseLogo: require('../assets/images/lgo.png'),
  90. codeUrl: "",
  91. cookiePassword: "",
  92. loginForm: {
  93. shortMessageCode: '',
  94. username: "",
  95. password: "",
  96. rememberMe: false,
  97. code: "",
  98. uuid: "",
  99. unionId : "",
  100. type : "2"
  101. },
  102. codeBtnWord: '获取验证码', // 获取验证码按钮文字
  103. waitTime:2, // 获取验证码按钮失效时间
  104. loginRules: {
  105. company: [
  106. {
  107. required: true,
  108. trigger: "blur",
  109. message: "企业名称不能为空",
  110. },
  111. ],
  112. username: [
  113. {
  114. required: true,
  115. trigger: "blur",
  116. message: "联系人不能为空",
  117. },
  118. ],
  119. phone: [
  120. {
  121. required: true,
  122. pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
  123. trigger: "blur",
  124. message: "请输入正确的手机号",
  125. },
  126. ],
  127. shortMessageCode: [
  128. {
  129. required: true,
  130. trigger: "blur",
  131. message: "验证码不能为空",
  132. },
  133. ],
  134. password: [
  135. {
  136. required: true,
  137. trigger: "blur",
  138. message: "密码不能为空",
  139. },
  140. ],
  141. again: [
  142. {
  143. required: true,
  144. trigger: "blur",
  145. message: "确认密码不能为空",
  146. },
  147. ],
  148. },
  149. loading: false,
  150. redirect: undefined,
  151. wxSrc: require("../assets/images/wx1.png"),
  152. sendShortMessageBtn : false,
  153. dialogVisible : false,
  154. companyList : [],
  155. chooseCompanyId : '',
  156. codeDialogVisible: false,
  157. passwordUpdate: false
  158. };
  159. },
  160. watch: {
  161. $route: {
  162. handler: function (route) {
  163. this.redirect = route.query && route.query.redirect;
  164. },
  165. immediate: true,
  166. },
  167. },
  168. created() {
  169. this.getCode();
  170. // this.getlistDomain();
  171. },
  172. methods: {
  173. changeImg(){
  174. this.wxSrc = require("../assets/images/wx.png")
  175. },
  176. returnImg(){
  177. this.wxSrc = require("../assets/images/wx1.png")
  178. },
  179. getCode() {
  180. getCodeImg().then((res) => {
  181. this.codeUrl = "data:image/gif;base64," + res.img;
  182. this.loginForm.uuid = res.uuid;
  183. });
  184. },
  185. handleImgCodeSubmit () {
  186. if (this.activeName === 'login_password') {
  187. this.handleLogin()
  188. } else {
  189. this.sendMessage()
  190. }
  191. },
  192. handleLogin() {
  193. this.$refs.loginForm.validate((valid) => {
  194. if (valid) {
  195. this.loading = true;
  196. // 验证码不能为空
  197. if (this.loginForm.shortMessageCode == null || this.loginForm.shortMessageCode == "") {
  198. this.msgError("请输入短信验证码!");
  199. this.loading = false;
  200. return;
  201. }
  202. forgetUser(this.loginForm).then((res) => {
  203. this.loading = false;
  204. this.passwordUpdate = true
  205. if (res.data.code == "0") {
  206. console.log("未认证!")
  207. this.$router.push({ path: "/login" });
  208. }
  209. }).catch(() => {
  210. this.loading = false;
  211. });
  212. }
  213. });
  214. },
  215. handleUpdate() {
  216. this.$refs.loginForm.validate((valid) => {
  217. if (valid) {
  218. this.loading = true;
  219. // 验证码不能为空
  220. if (this.loginForm.shortMessageCode == null || this.loginForm.shortMessageCode == "") {
  221. this.msgError("请输入短信验证码!");
  222. this.loading = false;
  223. return;
  224. }
  225. updateUser(this.loginForm).then((res) => {
  226. this.loading = false;
  227. this.msgSuccess("重置密码成功!");
  228. this.$router.push({ path: "/login" });
  229. }).catch(() => {
  230. this.loading = false;
  231. });
  232. }
  233. });
  234. },
  235. getUrlKey(name) {
  236. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  237. },
  238. changeLoginType(e){
  239. if (this.activeName === 'login_password') {
  240. this.loginRules.code = [
  241. {
  242. required: true,
  243. trigger: "change",
  244. message: "验证码不能为空",
  245. },
  246. ]
  247. } else {
  248. delete this.loginRules.code
  249. }
  250. this.getCode();
  251. },
  252. sendMessage(){
  253. // 验证码不能为空
  254. if (this.loginForm.phone == null || this.loginForm.phone == "") {
  255. this.msgError("请输入手机号!");
  256. this.loading = false;
  257. return;
  258. }
  259. if (this.codeDialogVisible) {
  260. if (!this.loginForm.code) {
  261. this.loading = false
  262. return this.msgError("请输入验证码!");
  263. } else {
  264. this.codeDialogVisible = false
  265. }
  266. } else {
  267. return this.codeDialogVisible = true
  268. }
  269. // 调用获取短信验证码接口
  270. sendShortMessage(this.loginForm.phone, this.loginForm.code, this.loginForm.uuid).then(response => {
  271. this.sendShortMessageBtn = true;
  272. this.msgSuccess("发送成功!");
  273. // 因为下面用到了定时器,需要保存this指向
  274. let that = this
  275. that.waitTime = 60;
  276. this.codeBtnWord = `${this.waitTime}s 后重新获取`
  277. let timer = setInterval(function(){
  278. if(that.waitTime>1){
  279. that.waitTime--
  280. that.codeBtnWord = `${that.waitTime}s 后重新获取`
  281. }else{
  282. clearInterval(timer)
  283. that.codeBtnWord = '获取验证码'
  284. that.waitTime = 60
  285. that.getCode();
  286. that.sendShortMessageBtn = false;
  287. }
  288. },1000)
  289. }).catch((response)=>{
  290. this.getCode();
  291. });
  292. },
  293. chooseLogin(){
  294. chooseCompanyLogin(this.chooseCompanyId).then(response => {
  295. if (response.code == "200") {
  296. // 认证通过
  297. if (response.data.sysUser.companyStatus == "00") {
  298. if(this.redirect == '/home'){
  299. this.$router.push({ path: "/homePage"+this.redirect || "/" });
  300. }else{
  301. this.$router.push({ path: this.redirect || "/" });
  302. }
  303. // this.$router.push({ path: this.redirect || "/" });
  304. // 认证未通过
  305. } else {
  306. console.log("未认证通过!")
  307. this.$router.push({ path: "/certification" });
  308. }
  309. }
  310. }).catch((response)=>{
  311. });
  312. }
  313. }
  314. };
  315. </script>
  316. <style rel="stylesheet/scss" lang="scss">
  317. @import "~@/assets/styles/login.scss";
  318. </style>