@nutui/nutui 3.1.22 → 3.1.23-beta.0

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 (176) hide show
  1. package/dist/nutui.es.js +20418 -4214
  2. package/dist/nutui.umd.js +20524 -4216
  3. package/dist/packages/_es/ActionSheet.js +149 -17
  4. package/dist/packages/_es/Address.js +535 -110
  5. package/dist/packages/_es/AddressList.js +615 -113
  6. package/dist/packages/_es/Animate.js +59 -17
  7. package/dist/packages/_es/Audio.js +257 -53
  8. package/dist/packages/_es/AudioOperate.js +100 -13
  9. package/dist/packages/_es/Avatar.js +162 -38
  10. package/dist/packages/_es/AvatarGroup.js +73 -14
  11. package/dist/packages/_es/BackTop.js +156 -43
  12. package/dist/packages/_es/Badge.js +86 -14
  13. package/dist/packages/_es/Barrage.js +120 -41
  14. package/dist/packages/_es/Button.js +128 -23
  15. package/dist/packages/_es/Calendar.js +246 -30
  16. package/dist/packages/_es/CalendarItem.js +1 -1
  17. package/dist/packages/_es/Card.js +107 -10
  18. package/dist/packages/_es/Cascader.js +496 -147
  19. package/dist/packages/_es/Category.js +58 -15
  20. package/dist/packages/_es/CategoryPane.js +111 -11
  21. package/dist/packages/_es/Cell.js +108 -21
  22. package/dist/packages/_es/CellGroup.js +44 -9
  23. package/dist/packages/_es/Checkbox.js +134 -29
  24. package/dist/packages/_es/CheckboxGroup.js +79 -29
  25. package/dist/packages/_es/CircleProgress.js +150 -28
  26. package/dist/packages/_es/Col.js +56 -14
  27. package/dist/packages/_es/Collapse.js +109 -32
  28. package/dist/packages/_es/CollapseItem.js +253 -59
  29. package/dist/packages/_es/Comment.js +434 -64
  30. package/dist/packages/_es/ConfigProvider.js +20 -8
  31. package/dist/packages/_es/CountDown.js +238 -56
  32. package/dist/packages/_es/CountUp.js +539 -140
  33. package/dist/packages/_es/DatePicker.js +315 -98
  34. package/dist/packages/_es/Dialog.js +289 -60
  35. package/dist/packages/_es/Divider.js +65 -13
  36. package/dist/packages/_es/Drag.js +197 -56
  37. package/dist/packages/_es/Ecard.js +159 -24
  38. package/dist/packages/_es/Elevator.js +255 -58
  39. package/dist/packages/_es/Ellipsis.js +200 -58
  40. package/dist/packages/_es/Empty.js +71 -12
  41. package/dist/packages/_es/FixedNav.js +122 -15
  42. package/dist/packages/_es/Form.js +151 -64
  43. package/dist/packages/_es/FormItem.js +114 -15
  44. package/dist/packages/_es/Grid.js +6 -5
  45. package/dist/packages/_es/GridItem.js +144 -33
  46. package/dist/packages/_es/Icon.js +40 -15
  47. package/dist/packages/_es/Image.js +137 -26
  48. package/dist/packages/_es/ImagePreview.js +547 -76
  49. package/dist/packages/_es/Indicator.js +62 -15
  50. package/dist/packages/_es/InfiniteLoading.js +249 -57
  51. package/dist/packages/_es/Input.js +433 -51
  52. package/dist/packages/_es/InputNumber.js +160 -41
  53. package/dist/packages/_es/Layout.js +5 -4
  54. package/dist/packages/_es/List.js +106 -18
  55. package/dist/packages/_es/Menu.js +168 -44
  56. package/dist/packages/_es/MenuItem.js +173 -37
  57. package/dist/packages/_es/Navbar.js +192 -30
  58. package/dist/packages/_es/NoticeBar.js +380 -74
  59. package/dist/packages/_es/Notify.js +227 -72
  60. package/dist/packages/_es/NumberKeyboard.js +272 -41
  61. package/dist/packages/_es/OldPicker.js +457 -130
  62. package/dist/packages/_es/OverLay.js +98 -24
  63. package/dist/packages/_es/Pagination.js +157 -39
  64. package/dist/packages/_es/Picker.js +460 -129
  65. package/dist/packages/_es/Popover.js +957 -318
  66. package/dist/packages/_es/Popup.js +299 -55
  67. package/dist/packages/_es/Price.js +118 -16
  68. package/dist/packages/_es/Progress.js +146 -14
  69. package/dist/packages/_es/PullRefresh.js +339 -84
  70. package/dist/packages/_es/Radio.js +90 -22
  71. package/dist/packages/_es/RadioGroup.js +37 -8
  72. package/dist/packages/_es/Range.js +408 -83
  73. package/dist/packages/_es/Rate.js +192 -36
  74. package/dist/packages/_es/Row.js +64 -22
  75. package/dist/packages/_es/SearchBar.js +238 -37
  76. package/dist/packages/_es/ShortPassword.js +225 -35
  77. package/dist/packages/_es/SideNavBar.js +81 -24
  78. package/dist/packages/_es/SideNavBarItem.js +46 -11
  79. package/dist/packages/_es/Signature.js +160 -41
  80. package/dist/packages/_es/Skeleton.js +136 -20
  81. package/dist/packages/_es/Sku.js +491 -84
  82. package/dist/packages/_es/Step.js +115 -20
  83. package/dist/packages/_es/Steps.js +53 -18
  84. package/dist/packages/_es/Sticky.js +138 -53
  85. package/dist/packages/_es/SubSideNavBar.js +82 -17
  86. package/dist/packages/_es/Swipe.js +178 -41
  87. package/dist/packages/_es/Swiper.js +433 -121
  88. package/dist/packages/_es/SwiperItem.js +53 -22
  89. package/dist/packages/_es/Switch.js +116 -21
  90. package/dist/packages/_es/TabPane.js +39 -12
  91. package/dist/packages/_es/Tabbar.js +72 -17
  92. package/dist/packages/_es/TabbarItem.js +151 -29
  93. package/dist/packages/_es/Table.js +178 -18
  94. package/dist/packages/_es/Tabs.js +202 -43
  95. package/dist/packages/_es/Tag.js +97 -20
  96. package/dist/packages/_es/TextArea.js +160 -42
  97. package/dist/packages/_es/TimeDetail.js +79 -18
  98. package/dist/packages/_es/TimePannel.js +48 -14
  99. package/dist/packages/_es/TimeSelect.js +112 -15
  100. package/dist/packages/_es/Toast.js +310 -71
  101. package/dist/packages/_es/Uploader.js +455 -104
  102. package/dist/packages/_es/Video.js +332 -74
  103. package/dist/packages/_es/common.js +128 -38
  104. package/dist/packages/_es/component.js +76 -35
  105. package/dist/packages/_es/index.js +6 -5
  106. package/dist/packages/_es/index2.js +30 -9
  107. package/dist/packages/_es/index3.js +8 -6
  108. package/dist/packages/_es/index4.js +64 -13
  109. package/dist/packages/_es/index5.js +780 -164
  110. package/dist/packages/_es/plugin-vue_export-helper.js +8 -7
  111. package/dist/packages/_es/pxCheck.js +5 -3
  112. package/dist/packages/_es/raf.js +15 -8
  113. package/dist/packages/imagepreview/index.scss +6 -1
  114. package/dist/packages/locale/lang/baseLang.js +3 -3
  115. package/dist/packages/locale/lang/en-US.js +105 -5
  116. package/dist/packages/locale/lang/id-ID.js +105 -5
  117. package/dist/packages/locale/lang/index.js +38 -16
  118. package/dist/packages/locale/lang/zh-CN.js +105 -5
  119. package/dist/packages/locale/lang/zh-TW.js +105 -5
  120. package/dist/smartips/attributes.json +8 -0
  121. package/dist/smartips/tags.json +3 -1
  122. package/dist/smartips/web-types.json +19 -1
  123. package/dist/style.css +1 -1
  124. package/dist/style.es.js +1 -1
  125. package/dist/styles/themes/default.scss +41 -41
  126. package/dist/styles/themes/jdb.scss +41 -41
  127. package/dist/styles/themes/jdt.scss +41 -41
  128. package/dist/types/__VUE/actionsheet/index.vue.d.ts +5 -5
  129. package/dist/types/__VUE/address/index.vue.d.ts +7 -7
  130. package/dist/types/__VUE/avatar/index.vue.d.ts +4 -4
  131. package/dist/types/__VUE/avatargroup/index.vue.d.ts +2 -2
  132. package/dist/types/__VUE/backtop/index.vue.d.ts +2 -2
  133. package/dist/types/__VUE/badge/index.vue.d.ts +2 -2
  134. package/dist/types/__VUE/button/index.vue.d.ts +8 -8
  135. package/dist/types/__VUE/calendar/index.vue.d.ts +1 -1
  136. package/dist/types/__VUE/cascader/index.vue.d.ts +4 -4
  137. package/dist/types/__VUE/cell/index.vue.d.ts +6 -6
  138. package/dist/types/__VUE/checkbox/index.vue.d.ts +2 -2
  139. package/dist/types/__VUE/collapseitem/index.vue.d.ts +2 -2
  140. package/dist/types/__VUE/comment/index.vue.d.ts +2 -2
  141. package/dist/types/__VUE/datepicker/index.vue.d.ts +4 -4
  142. package/dist/types/__VUE/dialog/index.vue.d.ts +4 -4
  143. package/dist/types/__VUE/fixednav/index.vue.d.ts +4 -4
  144. package/dist/types/__VUE/grid/index.vue.d.ts +4 -4
  145. package/dist/types/__VUE/image/index.vue.d.ts +4 -4
  146. package/dist/types/__VUE/imagepreview/imagePreviewItem.vue.d.ts +95 -0
  147. package/dist/types/__VUE/imagepreview/index.vue.d.ts +23 -25
  148. package/dist/types/__VUE/input/index.vue.d.ts +4 -4
  149. package/dist/types/__VUE/inputnumber/index.vue.d.ts +2 -2
  150. package/dist/types/__VUE/menu/index.vue.d.ts +2 -2
  151. package/dist/types/__VUE/menuitem/index.vue.d.ts +1 -1
  152. package/dist/types/__VUE/noticebar/index.vue.d.ts +3 -3
  153. package/dist/types/__VUE/notify/index.vue.d.ts +2 -2
  154. package/dist/types/__VUE/numberkeyboard/index.vue.d.ts +2 -2
  155. package/dist/types/__VUE/oldpicker/index.vue.d.ts +5 -5
  156. package/dist/types/__VUE/picker/Column.vue.d.ts +1 -1
  157. package/dist/types/__VUE/picker/index.vue.d.ts +6 -6
  158. package/dist/types/__VUE/popover/index.vue.d.ts +8 -8
  159. package/dist/types/__VUE/popup/index.vue.d.ts +6 -6
  160. package/dist/types/__VUE/radio/index.vue.d.ts +4 -4
  161. package/dist/types/__VUE/range/index.vue.d.ts +4 -4
  162. package/dist/types/__VUE/shortpassword/index.vue.d.ts +1 -1
  163. package/dist/types/__VUE/skeleton/index.vue.d.ts +4 -4
  164. package/dist/types/__VUE/sku/index.vue.d.ts +5 -5
  165. package/dist/types/__VUE/step/index.vue.d.ts +2 -2
  166. package/dist/types/__VUE/sticky/index.vue.d.ts +4 -4
  167. package/dist/types/__VUE/swipe/index.vue.d.ts +2 -2
  168. package/dist/types/__VUE/swiper/index.vue.d.ts +2 -2
  169. package/dist/types/__VUE/tabbar/index.vue.d.ts +2 -2
  170. package/dist/types/__VUE/tabbaritem/index.vue.d.ts +2 -2
  171. package/dist/types/__VUE/tag/index.vue.d.ts +2 -2
  172. package/dist/types/__VUE/timeselect/index.vue.d.ts +2 -2
  173. package/dist/types/__VUE/toast/index.vue.d.ts +4 -4
  174. package/dist/types/__VUE/uploader/index.vue.d.ts +4 -4
  175. package/dist/types/index.d.ts +1 -1
  176. package/package.json +1 -2
