原文:https://blog.csdn.net/qq_37782076/article/details/85123602

代码

  1. <template>
  2. <div class="content-container developer-container dev-register-container">
  3. <nav-bar
  4. :address="address"
  5. :title="title"
  6. :register="true">
  7. </nav-bar>
  8. <div class="steps">
  9. <el-steps :active="2" align-center>
  10. <el-step title="开发商信息"></el-step>
  11. <el-step title="提交资质"></el-step>
  12. <el-step title="管理员信息"></el-step>
  13. </el-steps>
  14. </div>
  15. <div class="form-list">
  16. <el-form ref="thirdForm" size="medium" label-position="right" :model="thirdForm" :rules="rules" label-width="100px">
  17. <el-form-item label="管理员姓名" prop="userName" v-if="firstForm.devpType==0">
  18. <el-input v-model.trim="thirdForm.userName" placeholder="请输入管理员姓名,最多20字" ></el-input>
  19. </el-form-item>
  20.  
  21. <el-form-item label="管理员账号" prop="account">
  22. <el-input v-model.trim="thirdForm.account" placeholder="请输入管理账号,最多50字"></el-input>
  23. </el-form-item>
  24.  
  25. <el-form-item label="登录密码" prop="password" >
  26. <el-input id="pwd" v-model.trim="thirdForm.password" type="password" placeholder="请输入长度为10-20位包含数字字母及其他特殊字符的密码" minlength="10" maxlength="20">
  27. <i slot="suffix" class="el-input__icon el-icon-view el-show" @click="showPwd"></i>
  28. </el-input>
  29. </el-form-item>
  30.  
  31. <el-form-item label="电子邮箱" prop="email">
  32. <el-input v-model.trim="thirdForm.email" placeholder="请输入电子邮箱,最多50字"></el-input>
  33. </el-form-item>
  34.  
  35. <el-form-item label="电话" prop="telephone" v-if="firstForm.devpType==0">
  36. <el-input v-model.trim="thirdForm.telephone" placeholder="请输入电话,最多50字"></el-input>
  37. </el-form-item>
  38.  
  39. <el-form-item label="传真" prop="fax" v-if="firstForm.devpType==0">
  40. <el-input v-model.trim="thirdForm.fax" placeholder="请输入传真,最多50字"></el-input>
  41. </el-form-item>
  42.  
  43. <el-form-item label="邮编" prop="postCode" v-if="firstForm.devpType==0">
  44. <el-input v-model.trim="thirdForm.postCode" placeholder="请输入邮编,最多10字" maxlength=10></el-input>
  45. </el-form-item>
  46.  
  47. <el-form-item label="手机号码" prop="phone" >
  48. <el-input v-model.trim="thirdForm.phone" placeholder="请输入手机号码" maxlength=11></el-input>
  49. </el-form-item>
  50.  
  51. <el-form-item label="图片验证码" prop="captchaCode" >
  52. <div class="vertification-area">
  53. <el-input v-model.trim="thirdForm.captchaCode" placeholder="请输入图片验证码" maxlength="10" style="margin-bottom: 0px; width: calc(100% - 110px); float: left;">
  54. </el-input>
  55. <img :src="captchaUrl" class="vertification-code" @click="refresh"/>
  56. </div>
  57. </el-form-item>
  58.  
  59. <el-form-item label="手机验证码" prop="phoneValidation" >
  60. <div>
  61. <el-input v-model.trim="thirdForm.phoneValidation" placeholder="请输入手机验证码" style="width: calc(100% - 110px);" maxlength="6"></el-input>
  62. <el-button v-show="sendAuthCode" @click="sendMsg(thirdForm.phone)" type="primary" class="sendMsg">发送验证码</el-button>
  63. <el-button v-show="!sendAuthCode" type="primary" class="sendMsg">{{auth_time}}秒</el-button>
  64. </div>
  65. </el-form-item>
  66. <el-form-item class="btn-wrap">
  67. <el-button class="previousStep" @click="previousStep()" >上一步</el-button>
  68. <el-button :disabled="this.sendAuthCode" type="primary" @click="nextStep('thirdForm')" class="submitButton">提交</el-button>
  69. </el-form-item>
  70. </el-form>
  71. </div>
  72. </div>
  73. </template>
  74.  
  75. <script>
  76. import md5 from '@/utils/MD5';
  77. import api from '@/api/mopApi';
  78. import global from '@/global';
  79. import navBar from '@/components/nav-bar';
  80. import titleBar from './basic/TitleBar';
  81.  
  82. export default {
  83. data() {
  84. return {
  85. title: '移动运营平台',
  86. address: 'title.png',
  87. sendAuthCode: true, /* 布尔值,通过v-show控制显示‘获取按钮’还是‘倒计时’ */
  88. auth_time: '120', /* 倒计时 计数器 */
  89. firstForm: {},
  90. thirdForm: {
  91. userName: '',
  92. account: '',
  93. password: '',
  94. email: '',
  95. telephone: '',
  96. fax: '',
  97. postCode: '',
  98. phone: '',
  99. phoneValidation: '',
  100. captchaCode: '',
  101. },
  102. captchaUrl: `${global.CTX}/captcha`,
  103. rules: {
  104. userName: [
  105. { required: true, message: '请输入管理员姓名', trigger: 'blur' },
  106. { min: 1, max: 20, message: '管理员姓名在20字以内', trigger: 'blur' },
  107.  
  108. ],
  109. account: [
  110. { required: true, message: '请输入管理员账号', trigger: 'blur' },
  111. { min: 1, max: 50, message: '管理员账号在50字以内', trigger: 'blur' },
  112. { pattern: /^\S+$/, message: '账号不允许有空格', trigger: 'blur' },
  113. ],
  114. password: [
  115. { required: true, message: '请输入长度为10-20位包含数字、字母、特殊字符的密码', trigger: 'blur' },
  116. { pattern: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W_]).{10,20}$/, message: '请输入长度为10-20位包含数字、字母、特殊字符的密码', trigger: 'blur' },
  117. ],
  118. postCode: [
  119. { max: 10, message: '邮编长度10位以内', trigger: 'blur' },
  120. ],
  121. fax: [
  122. { max: 50, message: '传真长度50字以内', trigger: 'blur' },
  123. ],
  124. email: [
  125. { required: true, message: '请输入邮箱', trigger: 'blur' },
  126. { max: 50, message: '邮箱在50字以内', trigger: 'blur' },
  127. { pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/, message: '请检查邮箱格式是否正确', trigger: 'blur' },
  128. ],
  129. //最后的校验规则,不需要自己写校验规则也可以写成 { type: 'email', message: '请检查邮箱格式是否正确', trigger: 'blur' },
  130. /*type的枚举值有
  131. string: Must be of type string. This is the default type.
  132. number: Must be of type number.
  133. boolean: Must be of type boolean.
  134. method: Must be of type function.
  135. regexp: Must be an instance of RegExp or a string that does not generate an exception when creating a new RegExp.
  136. integer: Must be of type number and an integer.
  137. float: Must be of type number and a floating point number.
  138. array: Must be an array as determined by Array.isArray.
  139. object: Must be of type object and not Array.isArray.
  140. enum: Value must exist in the enum.
  141. date: Value must be valid as determined by Date
  142. url: Must be of type url.
  143. hex: Must be of type hex.
  144. email: Must be of type email.
  145. https://github.com/yiminghe/async-validator#type
  146. https://www.cnblogs.com/chaoxiZ/p/10136780.html
  147. */
  148. telephone: [
  149. { max: 50, message: '电话长度在50位以内', trigger: 'blur' },
  150. ],
  151. phone: [
  152. { required: true, message: '请输入手机号码', trigger: 'blur' },
  153. { pattern: /^((1[3,5,8][0-9])|(14[5,7])|(17[0,5,6,7,8])|(19[7]))\d{8}$/, message: '请检查手机号是否正确', trigger: 'blur' },
  154. ],
  155. phoneValidation: [
  156. { required: true, message: '请输入手机验证码', trigger: 'blur' },
  157. ],
  158. captchaCode: [
  159. { required: true, message: '请输入图片验证码', trigger: 'blur' },
  160. ],
  161. },
  162. };
  163. },
  164. components: {
  165. titleBar,
  166. navBar,
  167. },
  168. methods: {
  169. // 是否显示密码
  170. showPwd() {
  171. const input = document.getElementById('pwd');
  172. if (input.type === 'password') {
  173. input.type = 'text';
  174. } else if (input.type === 'text') {
  175. input.type = 'password';
  176. }
  177. },
  178. // 刷新图片验证码
  179. refresh() {
  180. this.captchaUrl = `${global.CTX}/captcha?tm=${Math.random()}`;
  181. },
  182.  
  183. // 倒计时
  184. getAuthCode() {
  185. if (this.authTimeTimer) {
  186. clearTimeout(this.authTimeTimer);
  187. }
  188. this.authTimeTimer = setTimeout(() => {
  189. this.auth_time -= 1;
  190. if (this.auth_time < 0) {
  191. this.sendAuthCode = true;
  192. clearTimeout(this.authTimeTimer);
  193. } else {
  194. this.getAuthCode();
  195. }
  196. }, 1000);
  197. },
  198. // 发送短信
  199. sendMsg(phoneNum) {
  200. this.$refs.thirdForm.validateField('phone', (phoneError) => {
  201. console.log(`${phoneError}***************************`);
  202.  
  203. if (!phoneError) {
  204. this.auth_time = 120;
  205. this.sendAuthCode = false;
  206. api.sendMsg({
  207. params: {
  208. params: {
  209. phone: phoneNum,
  210. reason: 'developerReg',
  211. },
  212. },
  213. }).then(() => {
  214. this.getAuthCode();
  215. this.$confirm('验证码已发送至登记手机号上,请查收。', {
  216. confirmButtonText: '确定',
  217. center: true,
  218. });
  219. }).catch((err) => {
  220. this.sendAuthCode = true;
  221. this.$message({
  222. message: err.response.message,
  223. type: 'error',
  224. });
  225. });
  226. }
  227. });
  228. },
  229.  
  230. // 验证登入账号是否存在
  231. checkDevpUserAccount(account) {
  232. api.checkDevpUserAccount({
  233. params: {
  234. params: {
  235. account,
  236. },
  237. },
  238. }).then((data) => {
  239. if (data.state === 0) {
  240. this.checkCaptcha();
  241. }
  242. }).catch((err) => {
  243. this.$message({
  244. message: err.response.message,
  245. type: 'error',
  246. });
  247. });
  248. },
  249.  
  250. // 图片验证码验证是否正确
  251. checkCaptcha() {
  252. api.getCaptcha({
  253. params: {
  254. params: {
  255. captchaCode: this.thirdForm.captchaCode,
  256. },
  257. },
  258. }).then(() => {
  259. this.checkSmsValidCode();
  260. }).catch((err) => {
  261. this.$message({
  262. message: err.tip,
  263. type: 'error',
  264. });
  265. this.refresh();
  266. });
  267. },
  268.  
  269. // 验证短信验证码
  270. checkSmsValidCode() {
  271. api.verifySmsValidCode({
  272. params: {
  273. params: {
  274. phone: this.thirdForm.phone,
  275. reason: 'developerReg',
  276. validCode: this.thirdForm.phoneValidation,
  277. },
  278. },
  279. }).then((data) => {
  280. if (data.state === 0) {
  281. this.submit();
  282. }
  283. }).catch((err) => {
  284. this.$message({
  285. message: err.tip,
  286. type: 'error',
  287. });
  288. });
  289. },
  290.  
  291. // 上一步
  292. previousStep() {
  293. sessionStorage.setItem('needSecondStepCache', '1');
  294. this.$router.push({ name: 'DeveloperSecond' });
  295. },
  296. // 下一步
  297. nextStep(thirdForm) {
  298. this.$refs[thirdForm].validate((valid) => {
  299. if (valid) {
  300. this.checkDevpUserAccount(this.thirdForm.account);
  301. }
  302. });
  303. },
  304. // 向后台提交数据
  305. submit() {
  306. if (this.firstForm.devpType === '1') {
  307. this.thirdForm.userName = this.firstForm.devpNameself;
  308. }
  309. this.secondForm.cmmiLevel = (this.secondForm.cmmiLevel === '无' ? '' : this.secondForm.cmmiLevel);
  310. this.secondForm.isoLevel = (this.secondForm.isoLevel === '无' ? '' : this.secondForm.isoLevel);
  311. const passwordTemp = md5(this.thirdForm.password);
  312. api.registeredDeveloper({
  313. params: {
  314. data: {
  315. devpType: this.firstForm.devpType,
  316. devpName: this.firstForm.devpName,
  317. devpCode: this.firstForm.devpCode,
  318. logo: this.firstForm.logo,
  319. companyAddress: this.firstForm.companyAddress,
  320. companyDescrible: this.firstForm.companyDescrible,
  321. companyBusiness: this.firstForm.companyBusiness,
  322. identifyPositiveId: this.firstForm.identifyPositiveId,
  323. identifyReverseId: this.firstForm.identifyReverseId,
  324. employeeCode: this.firstForm.employeeCode,
  325. remarks: this.firstForm.remarks,
  326.  
  327. cmmiLevel: this.secondForm.cmmiLevel,
  328. isoLevel: this.secondForm.isoLevel,
  329. qualificationId: this.secondForm.qualificationId,
  330.  
  331. userName: this.thirdForm.userName,
  332. account: this.thirdForm.account,
  333. password: passwordTemp,
  334. email: this.thirdForm.email,
  335. telephone: this.thirdForm.telephone,
  336. fax: this.thirdForm.fax,
  337. postCode: this.thirdForm.postCode,
  338. phone: this.thirdForm.phone,
  339. },
  340. },
  341. }).then(() => {
  342. this.$router.push({
  343. name: 'ReturnSuccessMsg',
  344. params: {},
  345. });
  346. }).catch((err) => {
  347. this.$message({
  348. message: err.response.message,
  349. type: 'error',
  350. });
  351. });
  352. },
  353. },
  354. mounted() {
  355. this.firstForm = JSON.parse(sessionStorage.getItem('firstForm')) || {};
  356. this.secondForm = JSON.parse(sessionStorage.getItem('secondForm')) || {};
  357. },
  358. };
  359. </script>
  360.  
  361. <style scoped lang="less">
  362. .developer-container {
  363. overflow: hidden;
  364. .btn-wrap{
  365. border-top: 1px solid #EBEEF6;
  366. padding-top: 30px;
  367. font-size: 0;
  368. .previousStep{
  369. padding: 10px 28px;
  370. }
  371. .submitButton{
  372. padding: 10px 35px;
  373. }
  374. }
  375. }
  376. .fl {
  377. float: left;
  378. }
  379. .fr {
  380. float: right;
  381. }
  382. .block {
  383. float: right;
  384. margin-left: -5px;
  385. margin-top: 20px;
  386. }
  387. .disabled {
  388. cursor: default;
  389. color: #bbb;
  390. pointer-events: none;
  391. }
  392. .vertification-area {
  393. height: 36px;
  394. .vertification-code {
  395. float: left;
  396. height: 36px;
  397. line-height: 36px;
  398. width: 100px;
  399. margin-left: 10px;
  400. border-radius: 4px;
  401. color: #fff;
  402. font-size: 24px;
  403. text-align: center;
  404. font-weight: bolder;
  405. cursor: pointer;
  406. }
  407. }
  408. .el-icon-view{
  409. &:hover{
  410. cursor: pointer;
  411. }
  412. }
  413. </style>
  414. <style lang="less">
  415. .dev-register-container{
  416. .steps {
  417. padding:40px 22%;
  418. margin: 48px auto 0;
  419. background: #F9FAFC;
  420. border-bottom: 1px solid #EBEEF6;
  421. @media screen and (max-width: 1660px) {
  422. padding: 40px 16%;
  423. }
  424. @media screen and (max-width: 1280px) {
  425. padding: 40px 10%;
  426. }
  427. .el-step__line{
  428. top: 14px;
  429. }
  430. .el-step__head {
  431. .el-step__icon{
  432. width: 30px;
  433. height: 30px;
  434. font-size: 14px;
  435. border-color: #C0CCDA;
  436. color: #C0CCDA;
  437. }
  438. &.is-process{
  439. .el-step__icon{
  440. color:#fff;
  441. background: #C0CCDA;
  442. }
  443. }
  444. &.is-finish{
  445. .el-step__icon{
  446. color:#fff;
  447. background: #20A0FF;
  448. border-color: #20A0FF;
  449. }
  450. }
  451. }
  452. .el-step__title {
  453. font-size: 14px;
  454. color: #C0CCDA;
  455. font-weight: bold;
  456. &.is-process{
  457. color: #475669;
  458. }
  459. &.is-finish{
  460. color: #20A0FF;
  461. }
  462. }
  463. }
  464. .form-list {
  465. margin: 30px auto 0;
  466. max-width: 800px;
  467. width: 75%;
  468. }
  469. .sendMsg{
  470. height:36px;
  471. vertical-align:middle;
  472. width: 100px;
  473. margin-left: 5px;
  474. padding: 10px 15px;
  475. }
  476. }
  477. </style>

  

 对于表单中部分字段的校验看如下的代码,当校验不通过时phoneError返回值为校验的提示信息,当通过时phoneError的值为空,所以if语句中用(!phoneError)表示校验通过,完整代码及页面展示图如上。

  1. sendMsg(phoneNum) {
  2. this.$refs.thirdForm.validateField('phone', (phoneError) => {
  3. if(!phoneError){
  4. //当校验通过时,这里面写逻辑代码
  5. }
  6. })
  7. };
  8.  

  

