editPassword.vue 7.3 KB

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