@@ -1,131 +1,482 @@
1
1
  /*!
2
- * @nutui/nutui v3.1.22 Fri Jun 24 2022 18:11:16 GMT+0800 (中国标准时间)
2
+ * @nutui/nutui v3.1.23-beta.0 Mon Jun 27 2022 17:55:50 GMT+0800 (中国标准时间)
3
3
  * (c) 2022 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
6
- import { reactive as e, computed as t, resolveComponent as a, openBlock as l, createElementBlock as s, normalizeClass as i, renderSlot as n, Fragment as o, createCommentVNode as r, renderList as u, createElementVNode as p, toDisplayString as c, createVNode as d, createBlock as m, createTextVNode as f } from "vue";
7
- import { c as g } from "./component.js";
8
- import { _ as h } from "./plugin-vue_export-helper.js";
6
+ import { reactive, computed, resolveComponent, openBlock, createElementBlock, normalizeClass, renderSlot, Fragment, createCommentVNode, renderList, createElementVNode, toDisplayString, createVNode, createBlock, createTextVNode } from "vue";
7
+ import { c as createComponent } from "./component.js";
8
+ import { _ as _export_sfc } from "./plugin-vue_export-helper.js";
9
9
  import "../locale/lang";
10
- class y {
10
+ class UploadOptions {
11
11
  constructor() {
12
- this.url = "", this.name = "file", this.fileType = "image", this.method = "post", this.xhrState = 200, this.timeout = 3e4, this.headers = {}, this.withCredentials = false;
12
+ this.url = "";
13
+ this.name = "file";
14
+ this.fileType = "image";
15
+ this.method = "post";
16
+ this.xhrState = 200;
17
+ this.timeout = 30 * 1e3;
18
+ this.headers = {};
19
+ this.withCredentials = false;
13
20
  }
14
21
  }
15
- class _ {
16
- constructor(e2) {
17
- this.options = e2;
22
+ class Uploader {
23
+ constructor(options) {
24
+ this.options = options;
18
25
  }
19
26
  upload() {
20
27
  var _a;
21
- const e2 = this.options, t2 = new XMLHttpRequest();
22
- if (t2.timeout = e2.timeout, t2.upload) {
23
- t2.upload.addEventListener("progress", (t3) => {
28
+ const options = this.options;
29
+ const xhr = new XMLHttpRequest();
30
+ xhr.timeout = options.timeout;
31
+ if (xhr.upload) {
32
+ xhr.upload.addEventListener("progress", (e) => {
24
33
  var _a2;
25
- (_a2 = e2.onProgress) == null ? void 0 : _a2.call(e2, t3, e2);
26
- }, false), t2.onreadystatechange = () => {
34
+ (_a2 = options.onProgress) == null ? void 0 : _a2.call(options, e, options);
35
+ }, false);
36
+ xhr.onreadystatechange = () => {
27
37
  var _a2, _b;
28
- t2.readyState === 4 && (t2.status == e2.xhrState ? (_a2 = e2.onSuccess) == null ? void 0 : _a2.call(e2, t2.responseText, e2) : (_b = e2.onFailure) == null ? void 0 : _b.call(e2, t2.responseText, e2));
29
- }, t2.withCredentials = e2.withCredentials, t2.open(e2.method, e2.url, true);
30
- for (const [a2, l2] of Object.entries(e2.headers))
31
- t2.setRequestHeader(a2, l2);
32
- (_a = e2.onStart) == null ? void 0 : _a.call(e2, e2), t2.send(e2.formData);
38
+ if (xhr.readyState === 4) {
39
+ if (xhr.status == options.xhrState) {
40
+ (_a2 = options.onSuccess) == null ? void 0 : _a2.call(options, xhr.responseText, options);
41
+ } else {
42
+ (_b = options.onFailure) == null ? void 0 : _b.call(options, xhr.responseText, options);
43
+ }
44
+ }
45
+ };
46
+ xhr.withCredentials = options.withCredentials;
47
+ xhr.open(options.method, options.url, true);
48
+ for (const [key, value] of Object.entries(options.headers)) {
49
+ xhr.setRequestHeader(key, value);
50
+ }
51
+ (_a = options.onStart) == null ? void 0 : _a.call(options, options);
52
+ xhr.send(options.formData);
53
+ } else {
54
+ console.warn("\u6D4F\u89C8\u5668\u4E0D\u652F\u6301 XMLHttpRequest");
33
55
  }
34
56
  }
35
- uploadTaro(e2, t2) {
57
+ uploadTaro(uploadFile, env) {
36
58
  var _a;
37
- const a2 = this.options;
38
- if (t2 === "WEB")
59
+ const options = this.options;
60
+ if (env === "WEB") {
39
61
  this.upload();
40
- else {
41
- const t3 = e2({ url: a2.url, filePath: a2.taroFilePath, fileType: a2.fileType, header: { "Content-Type": "multipart/form-data", ...a2.headers }, formData: a2.formData, name: a2.name, success(e3) {
42
- var _a2, _b;
43
- a2.xhrState == e3.statusCode ? (_a2 = a2.onSuccess) == null ? void 0 : _a2.call(a2, e3, a2) : (_b = a2.onFailure) == null ? void 0 : _b.call(a2, e3, a2);
44
- }, fail(e3) {
45
- var _a2;
46
- (_a2 = a2.onFailure) == null ? void 0 : _a2.call(a2, e3, a2);
47
- } });
48
- (_a = a2.onStart) == null ? void 0 : _a.call(a2, a2), t3.progress((e3) => {
62
+ } else {
63
+ const uploadTask = uploadFile({
64
+ url: options.url,
65
+ filePath: options.taroFilePath,
66
+ fileType: options.fileType,
67
+ header: {
68
+ "Content-Type": "multipart/form-data",
69
+ ...options.headers
70
+ },
71
+ formData: options.formData,
72
+ name: options.name,
73
+ success(response) {
74
+ var _a2, _b;
75
+ if (options.xhrState == response.statusCode) {
76
+ (_a2 = options.onSuccess) == null ? void 0 : _a2.call(options, response, options);
77
+ } else {
78
+ (_b = options.onFailure) == null ? void 0 : _b.call(options, response, options);
79
+ }
80
+ },
81
+ fail(e) {
82
+ var _a2;
83
+ (_a2 = options.onFailure) == null ? void 0 : _a2.call(options, e, options);
84
+ }
85
+ });
86
+ (_a = options.onStart) == null ? void 0 : _a.call(options, options);
87
+ uploadTask.progress((res) => {
49
88
  var _a2;
50
- (_a2 = a2.onProgress) == null ? void 0 : _a2.call(a2, e3, a2);
89
+ (_a2 = options.onProgress) == null ? void 0 : _a2.call(options, res, options);
51
90
  });
52
91
  }
53
92
  }
54
93
  }
55
- const { translate: w } = g("uploader");
56
- class v {
94
+ const { translate: translate$1 } = createComponent("uploader");
95
+ class FileItem {
57
96
  constructor() {
58
- this.status = "ready", this.message = w("ready"), this.uid = new Date().getTime().toString(), this.percentage = 0, this.formData = {};
97
+ this.status = "ready";
98
+ this.message = translate$1("ready");
99
+ this.uid = new Date().getTime().toString();
100
+ this.percentage = 0;
101
+ this.formData = {};
59
102
  }
60
103
  }
61
- const { componentName: b, create: C, translate: k } = g("uploader"), S = C({ props: { name: { type: String, default: "file" }, url: { type: String, default: "" }, timeout: { type: [Number, String], default: 3e4 }, fileList: { type: Array, default: () => [] }, isPreview: { type: Boolean, default: true }, listType: { type: String, default: "picture" }, isDeletable: { type: Boolean, default: true }, method: { type: String, default: "post" }, capture: { type: Boolean, default: false }, maximize: { type: [Number, String], default: Number.MAX_VALUE }, maximum: { type: [Number, String], default: 1 }, clearInput: { type: Boolean, default: true }, accept: { type: String, default: "*" }, headers: { type: Object, default: {} }, data: { type: Object, default: {} }, uploadIcon: { type: String, default: "photograph" }, uploadIconSize: { type: [String, Number], default: "" }, xhrState: { type: [Number, String], default: 200 }, withCredentials: { type: Boolean, default: false }, multiple: { type: Boolean, default: false }, disabled: { type: Boolean, default: false }, autoUpload: { type: Boolean, default: true }, beforeUpload: { type: Function, default: null }, beforeDelete: { type: Function, default: (e2, t2) => true }, onChange: { type: Function } }, emits: ["start", "progress", "oversize", "success", "failure", "change", "delete", "update:fileList", "file-item-click"], setup(a2, { emit: l2 }) {
62
- const s2 = e(a2.fileList);
63
- let i2 = [];
64
- const n2 = t(() => ({ [b]: true })), o2 = (e2 = -1) => {
65
- e2 > -1 ? i2.splice(e2, 1) : i2 = [];
66
- }, r2 = (t2) => {
67
- t2.forEach((t3, n3) => {
68
- const r3 = new FormData();
69
- for (const [e2, t4] of Object.entries(a2.data))
70
- r3.append(e2, t4);
71
- r3.append(a2.name, t3);
72
- const u3 = e(new v());
73
- if (u3.name = t3.name, u3.status = "ready", u3.type = t3.type, u3.formData = r3, u3.message = k("waitingUpload"), ((e2, t4) => {
74
- const n4 = new y();
75
- n4.url = a2.url, n4.formData = e2.formData, n4.timeout = 1 * a2.timeout, n4.method = a2.method, n4.xhrState = a2.xhrState, n4.headers = a2.headers, n4.withCredentials = a2.withCredentials, n4.onStart = (a3) => {
76
- e2.status = "ready", e2.message = k("readyUpload"), o2(t4), l2("start", a3);
77
- }, n4.onProgress = (t5, a3) => {
78
- e2.status = "uploading", e2.message = k("uploading"), e2.percentage = (t5.loaded / t5.total * 100).toFixed(0), l2("progress", { event: t5, option: a3, percentage: e2.percentage });
79
- }, n4.onSuccess = (t5, a3) => {
80
- e2.status = "success", e2.message = k("success"), l2("success", { responseText: t5, option: a3, fileItem: e2 }), l2("update:fileList", s2);
81
- }, n4.onFailure = (t5, a3) => {
82
- e2.status = "error", e2.message = k("error"), l2("failure", { responseText: t5, option: a3, fileItem: e2 });
83
- };
84
- let r4 = new _(n4);
85
- a2.autoUpload ? r4.upload() : i2.push(new Promise((e3, t5) => {
86
- e3(r4);
87
- }));
88
- })(u3, n3), a2.isPreview && t3.type.includes("image")) {
89
- const e2 = new FileReader();
90
- e2.onload = (e3) => {
91
- u3.url = e3.target.result, s2.push(u3);
92
- }, e2.readAsDataURL(t3);
93
- } else
94
- s2.push(u3);
104
+ const { componentName, create, translate } = createComponent("uploader");
105
+ const _sfc_main = create({
106
+ props: {
107
+ name: { type: String, default: "file" },
108
+ url: { type: String, default: "" },
109
+ timeout: { type: [Number, String], default: 1e3 * 30 },
110
+ fileList: { type: Array, default: () => [] },
111
+ isPreview: { type: Boolean, default: true },
112
+ listType: { type: String, default: "picture" },
113
+ isDeletable: { type: Boolean, default: true },
114
+ method: { type: String, default: "post" },
115
+ capture: { type: Boolean, default: false },
116
+ maximize: { type: [Number, String], default: Number.MAX_VALUE },
117
+ maximum: { type: [Number, String], default: 1 },
118
+ clearInput: { type: Boolean, default: true },
119
+ accept: { type: String, default: "*" },
120
+ headers: { type: Object, default: {} },
121
+ data: { type: Object, default: {} },
122
+ uploadIcon: { type: String, default: "photograph" },
123
+ uploadIconSize: { type: [String, Number], default: "" },
124
+ xhrState: { type: [Number, String], default: 200 },
125
+ withCredentials: { type: Boolean, default: false },
126
+ multiple: { type: Boolean, default: false },
127
+ disabled: { type: Boolean, default: false },
128
+ autoUpload: { type: Boolean, default: true },
129
+ beforeUpload: {
130
+ type: Function,
131
+ default: null
132
+ },
133
+ beforeDelete: {
134
+ type: Function,
135
+ default: (file, files) => {
136
+ return true;
137
+ }
138
+ },
139
+ onChange: { type: Function }
140
+ },
141
+ emits: [
142
+ "start",
143
+ "progress",
144
+ "oversize",
145
+ "success",
146
+ "failure",
147
+ "change",
148
+ "delete",
149
+ "update:fileList",
150
+ "file-item-click"
151
+ ],
152
+ setup(props, { emit }) {
153
+ const fileList = reactive(props.fileList);
154
+ let uploadQueue = [];
155
+ const classes = computed(() => {
156
+ const prefixCls = componentName;
157
+ return {
158
+ [prefixCls]: true
159
+ };
95
160
  });
96
- }, u2 = (e2) => {
97
- const t2 = 1 * a2.maximum, i3 = 1 * a2.maximize, n3 = new Array();
98
- e2 = e2.filter((e3) => !(e3.size > i3) || (n3.push(e3), false)), n3.length && l2("oversize", n3);
99
- let o3 = e2.length + s2.length;
100
- return o3 > t2 && e2.splice(e2.length - (o3 - t2)), e2;
101
- };
102
- return { onChange: (e2) => {
103
- if (a2.disabled)
104
- return;
105
- const t2 = e2.target;
106
- let { files: i3 } = t2;
107
- if (a2.beforeUpload)
108
- a2.beforeUpload(i3).then((e3) => {
109
- const t3 = u2(new Array().slice.call(e3));
110
- r2(t3);
161
+ const clearInput = (el) => {
162
+ el.value = "";
163
+ };
164
+ const fileItemClick = (fileItem) => {
165
+ emit("file-item-click", { fileItem });
166
+ };
167
+ const executeUpload = (fileItem, index2) => {
168
+ const uploadOption = new UploadOptions();
169
+ uploadOption.url = props.url;
170
+ uploadOption.formData = fileItem.formData;
171
+ uploadOption.timeout = props.timeout * 1;
172
+ uploadOption.method = props.method;
173
+ uploadOption.xhrState = props.xhrState;
174
+ uploadOption.headers = props.headers;
175
+ uploadOption.withCredentials = props.withCredentials;
176
+ uploadOption.onStart = (option) => {
177
+ fileItem.status = "ready";
178
+ fileItem.message = translate("readyUpload");
179
+ clearUploadQueue(index2);
180
+ emit("start", option);
181
+ };
182
+ uploadOption.onProgress = (event, option) => {
183
+ fileItem.status = "uploading";
184
+ fileItem.message = translate("uploading");
185
+ fileItem.percentage = (event.loaded / event.total * 100).toFixed(0);
186
+ emit("progress", { event, option, percentage: fileItem.percentage });
187
+ };
188
+ uploadOption.onSuccess = (responseText, option) => {
189
+ fileItem.status = "success";
190
+ fileItem.message = translate("success");
191
+ emit("success", {
192
+ responseText,
193
+ option,
194
+ fileItem
195
+ });
196
+ emit("update:fileList", fileList);
197
+ };
198
+ uploadOption.onFailure = (responseText, option) => {
199
+ fileItem.status = "error";
200
+ fileItem.message = translate("error");
201
+ emit("failure", {
202
+ responseText,
203
+ option,
204
+ fileItem
205
+ });
206
+ };
207
+ let task = new Uploader(uploadOption);
208
+ if (props.autoUpload) {
209
+ task.upload();
210
+ } else {
211
+ uploadQueue.push(new Promise((resolve, reject) => {
212
+ resolve(task);
213
+ }));
214
+ }
215
+ };
216
+ const clearUploadQueue = (index2 = -1) => {
217
+ if (index2 > -1) {
218
+ uploadQueue.splice(index2, 1);
219
+ } else {
220
+ uploadQueue = [];
221
+ }
222
+ };
223
+ const submit = () => {
224
+ Promise.all(uploadQueue).then((res) => {
225
+ res.forEach((i) => i.upload());
111
226
  });
112
- else {
113
- const e3 = u2(new Array().slice.call(i3));
114
- r2(e3);
115
- }
116
- l2("change", { fileList: s2, event: e2 }), a2.clearInput && (t2.value = "");
117
- }, onDelete: (e2, t2) => {
118
- o2(t2), a2.beforeDelete(e2, s2) && (s2.splice(t2, 1), l2("delete", { file: e2, fileList: s2, index: t2 }));
119
- }, fileList: s2, classes: n2, fileItemClick: (e2) => {
120
- l2("file-item-click", { fileItem: e2 });
121
- }, clearUploadQueue: o2, submit: () => {
122
- Promise.all(i2).then((e2) => {
123
- e2.forEach((e3) => e3.upload());
124
- });
125
- } };
126
- } }), x = { key: 0, class: "nut-uploader__slot" }, D = ["accept", "multiple", "name", "disabled"], T = ["accept", "multiple", "name", "disabled"], L = { key: 0, class: "nut-uploader__preview-img" }, I = { key: 0, class: "nut-uploader__preview__progress" }, F = { class: "nut-uploader__preview__progress__msg" }, z = { key: 1, class: "nut-uploader__preview__progress" }, U = { class: "nut-uploader__preview__progress__msg" }, B = ["onClick", "src"], P = { key: 4, class: "nut-uploader__preview-img__file" }, A = ["onClick"], N = { class: "tips" }, j = { key: 1, class: "nut-uploader__preview-list" }, E = ["onClick"], O = ["accept", "multiple", "name", "disabled"], R = ["accept", "multiple", "name", "disabled"];
127
- var $ = h(S, [["render", function(e2, t2, g2, h2, y2, _2) {
128
- const w2 = a("nut-icon"), v2 = a("nut-progress");
129
- return l(), s("view", { class: i(e2.classes) }, [e2.$slots.default ? (l(), s("view", x, [n(e2.$slots, "default"), e2.maximum - e2.fileList.length ? (l(), s(o, { key: 0 }, [e2.capture ? (l(), s("input", { key: 0, class: "nut-uploader__input", type: "file", capture: "camera", accept: e2.accept, multiple: e2.multiple, name: e2.name, disabled: e2.disabled, onChange: t2[0] || (t2[0] = (...t3) => e2.onChange && e2.onChange(...t3)) }, null, 40, D)) : (l(), s("input", { key: 1, class: "nut-uploader__input", type: "file", accept: e2.accept, multiple: e2.multiple, name: e2.name, disabled: e2.disabled, onChange: t2[1] || (t2[1] = (...t3) => e2.onChange && e2.onChange(...t3)) }, null, 40, T))], 64)) : r("", true)])) : r("", true), (l(true), s(o, null, u(e2.fileList, (t3, a2) => (l(), s("view", { class: i(["nut-uploader__preview", [e2.listType]]), key: t3.uid }, [e2.listType != "picture" || e2.$slots.default ? e2.listType == "list" ? (l(), s("view", j, [p("view", { onClick: (a3) => e2.fileItemClick(t3), class: i(["nut-uploader__preview-img__file__name", [t3.status]]) }, [d(w2, { name: "link" }), f("\xA0" + c(t3.name), 1)], 10, E), d(w2, { class: "nut-uploader__preview-img__file__del", onClick: (l2) => e2.onDelete(t3, a2), color: "#808080", name: "del" }, null, 8, ["onClick"]), t3.status == "uploading" ? (l(), m(v2, { key: 0, size: "small", percentage: t3.percentage, "stroke-color": "linear-gradient(270deg, rgba(18,126,255,1) 0%,rgba(32,147,255,1) 32.815625%,rgba(13,242,204,1) 100%)", "show-text": false }, null, 8, ["percentage"])) : r("", true)])) : r("", true) : (l(), s("view", L, [t3.status == "ready" ? (l(), s("view", I, [p("view", F, c(t3.message), 1)])) : t3.status != "success" ? (l(), s("view", z, [d(w2, { color: "#fff", name: t3.status == "error" ? "failure" : "loading" }, null, 8, ["name"]), p("view", U, c(t3.message), 1)])) : r("", true), e2.isDeletable ? (l(), m(w2, { key: 2, color: "rgba(0,0,0,0.6)", onClick: (l2) => e2.onDelete(t3, a2), class: "close", name: "failure" }, null, 8, ["onClick"])) : r("", true), t3.type.includes("image") && t3.url ? (l(), s("img", { key: 3, class: "nut-uploader__preview-img__c", onClick: (a3) => e2.fileItemClick(t3), src: t3.url }, null, 8, B)) : (l(), s("view", P, [p("view", { onClick: (a3) => e2.fileItemClick(t3), class: "nut-uploader__preview-img__file__name" }, [d(w2, { color: "#808080", name: "link" }), f("\xA0" + c(t3.name), 1)], 8, A)])), p("view", N, c(t3.name), 1)]))], 2))), 128)), e2.listType == "picture" && !e2.$slots.default && e2.maximum - e2.fileList.length ? (l(), s("view", { key: 1, class: i(["nut-uploader__upload", [e2.listType]]) }, [d(w2, { size: e2.uploadIconSize, color: "#808080", name: e2.uploadIcon }, null, 8, ["size", "name"]), e2.capture ? (l(), s("input", { key: 0, class: "nut-uploader__input", type: "file", capture: "camera", accept: e2.accept, multiple: e2.multiple, name: e2.name, disabled: e2.disabled, onChange: t2[2] || (t2[2] = (...t3) => e2.onChange && e2.onChange(...t3)) }, null, 40, O)) : (l(), s("input", { key: 1, class: "nut-uploader__input", type: "file", accept: e2.accept, multiple: e2.multiple, name: e2.name, disabled: e2.disabled, onChange: t2[3] || (t2[3] = (...t3) => e2.onChange && e2.onChange(...t3)) }, null, 40, R))], 2)) : r("", true)], 2);
130
- }]]);
131
- export { $ as default };
227
+ };
228
+ const readFile = (files) => {
229
+ files.forEach((file, index2) => {
230
+ const formData = new FormData();
231
+ for (const [key, value] of Object.entries(props.data)) {
232
+ formData.append(key, value);
233
+ }
234
+ formData.append(props.name, file);
235
+ const fileItem = reactive(new FileItem());
236
+ fileItem.name = file.name;
237
+ fileItem.status = "ready";
238
+ fileItem.type = file.type;
239
+ fileItem.formData = formData;
240
+ fileItem.message = translate("waitingUpload");
241
+ executeUpload(fileItem, index2);
242
+ if (props.isPreview && file.type.includes("image")) {
243
+ const reader = new FileReader();
244
+ reader.onload = (event) => {
245
+ fileItem.url = event.target.result;
246
+ fileList.push(fileItem);
247
+ };
248
+ reader.readAsDataURL(file);
249
+ } else {
250
+ fileList.push(fileItem);
251
+ }
252
+ });
253
+ };
254
+ const filterFiles = (files) => {
255
+ const maximum = props.maximum * 1;
256
+ const maximize = props.maximize * 1;
257
+ const oversizes = new Array();
258
+ files = files.filter((file) => {
259
+ if (file.size > maximize) {
260
+ oversizes.push(file);
261
+ return false;
262
+ } else {
263
+ return true;
264
+ }
265
+ });
266
+ if (oversizes.length) {
267
+ emit("oversize", oversizes);
268
+ }
269
+ let currentFileLength = files.length + fileList.length;
270
+ if (currentFileLength > maximum) {
271
+ files.splice(files.length - (currentFileLength - maximum));
272
+ }
273
+ return files;
274
+ };
275
+ const onDelete = (file, index2) => {
276
+ clearUploadQueue(index2);
277
+ if (props.beforeDelete(file, fileList)) {
278
+ fileList.splice(index2, 1);
279
+ emit("delete", {
280
+ file,
281
+ fileList,
282
+ index: index2
283
+ });
284
+ }
285
+ };
286
+ const onChange = (event) => {
287
+ if (props.disabled) {
288
+ return;
289
+ }
290
+ const $el = event.target;
291
+ let { files } = $el;
292
+ if (props.beforeUpload) {
293
+ props.beforeUpload(files).then((f) => {
294
+ const _files = filterFiles(new Array().slice.call(f));
295
+ readFile(_files);
296
+ });
297
+ } else {
298
+ const _files = filterFiles(new Array().slice.call(files));
299
+ readFile(_files);
300
+ }
301
+ emit("change", {
302
+ fileList,
303
+ event
304
+ });
305
+ if (props.clearInput) {
306
+ clearInput($el);
307
+ }
308
+ };
309
+ return {
310
+ onChange,
311
+ onDelete,
312
+ fileList,
313
+ classes,
314
+ fileItemClick,
315
+ clearUploadQueue,
316
+ submit
317
+ };
318
+ }
319
+ });
320
+ const _hoisted_1 = {
321
+ key: 0,
322
+ class: "nut-uploader__slot"
323
+ };
324
+ const _hoisted_2 = ["accept", "multiple", "name", "disabled"];
325
+ const _hoisted_3 = ["accept", "multiple", "name", "disabled"];
326
+ const _hoisted_4 = {
327
+ key: 0,
328
+ class: "nut-uploader__preview-img"
329
+ };
330
+ const _hoisted_5 = {
331
+ key: 0,
332
+ class: "nut-uploader__preview__progress"
333
+ };
334
+ const _hoisted_6 = { class: "nut-uploader__preview__progress__msg" };
335
+ const _hoisted_7 = {
336
+ key: 1,
337
+ class: "nut-uploader__preview__progress"
338
+ };
339
+ const _hoisted_8 = { class: "nut-uploader__preview__progress__msg" };
340
+ const _hoisted_9 = ["onClick", "src"];
341
+ const _hoisted_10 = {
342
+ key: 4,
343
+ class: "nut-uploader__preview-img__file"
344
+ };
345
+ const _hoisted_11 = ["onClick"];
346
+ const _hoisted_12 = { class: "tips" };
347
+ const _hoisted_13 = {
348
+ key: 1,
349
+ class: "nut-uploader__preview-list"
350
+ };
351
+ const _hoisted_14 = ["onClick"];
352
+ const _hoisted_15 = ["accept", "multiple", "name", "disabled"];
353
+ const _hoisted_16 = ["accept", "multiple", "name", "disabled"];
354
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
355
+ const _component_nut_icon = resolveComponent("nut-icon");
356
+ const _component_nut_progress = resolveComponent("nut-progress");
357
+ return openBlock(), createElementBlock("view", {
358
+ class: normalizeClass(_ctx.classes)
359
+ }, [
360
+ _ctx.$slots.default ? (openBlock(), createElementBlock("view", _hoisted_1, [
361
+ renderSlot(_ctx.$slots, "default"),
362
+ _ctx.maximum - _ctx.fileList.length ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
363
+ _ctx.capture ? (openBlock(), createElementBlock("input", {
364
+ key: 0,
365
+ class: "nut-uploader__input",
366
+ type: "file",
367
+ capture: "camera",
368
+ accept: _ctx.accept,
369
+ multiple: _ctx.multiple,
370
+ name: _ctx.name,
371
+ disabled: _ctx.disabled,
372
+ onChange: _cache[0] || (_cache[0] = (...args) => _ctx.onChange && _ctx.onChange(...args))
373
+ }, null, 40, _hoisted_2)) : (openBlock(), createElementBlock("input", {
374
+ key: 1,
375
+ class: "nut-uploader__input",
376
+ type: "file",
377
+ accept: _ctx.accept,
378
+ multiple: _ctx.multiple,
379
+ name: _ctx.name,
380
+ disabled: _ctx.disabled,
381
+ onChange: _cache[1] || (_cache[1] = (...args) => _ctx.onChange && _ctx.onChange(...args))
382
+ }, null, 40, _hoisted_3))
383
+ ], 64)) : createCommentVNode("", true)
384
+ ])) : createCommentVNode("", true),
385
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.fileList, (item, index2) => {
386
+ return openBlock(), createElementBlock("view", {
387
+ class: normalizeClass(["nut-uploader__preview", [_ctx.listType]]),
388
+ key: item.uid
389
+ }, [
390
+ _ctx.listType == "picture" && !_ctx.$slots.default ? (openBlock(), createElementBlock("view", _hoisted_4, [
391
+ item.status == "ready" ? (openBlock(), createElementBlock("view", _hoisted_5, [
392
+ createElementVNode("view", _hoisted_6, toDisplayString(item.message), 1)
393
+ ])) : item.status != "success" ? (openBlock(), createElementBlock("view", _hoisted_7, [
394
+ createVNode(_component_nut_icon, {
395
+ color: "#fff",
396
+ name: item.status == "error" ? "failure" : "loading"
397
+ }, null, 8, ["name"]),
398
+ createElementVNode("view", _hoisted_8, toDisplayString(item.message), 1)
399
+ ])) : createCommentVNode("", true),
400
+ _ctx.isDeletable ? (openBlock(), createBlock(_component_nut_icon, {
401
+ key: 2,
402
+ color: "rgba(0,0,0,0.6)",
403
+ onClick: ($event) => _ctx.onDelete(item, index2),
404
+ class: "close",
405
+ name: "failure"
406
+ }, null, 8, ["onClick"])) : createCommentVNode("", true),
407
+ item.type.includes("image") && item.url ? (openBlock(), createElementBlock("img", {
408
+ key: 3,
409
+ class: "nut-uploader__preview-img__c",
410
+ onClick: ($event) => _ctx.fileItemClick(item),
411
+ src: item.url
412
+ }, null, 8, _hoisted_9)) : (openBlock(), createElementBlock("view", _hoisted_10, [
413
+ createElementVNode("view", {
414
+ onClick: ($event) => _ctx.fileItemClick(item),
415
+ class: "nut-uploader__preview-img__file__name"
416
+ }, [
417
+ createVNode(_component_nut_icon, {
418
+ color: "#808080",
419
+ name: "link"
420
+ }),
421
+ createTextVNode("\xA0" + toDisplayString(item.name), 1)
422
+ ], 8, _hoisted_11)
423
+ ])),
424
+ createElementVNode("view", _hoisted_12, toDisplayString(item.name), 1)
425
+ ])) : _ctx.listType == "list" ? (openBlock(), createElementBlock("view", _hoisted_13, [
426
+ createElementVNode("view", {
427
+ onClick: ($event) => _ctx.fileItemClick(item),
428
+ class: normalizeClass(["nut-uploader__preview-img__file__name", [item.status]])
429
+ }, [
430
+ createVNode(_component_nut_icon, { name: "link" }),
431
+ createTextVNode("\xA0" + toDisplayString(item.name), 1)
432
+ ], 10, _hoisted_14),
433
+ createVNode(_component_nut_icon, {
434
+ class: "nut-uploader__preview-img__file__del",
435
+ onClick: ($event) => _ctx.onDelete(item, index2),
436
+ color: "#808080",
437
+ name: "del"
438
+ }, null, 8, ["onClick"]),
439
+ item.status == "uploading" ? (openBlock(), createBlock(_component_nut_progress, {
440
+ key: 0,
441
+ size: "small",
442
+ percentage: item.percentage,
443
+ "stroke-color": "linear-gradient(270deg, rgba(18,126,255,1) 0%,rgba(32,147,255,1) 32.815625%,rgba(13,242,204,1) 100%)",
444
+ "show-text": false
445
+ }, null, 8, ["percentage"])) : createCommentVNode("", true)
446
+ ])) : createCommentVNode("", true)
447
+ ], 2);
448
+ }), 128)),
449
+ _ctx.listType == "picture" && !_ctx.$slots.default && _ctx.maximum - _ctx.fileList.length ? (openBlock(), createElementBlock("view", {
450
+ key: 1,
451
+ class: normalizeClass(["nut-uploader__upload", [_ctx.listType]])
452
+ }, [
453
+ createVNode(_component_nut_icon, {
454
+ size: _ctx.uploadIconSize,
455
+ color: "#808080",
456
+ name: _ctx.uploadIcon
457
+ }, null, 8, ["size", "name"]),
458
+ _ctx.capture ? (openBlock(), createElementBlock("input", {
459
+ key: 0,
460
+ class: "nut-uploader__input",
461
+ type: "file",
462
+ capture: "camera",
463
+ accept: _ctx.accept,
464
+ multiple: _ctx.multiple,
465
+ name: _ctx.name,
466
+ disabled: _ctx.disabled,
467
+ onChange: _cache[2] || (_cache[2] = (...args) => _ctx.onChange && _ctx.onChange(...args))
468
+ }, null, 40, _hoisted_15)) : (openBlock(), createElementBlock("input", {
469
+ key: 1,
470
+ class: "nut-uploader__input",
471
+ type: "file",
472
+ accept: _ctx.accept,
473
+ multiple: _ctx.multiple,
474
+ name: _ctx.name,
475
+ disabled: _ctx.disabled,
476
+ onChange: _cache[3] || (_cache[3] = (...args) => _ctx.onChange && _ctx.onChange(...args))
477
+ }, null, 40, _hoisted_16))
478
+ ], 2)) : createCommentVNode("", true)
479
+ ], 2);
480
+ }
481
+ var index = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
482
+ export { index as default };