1.新建修改密码vue文件CgPwd.vue

代码如下:

<template>
<!-- 修改密码界面 -->
<el-dialog :title="$t('common.changePassword')" width="40%" :visible.sync="cgpwdVisible" :close-on-click-modal="false" :modal-append-to-body='false'>
<el-form :model="dataForm" label-width="80px" :rules="dataFormRules" ref="dataForm" :size="size"
label-position="right">
<el-form-item label="旧密码" prop="oldpassword">
<el-input v-model="dataForm.oldpassword" type="password" auto-complete="off"></el-input>
</el-form-item>
<el-form-item label="新密码" prop="newpassword">
<el-input v-model="dataForm.newpassword" type="password" auto-complete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer" style="margin-top: 5px;">
<el-button :size="size" @click.native="cgpwdVisible = false">{{$t('action.cancel')}}</el-button>
<el-button :size="size" type="primary" @click.native="submitForm" :loading="editLoading">{{$t('action.submit')}}</el-button>
</div>
</el-dialog>
</template> <script>
import axios from 'axios';
export default {
data() {
return {
size: 'small',
cgpwdVisible: false, // 编辑界面是否显示
editLoading: false, //载入图标
//初始化数据
dataForm: {
oldpassword: '',
newpassword: ''
},
//设置属性
dataFormRules: {
oldpassword: [
{ required: true, message: '请输入旧密码', trigger: 'blur' }
],
newpassword: [
{ required: true, message: '请输入新密码', trigger: 'blur' }
]
},
//获取全局url
baseUrl: this.global.baseUrl
}
},
methods: {
 // 设置可见性
setCgpwdVisible: function (cgpwdVisible) {
this.cgpwdVisible = cgpwdVisible
},
      // 提交请求
     submitForm: function () {
      //this.$refs.XXX 获取ref绑定的节点
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗?', '提示', {}).then(() => {
            let params = Object.assign({}, this.dataForm)
            params.user = 'admin'
            this.$api.cgpwd.pwdUpd(params).then((res) => {
              this.editLoading = true
              if(res.code == 200) {
                this.$message({ message: '操作成功' + res.msg, type: 'success' })
                this.cgpwdVisible = false       //隐藏该窗口
              } else {
                this.$message({message: '操作失败, ' + res.msg, type: 'error'})
              }
              this.editLoading = false
              this.$refs['dataForm'].resetFields()    //重置表单
            })
          })
        }
      })
     }
  },
//mounted: 在这发起后端请求,拿回数据,配合路由钩子做一些事情  (dom渲染完成 组件挂载完成 )
mounted() { }
}
</script> <style scoped> </style>

2.修改原有密码修改button

        <span class="main-operation-item">
<el-button size="small" icon="fa fa-key" @click="showCgpwdDialog"> 修改密码</el-button>
</span>

3.增加动态引用

    <!--修改密码界面-->
<CgPwd ref="cgpwdDialog" @afterRestore="afterCgpwd"></CgPwd>

4.在原有vue文件script中进行修改

//引入Cgpwd.vue文件
import CgPwd from "@/views/Sys/CgPwd" export default {
...
//在components中添加CgPwd,这样<CgPwd>才不会报错
components:{
...
CgPwd
},
...
methods: {
...
//显示密码修改弹窗界面
showCgpwdDialog: function() {
this.$refs.cgpwdDialog.setCgpwdVisible(true)
},
...
},
mounted() {
}
}

5.添加路由

新建文件cgpwd.js

import axios from '../axios'

/*
* 用户密码修改
*/ // 保存
export const pwdUpd = (data) => {
return axios({
url: '/user/pwdupd',
method: 'post',
data
})
}

6.在接口统一集成模块api.js中添加

import * as cgpwd from './moudules/cgpwd'

export default {
...
cgpwd
}

7.在后台controller中添加代码

使用@RequestBody来接收body

/**
* 修改密码
* @return
*/
@RequestMapping(value="/pwdupd")
public String pwdupd(@RequestBody String body) {
return body;
}

8.添加权限例外

