123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <template>
- <el-form>
- <el-form-item label="用户名">
- <el-input v-model.trim="user.name" readonly />
- </el-form-item>
- <el-form-item label="密码">
- <el-input v-model.trim="user.password" type="password" placeholder="不修改请留空" />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="submit">修改</el-button>
- </el-form-item>
- </el-form>
- </template>
- <script>
- import { updateData } from '@/api/sys/user/user'
- export default {
- props: {
- user: {
- type: Object,
- default: () => {
- return {
- password: ''
- }
- }
- }
- },
- methods: {
- async logout() {
- await this.$store.dispatch('user/logout')
- this.$router.push('/login')
- },
- async submit() {
- // 验证密码是否合法
- const validReg = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~@#$%^&+=])(?=\S+$).{8,}$/
- if (!this.user.password) {
- this.$notify.error({
- title: '错误',
- message: '密码不能为空',
- duration: 2000
- })
- return
- } else if (!validReg.test(this.user.password)) {
- this.$notify.error({
- title: '错误',
- message: '密码必须包含大小写字母、数字和特殊字符且不能小于8位',
- duration: 2000
- })
- return
- }
- updateData(this.user).then(() => {
- this.$notify({
- title: '成功',
- message: '用户资料保存成功!!',
- type: 'success',
- duration: 2000
- })
- this.logout()
- })
- }
- }
- }
- </script>
|