changePassword.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view style="margin: 20upx 40upx 0;">
  3. <u-navbar :back-text="i18n('Back')" title-width="300" :back-text-style="backStyle" back-icon-color="#fff" title-color="#fff" :background="background"
  4. :title="i18n('ChangePassword')"></u-navbar>
  5. <!-- <uni-forms ref="form" @submit="submit">
  6. <uni-forms-item label="原密码:" name="possWorld" >
  7. <input class="input" type="text" placeholder="请输入原密码" @input="binddata('possWorld',$event.detail.value)" />
  8. </uni-forms-item>
  9. <uni-forms-item label="新密码:" name="newPossWorld" >
  10. <input class="input" type="text" placeholder="请设置6-20位登录密码" @input="binddata('newPossWorld',$event.detail.value)" />
  11. </uni-forms-item>
  12. <uni-forms-item label="确认密码:" name="possWorldActive" >
  13. <input class="input" type="text" placeholder="请再次输入登录密码" @input="binddata('possWorldActive',$event.detail.value)" />
  14. </uni-forms-item>
  15. </uni-forms> -->
  16. <u-form :model="form" ref="uForm">
  17. <u-form-item :label="i18n('originalPassword')" :label-width="160">
  18. <u-input v-model="form.possWorld" type="password" maxlength="20" :password-icon="true" :placeholder="$i18n.locale=='zh'?'请输入原密码':'Please Enter old Password'" />
  19. </u-form-item>
  20. <u-form-item :label="i18n('newPassword')" :label-width="160">
  21. <u-input v-model="form.newPossWorld" type="password" maxlength="20" :password-icon="true" :placeholder="$i18n.locale=='zh'?'请设置8-20位密码':'Please Set new password of 8 to 20 digits'" />
  22. </u-form-item>
  23. <u-form-item :label="i18n('confirmPassword')" :label-width="160">
  24. <u-input v-model="form.possWorldActive" type="password" maxlength="20" :password-icon="true" :placeholder="$i18n.locale=='zh'?'请再次输入密码':'Please Enter new Password again'" />
  25. </u-form-item>
  26. </u-form>
  27. <view class="next">
  28. <u-button type="primary" @click="pwdSetting">{{i18n('submit')}}</u-button>
  29. </view>
  30. <u-toast ref="uToast" />
  31. </view>
  32. </template>
  33. <script>
  34. import listCell from '@/components/JumpBox';
  35. export default {
  36. components: {
  37. listCell
  38. },
  39. data() {
  40. return {
  41. form: {
  42. possWorld: '',
  43. newPossWorld: '',
  44. possWorldActive: ''
  45. },
  46. token: '',
  47. background: {
  48. backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
  49. },
  50. backStyle: {
  51. color: '#FFFFFF',
  52. },
  53. };
  54. },
  55. onShow() {
  56. this.token = uni.getStorageSync('Auth-Token');
  57. },
  58. methods: {
  59. submit(e) {
  60. const {
  61. validate,
  62. value
  63. } = e;
  64. console.log('表单数据:', value);
  65. },
  66. async pwdSetting() {
  67. if (this.form.possWorld == "" || this.form.possWorld == null) {
  68. this.msg(this.$i18n.locale == 'zh' ? '原密码不能为空' : 'The old password cannot be empty', "warning");
  69. return;
  70. }
  71. if (this.form.newPossWorld == "" || this.form.newPossWorld == null) {
  72. this.msg(this.$i18n.locale == 'zh' ? '新密码不能为空' : 'New password cannot be empty', "warning");
  73. return;
  74. }
  75. if (this.form.possWorldActive == "" || this.form.possWorldActive == null) {
  76. this.msg(this.$i18n.locale == 'zh' ? '确认密码不能为空' : 'Confirm password cannot be empty', "warning");
  77. return;
  78. }
  79. //判断两次密码是否一致
  80. if (this.form.newPossWorld != this.form.possWorldActive) {
  81. this.msg('新密码与确认密码不一致', "warning");
  82. return;
  83. }
  84. //校验密码格式
  85. var message = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,20}$/.test(this.form.possWorldActive) ?
  86. "" : this.$i18n.locale == 'zh' ? '请输入8到20位密码,大小写字母,数字,特殊符号至少三项' :'Please input 8 to 20 digits password, at least 3 items of upper and lower case letters, numbers and special symbols';
  87. if (message != "") {
  88. return this.msg(message, "warning");
  89. }
  90. let Storage_data = JSON.parse(uni.getStorageSync('user'));
  91. let param = JSON.stringify({
  92. id: Storage_data.umsUser.id,
  93. password: this.form.possWorldActive,
  94. Authorization: this.token
  95. });
  96. const res = await this.$myRequest({
  97. url: '/ums/umsUsers/changePassword',
  98. data: {
  99. param
  100. },
  101. method: 'post'
  102. });
  103. if (res.status == '200') {
  104. this.$refs.uToast.show({
  105. title: this.$i18n.locale == 'zh' ? '密码修改成功,请使用新密码重新登录系统!' : 'Password modified successfully, please use the new password to login the system again!',
  106. type: "success",
  107. })
  108. setTimeout(() => {
  109. this.navTo('/pages/public/login');
  110. }, 2000);
  111. return;
  112. } else {
  113. this.msg('error');
  114. }
  115. },
  116. msg(msg, type) {
  117. if (msg == 'error') {
  118. msg = this.i18n('ThesystemisbusyPleasetryagainlater') + "!" //系统繁忙,请稍后再试
  119. }
  120. return this.$refs.uToast.show({
  121. title: msg,
  122. type: type,
  123. // url: '/pages/user/index'
  124. })
  125. },
  126. navTo(route) {
  127. this.$mRouter.push({
  128. route
  129. });
  130. },
  131. i18n(data) {
  132. return this.$t('common.' + data);
  133. },
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. page,
  139. body.pages-profile-profileSetUp-setUp uni-page-body {
  140. background-color: #fff !important;
  141. .uni-input-placeholder,
  142. .uni-input-form,
  143. .uni-input-wrapper,
  144. uni-input {
  145. text-align: right;
  146. }
  147. .next {
  148. margin-top: 100upx;
  149. }
  150. }
  151. </style>