stepAppeal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>密码重置</p>
  5. <a href="javascript:void(0)" class="back" @click="jump('select')"><i class="el-icon-back"></i></a>
  6. </div>
  7. <div class="f-form">
  8. <div class="page-part">
  9. <mt-field placeholder="新手机号码"
  10. v-model="valid.mobile"
  11. :state="state.mobile"
  12. type="tel"
  13. @blur.native.capture="validateMobile"
  14. ></mt-field>
  15. </div>
  16. <div class="page-part">
  17. <mt-field auto-complete="off"
  18. placeholder="短信验证码"
  19. v-model="valid.token"
  20. :state="state.token"
  21. @blur.native.capture="validateCode">
  22. <span class="token" @click="getCheckCode" v-text="tokenText" v-if="state.mobile === 'success'">获取验证码</span>
  23. <span class="token-no" v-text="tokenText" v-if="state.mobile !== 'success'">获取验证码</span>
  24. </mt-field>
  25. </div>
  26. <div class="page-part">
  27. <mt-field placeholder="新密码"
  28. type="password"
  29. v-model="valid.password"
  30. :attr="{maxlength: 20}"
  31. :state="state.password"
  32. @input.native="validatePassword"
  33. @blur.native.capture="validatePasswordTip"></mt-field>
  34. <template v-if="valid.password">
  35. <p class="pwd">密码强度 <em :class="{sm:progress === '弱', md: progress === '中', ld:progress === '强'}"></em> <em :class="{md: progress === '中', ld:progress === '强'}"></em> <em :class="{ld:progress === '强'}"></em> <span :class="{smstep:progress === '弱', mdstep: progress === '中', ldstep:progress === '强'}" v-text="progress">强</span></p>
  36. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  37. </template>
  38. </div>
  39. <div class="page-part">
  40. <mt-field placeholder="确认密码"
  41. type="password"
  42. v-model="valid.confirm"
  43. auto-complete="off"
  44. :state="state.confirm"
  45. @blur.native.capture="validateConfirm"
  46. ></mt-field>
  47. </div>
  48. <div class="page-part">
  49. <mt-field placeholder="申诉说明"
  50. type="textarea"
  51. rows="4"
  52. v-model="valid.description"></mt-field>
  53. <p class="pwd">请描述您申诉的原因,并尽可能多地列举出证明此 账号为您所有的证据</p>
  54. </div>
  55. <div class="page-part">
  56. <mt-field placeholder="姓名"
  57. v-model="valid.contactName"
  58. :state="state.contactName"
  59. @blur.native.capture="validateContactName"
  60. ></mt-field>
  61. </div>
  62. <div class="page-part">
  63. <mt-field placeholder="联系电话"
  64. v-model="valid.contactTel"
  65. :state="state.contactTel"
  66. type="tel"
  67. @blur.native.capture="validateContactTel"
  68. ></mt-field>
  69. </div>
  70. <div class="page-part">
  71. <mt-field placeholder="电子邮箱"
  72. v-model="valid.contactEmail"
  73. :state="state.contactEmail"
  74. type="email"
  75. @blur.native.capture="validateContactEmail"
  76. ></mt-field>
  77. </div>
  78. <div class="page-part">
  79. <mt-button size="large" type="primary" @click="sureAccount('last')">提 交</mt-button>
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. export default {
  86. name: 'step-one',
  87. data () {
  88. return {
  89. state: {
  90. mobile: 'error',
  91. token: 'error',
  92. password: 'error',
  93. confirm: 'error',
  94. contactName: 'error',
  95. contactTel: 'error',
  96. contactEmail: 'error'
  97. },
  98. valid: {
  99. mobile: '',
  100. token: '',
  101. password: '',
  102. confirm: '',
  103. description: '',
  104. contactName: '',
  105. contactTel: '',
  106. contactEmail: ''
  107. },
  108. tokenCode: '',
  109. tokenTime: 60,
  110. tokenText: '获取验证码',
  111. progress: '弱'
  112. }
  113. },
  114. methods: {
  115. jump (type) {
  116. this.$emit('stepEvent', type)
  117. },
  118. // 弹窗处理
  119. downToast (type) {
  120. this.$toast({
  121. message: type,
  122. iconClass: 'el-icon-warning'
  123. })
  124. },
  125. // 验证手机号
  126. validateMobile () {
  127. let reg = /^1[0-9]{10}$/
  128. if (!this.valid.mobile) {
  129. this.downToast('请先填写手机号')
  130. this.state.mobile = 'error'
  131. } else {
  132. if (!reg.test(this.valid.mobile)) {
  133. this.downToast('请填写正确的手机号')
  134. this.state.mobile = 'warning'
  135. } else {
  136. this.state.mobile = 'success'
  137. }
  138. }
  139. },
  140. // 验证正确的验证码
  141. validateCode () {
  142. if (!this.valid.token) {
  143. this.downToast('请先填写验证码')
  144. this.state.token = 'error'
  145. } else {
  146. if (!this.valid.mobile) {
  147. this.downToast('请先填写正确的手机号码')
  148. this.state.token = 'warning'
  149. } else {
  150. if (this.tokenCode) {
  151. let param = new FormData()
  152. param.append('mobile', this.valid.mobile)
  153. param.append('token', this.tokenCode)
  154. param.append('code', this.valid.token)
  155. let config = {
  156. headers: {'Content-Type': 'multipart/form-data'}
  157. }
  158. this.$http.post('/appeal/check/mobile', param, config)
  159. .then(response => {
  160. if (response.data.success) {
  161. this.state.token = 'success'
  162. } else {
  163. this.$toast({
  164. message: response.data.errMsg,
  165. iconClass: 'el-icon-error'
  166. })
  167. }
  168. }).catch((err) => {
  169. this.downToast(err.errMsg)
  170. })
  171. } else {
  172. this.downToast('请点击先获取验证码信息')
  173. this.state.token = 'warning'
  174. }
  175. }
  176. }
  177. },
  178. // 获取验证码
  179. getCheckCode () {
  180. if (this.tokenTime > 0 && this.tokenTime < 60) {
  181. this.downToast('请稍后再点击,我在倒计时')
  182. } else {
  183. if (this.state.mobile === 'success') {
  184. this.$indicator.open('获取中...')
  185. let _this = this
  186. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.valid.mobile}})
  187. .then(response => {
  188. this.$indicator.close()
  189. if (response.data) {
  190. this.tokenCode = response.data.token
  191. this.$toast({
  192. message: '验证码已经发送到您的手机,请注意查收',
  193. iconClass: 'el-icon-success'
  194. })
  195. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  196. let setTime = setInterval(() => {
  197. _this.tokenTime--
  198. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  199. if (this.tokenTime <= 0) {
  200. clearInterval(setTime)
  201. _this.tokenText = '获取验证码'
  202. _this.tokenTime = 60
  203. }
  204. }, 1000)
  205. }
  206. }).catch((err) => {
  207. this.$indicator.close()
  208. this.downToast(err.errMsg)
  209. })
  210. }
  211. }
  212. },
  213. // 验证密码强度
  214. validatePassword () {
  215. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  216. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  217. if (reg1.test(this.valid.password)) {
  218. this.progress = '强'
  219. } else if (reg2.test(this.valid.password)) {
  220. this.progress = '中'
  221. } else {
  222. this.progress = '弱'
  223. }
  224. },
  225. // 验证密码
  226. validatePasswordTip () {
  227. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  228. if (!this.valid.password) {
  229. this.downToast('请输入密码')
  230. this.state.password = 'error'
  231. } else {
  232. if (!reg2.test(this.valid.password)) {
  233. this.downToast('密码须为8-20字符的英文、数字混合')
  234. this.state.password = 'warning'
  235. } else {
  236. this.state.password = 'success'
  237. if (this.valid.confirm) {
  238. this.validateConfirm()
  239. }
  240. }
  241. }
  242. },
  243. // 验证二次密码
  244. validateConfirm () {
  245. if (!this.valid.confirm) {
  246. this.downToast('请再次输入密码')
  247. this.state.confirm = 'error'
  248. } else {
  249. if (this.valid.confirm === this.valid.password) {
  250. this.state.confirm = 'success'
  251. } else {
  252. this.state.confirm = 'warning'
  253. this.downToast('两次输入密码不一致,请重新输入')
  254. }
  255. }
  256. },
  257. // 验证姓名
  258. validateContactName () {
  259. if (!this.valid.contactName) {
  260. this.downToast('请填写您的姓名')
  261. this.state.contactName = 'error'
  262. } else {
  263. if (this.valid.contactName.length > 20) {
  264. this.downToast('输入长度过长,限定20个字符以内')
  265. this.state.contactName = 'warning'
  266. } else {
  267. this.state.contactName = 'success'
  268. }
  269. }
  270. },
  271. // 验证电话
  272. validateContactTel () {
  273. let reg = /^1[0-9]{10}$/
  274. if (!this.valid.contactTel) {
  275. this.downToast('请填写联系电话')
  276. this.state.contactTel = 'error'
  277. } else {
  278. if (!reg.test(this.valid.contactTel)) {
  279. this.downToast('请填写正确的联系电话')
  280. this.state.contactTel = 'warning'
  281. } else {
  282. this.state.contactTel = 'success'
  283. }
  284. }
  285. },
  286. // 验证邮箱
  287. validateContactEmail () {
  288. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  289. if (!this.valid.contactEmail) {
  290. this.downToast('请填写联系电子邮箱')
  291. this.state.contactEmail = 'error'
  292. } else {
  293. if (!reg.test(this.valid.contactEmail)) {
  294. this.downToast('请输入正确的邮箱地址格式')
  295. this.state.contactEmail = 'warning'
  296. } else {
  297. this.state.contactEmail = 'success'
  298. }
  299. }
  300. },
  301. sureAccount (type) {
  302. if (this.state.mobile !== 'success' ||
  303. this.state.token !== 'success' ||
  304. this.state.password !== 'success' ||
  305. this.state.confirm !== 'success' ||
  306. this.state.contactName !== 'success' ||
  307. this.state.contactTel !== 'success' ||
  308. this.state.contactEmail !== 'success') {
  309. this.downToast('请确认填写部分是否有误')
  310. } else {
  311. this.$indicator.open('验证过程中...')
  312. let param = new FormData()
  313. param.append('mobile', this.valid.mobile)
  314. param.append('code', this.valid.token)
  315. param.append('password', this.valid.password)
  316. param.append('description', this.valid.description)
  317. param.append('contactName', this.valid.contactName)
  318. param.append('contactTel', this.valid.contactTel)
  319. param.append('contactEmail', this.valid.contactEmail)
  320. param.append('token', this.tokenCode)
  321. let config = {
  322. headers: {'Content-Type': 'multipart/form-data'}
  323. }
  324. this.$http.post('/appeal/resetPwd', param, config)
  325. .then(response => {
  326. this.$indicator.close()
  327. if (response.data.success) {
  328. this.$emit('stepEvent', type)
  329. this.$emit('lastEvent', 'appeal')
  330. } else {
  331. this.downToast(response.data.errMsg)
  332. }
  333. }).catch((err) => {
  334. this.$indicator.close()
  335. this.downToast(err.errMsg)
  336. })
  337. }
  338. }
  339. }
  340. }
  341. </script>