antd-bridge.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. (function () {
  2. const React = window.React;
  3. const ReactDOM = window.ReactDOM;
  4. const antd = window.antd;
  5. const h = React.createElement;
  6. const theme = {
  7. token: {
  8. colorPrimary: '#ff5c2b',
  9. colorInfo: '#ff5c2b',
  10. colorSuccess: '#4f9d69',
  11. colorWarning: '#e0a83a',
  12. colorError: '#e64718',
  13. colorTextBase: '#17140f',
  14. colorText: '#2c271f',
  15. colorTextSecondary: '#7d7466',
  16. colorTextTertiary: '#a79d8d',
  17. colorTextQuaternary: '#c3baa9',
  18. colorBorder: '#e2dacb',
  19. colorBorderSecondary: '#efe9dc',
  20. colorBgContainer: '#fffdf8',
  21. colorBgElevated: '#fffdf8',
  22. colorBgLayout: '#f6f2e9',
  23. colorBgSpotlight: '#17140f',
  24. colorFillQuaternary: 'rgba(23,20,15,0.05)',
  25. colorFillTertiary: 'rgba(23,20,15,0.03)',
  26. borderRadius: 10,
  27. borderRadiusLG: 16,
  28. borderRadiusSM: 8,
  29. borderRadiusXS: 6,
  30. controlHeight: 36,
  31. controlHeightSM: 28,
  32. controlHeightLG: 44,
  33. fontFamily: '"PingFang SC","Hiragino Sans GB","Microsoft YaHei",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif',
  34. fontSize: 14,
  35. fontSizeHeading1: 30,
  36. fontSizeHeading2: 24,
  37. fontSizeHeading3: 19,
  38. lineWidth: 1,
  39. wireframe: false
  40. },
  41. components: {
  42. Button: {
  43. primaryShadow: '0 10px 26px rgba(255,92,43,0.26)',
  44. defaultShadow: 'none',
  45. dangerShadow: 'none',
  46. fontWeight: 600,
  47. paddingInline: 18
  48. },
  49. Card: {
  50. headerBg: 'transparent',
  51. colorBorderSecondary: '#e2dacb',
  52. paddingLG: 18
  53. },
  54. Segmented: {
  55. itemSelectedBg: '#fffdf8',
  56. trackBg: '#efe9dc'
  57. },
  58. Table: {
  59. headerBg: '#f6f2e9',
  60. headerColor: '#7d7466',
  61. borderColor: '#e2dacb'
  62. },
  63. Modal: {
  64. contentBg: '#fffdf8',
  65. headerBg: 'transparent'
  66. },
  67. Drawer: {
  68. colorBgElevated: '#fffdf8'
  69. },
  70. Tabs: {
  71. itemColor: '#7d7466',
  72. itemSelectedColor: '#17140f',
  73. inkBarColor: '#ff5c2b'
  74. },
  75. Steps: {
  76. colorPrimary: '#ff5c2b',
  77. navArrowColor: '#e2dacb'
  78. },
  79. Input: {
  80. activeBorderColor: '#17140f',
  81. hoverBorderColor: '#c3baa9'
  82. },
  83. InputNumber: {
  84. activeBorderColor: '#17140f',
  85. hoverBorderColor: '#c3baa9'
  86. },
  87. Select: {
  88. optionSelectedBg: '#ffe0d2',
  89. optionSelectedColor: '#17140f'
  90. },
  91. Slider: {
  92. railBg: '#e2dacb',
  93. railHoverBg: '#d3c9b7'
  94. },
  95. Switch: {
  96. colorPrimary: '#ff5c2b',
  97. colorPrimaryHover: '#ff7a50'
  98. },
  99. Upload: {
  100. colorPrimary: '#ff5c2b'
  101. },
  102. Empty: {
  103. colorTextDescription: '#a79d8d'
  104. },
  105. Statistic: {
  106. contentFontSize: 30
  107. },
  108. Tag: {
  109. defaultBg: '#fffdf8',
  110. defaultColor: '#2c271f'
  111. }
  112. }
  113. };
  114. const roots = new Map();
  115. function render(container, element) {
  116. if (!container) return;
  117. let root = roots.get(container);
  118. if (!root || !container.isConnected) {
  119. root = ReactDOM.createRoot(container);
  120. roots.set(container, root);
  121. }
  122. const locale = antd.locale ? antd.locale.zhCN : undefined;
  123. root.render(h(antd.ConfigProvider, { theme: theme, prefixCls: 'ant', locale: locale }, element));
  124. }
  125. function reset(container) {
  126. const root = roots.get(container);
  127. if (root) {
  128. root.unmount();
  129. roots.delete(container);
  130. }
  131. }
  132. function pickValue(v) {
  133. if (v && v.target && 'value' in v.target) return v.target.value;
  134. return v;
  135. }
  136. function hydrate(root) {
  137. if (!root) return;
  138. root.querySelectorAll('[data-ui]').forEach(function (el) {
  139. const name = el.getAttribute('data-ui');
  140. const Comp = antd[name];
  141. if (!Comp) return;
  142. let props = {};
  143. try {
  144. props = JSON.parse(el.getAttribute('data-props') || '{}');
  145. } catch (e) {
  146. props = {};
  147. }
  148. const text = el.getAttribute('data-text');
  149. const event = el.getAttribute('data-on');
  150. const handlers = {};
  151. if (event) {
  152. handlers[event] = function (v) {
  153. el.dispatchEvent(new CustomEvent('antd:' + event, { detail: { value: pickValue(v) }, bubbles: true }));
  154. };
  155. }
  156. const children = text != null ? text : (el.textContent.trim() || undefined);
  157. const iconHtml = el.getAttribute('data-icon-html');
  158. if (iconHtml) {
  159. props.icon = h('span', { className: 'ant-btn-icon', dangerouslySetInnerHTML: { __html: iconHtml } });
  160. }
  161. render(el, h(Comp, Object.assign({}, props, handlers), children));
  162. });
  163. }
  164. window.PL = window.PL || {};
  165. window.PL.ui = {
  166. h: h,
  167. render: render,
  168. reset: reset,
  169. hydrate: hydrate,
  170. antd: antd,
  171. theme: theme,
  172. message: antd.message,
  173. notification: antd.notification,
  174. locale: antd.locale ? antd.locale.zhCN : null
  175. };
  176. })();