validateField方法对部分表单字段进行校验的更多相关文章

  1. 如何设置织梦cms自定义表单字段为必填项

    1.编辑器打开\plus\diy.php2.在40行左右找到此行代码:$dede_fields = empty($dede_fields) ? '' : trim($dede_fields);3.在这 ...

  2. 嵌入式表单字段中的内容可能被server更改以删除不安全的内容。是否要又一次载入您的页面以查看保存结果?

    嵌入式表单字段中的内容可能被server更改以删除不安全的内容.是否要又一次载入您的页面以查看保存结果?         近期有朋友问到,当他在SharePoint首页上进行编辑时.插入一段代码. 完 ...

  3. Spring Boot 2 + Thymeleaf:表单字段绑定、表单提交处理

    Spring Boot中Thymeleaf对表单处理的一些用法:(1)使用th:field属性:进行表单字段绑定(2)使用ids对象:一般用于lable配合radio或checkbox使用(3)表单提 ...

  4. angular4 动态Form中获取表单字段并在页面中使用的方法

    主要有两种方式 第一种 使用get属性 页面中使用如下: 第二种 使用普通方法事件  页面中使用如下 *转载请附出处

  5. Magento后台表单字段添加备注

    Magento的后台表单封装的非常好,各种字段都能够直接找到方法调用.在最近的一个项目中,为客户定制了一款定时变价功能,该功能需要导入一个csv作为变价的基础.为了方便客户,我们需要在上传表单位置添加 ...

  6. Django表单字段汇总

    Field.clean(value)[source] 虽然表单字段的Field类主要使用在Form类中,但也可以直接实例化它们来使用,以便更好地了解它们是如何工作的.每个Field的实例都有一个cle ...

  7. 通过jquery.validate.js校验表单字段是否合法

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. 第四章:Django表单 - 3:Django表单字段汇总

    Field.clean(value)[source] 虽然表单字段的Field类主要使用在Form类中,但也可以直接实例化它们来使用,以便更好地了解它们是如何工作的.每个Field的实例都有一个cle ...

  9. Django:表单字段如何在模板中用中文显示

    在处理中文显示的时候,刚开始接触django时,很容易弄混表单汉化和Admin后台汉化. 1.表单汉化:是针对用户的.用户浏览网页时,表单的名称如果是英文的,不够友好,所以需要显示为中文,虽然代码编写 ...

