GlobalMessage.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script lang="ts" setup>
  2. import { deepClone, isFunction } from 'wot-design-uni/components/common/util'
  3. const { messageOptions, currentPage } = storeToRefs(useGlobalMessage())
  4. const messageBox = useMessage('globalMessage')
  5. const currentPath = getCurrentPath()
  6. // #ifdef MP-ALIPAY
  7. const hackAlipayVisible = ref(false)
  8. nextTick(() => {
  9. hackAlipayVisible.value = true
  10. })
  11. // #endif
  12. watch(() => messageOptions.value, (newVal) => {
  13. if (newVal) {
  14. if (currentPage.value === currentPath) {
  15. const option = deepClone(newVal)
  16. messageBox.show(option).then((res) => {
  17. if (isFunction(option.success)) {
  18. option.success(res)
  19. }
  20. }).catch((err) => {
  21. if (isFunction(option.fail)) {
  22. option.fail(err)
  23. }
  24. })
  25. }
  26. }
  27. else {
  28. messageBox.close()
  29. }
  30. })
  31. </script>
  32. <script lang="ts">
  33. export default {
  34. options: {
  35. virtualHost: true,
  36. addGlobalClass: true,
  37. styleIsolation: 'shared',
  38. },
  39. }
  40. </script>
  41. <template>
  42. <!-- #ifdef MP-ALIPAY -->
  43. <wd-message-box v-if="hackAlipayVisible" selector="globalMessage" />
  44. <!-- #endif -->
  45. <!-- #ifndef MP-ALIPAY -->
  46. <wd-message-box selector="globalMessage" />
  47. <!-- #endif -->
  48. </template>