registerUser.vue 15 KB

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