@pisell/materials 2.2.102 → 2.2.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/index.js +1 -1
  5. package/build/lowcode/meta.js +1 -1
  6. package/build/lowcode/preview.js +148 -164
  7. package/build/lowcode/render/default/view.js +22 -36
  8. package/build/lowcode/view.js +22 -36
  9. package/es/components/pisellWalletPassCard/index.js +6 -1
  10. package/es/components/productCard/cartSkuCard/components/packages/utils.d.ts +1 -1
  11. package/es/components/productCard/components/Packages/utils.d.ts +1 -1
  12. package/es/components/walletCard/Guide/index.d.ts +4 -0
  13. package/es/locales/en-US.d.ts +1 -0
  14. package/es/locales/en-US.js +1 -0
  15. package/es/locales/zh-CN.d.ts +1 -0
  16. package/es/locales/zh-CN.js +1 -0
  17. package/es/locales/zh-TW.d.ts +1 -0
  18. package/es/locales/zh-TW.js +1 -0
  19. package/es/utils/platform.d.ts +1 -1
  20. package/lib/components/pisellWalletPassCard/index.js +9 -1
  21. package/lib/components/productCard/cartSkuCard/components/packages/utils.d.ts +1 -1
  22. package/lib/components/productCard/components/Packages/utils.d.ts +1 -1
  23. package/lib/components/walletCard/Guide/index.d.ts +4 -0
  24. package/lib/locales/en-US.d.ts +1 -0
  25. package/lib/locales/en-US.js +1 -0
  26. package/lib/locales/zh-CN.d.ts +1 -0
  27. package/lib/locales/zh-CN.js +1 -0
  28. package/lib/locales/zh-TW.d.ts +1 -0
  29. package/lib/locales/zh-TW.js +1 -0
  30. package/lib/utils/platform.d.ts +1 -1
  31. package/lowcode/pisell-wallet-pass-card/meta.ts +19 -0
  32. package/package.json +1 -1
  33. package/es/components/media/index.d.ts +0 -18
  34. package/es/components/media/index.js +0 -340
  35. package/es/components/media/index.less +0 -100
  36. package/es/components/pisellVHFix/index.d.ts +0 -13
  37. package/es/components/pisellVHFix/index.js +0 -36
  38. package/es/components/pisellVHFix/index.less +0 -10
  39. package/lib/components/media/index.d.ts +0 -18
  40. package/lib/components/media/index.js +0 -265
  41. package/lib/components/media/index.less +0 -100
  42. package/lib/components/pisellVHFix/index.d.ts +0 -13
  43. package/lib/components/pisellVHFix/index.js +0 -56
  44. package/lib/components/pisellVHFix/index.less +0 -10
@@ -512,6 +512,7 @@ var PisellWalletPassCard = function PisellWalletPassCard(props) {
512
512
  });
513
513
  };
