page.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view class="cl-page">
  3. <!-- toast -->
  4. <cl-toast ref="toast"></cl-toast>
  5. <!-- message-->
  6. <cl-message ref="message"></cl-message>
  7. <!-- loading-mask -->
  8. <cl-loading-mask
  9. ref="loader"
  10. :loading="loader.loading"
  11. :text="loader.text"
  12. ></cl-loading-mask>
  13. <!-- confirm -->
  14. <cl-confirm ref="confirm"></cl-confirm>
  15. <!-- content -->
  16. <slot></slot>
  17. </view>
  18. </template>
  19. <script>
  20. import { mapGetters } from "vuex";
  21. export default {
  22. componentName: "ClPage",
  23. props: {
  24. getUserInfo: Boolean,
  25. },
  26. data() {
  27. return {
  28. loader: {
  29. loading: false,
  30. text: "加载中",
  31. },
  32. };
  33. },
  34. computed: {
  35. ...mapGetters(["userInfo"]),
  36. },
  37. watch: {
  38. userInfo(val) {
  39. if (val) {
  40. this.$emit("userInfo", val);
  41. }
  42. },
  43. },
  44. mounted() {
  45. const { showLoading, hideLoading, showMessage, showToast, showConfirm } = this;
  46. this.$parent.$app = {
  47. showLoading,
  48. hideLoading,
  49. showMessage,
  50. showToast,
  51. showConfirm,
  52. };
  53. },
  54. methods: {
  55. showLoading(options = {}) {
  56. Object.assign(this.loader, options, {
  57. loading: true,
  58. });
  59. },
  60. hideLoading() {
  61. this.loader.loading = false;
  62. },
  63. showMessage(options) {
  64. this.$refs["message"].open(options);
  65. },
  66. showToast(options) {
  67. this.$refs["toast"].open(options);
  68. },
  69. showConfirm(options) {
  70. this.$refs["confirm"].open(options);
  71. },
  72. },
  73. };
  74. </script>