123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <template>
- <div class="app-container common-list-page">
- <el-form
- ref="temp"
- :model="temp"
- :rules="rules"
- status-icon
- label-width="100px"
- >
- <el-form-item label="旧密码:" prop="oldpassword">
- <el-input v-model="temp.oldpassword" type="password" auto-complete="off" />
- </el-form-item>
- <el-form-item label="新密码:" prop="password">
- <el-input v-model="temp.password" type="password" auto-complete="off" />
- </el-form-item>
- <el-form-item label="确认密码:" prop="password1">
- <el-input v-model="temp.password1" type="password" auto-complete="off" />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click.native.prevent="toAmend">确认修改</el-button>
- </el-form-item>
- </el-form>
- </div>
- </template>
- <script>
- import { PostDataByName } from '@/api/common'
- export default {
- data() {
- var oldPass = (rule, value, callback) => {
- if (!value) {
- callback(new Error('请输入旧密码'))
- } else if (value.toString().length < 6 || value.toString().length > 18) {
- callback(new Error('密码长度为6-18位'))
- } else {
- callback()
- }
- }
- var validatePass = (rule, value, callback) => {
- console.log(value)
- if (!value) {
- callback(new Error('请输入新密码'))
- } else if (value.toString().length < 6 || value.toString().length > 18) {
- callback(new Error('密码长度为6-18位'))
- } else {
- callback()
- }
- }
- var validatePass2 = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('请再次输入密码'))
- } else if (value !== this.temp.password) {
- callback(new Error('两次输入密码不一致!'))
- } else {
- callback()
- }
- }
- return {
- resetForm: {
- name: 'updatePwd',
- returntype: 'Map',
- parammaps: {
- password: '',
- username: this.$store.state.user.name
- }
- },
- temp: {},
- rules: {
- oldpassword: [
- { required: true, validator: oldPass, trigger: 'blur' }
- ],
- password: [
- { required: true, validator: validatePass, trigger: 'blur' }
- ],
- password1: [
- { required: true, validator: validatePass2, trigger: 'blur' }
- ]
- }
- }
- },
- methods: {
- toAmend() {
- console.log(111)
- this.$refs['temp'].validate(valid => {
- if (valid) {
- this.resetForm.parammaps.password = this.temp.password
- this.resetForm.parammaps.username = this.$store.state.user.name
- PostDataByName(this.resetForm).then(response => {
- if (response.msg === 'fail') {
- this.$notify({
- title: '失败',
- message: '修改失败',
- type: 'danger',
- duration: 2000
- })
- } else {
- setTimeout(() => {
- this.logout() // 调用跳转到登陆页的方法
- }, 1000)
- this.$notify({
- title: '成功',
- message: '修改成功',
- type: 'success',
- duration: 2000
- })
- }
- console.log(response)
- })
- }
- })
- },
- // 这是修改成功后重新返回登陆页的方法,看个人需要自行调整
- async logout() {
- await this.$store.dispatch('user/logout')
- this.$router.push(`/login`)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .el-form {
- width: 60%;
- margin: 50px auto 0;
- text-align: center;
- button {
- margin: 20px 0 0;
- }
- }
- </style>
|