514
514
  var renderBalanceInfo = function renderBalanceInfo() {
515
+ var _props$metadata;
515
516
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
516
517
  className: "pisell-card-amount-wrap"
517
518
  }, showRedeem && !disabled && /*#__PURE__*/React.createElement("div", {
@@ -538,7 +539,11 @@ var PisellWalletPassCard = function PisellWalletPassCard(props) {
538
539
  className: "pisell-card-amount-item-label"
539
540
  }, getText('pisell-discount-card-title')), /*#__PURE__*/React.createElement("div", {
540
541
  className: "pisell-card-amount-item-value"
541
- }, discount, "% ", getText('pisell-discount-card-unit')))), /*#__PURE__*/React.createElement("div", {
542
+ }, ((_props$metadata = props.metadata) === null || _props$metadata === void 0 ? void 0 : _props$metadata.discount_card_type) === 'fixed_amount' ? /*#__PURE__*/React.createElement(React.Fragment, null, getText('pisell-discount-card-fixed-amount-prefix'), ' ', /*#__PURE__*/React.createElement(Amount, {
543
+ className: "pisell-card-amount-item-value",
544
+ useThousandsSeparator: true,
545
+ value: discount
546
+ })) : /*#__PURE__*/React.createElement(React.Fragment, null, discount, "% ", getText('pisell-discount-card-unit'))))), /*#__PURE__*/React.createElement("div", {
542
547
  className: "pisell-card-code-wrap"
543
548
  }, /*#__PURE__*/React.createElement("div", {
544
549
  className: "pisell-card-code"
@@ -17,4 +17,4 @@ export declare const minusSign: (item: any, type?: string) => "" | "-";
17
17
  * @Author: WangHan
18
18
  * @Date: 2024-11-22 10:58
19
19
  */
20
- export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => any;
20
+ export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => string | number;
@@ -17,4 +17,4 @@ export declare const minusSign: (item: any, type?: string) => "" | "-";
17
17
  * @Author: WangHan
18
18
  * @Date: 2024-11-22 10:58
19
19
  */
20
- export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => any;
20
+ export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => string | number;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import './index.less';
3
+ declare const Guide: (props: any) => JSX.Element;
4
+ export default Guide;
@@ -136,6 +136,7 @@ declare const _default: {
136
136
  'pisell-adjust-price-discount-can-be-maximum': string;
137
137
  'pisell-discount-card-title': string;
138
138
  'pisell-discount-card-unit': string;
139
+ 'pisell-discount-card-fixed-amount-prefix': string;
139
140
  'pisell-data-source-table-add': string;
140
141
  'pisell-data-source-table-edit': string;
141
142
  'pisell-data-source-table-detail': string;
@@ -163,6 +163,7 @@ export default {
163
163
  'pisell-adjust-price-discount-can-be-maximum': "Discount can be maximum",
164
164
  'pisell-discount-card-title': 'Discount',
165
165
  'pisell-discount-card-unit': 'off',
166
+ 'pisell-discount-card-fixed-amount-prefix': 'Save',
166
167
  // 数据源表格
167
168
  'pisell-data-source-table-add': 'Add',
168
169
  'pisell-data-source-table-edit': 'Edit',
@@ -136,6 +136,7 @@ declare const _default: {
136
136
  'pisell-adjust-price-discount-can-be-maximum': string;
137
137
  'pisell-discount-card-title': string;
138
138
  'pisell-discount-card-unit': string;
139
+ 'pisell-discount-card-fixed-amount-prefix': string;
139
140
  'pisell-data-source-table-add': string;
140
141
  'pisell-data-source-table-edit': string;
141
142
  'pisell-data-source-table-detail': string;
@@ -163,6 +163,7 @@ export default {
163
163
  'pisell-adjust-price-discount-can-be-maximum': "折扣最高可达",
164
164
  'pisell-discount-card-title': '折扣',
165
165
  'pisell-discount-card-unit': '折扣',
166
+ 'pisell-discount-card-fixed-amount-prefix': '立减',
166
167
  'pisell-data-source-table-add': '添加',
167
168
  'pisell-data-source-table-edit': '编辑',
168
169
  'pisell-data-source-table-detail': '详情',
@@ -136,6 +136,7 @@ declare const _default: {
136
136
  'pisell-adjust-price-discount-can-be-maximum': string;
137
137
  'pisell-discount-card-title': string;
138
138
  'pisell-discount-card-unit': string;
139
+ 'pisell-discount-card-fixed-amount-prefix': string;
139
140
  'pisell-data-source-table-add': string;
140
141
  'pisell-data-source-table-edit': string;
141
142
  'pisell-data-source-table-detail': string;
@@ -163,6 +163,7 @@ export default {
163
163
  'pisell-adjust-price-discount-can-be-maximum': "折扣最高可達",
164
164
  'pisell-discount-card-title': '折扣',
165
165
  'pisell-discount-card-unit': '折扣',
166
+ 'pisell-discount-card-fixed-amount-prefix': '立減',
166
167
  // 数据源表格
167
168
  'pisell-data-source-table-add': '添加',
168
169
  'pisell-data-source-table-edit': '編輯',
@@ -1 +1 @@
1
- export declare const isMobile: () => any;
1
+ export declare const isMobile: () => boolean;
@@ -420,6 +420,7 @@ var PisellWalletPassCard = (props) => {
420
420
  }
421
421
  );
422
422
  const renderBalanceInfo = () => {
423
+ var _a;
423
424
  return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-wrap" }, showRedeem && !disabled && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item pisell-wallet-pass-card-redeem" }, /* @__PURE__ */ import_react.default.createElement(
424
425
  "div",
425
426
  {
@@ -441,7 +442,14 @@ var PisellWalletPassCard = (props) => {
441
442
  originDom: createOriginalBalanceDom(),
442
443
  active,
443
444
  data: props
444
- }) : createOriginalBalanceDom()), showDiscount && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item-label" }, (0, import_locales.getText)("pisell-discount-card-title")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item-value" }, discount, "% ", (0, import_locales.getText)("pisell-discount-card-unit")))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-code-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-code" }, showCode && !isMini && /* @__PURE__ */ import_react.default.createElement("div", null, code), showValidDate && /* @__PURE__ */ import_react.default.createElement("div", null, (0, import_locales.getText)("pisell-wallet-pass-card-valid-to"), " ", !!validDate ? validDate : (0, import_locales.getText)("pisell-wallet-pass-card-expireDate")))));
445
+ }) : createOriginalBalanceDom()), showDiscount && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item-label" }, (0, import_locales.getText)("pisell-discount-card-title")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item-value" }, ((_a = props.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount" ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, (0, import_locales.getText)("pisell-discount-card-fixed-amount-prefix"), " ", /* @__PURE__ */ import_react.default.createElement(
446
+ import_Amount.default,
447
+ {
448
+ className: "pisell-card-amount-item-value",
449
+ useThousandsSeparator: true,
450
+ value: discount
451
+ }
452
+ )) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, discount, "% ", (0, import_locales.getText)("pisell-discount-card-unit"))))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-code-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-code" }, showCode && !isMini && /* @__PURE__ */ import_react.default.createElement("div", null, code), showValidDate && /* @__PURE__ */ import_react.default.createElement("div", null, (0, import_locales.getText)("pisell-wallet-pass-card-valid-to"), " ", !!validDate ? validDate : (0, import_locales.getText)("pisell-wallet-pass-card-expireDate")))));
445
453
  };
