registerUser.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  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. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  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. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  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. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  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. <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">
  34. <el-input v-model="loginForm.again" type="password" auto-complete="off" placeholder="确认密码" maxlength="12">
  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>
  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",
  143. message: "企业名称不能为空",
  144. },
  145. ],
  146. username: [
  147. {
  148. required: true,
  149. trigger: "blur",
  150. message: "联系人不能为空",
  151. },
  152. ],
  153. phone: [
  154. {
  155. required: true,
  156. pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
  157. trigger: "blur",
  158. message: "请输入正确的手机号",
  159. },
  160. ],
  161. shortMessageCode: [
  162. {
  163. required: true,
  164. trigger: "blur",
  165. message: "验证码不能为空",
  166. },
  167. ],
  168. password: [
  169. {
  170. required: true,
  171. pattern: /^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]{6,12}$/,
  172. trigger: "blur",
  173. message: "密码必须由字母、数字组成,区分大小写",
  174. },
  175. ],
  176. again: [
  177. {
  178. required: true,
  179. trigger: "blur",
  180. message: "确认密码不能为空",
  181. },
  182. { required: true, validator: equalToPassword, trigger: "blur" }
  183. ],
  184. },
  185. loading: false,
  186. redirect: undefined,
  187. wxSrc: require("../assets/images/wx1.png"),
  188. sendShortMessageBtn : false,
  189. dialogVisible : false,
  190. companyList : [],
  191. chooseCompanyId : '',
  192. codeDialogVisible: false
  193. };
  194. },
  195. watch: {
  196. $route: {
  197. handler: function (route) {
  198. this.redirect = route.query && route.query.redirect;
  199. },
  200. immediate: true,
  201. },
  202. },
  203. created() {
  204. this.getCode();
  205. // this.getlistDomain();
  206. },
  207. methods: {
  208. changeImg(){
  209. this.wxSrc = require("../assets/images/wx.png")
  210. },
  211. returnImg(){
  212. this.wxSrc = require("../assets/images/wx1.png")
  213. },
  214. getCode() {
  215. getCodeImg().then((res) => {
  216. this.codeUrl = "data:image/gif;base64," + res.img;
  217. this.loginForm.uuid = res.uuid;
  218. });
  219. },
  220. handleImgCodeSubmit () {
  221. if (this.activeName === 'login_password') {
  222. this.handleLogin()
  223. } else {
  224. this.sendMessage()
  225. }
  226. },
  227. handleLogin() {
  228. this.$refs.loginForm.validate((valid) => {
  229. if (valid) {
  230. this.loading = true;
  231. // 验证码不能为空
  232. if (this.loginForm.shortMessageCode == null || this.loginForm.shortMessageCode == "") {
  233. this.msgError("请输入短信验证码!");
  234. this.loading = false;
  235. return;
  236. }
  237. if (!this.loginForm.checked) {
  238. this.msgError("请阅读平台协议并确认");
  239. this.loading = false;
  240. return;
  241. }
  242. this.loginForm.type = "2";
  243. registerUser(this.loginForm).then((res) => {
  244. this.loading = false;
  245. if (res.data.code == "0") {
  246. console.log("未认证!")
  247. this.$router.push({ path: "/login" });
  248. }
  249. }).catch(() => {
  250. this.loading = false;
  251. });
  252. }
  253. });
  254. },
  255. getUrlKey(name) {
  256. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  257. },
  258. changeLoginType(e){
  259. if (this.activeName === 'login_password') {
  260. this.loginRules.code = [
  261. {
  262. required: true,
  263. trigger: "change",
  264. message: "验证码不能为空",
  265. },
  266. ]
  267. } else {
  268. delete this.loginRules.code
  269. }
  270. this.getCode();
  271. },
  272. sendMessage(){
  273. // 验证码不能为空
  274. if (this.loginForm.phone == null || this.loginForm.phone == "") {
  275. this.msgError("请输入手机号!");
  276. this.loading = false;
  277. return;
  278. }
  279. if (this.codeDialogVisible) {
  280. if (!this.loginForm.code) {
  281. this.loading = false
  282. return this.msgError("请输入验证码!");
  283. } else {
  284. this.codeDialogVisible = false
  285. }
  286. } else {
  287. return this.codeDialogVisible = true
  288. }
  289. // 调用获取短信验证码接口
  290. sendShortMessage(this.loginForm.phone, this.loginForm.code, this.loginForm.uuid).then(response => {
  291. this.sendShortMessageBtn = true;
  292. this.msgSuccess("发送成功!");
  293. // 因为下面用到了定时器,需要保存this指向
  294. let that = this
  295. that.waitTime = 60;
  296. this.codeBtnWord = `${this.waitTime}s 后重新获取`
  297. let timer = setInterval(function(){
  298. if(that.waitTime>1){
  299. that.waitTime--
  300. that.codeBtnWord = `${that.waitTime}s 后重新获取`
  301. }else{
  302. clearInterval(timer)
  303. that.codeBtnWord = '获取验证码'
  304. that.waitTime = 60
  305. that.getCode();
  306. that.sendShortMessageBtn = false;
  307. }
  308. },1000)
  309. }).catch((response)=>{
  310. this.getCode();
  311. });
  312. },
  313. chooseLogin(){
  314. chooseCompanyLogin(this.chooseCompanyId).then(response => {
  315. if (response.code == "200") {
  316. // 认证通过
  317. if (response.data.sysUser.companyStatus == "00") {
  318. if(this.redirect == '/home'){
  319. this.$router.push({ path: "/homePage"+this.redirect || "/" });
  320. }else{
  321. this.$router.push({ path: this.redirect || "/" });
  322. }
  323. // this.$router.push({ path: this.redirect || "/" });
  324. // 认证未通过
  325. } else {
  326. console.log("未认证通过!")
  327. this.$router.push({ path: "/certification" });
  328. }
  329. }
  330. }).catch((response)=>{
  331. });
  332. }
  333. }
  334. };
  335. </script>
  336. <style rel="stylesheet/scss" lang="scss">
  337. @import "~@/assets/styles/login.scss";
  338. </style>