editPassword.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.showToast({
  165. title: '密码长度最少10位 最多16位,必须同时包含一个大写字母、一个小写字母、一个数字和一个特殊字符!@#*?&',
  166. icon: "none",
  167. duration: 5000
  168. });
  169. return
  170. }
  171. uni.showModal({
  172. title: '确认提交?',
  173. cancelColor: '#999999',
  174. confirmColor: '#0183FA',
  175. content: '',
  176. success(res) {
  177. if (res.confirm) {
  178. // console.log('确定')
  179. self.authForgetPassword();
  180. } else if (res.cancel) {
  181. // console.log('取消')
  182. }
  183. }
  184. })
  185. },
  186. async authForgetPassword(){
  187. let self = this;
  188. let obj = {
  189. mobile:this.form.mobile,
  190. captcha:this.form.captcha,
  191. newPassword:md5.hex_md5(this.form.newPassword),
  192. confirmPassword:md5.hex_md5(this.form.confirmPassword),
  193. };
  194. const {
  195. data
  196. } = await authForgetPassword(obj);
  197. if (data.code == 200) {
  198. uni.showToast({
  199. title: '操作成功',
  200. icon: "none",
  201. mask: true,
  202. duration: 2000
  203. });
  204. setTimeout(function(){
  205. uni.navigateBack();
  206. },2000);
  207. }
  208. },
  209. },
  210. }
  211. </script>
  212. <style lang="stylus" scoped>
  213. #editPassword {
  214. height:100%;
  215. display: flex;
  216. flex-direction: column;
  217. flex:1;
  218. background-color: #FFFFFF;
  219. overflow-y: scroll;
  220. overflow-x: hidden;
  221. .page-title{
  222. line-height:120rpx;
  223. font-weight: 700;
  224. font-size: 34rpx;
  225. margin-left:30rpx;
  226. }
  227. .input-disabled-box{
  228. padding:0 30rpx;
  229. view:nth-child(1){
  230. line-height: 80rpx;
  231. font-size:30rpx;
  232. font-weight:700;
  233. }
  234. view:nth-child(2){
  235. font-size:30rpx;
  236. width:630rpx;
  237. height:100rpx;
  238. line-height:100rpx;
  239. border-radius:10rpx;
  240. background-color: #F5F5F5;
  241. color:#666;
  242. padding:0 30rpx;
  243. }
  244. }
  245. .input-max-box{
  246. padding:0 30rpx;
  247. view{
  248. line-height: 80rpx;
  249. font-size:30rpx;
  250. font-weight:700;
  251. }
  252. input{
  253. width:630rpx;
  254. height:100rpx;
  255. line-height:100rpx;
  256. border-radius:10rpx;
  257. border:1px solid #D8D8D8;
  258. padding:0 30rpx;
  259. }
  260. }
  261. .input-button-max-box{
  262. padding:0 30rpx;
  263. view:nth-child(1){
  264. line-height: 80rpx;
  265. font-size:30rpx;
  266. font-weight:700;
  267. }
  268. .input-button-box{
  269. display: flex;
  270. input{
  271. width:412rpx;
  272. height:100rpx;
  273. line-height:100rpx;
  274. border-radius:10rpx;
  275. border:1px solid #D8D8D8;
  276. padding:0 30rpx;
  277. margin-right:18rpx;
  278. }
  279. view{
  280. width:200rpx;
  281. line-height:100rpx;
  282. text-align: center;
  283. font-size:30rpx;
  284. border-radius:10rpx;
  285. }
  286. .checkButton{
  287. color:#333;
  288. background-color: #E8E8E8;
  289. }
  290. .noCheckButton{
  291. color:#fff;
  292. background-color: #0183FA;
  293. }
  294. }
  295. }
  296. .bottom-button-box{
  297. display: flex;
  298. margin:43rpx 0;
  299. view{
  300. font-size:30rpx;
  301. line-height:100rpx;
  302. text-align: center;
  303. }
  304. view:nth-child(1){
  305. width:220rpx;
  306. margin:0 33rpx 0 30rpx;
  307. border-radius: 50rpx 50rpx 50rpx 50rpx;
  308. border: 1rpx solid #E0E0E0;
  309. }
  310. view:nth-child(2){
  311. width:437rpx;
  312. color:#fff;
  313. background: #0183FA;
  314. border-radius: 50rpx 50rpx 50rpx 50rpx;
  315. }
  316. }
  317. }
  318. </style>