基于umi的开发模板

game_modal.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from "react";
  2. import { Modal } from "antd";
  3. import ModalCloseBtn from '@/utils/logic_tools/GameModal/CloseButton';
  4. import { game_container_id } from '@/utils/game_setting/game_config';
  5. import { intl_get } from '@/utils/tools/intl_helper';
  6. export interface ModalItem {
  7. key: any,
  8. type: string,
  9. }
  10. export class GameModalController {
  11. public static modal_list: Array<ModalItem> = [];
  12. constructor() {}
  13. static destoryAll() {
  14. Modal.destroyAll();
  15. }
  16. static recordModal(key: any, type: string) {
  17. this.modal_list.push({
  18. key,
  19. type,
  20. });
  21. }
  22. static checkBeforeModal(type: string) {
  23. const target = this.findTypeModal(type);
  24. target.map(item => this.closeTypeModal(item.key, type));
  25. }
  26. static findTypeModal(type: string) {
  27. return this.modal_list.filter(item => item.type === type);
  28. }
  29. static closeTypeModal(key: any, type: string) {
  30. const targetIndex = this.modal_list.findIndex(item => (item.key === key && item.type === type));
  31. if (targetIndex || targetIndex === 0) {
  32. const target = this.modal_list[targetIndex];
  33. target.key.destroy();
  34. this.modal_list.splice(targetIndex, 1);
  35. }
  36. }
  37. static showPauseModal({
  38. mount = document.getElementById(game_container_id),
  39. className = "game-status-modal",
  40. content = intl_get({ id: "pause_modal_tip_text" }),
  41. okText = intl_get({ id: "pause_modal_ok_text" }),
  42. onOk = () => {},
  43. onCancel = () => {},
  44. }: any = {}) {
  45. this.checkBeforeModal("pause");
  46. const result = Modal.info({
  47. icon: null,
  48. iconType: undefined,
  49. title: null,
  50. content: (
  51. <div style={{ textAlign: 'center' }}>
  52. <ModalCloseBtn onClick={() => { onCancel(); }} />
  53. {content}
  54. </div>
  55. ),
  56. okText,
  57. width: 290,
  58. className,
  59. getContainer: () => mount || document.body,
  60. onOk
  61. });
  62. this.recordModal(result, "pause");
  63. if (document.body.style.overflow === "hidden") {
  64. document.body.style.overflow = "";
  65. }
  66. return result;
  67. }
  68. static showErrorModal({
  69. mount = document.getElementById(game_container_id),
  70. className = "game-status-modal",
  71. type = "common",
  72. okText = intl_get({ id: "error_loading_ok_text" }),
  73. onOk = () => {},
  74. onCancel = () => {},
  75. }: any = {}) {
  76. this.checkBeforeModal("error");
  77. let content = intl_get({ id: `error_loading_${type}_tip_text` });
  78. const result = Modal.error({
  79. icon: null,
  80. iconType: undefined,
  81. title: null,
  82. content: (
  83. <div style={{ textAlign: 'center' }}>
  84. <ModalCloseBtn onClick={() => { onCancel(); }} />
  85. {content}
  86. </div>
  87. ),
  88. okText,
  89. width: 290,
  90. className,
  91. getContainer: () => mount || document.body,
  92. onOk
  93. });
  94. this.recordModal(result, "error");
  95. if (document.body.style.overflow === "hidden") {
  96. document.body.style.overflow = "";
  97. }
  98. return result;
  99. }
  100. }