mint-ui MessageBox
将二次确认框统一封装为store / Vuex中,因为大部分工程会将vuex别名为store,这里注明一下。
1、store分模块,common公共方法:
JavaScript Code复制内容到剪贴板
- const actions = {
- /**
- * 二次确认框
- * params{
- * message : 确认文本
- * title : 标题
- * confirm : 确定按钮
- * cancle : 取消按钮
- * }
- */
- confirmMessageBox({ state, commit }, params){
- let messageTips = params.hasOwnProperty("message")?params.message:"是否确认",
- title = params.hasOwnProperty("title")?params.title:"",
- confirmButtonText = params.hasOwnProperty("confirm")?params.confirm:"确定",
- cancelButtonText = params.hasOwnProperty("cancle")?params.cancle:"取消";
- return new Promise(function (resolve, reject) {
- MessageBox.confirm('', {
- title:title,
- message: messageTips,
- confirmButtonText: confirmButtonText,
- cancelButtonText: cancelButtonText
- }).then(action => {
- resolve(true);
- }).catch(err => {
- resolve(false);
- })
- })
- },
- }
调用方法:
JavaScript Code复制内容到剪贴板
- <template>
- <button @click="toRefund">退款</button>
- </template>
- <script>
- export default {
- name: "test",
- methods: {
- async toRefund() {
- let msgParams = {
- "message" : "是否确认退费",
- }
- let res = await this.$store.dispatch("common/confirmMessageBox", msgParams);
- if(!res){
- return false;
- }
- },
- },
- };
- </script>
默认提示框:
JavaScript Code复制内容到剪贴板
- import { MessageBox } from 'mint-ui'
- MessageBox('提示', '操作成功');
JavaScript Code复制内容到剪贴板
- import { MessageBox } from 'mint-ui'
- import { Toast } from 'mint-ui'
- export default {
- name: 'publishBase',
- methods: {
- publishFree() {
- MessageBox.confirm('', {
- title: '提示',
- message: '发布此内容需将个人信息补充完整',
- confirmButtonText: '去补充',
- cancelButtonText: '取消'
- }).then(action => {
- if(action == 'confirm') {
- if(userLevel == this.$store.state.common.averageUser) {
- // 普通用户跳转进入个人信息补充页user-07
- window.location.href = '#';
- //this.$router.push('/cms/publish-base/' + type);
- } else if(userLevel == this.$store.state.common.primaryUser) {
- // 初级用户跳转进入个人信息补充页user-07-02
- window.location.href = '#';
- //this.$router.push('/cms/publish-base/' + type);
- }
- }
- }).catch(err => {
- //Toast('您已取消补充信息');
- });
- return false;
- },
- }
- }
JavaScript Code复制内容到剪贴板
- //删除发布
- this.$messagebox.confirm('', {
- message: '是否确定删除?',
- confirmButtonText: '确定',
- cancelButtonText: '取消'
- }).then(action => {
- let params = {
- publish_id: id,
- userId: this.$store.state.common.userId
- };
- this.request.post(this.$store.state.cms.api.deletePublish, params).then(response => {
- if(!response) {
- return false;
- }
- let res = response;
- this.publishList.splice(index, 1);
- let instance = this.$toast('删除成功');
- setTimeout(() => {
- instance.close();
- }, 1000);
- // success callback
- })
- }).catch(err => {
- //this.$toast('您已取消删除');
- })
JavaScript Code复制内容到剪贴板
- import { MessageBox } from 'mint-ui'
- import { Toast } from 'mint-ui'
- MessageBox.confirm('', {
- message: '已保存至草稿箱',
- confirmButtonText: '去草稿箱',
- cancelButtonText: '返回'
- }).then(action => {
- this.$router.push('/cms/publish-base/' + type);
- }).catch(err => {
- Toast('您已取消补充信息');
- });
上面的是CSS样式发生了变化,代码还是mint ui的,没变化,点击确定后的事件:
JavaScript Code复制内容到剪贴板
- this.$messagebox({
- title:"提示", // 标题,可为空,默认为:提示
- message: '响应失败,请联系管理员',
- }).then(action => {
- alert(0);
- //this.$router.go(-1); //取消返回上一个路由地址
- });
禁用点击遮罩层关闭messagebox框
JavaScript Code复制内容到剪贴板
- this.$messagebox.confirm('', {
- message: '是否确定删除?',
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- closeOnClickModal: false, //取消点击遮罩层关闭提示框
- }).then(action => {
- // 点击确定事件回调
- }).catch(err => {
- // let instance = this.$toast('删除成功');
- // setTimeout(() => {
- // instance.close();
- // }, 1000);
- })