editPassword.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <!-- 修改密码 -->
  2. <template>
  3. <view id="editPassword">
  4. <view class="page-title">修改密码</view>
  5. <view class="input-disabled-box">
  6. <view>手机号</view>
  7. <view>{{form.mobile}}</view>
  8. </view>
  9. <view class="input-button-max-box">
  10. <view>手机验证码</view>
  11. <view class="input-button-box">
  12. <input maxlength="6" v-model="form.captcha" focus placeholder="请输入手机验证码"/>
  13. <view @click="getCode()"
  14. :class="codeType?'checkButton':'noCheckButton'">
  15. {{codeType?seconds+'秒后重试':'获取验证码'}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="input-max-box">
  20. <view>新密码</view>
  21. <input type="password" maxlength="16" v-model="form.newPassword" focus placeholder="请输入新密码"/>
  22. </view>
  23. <view class="input-max-box">
  24. <view>确认新密码</view>
  25. <input type="password" maxlength="16" v-model="form.confirmPassword" focus placeholder="请再次输入确认密码"/>
  26. </view>
  27. <view class="bottom-button-box">
  28. <view @click="outButton()">稍后修改</view>
  29. <view @click="submitButton()">确定修改</view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import md5 from '@/utils/md5.js'
  35. import {
  36. systemUserDetail,
  37. authNumCaptcha,
  38. authForgetPassword,
  39. } from '@/pages_basics/api/index.js'
  40. export default {
  41. data() {
  42. return {
  43. form:{
  44. mobile:"",
  45. captcha:"",
  46. newPassword:"",
  47. confirmPassword:"",
  48. },
  49. codeType:false,
  50. seconds:0,
  51. timer:null,
  52. }
  53. },
  54. onLoad(option) {
  55. },
  56. onShow() {
  57. this.systemUserDetail();
  58. },
  59. methods: {
  60. //获取用户信息
  61. async systemUserDetail(){
  62. const {
  63. data
  64. } = await systemUserDetail({userId:uni.getStorageSync('userId')});
  65. if (data.code == 200) {
  66. this.$set(this.form,'mobile',data.data.mobile);
  67. }
  68. },
  69. //返回上级页面
  70. outButton(){
  71. uni.navigateBack();
  72. },
  73. //获取验证码
  74. getCode(){
  75. let self = this;
  76. const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/
  77. if(this.codeType){
  78. uni.showToast({
  79. title: '请稍后再试',
  80. icon: "none",
  81. duration: 3000
  82. });
  83. return
  84. }
  85. this.authNumCaptcha();
  86. },
  87. //获取验证码
  88. async authNumCaptcha() {
  89. let self = this;
  90. const {
  91. data
  92. } = await authNumCaptcha({mobile:this.form.mobile});
  93. if (data.code == 200) {
  94. uni.showToast({
  95. title: '发送成功',
  96. mask: true,
  97. icon: "none",
  98. duration: 2000
  99. });
  100. const TIME_COUNT = 60;
  101. this.$set(this, 'codeType', true);
  102. if (!this.timer) {
  103. this.$set(this, 'seconds', TIME_COUNT);
  104. this.timer = setInterval(() => {
  105. if (this.seconds > 1 && this.seconds <= TIME_COUNT) {
  106. this.seconds -= 1;
  107. } else {
  108. this.$set(this, 'codeType', false);
  109. clearInterval(this.timer);
  110. this.$set(this, 'timer', null);
  111. }
  112. }, 1000);
  113. }
  114. }
  115. },
  116. //提交
  117. submitButton(){
  118. let self = this;
  119. const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/
  120. const password = /^(?=(?:.*[A-Z]){1})(?=(?:.*[a-z]){1})(?=(?:.*[0-9]){1})(?=(?:.*[!@#*?&]){1})(?!(.)\1)(.{10,16})$/
  121. if(!this.form.mobile){
  122. uni.showToast({
  123. title: '请输入手机号码',
  124. icon: "none",
  125. duration: 3000
  126. });
  127. return
  128. }else if (!reg.test(this.form.mobile)) {
  129. uni.showToast({
  130. title: '请输入正确的手机号码',
  131. icon: "none",
  132. duration: 3000
  133. });
  134. return
  135. }else if(!this.form.captcha){
  136. uni.showToast({
  137. title: '请输入手机验证码',
  138. icon: "none",
  139. duration: 3000
  140. });
  141. return
  142. }else if(!this.form.newPassword){
  143. uni.showToast({
  144. title: '请输入新密码',
  145. icon: "none",
  146. duration: 3000
  147. });
  148. return
  149. }else if(!this.form.confirmPassword){
  150. uni.showToast({
  151. title: '请再次输入确认密码',
  152. icon: "none",
  153. duration: 3000
  154. });
  155. return
  156. }else if(this.form.newPassword!=this.form.confirmPassword){
  157. uni.showToast({
  158. title: '新密码与确认新密码不一致',
  159. icon: "none",
  160. duration: 3000
  161. });
  162. return
  163. }else if(!password.test(this.form.newPassword)||!password.test(this.form.confirmPassword)){
  164. uni.showModal({
  165. title: '',
  166. content: '密码长度最少10位 最多16位,必须同时包含一个大写字母、一个小写字母、一个数字和一个特殊字符!@#*?&',
  167. showCancel:false,
  168. confirmColor: '#0183FA',
  169. })
  170. return
  171. }
  172. uni.showModal({
  173. title: '确认提交?',
  174. cancelColor: '#999999',
  175. confirmColor: '#0183FA',
  176. content: '',
  177. success(res) {
  178. if (res.confirm) {
  179. // console.log('确定')
  180. self.authForgetPassword();
  181. } else if (res.cancel) {
  182. // console.log('取消')
  183. }
  184. }
  185. })
  186. },
  187. async authForgetPassword(){
  188. let self = this;
  189. let obj = {
  190. mobile:this.form.mobile,
  191. captcha:this.form.captcha,
  192. newPassword:md5.hex_md5(this.form.newPassword),
  193. confirmPassword:md5.hex_md5(this.form.confirmPassword),
  194. };
  195. const {
  196. data
  197. } = await authForgetPassword(obj);
  198. if (data.code == 200) {
  199. uni.showToast({
  200. title: '操作成功',
  201. icon: "none",
  202. mask: true,
  203. duration: 2000
  204. });
  205. setTimeout(function(){
  206. uni.navigateBack();
  207. },2000);
  208. }
  209. },
  210. },
  211. }
  212. </script>
  213. <style lang="stylus" scoped>
  214. #editPassword {
  215. height:100%;
  216. display: flex;
  217. flex-direction: column;
  218. flex:1;
  219. background-color: #FFFFFF;
  220. overflow-y: scroll;
  221. overflow-x: hidden;
  222. .page-title{
  223. line-height:120rpx;
  224. font-weight: 700;
  225. font-size: 34rpx;
  226. margin-left:30rpx;
  227. }
  228. .input-disabled-box{
  229. padding:0 30rpx;
  230. view:nth-child(1){
  231. line-height: 80rpx;
  232. font-size:30rpx;
  233. font-weight:700;
  234. }
  235. view:nth-child(2){
  236. font-size:30rpx;
  237. width:630rpx;
  238. height:100rpx;
  239. line-height:100rpx;
  240. border-radius:10rpx;
  241. background-color: #F5F5F5;
  242. color:#666;
  243. padding:0 30rpx;
  244. }
  245. }
  246. .input-max-box{
  247. padding:0 30rpx;
  248. view{
  249. line-height: 80rpx;
  250. font-size:30rpx;
  251. font-weight:700;
  252. }
  253. input{
  254. width:630rpx;
  255. height:100rpx;
  256. line-height:100rpx;
  257. border-radius:10rpx;
  258. border:1px solid #D8D8D8;
  259. padding:0 30rpx;
  260. }
  261. }
  262. .input-button-max-box{
  263. padding:0 30rpx;
  264. view:nth-child(1){
  265. line-height: 80rpx;
  266. font-size:30rpx;
  267. font-weight:700;
  268. }
  269. .input-button-box{
  270. display: flex;
  271. input{
  272. width:412rpx;
  273. height:100rpx;
  274. line-height:100rpx;
  275. border-radius:10rpx;
  276. border:1px solid #D8D8D8;
  277. padding:0 30rpx;
  278. margin-right:18rpx;
  279. }
  280. view{
  281. width:200rpx;
  282. line-height:100rpx;
  283. text-align: center;
  284. font-size:30rpx;
  285. border-radius:10rpx;
  286. }
  287. .checkButton{
  288. color:#333;
  289. background-color: #E8E8E8;
  290. }
  291. .noCheckButton{
  292. color:#fff;
  293. background-color: #0183FA;
  294. }
  295. }
  296. }
  297. .bottom-button-box{
  298. display: flex;
  299. margin:43rpx 0;
  300. view{
  301. font-size:30rpx;
  302. line-height:100rpx;
  303. text-align: center;
  304. }
  305. view:nth-child(1){
  306. width:220rpx;
  307. margin:0 33rpx 0 30rpx;
  308. border-radius: 50rpx 50rpx 50rpx 50rpx;
  309. border: 1rpx solid #E0E0E0;
  310. }
  311. view:nth-child(2){
  312. width:437rpx;
  313. color:#fff;
  314. background: #0183FA;
  315. border-radius: 50rpx 50rpx 50rpx 50rpx;
  316. }
  317. }
  318. }
  319. </style>