import com.vuebg.admin.security.JwtAuthenticationFilter;
import com.vuebg.admin.security.JwtAuthenticationProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler; /**
* Spring Security Config
* @author
* @date 2018-12-12
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired
private UserDetailsService userDetailsService; @Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
// 使用自定义身份验证组件
auth.authenticationProvider(new JwtAuthenticationProvider(userDetailsService));
} /**
* 添加不需要进行权限验证的url
* @param http
* @throws Exception
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// 禁用 csrf, 由于使用的是JWT,我们这里不需要csrf
http.cors().and().csrf().disable()
.authorizeRequests()
// 跨域预检请求
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
...//修改密码
.antMatchers("/user/pwdupd").permitAll()
// 其他所有请求需要身份认证
.anyRequest().authenticated();
// 退出登录处理器
http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
// token验证过滤器
http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
} @Bean
@Override
public AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
} }

9.结果如下

vue-element添加修改密码弹窗的更多相关文章

  1. roundcute 添加修改密码插件

    添加修改密码插件 现打开main.inc.php 文件,搜索“$rcmail_config['plugins']”,找到: // List of active plugins (in plugins/ ...

  2. vue element Admin - 修改浏览器标签名 + 添加tagView标签 +固定导航头部 + 添加侧边栏Logo

    1 .修改浏览器标签名称: 修改浏览器标签名称在文件:\src\settings.js   image.png 2 .修改固定头部Header和侧边栏 Logo:   image.png 1)侧边栏文 ...

  3. exchang2010OWA主界面添加修改密码选项

    原文链接:http://www.mamicode.com/info-detail-1444660.html exchange邮箱用户可以登录OWA修改密码,当AD用户密码过期或者重置密码勾选了“用户下 ...

  4. 学用MVC4做网站六后台管理:6.1.3管理员修改密码

    6.1.3修改密码 需要两个action.一个是点击修改密码的链接要显示修改密码的分部视图(对话框形式):另一个是提交的处理action. 1.打开[AdministratorController]添 ...

  5. sharepoint修改密码

    增加SharePoint2010修改域密码功能 前提SharePoint2010的用户基于AD的,因此修改密码是修改了AD的密码,当然也可以修改本机密码(非域的密码).这里我们讨论修改域密码.我们修改 ...

  6. 循序渐进VUE+Element 前端应用开发(24)--- 修改密码的前端界面和ABP后端设置处理

    用户在系统登录后,一般会提供一个入口给当前用户更改当前的密码,其实更改密码操作是很简单的一个处理,不过本篇随笔主要是介绍结合前后端来实现这个操作,后端是基于ABP框架的,需要对密码的安全性进行一个设置 ...

  7. 打通前后端全栈开发node+vue进阶【课程学习系统项目实战详细讲解】(3):用户添加/修改/删除 vue表格组件 vue分页组件

    第三章 建议学习时间8小时      总项目预计10章 学习方式:详细阅读,并手动实现相关代码(如果没有node和vue基础,请学习前面的vue和node基础博客[共10章] 演示地址:后台:demo ...

  8. Vue 两个字段联合校验典型例子--修改密码

    1.前言   本文是前文<Vue Element-ui表单校验规则,你掌握了哪些?>针对多字段联合校验的典型应用.   在修改密码时,一般需要确认两次密码一致,涉及2个属性字段.类似的涉及 ...

  9. MVC5 网站开发之六 管理员 2、添加、删除、重置密码、修改密码、列表浏览

    目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 MVC5 网站开发之三 数据存储层功能实现 MVC5 网站开发之四 业务逻辑层的架构和基本功能 MVC5 网 ...

随机推荐

  1. Vue知识整理10:条件渲染(v-if v-show)

    在Vue中使用v-if等条件实现条件的判断来实现对象的显示. 也可以采用 v-show条件来实现对象的显示.

  2. 八:flask-重定向示例

    现象:访问地址a,跳转到地址b,在flask中,使用redirect()来进行重定向 永久性重定向:301,多用于旧网址被废弃了,需要跳转到新网址访问 例如请求www.jingdong.com,会自动 ...

  3. 如何通过shell脚本或一行命令更改root密码?

    哪个能用就用哪个吧! 方法一, echo -e "newpwd\nnewpwd" | (passwd root) 方法二, echo "newpwd" | pa ...

  4. cobbler批量安装系统

    cobbler是一个可以实现批量安装系统的Linux应用程序.它有别于pxe+kickstart,cobbler可以实现同个服务器批量安装不同操作系统版本. 1.系统环境准备及其下载cobbler 1 ...

  5. 别把&和nohup混为一谈, 根本不是同一个东西好不好 ------ 聊聊./a.out & , nohut ./a.out , nohup ./a.out &的区别

    在第一家公司工作的时候, 我认识了&,在第二家公司工作的时候, 我认识了nohup,  这就是渊源.  随后, 我就一直糊涂用他们, 但并不懂这两个东西. 网上很多地方是乱扯, 瞎复制, 为什 ...

  6. 阿里云 centos 部署 Django 可能遇到的问题

    问题一:版本限制   File "/Users/icourt/Desktop/hf/venv/lib/python3.7/site-packages/django/db/backends/m ...

  7. LeetCode算法题-Goat Latin Easy(Java实现)

    这是悦乐书的第322次更新,第344篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第192题(顺位题号是824).给出句子S,由空格分隔的单词组成.每个单词仅由小写和大写 ...

  8. Java课堂疑问解答与思考5

    一:运行 TestInherits.java 示例,观察输出,总结. TestInherits.java class Grandparent { public Grandparent() { Syst ...

  9. idea把java web项目打成war包

    1.新建artifacts 2.设置你的目录内容路径 3.找到项目web或webapp的路径 4.可以直接添加已经跑通的项目 5.配置完成点OK 6.编译打成war包 7.点击编译结束打完收工 8.找 ...

  10. k8s/01开启云原生之门(Mooc)

    一.kubernetes(k8s)基础知识 1.简介 在2017年Kubernetes战胜了两个强大的竞争对手Swarm和Mesos,成为容器管理与调度编排领域的首选平台和事实标准. 2014年k8s ...