提交 a012b3ed 编写于 作者: zhujiamin's avatar zhujiamin

表单值变更 退出时确认框重复渲染

上级 5dcf7605
import { toastController, alertController } from '@ionic/core'; import { toastController, alertController } from '@ionic/core';
import { Store } from 'vuex';
/** /**
* 消息提示 * 消息提示
* *
...@@ -8,6 +8,11 @@ import { toastController, alertController } from '@ionic/core'; ...@@ -8,6 +8,11 @@ import { toastController, alertController } from '@ionic/core';
*/ */
export class Notice { export class Notice {
/**
* store
*/
public store:Store<any> = null;
/** /**
* 唯一实例 * 唯一实例
* *
...@@ -23,6 +28,7 @@ export class Notice { ...@@ -23,6 +28,7 @@ export class Notice {
* @memberof Notice * @memberof Notice
*/ */
constructor() { constructor() {
this.store = Store;
if (Notice.instance) { if (Notice.instance) {
return Notice.instance; return Notice.instance;
} }
...@@ -87,30 +93,35 @@ export class Notice { ...@@ -87,30 +93,35 @@ export class Notice {
* @returns {Promise<any>} * @returns {Promise<any>}
* @memberof Notice * @memberof Notice
*/ */
public async confirm(title: string, message: string): Promise<boolean> { public async confirm(title: string, message: string, store?: Store<any>): Promise<boolean> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const alert = await alertController.create({ const alert = await alertController.create({
header: title ? title : '标题', header: title ? title : '标题',
message: message, message: message,
buttons: [ buttons: [
{ {
text: '取消', text: '取消',
handler: () => { handler: () => {
resolve(false); store.commit('changeHasClose',true);
} resolve(false);
}, }
{ },
text: '确认', {
cssClass: 'secondary', text: '确认',
handler: () => { cssClass: 'secondary',
resolve(true); handler: () => {
} store.commit('changeHasClose',true);
}, resolve(true);
], }
}); },
],
});
if (store.state.hasClose) {
await alert.present(); await alert.present();
}); }
} store.commit('changeHasClose',false);
});
}
/** /**
* 创建对象 * 创建对象
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册