index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import BsModal from './Modal.vue';
  2. import { Modal } from 'ant-design-vue';
  3. import { createApp, h, onBeforeMount, onMounted, reactive, toRaw } from 'vue';
  4. import { set, get } from 'lodash';
  5. import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons-vue';
  6. export const useBsModal = (options, modalRef) => {
  7. const modalOptions = reactive(options.modalOptions);
  8. const setModalPropsValue = (path, value) => {
  9. set(modalOptions, path, value);
  10. };
  11. const getModalPropsValue = (path) => {
  12. return toRaw(get(modalOptions, path, undefined));
  13. };
  14. const initModalOptions = () => {
  15. const sizeMap = {
  16. small: '500px',
  17. middle: "1000px",
  18. large: "1500px",
  19. };
  20. setModalPropsValue('modalExtraProps.okButtonProps', {
  21. icon: h(CheckCircleOutlined),
  22. ...options.modalOptions?.modalExtraProps?.okButtonProps,
  23. });
  24. setModalPropsValue('modalExtraProps.cancelButtonProps', {
  25. icon: h(CloseCircleOutlined),
  26. ...options.modalOptions?.modalExtraProps?.cancelButtonProps,
  27. });
  28. if (options.modalOptions?.size) {
  29. setModalPropsValue('width', sizeMap[options.modalOptions?.size]);
  30. }
  31. };
  32. onMounted(() => {
  33. initModalOptions();
  34. });
  35. const showBsModal = (options = {}) => {
  36. const modal = Modal.confirm({
  37. class: 'bs-modal-confirm',
  38. closable: true,
  39. centered: true,
  40. icon: () => h(null),
  41. okText: '确认',
  42. cancelText: '取消',
  43. ...modalOptions,
  44. ...modalOptions?.modalExtraProps,
  45. ...options,
  46. });
  47. return modal;
  48. };
  49. return {
  50. modalOptions,
  51. showBsModal,
  52. setModalPropsValue,
  53. getModalPropsValue,
  54. };
  55. };
  56. export default BsModal;