dialog.ts 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {defineStore} from "pinia";
  2. export const useDialogStore = defineStore('dialog', {
  3. state: () => ({
  4. dialogShows: <any>[],
  5. confirmParam: <any>{
  6. show: false,
  7. title: '提示',
  8. content: '',
  9. onSubmit: () => {},
  10. onCancel: () => {},
  11. }
  12. }),
  13. getters: {
  14. },
  15. actions: {
  16. add(key) {
  17. const oldDom: any = document.body.getElementsByClassName(this.dialogShows[0])?.[0]
  18. if (oldDom) {
  19. oldDom.style.display = 'none'
  20. }
  21. this.dialogShows.unshift(key)
  22. },
  23. del(key) {
  24. this.dialogShows = this.dialogShows.filter(v => v !== key)
  25. const newDom: any = document.body.getElementsByClassName(this.dialogShows[0])?.[0]
  26. if (newDom) {
  27. newDom.style.display = 'unset'
  28. }
  29. },
  30. confirm({title = '提示', content, onSubmit, onCancel = () => {}}) {
  31. this.confirmParam = {
  32. show: true,
  33. title: title,
  34. content,
  35. onSubmit: onSubmit,
  36. onCancel: onCancel
  37. }
  38. }
  39. },
  40. })