index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { createApp } from 'vue'
  2. import necessaryInfoDialog from './components/necessaryInfoDialog.vue'
  3. import vuetify from '@/plugins/vuetify'
  4. const toastMessage = (type, option = {}) => {
  5. return new Promise((resolve, reject) => {
  6. const componentName = type === 'necessaryInfoDialog' ? necessaryInfoDialog : null
  7. const rootNode = document.createElement("div")
  8. document.querySelector('.v-application').appendChild(rootNode)
  9. const app = createApp(componentName, {
  10. // title,
  11. // text,
  12. option,
  13. cancel () {
  14. app.unmount()
  15. rootNode.remove()
  16. if (option.cancelCallback) {
  17. reject()
  18. }
  19. },
  20. sure () {
  21. app.unmount()
  22. rootNode.remove()
  23. resolve()
  24. },
  25. other () {
  26. app.unmount()
  27. rootNode.remove()
  28. resolve({ otherClick: true })
  29. }
  30. })
  31. app.use(vuetify)
  32. app.mount(rootNode)
  33. })
  34. }
  35. // 注册插件app.use()会自动执行install函数
  36. toastMessage.install = (app) => {
  37. app.config.globalProperties.Curtain = toastMessage
  38. }
  39. export default toastMessage