随机推荐

  1. 201871010134-周英杰 《面向对象程序设计(java)》第十二周学习总结

    201871010134-周英杰 <面向对象程序设计(java)>第十二周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...

  2. 大宗商品市场的未来王者 | 现货贸易商PK期货风险管理子公司

    https://mp.weixin.qq.com/s/z-kkeIor6vDb9Oer73Ct6w 大宗商品市场卧虎藏龙,参与者众多,然而能称之为王者的却寥寥无几. 在国外,以嘉能可.托克.摩科瑞为代 ...

  3. 2019 SDN上机第3次作业

    1. 利用Mininet仿真平台构建如下图所示的网络拓扑,配置主机h1和h2的IP地址(h1:10.0.0.1,h2:10.0.0.2),测试两台主机之间的网络连通性 创建拓扑 配置主机h1和h2的I ...

  4. numpy cookbook

    1.第一章 import numpy as np import matplotlib.pyplot as plt import scipy import PIL import scipy.misc l ...

  5. 爬虫之获取UA模块

    from fake_useragent import UserAgent ua = UserAgent(verify_ssl=False)res = ua.randomprint(res) 注: 实列 ...

  6. 怎么删除STL容器的元素

    在STL容器有顺序容器和关联容器两种. 顺序容器删除元素的方法有两种: 1.c.erase(p) 从c中删除迭代器p指定的元素.p必须指向c中一个真实元素,不能等于c.end().返回一个指向p之后元 ...

  7. 前端Vue项目——课程详情页面实现

    一.详情页面路由跳转 应用 Vue Router 编程式导航通过 this.$router.push() 来实现路由跳转. 1.绑定查看详情事件 修改 src/components/Course/Co ...

  8. [LeetCode] 916. Word Subsets 单词子集合

    We are given two arrays A and B of words.  Each word is a string of lowercase letters. Now, say that ...

  9. [LeetCode] 647. Palindromic Substrings 回文子字符串

    Given a string, your task is to count how many palindromic substrings in this string. The substrings ...

  10. 【对不同形式矩阵的总结】WC 2009 最短路径问题(线段树+矩阵乘法)

    题意 ​ 题目链接:https://www.luogu.org/problem/P4150 ​ 一个 \(6\times n\) 的网格图,每个格点有一个初始权值.有两种操作: 修改一个格子的权值 求 ...