editPassword.vue 7.5 KB

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