u-button.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "u-button",
  5. mixins: [common_vendor.mpMixin, common_vendor.mixin, common_vendor.buttonMixin, common_vendor.openType, common_vendor.props$4],
  6. data() {
  7. return {};
  8. },
  9. computed: {
  10. // 生成bem风格的类名
  11. bemClass() {
  12. if (!this.color) {
  13. return this.bem(
  14. "button",
  15. ["type", "shape", "size"],
  16. ["disabled", "plain", "hairline"]
  17. );
  18. } else {
  19. return this.bem(
  20. "button",
  21. ["shape", "size"],
  22. ["disabled", "plain", "hairline"]
  23. );
  24. }
  25. },
  26. loadingColor() {
  27. if (this.plain) {
  28. return this.color ? this.color : common_vendor.color[`u-${this.type}`];
  29. }
  30. if (this.type === "info") {
  31. return "#c9c9c9";
  32. }
  33. return "rgb(200, 200, 200)";
  34. },
  35. iconColorCom() {
  36. if (this.iconColor)
  37. return this.iconColor;
  38. if (this.plain) {
  39. return this.color ? this.color : this.type;
  40. } else {
  41. return this.type === "info" ? "#000000" : "#ffffff";
  42. }
  43. },
  44. baseColor() {
  45. let style = {};
  46. if (this.color) {
  47. style.color = this.plain ? this.color : "white";
  48. if (!this.plain) {
  49. style["background-color"] = this.color;
  50. }
  51. if (this.color.indexOf("gradient") !== -1) {
  52. style.borderTopWidth = 0;
  53. style.borderRightWidth = 0;
  54. style.borderBottomWidth = 0;
  55. style.borderLeftWidth = 0;
  56. if (!this.plain) {
  57. style.backgroundImage = this.color;
  58. }
  59. } else {
  60. style.borderColor = this.color;
  61. style.borderWidth = "1px";
  62. style.borderStyle = "solid";
  63. }
  64. }
  65. return style;
  66. },
  67. // nvue版本按钮的字体不会继承父组件的颜色,需要对每一个text组件进行单独的设置
  68. nvueTextStyle() {
  69. let style = {};
  70. if (this.type === "info") {
  71. style.color = "#323233";
  72. }
  73. if (this.color) {
  74. style.color = this.plain ? this.color : "white";
  75. }
  76. style.fontSize = this.textSize + "px";
  77. return style;
  78. },
  79. // 字体大小
  80. textSize() {
  81. let fontSize = 14, { size } = this;
  82. if (size === "large")
  83. fontSize = 16;
  84. if (size === "normal")
  85. fontSize = 14;
  86. if (size === "small")
  87. fontSize = 12;
  88. if (size === "mini")
  89. fontSize = 10;
  90. return fontSize;
  91. }
  92. },
  93. emits: [
  94. "click",
  95. "getphonenumber",
  96. "getuserinfo",
  97. "error",
  98. "opensetting",
  99. "launchapp",
  100. "agreeprivacyauthorization"
  101. ],
  102. methods: {
  103. addStyle: common_vendor.addStyle,
  104. clickHandler(e) {
  105. if (!this.disabled && !this.loading) {
  106. common_vendor.throttle(() => {
  107. this.$emit("click", e);
  108. }, this.throttleTime);
  109. }
  110. this.stop && this.preventEvent(e);
  111. },
  112. // 下面为对接uniapp官方按钮开放能力事件回调的对接
  113. getphonenumber(res) {
  114. this.$emit("getphonenumber", res);
  115. },
  116. getuserinfo(res) {
  117. this.$emit("getuserinfo", res);
  118. },
  119. error(res) {
  120. this.$emit("error", res);
  121. },
  122. opensetting(res) {
  123. this.$emit("opensetting", res);
  124. },
  125. launchapp(res) {
  126. this.$emit("launchapp", res);
  127. },
  128. agreeprivacyauthorization(res) {
  129. this.$emit("agreeprivacyauthorization", res);
  130. }
  131. }
  132. };
  133. if (!Array) {
  134. const _easycom_u_loading_icon2 = common_vendor.resolveComponent("u-loading-icon");
  135. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  136. (_easycom_u_loading_icon2 + _easycom_u_icon2)();
  137. }
  138. const _easycom_u_loading_icon = () => "../u-loading-icon/u-loading-icon.js";
  139. const _easycom_u_icon = () => "../u-icon/u-icon.js";
  140. if (!Math) {
  141. (_easycom_u_loading_icon + _easycom_u_icon)();
  142. }
  143. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  144. return common_vendor.e({
  145. a: _ctx.loading
  146. }, _ctx.loading ? {
  147. b: common_vendor.p({
  148. mode: _ctx.loadingMode,
  149. size: _ctx.loadingSize * 1.15,
  150. color: $options.loadingColor
  151. }),
  152. c: common_vendor.t(_ctx.loadingText || _ctx.text),
  153. d: common_vendor.s({
  154. fontSize: $options.textSize + "px"
  155. })
  156. } : common_vendor.e({
  157. e: _ctx.icon
  158. }, _ctx.icon ? {
  159. f: common_vendor.p({
  160. name: _ctx.icon,
  161. color: $options.iconColorCom,
  162. size: $options.textSize * 1.35,
  163. customStyle: {
  164. marginRight: "2px"
  165. }
  166. })
  167. } : {}, {
  168. g: common_vendor.t(_ctx.text),
  169. h: common_vendor.s({
  170. fontSize: $options.textSize + "px"
  171. })
  172. }), {
  173. i: Number(_ctx.hoverStartTime),
  174. j: Number(_ctx.hoverStayTime),
  175. k: _ctx.formType,
  176. l: _ctx.openType,
  177. m: _ctx.appParameter,
  178. n: _ctx.hoverStopPropagation,
  179. o: _ctx.sendMessageTitle,
  180. p: _ctx.sendMessagePath,
  181. q: _ctx.lang,
  182. r: _ctx.dataName,
  183. s: _ctx.sessionFrom,
  184. t: _ctx.sendMessageImg,
  185. v: _ctx.showMessageCard,
  186. w: common_vendor.o((...args) => $options.getphonenumber && $options.getphonenumber(...args)),
  187. x: common_vendor.o((...args) => $options.getuserinfo && $options.getuserinfo(...args)),
  188. y: common_vendor.o((...args) => $options.error && $options.error(...args)),
  189. z: common_vendor.o((...args) => $options.opensetting && $options.opensetting(...args)),
  190. A: common_vendor.o((...args) => $options.launchapp && $options.launchapp(...args)),
  191. B: common_vendor.o((...args) => $options.agreeprivacyauthorization && $options.agreeprivacyauthorization(...args)),
  192. C: !_ctx.disabled && !_ctx.loading ? "u-button--active" : "",
  193. D: common_vendor.s($options.baseColor),
  194. E: common_vendor.s($options.addStyle(_ctx.customStyle)),
  195. F: common_vendor.o((...args) => $options.clickHandler && $options.clickHandler(...args)),
  196. G: common_vendor.n($options.bemClass)
  197. });
  198. }
  199. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-461e713c"], ["__file", "C:/Users/Administrator/Desktop/srcaaa/node_modules/uview-plus/components/u-button/u-button.vue"]]);
  200. wx.createComponent(Component);