446
454
  const getInputItem = (name2) => {
447
455
  if ("validDate" === name2) {
@@ -17,4 +17,4 @@ export declare const minusSign: (item: any, type?: string) => "" | "-";
17
17
  * @Author: WangHan
18
18
  * @Date: 2024-11-22 10:58
19
19
  */
20
- export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => any;
20
+ export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => string | number;
@@ -17,4 +17,4 @@ export declare const minusSign: (item: any, type?: string) => "" | "-";
17
17
  * @Author: WangHan
18
18
  * @Date: 2024-11-22 10:58
19
19
  */
20
- export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => any;
20
+ export declare const _formatAmount: (price?: number, amountSymbol?: string, digit?: number) => string | number;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import './index.less';
3
+ declare const Guide: (props: any) => JSX.Element;
4
+ export default Guide;
@@ -136,6 +136,7 @@ declare const _default: {
136
136
  'pisell-adjust-price-discount-can-be-maximum': string;
137
137
  'pisell-discount-card-title': string;
138
138
  'pisell-discount-card-unit': string;
139
+ 'pisell-discount-card-fixed-amount-prefix': string;
139
140
  'pisell-data-source-table-add': string;
140
141
  'pisell-data-source-table-edit': string;
141
142
  'pisell-data-source-table-detail': string;
@@ -169,6 +169,7 @@ var en_US_default = {
169
169
  "pisell-adjust-price-discount-can-be-maximum": "Discount can be maximum",
170
170
  "pisell-discount-card-title": "Discount",
171
171
  "pisell-discount-card-unit": "off",
172
+ "pisell-discount-card-fixed-amount-prefix": "Save",
172
173
  // 数据源表格
173
174
  "pisell-data-source-table-add": "Add",
174
175
  "pisell-data-source-table-edit": "Edit",
@@ -136,6 +136,7 @@ declare const _default: {
136
136
  'pisell-adjust-price-discount-can-be-maximum': string;
137
137
  'pisell-discount-card-title': string;
138
138
  'pisell-discount-card-unit': string;
139
+ 'pisell-discount-card-fixed-amount-prefix': string;
139
140
  'pisell-data-source-table-add': string;
140
141
  'pisell-data-source-table-edit': string;
141
142
  'pisell-data-source-table-detail': string;
@@ -169,6 +169,7 @@ var zh_CN_default = {
169
169
  "pisell-adjust-price-discount-can-be-maximum": "折扣最高可达",
170
170
  "pisell-discount-card-title": "折扣",
171
171
  "pisell-discount-card-unit": "折扣",
172
+ "pisell-discount-card-fixed-amount-prefix": "立减",
172
173
  "pisell-data-source-table-add": "添加",
173
174
  "pisell-data-source-table-edit": "编辑",
174
175
  "pisell-data-source-table-detail": "详情",
@@ -136,6 +136,7 @@ declare const _default: {
136
136
  'pisell-adjust-price-discount-can-be-maximum': string;
137
137
  'pisell-discount-card-title': string;
138
138
  'pisell-discount-card-unit': string;
139
+ 'pisell-discount-card-fixed-amount-prefix': string;
139
140
  'pisell-data-source-table-add': string;
140
141
  'pisell-data-source-table-edit': string;
141
142
  'pisell-data-source-table-detail': string;
@@ -169,6 +169,7 @@ var zh_TW_default = {
169
169
  "pisell-adjust-price-discount-can-be-maximum": "折扣最高可達",
170
170
  "pisell-discount-card-title": "折扣",
171
171
  "pisell-discount-card-unit": "折扣",
172
+ "pisell-discount-card-fixed-amount-prefix": "立減",
172
173
  // 数据源表格
173
174
  "pisell-data-source-table-add": "添加",
174
175
  "pisell-data-source-table-edit": "編輯",
@@ -1 +1 @@
1
- export declare const isMobile: () => any;
1
+ export declare const isMobile: () => boolean;
@@ -153,6 +153,19 @@ export default {
153
153
  propType: 'bool',
154
154
  setter: 'BoolSetter',
155
155
  defaultValue: true,
156
+ },
157
+ {
158
+ name: 'discount',
159
+ title: { label: '折扣' },
160
+ propType: 'string',
161
+ setter: ['StringSetter', 'NumberSetter', 'VariableSetter'],
162
+ },
163
+ {
164
+ name: 'showDiscount',
165
+ title: { label: '显示折扣' },
166
+ propType: 'bool',
167
+ setter: 'BoolSetter',
168
+ defaultValue: true,
156
169
  },
157
170
  {
158
171
  name: 'code',
@@ -213,6 +226,12 @@ export default {
213
226
  setter: 'BoolSetter',
214
227
  defaultValue: true,
215
228
  },
229
+ {
230
+ name: 'metadata',
231
+ title: { label: '元信息' },
232
+ propType: 'object',
233
+ setter: 'JsonSetter',
234
+ }
216
235
  ],
217
236
  },
218
237
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "2.2.102",
3
+ "version": "2.2.103",
4
4
  "scripts": {
5
5
  "dev": "father dev",
6
6
  "build": "father build",
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- export interface MediaProps {
3
- __designMode?: 'design' | undefined;
4
- value?: string | string[];
5
- onChange?: (value: string | string[]) => void;
6
- multiple?: boolean;
7
- maxCount?: number;
8
- accept?: string;
9
- disabled?: boolean;
10
- className?: string;
11
- style?: React.CSSProperties;
12
- placeholder?: string;
13
- showUploadList?: boolean;
14
- listType?: 'text' | 'picture' | 'picture-card';
15
- }
16
- import './index.less';
17
- declare const Media: React.ForwardRefExoticComponent<MediaProps & React.RefAttributes<HTMLDivElement>>;
18
- export default Media;
@@ -1,340 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
14
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
18
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
- import React, { forwardRef, useMemo, useState, useCallback } from 'react';
21
- import { Button, Modal, Upload, Image, message } from 'antd';
22
- import { PlusOutlined, PictureOutlined } from '@ant-design/icons';
23
- import { useRequest } from 'ahooks';
24
- import { request } from "../table/utils";
25
- import useEngineContext from "../../hooks/useEngineContext";
26
- import "./index.less";
27
- var Media = /*#__PURE__*/forwardRef(function (props, ref) {
28
- var __designMode = props.__designMode,
29
- value = props.value,
30
- onChange = props.onChange,
31
- _props$multiple = props.multiple,
32
- multiple = _props$multiple === void 0 ? false : _props$multiple,
33
- _props$maxCount = props.maxCount,
34
- maxCount = _props$maxCount === void 0 ? 10 : _props$maxCount,
35
- _props$accept = props.accept,
36
- accept = _props$accept === void 0 ? 'image/*,video/*,audio/*' : _props$accept,
37
- _props$disabled = props.disabled,
38
- disabled = _props$disabled === void 0 ? false : _props$disabled,
39
- className = props.className,
40
- style = props.style,
41
- _props$placeholder = props.placeholder,
42
- placeholder = _props$placeholder === void 0 ? '選擇媒體文件' : _props$placeholder,
43
- _props$showUploadList = props.showUploadList,
44
- showUploadList = _props$showUploadList === void 0 ? true : _props$showUploadList,
45
- _props$listType = props.listType,
46
- listType = _props$listType === void 0 ? 'picture-card' : _props$listType;
47
- var _useState = useState(false),
48
- _useState2 = _slicedToArray(_useState, 2),
49
- isModalVisible = _useState2[0],
50
- setIsModalVisible = _useState2[1];
51
- var _useState3 = useState([]),
52
- _useState4 = _slicedToArray(_useState3, 2),
53
- selectedItems = _useState4[0],
54
- setSelectedItems = _useState4[1];
55
- var _useState5 = useState(false),
56
- _useState6 = _slicedToArray(_useState5, 2),
57
- uploading = _useState6[0],
58
- setUploading = _useState6[1];
59
- var _useEngineContext = useEngineContext(),
60
- appHelper = _useEngineContext.appHelper;
61
- var _ref = (appHelper === null || appHelper === void 0 ? void 0 : appHelper.constants) || {},
62
- mediaUploadUrl = _ref.mediaUploadUrl,
63
- getHeaders = _ref.getHeaders;
64
-
65
- // 获取媒体库列表
66
- var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
67
- var _yield$request$getReq, data;
68
- return _regeneratorRuntime().wrap(function _callee$(_context) {
69
- while (1) switch (_context.prev = _context.next) {
70
- case 0:
71
- _context.next = 2;
72
- return request.getRequest().get("/media:list", {
73
- page: 1,
74
- pageSize: 100
75
- }, {
76
- isNocobase: true,
77
- fullResult: true,
78
- headers: {
79
- 'x-data-source': 'pisell2'
80
- }
81
- });
82
- case 2:
83
- _yield$request$getReq = _context.sent;
84
- data = _yield$request$getReq.data;
85
- return _context.abrupt("return", (data === null || data === void 0 ? void 0 : data.data) || []);
86
- case 5:
87
- case "end":
88
- return _context.stop();
89
- }
90
- }, _callee);
91
- })), {
92
- manual: true
93
- }),
94
- mediaList = _useRequest.data,
95
- fetchMediaList = _useRequest.run;
96
-
97
- // 上传文件
98
- var _useRequest2 = useRequest( /*#__PURE__*/function () {
99
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(file) {
100
- var formData, _yield$request$getReq2, data;
101
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
102
- while (1) switch (_context2.prev = _context2.next) {
103
- case 0:
104
- formData = new FormData();
105
- formData.append('file', file);
106
- formData.append('group_id', '0');
107
- _context2.next = 5;
108
- return request.getRequest().post(mediaUploadUrl || '/api/media:upload', formData, {
109
- headers: _objectSpread(_objectSpread({}, getHeaders === null || getHeaders === void 0 ? void 0 : getHeaders()), {}, {
110
- 'Content-Type': 'multipart/form-data'
111
- })
112
- });
113
- case 5:
114
- _yield$request$getReq2 = _context2.sent;
115
- data = _yield$request$getReq2.data;
116
- return _context2.abrupt("return", data);
117
- case 8:
118
- case "end":
119
- return _context2.stop();
120
- }
121
- }, _callee2);
122
- }));
123
- return function (_x) {
124
- return _ref3.apply(this, arguments);
125
- };
126
- }(), {
127
- manual: true,
128
- onSuccess: function onSuccess(result) {
129
- message.success('上傳成功');
130
- fetchMediaList();
131
- },
132
- onError: function onError() {
133
- message.error('上傳失敗');
134
- }
135
- }),
136
- uploadFile = _useRequest2.run;
137
-
138
- // 处理文件上传
139
- var handleUpload = useCallback( /*#__PURE__*/function () {
140
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(file) {
141
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
142
- while (1) switch (_context3.prev = _context3.next) {
143
- case 0:
144
- if (!(file.size > 10 * 1024 * 1024)) {
145
- _context3.next = 3;
146
- break;
147
- }
148
- message.error('文件大小不能超過10MB');
149
- return _context3.abrupt("return", false);
150
- case 3:
151
- setUploading(true);
152
- _context3.prev = 4;
153
- _context3.next = 7;
154
- return uploadFile(file);
155
- case 7:
156
- _context3.prev = 7;
157
- setUploading(false);
158
- return _context3.finish(7);
159
- case 10:
160
- return _context3.abrupt("return", false);
161
- case 11:
162
- case "end":
163
- return _context3.stop();
164
- }
165
- }, _callee3, null, [[4,, 7, 10]]);
166
- }));
167
- return function (_x2) {
168
- return _ref4.apply(this, arguments);
169
- };
170
- }(), [uploadFile]);
171
-
172
- // 打开媒体库模态框
173
- var showModal = useCallback(function () {
174
- if (__designMode === 'design') {
175
- return;
176
- }
177
- setIsModalVisible(true);
178
- fetchMediaList();
179
- }, [__designMode, fetchMediaList]);
180
-
181
- // 关闭媒体库模态框
182
- var handleCancel = useCallback(function () {
183
- setIsModalVisible(false);
184
- setSelectedItems([]);
185
- }, []);
186
-
187
- // 选择媒体文件
188
- var handleSelect = useCallback(function (item) {
189
- if (multiple) {
190
- var isSelected = selectedItems.find(function (selected) {
191
- return selected.id === item.id;
192
- });
193
- if (isSelected) {
194
- setSelectedItems(selectedItems.filter(function (selected) {
195
- return selected.id !== item.id;
196
- }));
197
- } else {
198
- if (selectedItems.length >= maxCount) {
199
- message.warning("\u6700\u591A\u53EA\u80FD\u9078\u64C7".concat(maxCount, "\u500B\u6587\u4EF6"));
200
- return;
201
- }
202
- setSelectedItems([].concat(_toConsumableArray(selectedItems), [item]));
203
- }
204
- } else {
205
- setSelectedItems([item]);
206
- }
207
- }, [multiple, selectedItems, maxCount]);
208
-
209
- // 确认选择
210
- var handleOk = useCallback(function () {
211
- if (selectedItems.length === 0) {
212
- message.warning('請選擇媒體文件');
213
- return;
214
- }
215
- var urls = selectedItems.map(function (item) {
216
- return item.url;
217
- });
218
- var result = multiple ? urls : urls[0];
219
- onChange === null || onChange === void 0 || onChange(result);
220
- setIsModalVisible(false);
221
- setSelectedItems([]);
222
- }, [selectedItems, multiple, onChange]);
223
-
224
- // 渲染当前选中的文件
225
- var renderCurrentFiles = useMemo(function () {
226
- if (!value) return null;
227
- var files = Array.isArray(value) ? value : [value];
228
- if (listType === 'picture-card') {
229
- return /*#__PURE__*/React.createElement("div", {
230
- className: "pisell-media-current-files"
231
- }, files.map(function (url, index) {
232
- return /*#__PURE__*/React.createElement("div", {
233
- key: index,
234
- className: "pisell-media-file-item"
235
- }, /*#__PURE__*/React.createElement(Image, {
236
- src: url,
237
- alt: "file-".concat(index),
238
- width: 80,
239
- height: 80,
240
- style: {
241
- objectFit: 'cover'
242
- }
243
- }), /*#__PURE__*/React.createElement("div", {
244
- className: "pisell-media-file-actions"
245
- }, /*#__PURE__*/React.createElement(Button, {
246
- type: "text",
247
- size: "small",
248
- onClick: function onClick() {
249
- var newFiles = files.filter(function (_, i) {
250
- return i !== index;
251
- });
252
- onChange === null || onChange === void 0 || onChange(multiple ? newFiles : newFiles[0] || '');
253
- }
254
- }, "\u522A\u9664")));
255
- }));
256
- }
257
- return /*#__PURE__*/React.createElement("div", {
258
- className: "pisell-media-current-files"
259
- }, files.map(function (url, index) {
260
- return /*#__PURE__*/React.createElement("div", {
261
- key: index,
262
- className: "pisell-media-file-item"
263
- }, /*#__PURE__*/React.createElement("span", null, url), /*#__PURE__*/React.createElement(Button, {
264
- type: "text",
265
- size: "small",
266
- onClick: function onClick() {
267
- var newFiles = files.filter(function (_, i) {
268
- return i !== index;
269
- });
270
- onChange === null || onChange === void 0 || onChange(multiple ? newFiles : newFiles[0] || '');
271
- }
272
- }, "\u522A\u9664"));
273
- }));
274
- }, [value, listType, multiple, onChange]);
275
- return /*#__PURE__*/React.createElement("div", {
276
- ref: ref,
277
- className: "pisell-media ".concat(className || ''),
278
- style: style
279
- }, /*#__PURE__*/React.createElement(Button, {
280
- type: "dashed",
281
- icon: /*#__PURE__*/React.createElement(PictureOutlined, null),
282
- onClick: showModal,
283
- disabled: disabled,
284
- style: {
285
- width: '100%',
286
- height: listType === 'picture-card' ? 80 : 32
287
- }
288
- }, placeholder), showUploadList && renderCurrentFiles, /*#__PURE__*/React.createElement(Modal, {
289
- title: "\u5A92\u9AD4\u5EAB",
290
- open: isModalVisible,
291
- onCancel: handleCancel,
292
- onOk: handleOk,
293
- width: 800,
294
- okText: "\u78BA\u5B9A",
295
- cancelText: "\u53D6\u6D88"
296
- }, /*#__PURE__*/React.createElement("div", {
297
- className: "pisell-media-modal"
298
- }, /*#__PURE__*/React.createElement("div", {
299
- className: "pisell-media-upload"
300
- }, /*#__PURE__*/React.createElement(Upload, {
301
- accept: accept,
302
- beforeUpload: handleUpload,
303
- showUploadList: false,
304
- disabled: uploading
305
- }, /*#__PURE__*/React.createElement(Button, {
306
- icon: /*#__PURE__*/React.createElement(PlusOutlined, null),
307
- loading: uploading
308
- }, "\u4E0A\u50B3\u6587\u4EF6"))), /*#__PURE__*/React.createElement("div", {
309
- className: "pisell-media-list"
310
- }, mediaList === null || mediaList === void 0 ? void 0 : mediaList.map(function (item) {
311
- var isSelected = selectedItems.find(function (selected) {
312
- return selected.id === item.id;
313
- });
314
- return /*#__PURE__*/React.createElement("button", {
315
- key: item.id,
316
- className: "pisell-media-item ".concat(isSelected ? 'selected' : ''),
317
- onClick: function onClick() {
318
- return handleSelect(item);
319
- },
320
- type: "button"
321
- }, /*#__PURE__*/React.createElement(Image, {
322
- src: item.url,
323
- alt: item.name,
324
- width: 80,
325
- height: 80,
326
- style: {
327
- objectFit: 'cover'
328
- }
329
- }), /*#__PURE__*/React.createElement("div", {
330
- className: "pisell-media-item-info"
331
- }, /*#__PURE__*/React.createElement("div", {
332
- className: "pisell-media-item-name"
333
- }, item.name), /*#__PURE__*/React.createElement("div", {
334
- className: "pisell-media-item-size"
335
- }, (item.size / 1024 / 1024).toFixed(2), " MB")));
336
- })), selectedItems.length > 0 && /*#__PURE__*/React.createElement("div", {
337
- className: "pisell-media-selected"
338
- }, "\u5DF2\u9078\u64C7 ", selectedItems.length, " \u500B\u6587\u4EF6"))));
339
- });
340
- export default Media;