wd-loading.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const __default__ = {
  4. name: "wd-loading",
  5. options: {
  6. virtualHost: true,
  7. addGlobalClass: true,
  8. styleIsolation: "shared"
  9. }
  10. };
  11. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  12. ...__default__,
  13. props: common_vendor.loadingProps,
  14. setup(__props) {
  15. const svgDefineId = common_vendor.context.id++;
  16. const svgDefineId1 = common_vendor.context.id++;
  17. const svgDefineId2 = common_vendor.context.id++;
  18. const icon = {
  19. outline(color = "#4D80F0") {
  20. return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 42"><defs><linearGradient x1="100%" y1="0%" x2="0%" y2="0%" id="${svgDefineId}"><stop stop-color="#FFF" offset="0%" stop-opacity="0"/><stop stop-color="#FFF" offset="100%"/></linearGradient></defs><g fill="none" fill-rule="evenodd"><path d="M21 1c11.046 0 20 8.954 20 20s-8.954 20-20 20S1 32.046 1 21 9.954 1 21 1zm0 7C13.82 8 8 13.82 8 21s5.82 13 13 13 13-5.82 13-13S28.18 8 21 8z" fill="${color}"/><path d="M4.599 21c0 9.044 7.332 16.376 16.376 16.376 9.045 0 16.376-7.332 16.376-16.376" stroke="url(#${svgDefineId}) " stroke-width="3.5" stroke-linecap="round"/></g></svg>`;
  21. },
  22. ring(color = "#4D80F0", intermediateColor2 = "#a6bff7") {
  23. return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><linearGradient id="${svgDefineId1}" gradientUnits="userSpaceOnUse" x1="50" x2="50" y2="180"><stop offset="0" stop-color="${color}"></stop> <stop offset="1" stop-color="${intermediateColor2}"></stop></linearGradient> <path fill="url(#${svgDefineId1})" d="M20 100c0-44.1 35.9-80 80-80V0C44.8 0 0 44.8 0 100s44.8 100 100 100v-20c-44.1 0-80-35.9-80-80z"></path> <linearGradient id="${svgDefineId2}" gradientUnits="userSpaceOnUse" x1="150" y1="20" x2="150" y2="180"><stop offset="0" stop-color="#fff" stop-opacity="0"></stop> <stop offset="1" stop-color="${intermediateColor2}"></stop></linearGradient> <path fill="url(#${svgDefineId2})" d="M100 0v20c44.1 0 80 35.9 80 80s-35.9 80-80 80v20c55.2 0 100-44.8 100-100S155.2 0 100 0z"></path> <circle cx="100" cy="10" r="10" fill="${color}"></circle></svg>`;
  24. }
  25. };
  26. const props = __props;
  27. const svg = common_vendor.ref("");
  28. const intermediateColor = common_vendor.ref("");
  29. const iconSize = common_vendor.ref(null);
  30. common_vendor.watch(
  31. () => props.size,
  32. (newVal) => {
  33. iconSize.value = common_vendor.addUnit(newVal);
  34. },
  35. {
  36. deep: true,
  37. immediate: true
  38. }
  39. );
  40. common_vendor.watch(
  41. () => props.type,
  42. () => {
  43. buildSvg();
  44. },
  45. {
  46. deep: true,
  47. immediate: true
  48. }
  49. );
  50. const rootStyle = common_vendor.computed(() => {
  51. const style = {};
  52. if (common_vendor.isDef(iconSize.value)) {
  53. style.height = common_vendor.addUnit(iconSize.value);
  54. style.width = common_vendor.addUnit(iconSize.value);
  55. }
  56. return `${common_vendor.objToStyle(style)} ${props.customStyle}`;
  57. });
  58. common_vendor.onBeforeMount(() => {
  59. intermediateColor.value = common_vendor.gradient(props.color, "#ffffff", 2)[1];
  60. buildSvg();
  61. });
  62. function buildSvg() {
  63. const { type, color } = props;
  64. let ringType = common_vendor.isDef(type) ? type : "ring";
  65. const svgStr = `"data:image/svg+xml;base64,${common_vendor.encode(ringType === "ring" ? icon[ringType](color, intermediateColor.value) : icon[ringType](color))}"`;
  66. svg.value = svgStr;
  67. }
  68. return (_ctx, _cache) => {
  69. return {
  70. a: common_vendor.s(`background-image: url(${svg.value});`),
  71. b: common_vendor.n(`wd-loading ${props.customClass}`),
  72. c: common_vendor.s(rootStyle.value)
  73. };
  74. };
  75. }
  76. });
  77. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-eccc123e"]]);
  78. wx.createComponent(Component);