uni-popup-dialog.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. "use strict";
  2. const uni_modules_uniPopup_components_uniPopup_popup = require("../uni-popup/popup.js");
  3. const common_vendor = require("../../../../common/vendor.js");
  4. const uni_modules_uniPopup_components_uniPopup_i18n_index = require("../uni-popup/i18n/index.js");
  5. const { t } = common_vendor.initVueI18n(uni_modules_uniPopup_components_uniPopup_i18n_index.messages);
  6. const _sfc_main = {
  7. name: "uniPopupDialog",
  8. mixins: [uni_modules_uniPopup_components_uniPopup_popup.popup],
  9. emits: ["confirm", "close"],
  10. props: {
  11. inputType: {
  12. type: String,
  13. default: "text"
  14. },
  15. value: {
  16. type: [String, Number],
  17. default: ""
  18. },
  19. placeholder: {
  20. type: [String, Number],
  21. default: ""
  22. },
  23. type: {
  24. type: String,
  25. default: "error"
  26. },
  27. mode: {
  28. type: String,
  29. default: "base"
  30. },
  31. title: {
  32. type: String,
  33. default: ""
  34. },
  35. content: {
  36. type: String,
  37. default: ""
  38. },
  39. beforeClose: {
  40. type: Boolean,
  41. default: false
  42. },
  43. cancelText: {
  44. type: String,
  45. default: ""
  46. },
  47. confirmText: {
  48. type: String,
  49. default: ""
  50. }
  51. },
  52. data() {
  53. return {
  54. dialogType: "error",
  55. focus: false,
  56. val: ""
  57. };
  58. },
  59. computed: {
  60. okText() {
  61. return this.confirmText || t("uni-popup.ok");
  62. },
  63. closeText() {
  64. return this.cancelText || t("uni-popup.cancel");
  65. },
  66. placeholderText() {
  67. return this.placeholder || t("uni-popup.placeholder");
  68. },
  69. titleText() {
  70. return this.title || t("uni-popup.title");
  71. }
  72. },
  73. watch: {
  74. type(val) {
  75. this.dialogType = val;
  76. },
  77. mode(val) {
  78. if (val === "input") {
  79. this.dialogType = "info";
  80. }
  81. },
  82. value(val) {
  83. this.val = val;
  84. }
  85. },
  86. created() {
  87. this.popup.disableMask();
  88. if (this.mode === "input") {
  89. this.dialogType = "info";
  90. this.val = this.value;
  91. } else {
  92. this.dialogType = this.type;
  93. }
  94. },
  95. mounted() {
  96. this.focus = true;
  97. },
  98. methods: {
  99. /**
  100. * 点击确认按钮
  101. */
  102. onOk() {
  103. if (this.mode === "input") {
  104. this.$emit("confirm", this.val);
  105. } else {
  106. this.$emit("confirm");
  107. }
  108. if (this.beforeClose)
  109. return;
  110. this.popup.close();
  111. },
  112. /**
  113. * 点击取消按钮
  114. */
  115. closeDialog() {
  116. this.$emit("close");
  117. if (this.beforeClose)
  118. return;
  119. this.popup.close();
  120. },
  121. close() {
  122. this.popup.close();
  123. }
  124. }
  125. };
  126. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  127. return common_vendor.e({
  128. a: common_vendor.t($options.titleText),
  129. b: common_vendor.n("uni-popup__" + $data.dialogType),
  130. c: $props.mode === "base"
  131. }, $props.mode === "base" ? {
  132. d: common_vendor.t($props.content)
  133. } : {
  134. e: $props.inputType,
  135. f: $options.placeholderText,
  136. g: $data.focus,
  137. h: $data.val,
  138. i: common_vendor.o(($event) => $data.val = $event.detail.value)
  139. }, {
  140. j: common_vendor.t($options.closeText),
  141. k: common_vendor.o((...args) => $options.closeDialog && $options.closeDialog(...args)),
  142. l: common_vendor.t($options.okText),
  143. m: common_vendor.o((...args) => $options.onOk && $options.onOk(...args))
  144. });
  145. }
  146. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "F:/development/HbuildWorkspace/KPS/uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue"]]);
  147. wx.createComponent(Component);