提交 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,7 +93,7 @@ export class Notice { ...@@ -87,7 +93,7 @@ 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 : '标题',
...@@ -96,6 +102,7 @@ export class Notice { ...@@ -96,6 +102,7 @@ export class Notice {
{ {
text: '取消', text: '取消',
handler: () => { handler: () => {
store.commit('changeHasClose',true);
resolve(false); resolve(false);
} }
}, },
...@@ -103,12 +110,16 @@ export class Notice { ...@@ -103,12 +110,16 @@ export class Notice {
text: '确认', text: '确认',
cssClass: 'secondary', cssClass: 'secondary',
handler: () => { handler: () => {
store.commit('changeHasClose',true);
resolve(true); resolve(true);
} }
}, },
], ],
}); });
if (store.state.hasClose) {
await alert.present(); await alert.present();
}
store.commit('changeHasClose',false);
}); });
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册