@cloudbase/weda-ui 0.2.10 → 0.2.14

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 (111) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/package.json +61 -40
  3. package/src/.DS_Store +0 -0
  4. package/src/configs/.DS_Store +0 -0
  5. package/src/configs/components/button.json +7 -3
  6. package/src/configs/components/form/richText.json +1 -1
  7. package/src/configs/components/form/uploader.json +29 -1
  8. package/src/configs/components/form/uploaderFile.json +158 -0
  9. package/src/configs/components/image.json +12 -3
  10. package/src/configs/components/link.json +3 -3
  11. package/src/configs/components/richtextview.json +2 -2
  12. package/src/configs/components/scrollVeiw.json +5 -5
  13. package/src/configs/components/swiper.json +6 -6
  14. package/src/configs/components/tabs.json +3 -3
  15. package/src/configs/components/text.json +39 -4
  16. package/src/configs/index.js +5 -3
  17. package/src/mp/.gitignore +10 -0
  18. package/src/mp/components/button/index.js +1 -0
  19. package/src/mp/components/button/index.wxss +8 -0
  20. package/src/mp/components/form/select/index.js +18 -0
  21. package/src/mp/components/form/uploader/index.js +26 -29
  22. package/src/mp/components/form/uploaderFile/index.js +233 -0
  23. package/src/mp/components/form/uploaderFile/index.json +9 -0
  24. package/src/mp/components/form/uploaderFile/index.wxml +46 -0
  25. package/src/mp/components/form/uploaderFile/index.wxss +105 -0
  26. package/src/mp/components/text/index.js +33 -0
  27. package/src/mp/components/text/index.wxml +1 -1
  28. package/src/mp/components/text/index.wxss +18 -0
  29. package/src/mp/index.json +1 -0
  30. package/src/mp/utils/platform.js +20 -0
  31. package/src/mp/utils/tcb.js +11 -0
  32. package/src/web/.DS_Store +0 -0
  33. package/src/web/actions/showModal/{index.jsx → index.tsx} +53 -3
  34. package/src/web/components/auth/index.js +2 -2
  35. package/src/web/components/button/index.css +9 -0
  36. package/src/web/components/button/{index.jsx → index.tsx} +27 -41
  37. package/src/web/components/container/{index.jsx → index.tsx} +6 -10
  38. package/src/web/components/drawer/index.tsx +57 -0
  39. package/src/web/components/form/checkbox/{index.jsx → index.tsx} +24 -48
  40. package/src/web/components/form/enumSelect/MultipleSelect.jsx +1 -6
  41. package/src/web/components/form/enumSelect/{NormalSelect.jsx → NormalSelect.tsx} +3 -14
  42. package/src/web/components/form/form/index.tsx +48 -0
  43. package/src/web/components/form/formcell/{index.jsx → index.tsx} +6 -13
  44. package/src/web/components/form/input/index.css +39 -0
  45. package/src/web/components/form/input/{index.jsx → index.tsx} +33 -67
  46. package/src/web/components/form/radio/{index.jsx → index.tsx} +19 -42
  47. package/src/web/components/form/{renderDecorator.jsx → renderDecorator.tsx} +1 -3
  48. package/src/web/components/form/select/{h5.jsx → h5.tsx} +18 -62
  49. package/src/web/components/form/select/{index.jsx → index.tsx} +51 -94
  50. package/src/web/components/form/select/region/{cities.js → cities.ts} +1 -1
  51. package/src/web/components/form/select/region/{index.js → index.ts} +3 -3
  52. package/src/web/components/form/select/region/{provinces.js → provinces.ts} +1 -1
  53. package/src/web/components/form/select/region/{regions.js → regions.ts} +1 -1
  54. package/src/web/components/form/select/time.jsx +2 -2
  55. package/src/web/components/form/switch/{index.jsx → index.tsx} +30 -47
  56. package/src/web/components/form/textarea/{index.jsx → index.tsx} +22 -55
  57. package/src/web/components/form/tips/{index.jsx → index.tsx} +8 -22
  58. package/src/web/components/form/types.d.ts +12 -0
  59. package/src/web/components/form/uploader/{index.jsx → index.tsx} +16 -14
  60. package/src/web/components/form/uploader/{uploader.h5.jsx → uploader.h5.tsx} +67 -57
  61. package/src/web/components/form/uploader/{uploader.pc.jsx → uploader.pc.tsx} +26 -43
  62. package/src/web/components/form/uploaderFile/fail.svg +12 -0
  63. package/src/web/components/form/uploaderFile/index.css +423 -0
  64. package/src/web/components/form/uploaderFile/index.jsx +30 -0
  65. package/src/web/components/form/uploaderFile/pending.svg +18 -0
  66. package/src/web/components/form/uploaderFile/success.svg +12 -0
  67. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +578 -0
  68. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +507 -0
  69. package/src/web/components/image/{image.jsx → image.tsx} +8 -21
  70. package/src/web/components/image/{index.jsx → index.tsx} +22 -37
  71. package/src/web/components/index.js +36 -1
  72. package/src/web/components/link/{index.jsx → index.tsx} +19 -36
  73. package/src/web/components/modal/{index.jsx → index.tsx} +22 -9
  74. package/src/web/components/picker/{datePicker.jsx → datePicker.tsx} +11 -12
  75. package/src/web/components/picker/{picker.jsx → picker.tsx} +7 -10
  76. package/src/web/components/picker/{timePicker.jsx → timePicker.tsx} +8 -16
  77. package/src/web/components/richText/{const.js → const.ts} +0 -0
  78. package/src/web/components/richText/index.jsx +5 -2
  79. package/src/web/components/richTextView/index.tsx +67 -0
  80. package/src/web/components/scrollView/{index.jsx → index.tsx} +18 -33
  81. package/src/web/components/slot/{index.jsx → index.tsx} +8 -9
  82. package/src/web/components/swiper/index.css +1 -1
  83. package/src/web/components/swiper/{index.jsx → index.tsx} +73 -78
  84. package/src/web/components/tabs/index.tsx +33 -0
  85. package/src/web/components/tabs/{tabs.h5.jsx → tabs.h5.tsx} +4 -33
  86. package/src/web/components/tabs/{tabs.pc.jsx → tabs.pc.tsx} +5 -39
  87. package/src/web/components/text/index.css +18 -0
  88. package/src/web/components/text/index.tsx +69 -0
  89. package/src/web/components/uploaderFileView/index.css +11 -0
  90. package/src/web/components/uploaderFileView/index.jsx +75 -0
  91. package/src/web/components/uploaderView/{index.jsx → index.tsx} +12 -15
  92. package/src/web/types.d.ts +20 -0
  93. package/src/web/utils/constant.js +2 -0
  94. package/src/web/utils/loading-fallback.tsx +2 -0
  95. package/src/web/utils/platform.js +77 -6
  96. package/src/web/utils/tcb.js +0 -8
  97. package/src/web/utils/useSetState.ts +14 -0
  98. package/src/web/utils/useSyncValue.ts +17 -0
  99. package/src/web/wedatheme/.git +1 -0
  100. package/src/web/wedatheme/.gitignore +5 -0
  101. package/src/web/wedatheme/.npmrc +1 -0
  102. package/src/web/wedatheme/package-lock.json +14335 -0
  103. package/src/configs/components/button.svg +0 -18
  104. package/src/web/components/drawer/index.jsx +0 -64
  105. package/src/web/components/form/enumSelect/hooks/index.js +0 -49
  106. package/src/web/components/form/form/index.jsx +0 -76
  107. package/src/web/components/link/test/__snapshots__/storybook.test.js.snap +0 -754
  108. package/src/web/components/richTextView/index.jsx +0 -89
  109. package/src/web/components/tabs/index.jsx +0 -10
  110. package/src/web/components/text/index.jsx +0 -71
  111. package/src/web/utils/useSyncValue.js +0 -14
@@ -8,7 +8,7 @@
8
8
  "content": {
9
9
  "type": "string",
10
10
  "default": "这是一个链接",
11
- "title": "内容",
11
+ "title": "文本内容",
12
12
  "x-category": "基础属性",
13
13
  "x-index": 100
14
14
  },
@@ -16,7 +16,7 @@
16
16
  "type": "string",
17
17
  "x-component": "page-list",
18
18
  "default": "https://cloud.tencent.com",
19
- "title": "链接地址",
19
+ "title": "跳转页面",
20
20
  "description": "通过下拉选择应用页面,可以实现内部页面跳转",
21
21
  "x-category": "基础属性",
22
22
  "x-index": 120,
@@ -54,7 +54,7 @@
54
54
  "description": "",
55
55
  "category": "文本",
56
56
  "componentOrder": 10,
57
- "icon": "//main.qcloudimg.com/raw/eb8a45dc259eb4925d89ac88be1ecdd9/Link.svg"
57
+ "icon": "//imgcache.qq.com/qcloud/lowcode/static/ide/left-material-icon/Link.svg"
58
58
  },
59
59
  "events": [
60
60
  {
@@ -3,7 +3,7 @@
3
3
  "data": {
4
4
  "properties": {
5
5
  "value": {
6
- "title": "显示富文本内容",
6
+ "title": "内容",
7
7
  "type": "string",
8
8
  "x-component": "textarea",
9
9
  "default": "<p style='color:red'>这是富文本</p>",
@@ -17,6 +17,6 @@
17
17
  "description": "富文本展示",
18
18
  "category": "文本",
19
19
  "componentOrder": 0,
20
- "icon": "//main.qcloudimg.com/raw/9c42d779f51105715a032d139344c508/RichTextView.svg"
20
+ "icon": "//imgcache.qq.com/qcloud/lowcode/static/ide/left-material-icon/RichTextView.svg"
21
21
  }
22
22
  }
@@ -29,16 +29,16 @@
29
29
  "x-category": "基础属性"
30
30
  },
31
31
  "upperThreshold": {
32
- "title": "距顶部/左边多远时,触发 scrolltoupper 事件",
32
+ "title": "距顶部/左边多远时,触发scrolltoupper事件",
33
33
  "type": "number",
34
34
  "default": 50,
35
- "x-category": "基础属性"
35
+ "x-category": "高级属性"
36
36
  },
37
37
  "lowerThreshold": {
38
- "title": "距底部/右边多远时,触发 scrolltolower 事件",
38
+ "title": "距底部/右边多远时,触发scrolltolower事件",
39
39
  "type": "number",
40
40
  "default": 50,
41
- "x-category": "基础属性"
41
+ "x-category": "高级属性"
42
42
  },
43
43
  "scrollTop": {
44
44
  "title": "竖向滚动条位置",
@@ -51,7 +51,7 @@
51
51
  "x-category": "高级属性"
52
52
  },
53
53
  "scrollIntoView": {
54
- "title": "滚动到的元素Id",
54
+ "title": "滚到的元素ID",
55
55
  "type": "string",
56
56
  "x-category": "高级属性"
57
57
  },
@@ -3,13 +3,13 @@
3
3
  "data": {
4
4
  "properties": {
5
5
  "autoplay": {
6
- "title": "是否自动切换",
6
+ "title": "自动切换",
7
7
  "default": true,
8
8
  "type": "boolean",
9
9
  "x-category": "基础属性"
10
10
  },
11
11
  "indicatorDots": {
12
- "title": "是否显示面板指示点",
12
+ "title": "导航锚点",
13
13
  "default": true,
14
14
  "type": "boolean",
15
15
  "x-category": "高级属性"
@@ -33,26 +33,26 @@
33
33
  "x-category": "高级属性"
34
34
  },
35
35
  "circular": {
36
- "title": "是否采用衔接滑动",
36
+ "title": "衔接滑动",
37
37
  "default": true,
38
38
  "type": "boolean",
39
39
  "x-category": "高级属性"
40
40
  },
41
41
  "vertical": {
42
- "title": "滑动方向是否为纵向",
42
+ "title": "纵向轮播",
43
43
  "default": false,
44
44
  "type": "boolean",
45
45
  "x-category": "基础属性"
46
46
  },
47
47
  "indicatorColor": {
48
- "title": "指示点颜色",
48
+ "title": "锚点颜色",
49
49
  "type": "string",
50
50
  "x-component": "color",
51
51
  "default": "rgba(200, 200, 200, 0.9)",
52
52
  "x-category": "高级属性"
53
53
  },
54
54
  "indicatorActiveColor": {
55
- "title": "当前选中的指示点颜色",
55
+ "title": "锚点激活色",
56
56
  "type": "string",
57
57
  "x-component": "color",
58
58
  "default": "rgba(0, 0, 0, 0.9)",
@@ -7,7 +7,7 @@
7
7
  "x-props": {
8
8
  "data-hidebind": true
9
9
  },
10
- "x-index":1,
10
+ "x-index": 1,
11
11
  "type": "array",
12
12
  "maxLength": 20,
13
13
  "default": [
@@ -25,7 +25,7 @@
25
25
  "type": "object",
26
26
  "properties": {
27
27
  "title": {
28
- "title": "标题",
28
+ "title": "标签名称",
29
29
  "type": "string",
30
30
  "default": "标题"
31
31
  }
@@ -71,6 +71,6 @@
71
71
  "title": "选项卡",
72
72
  "description": "选项卡组件",
73
73
  "category": "展示",
74
- "icon": "//qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_files/static/comp/icons/Tabs.svg"
74
+ "icon": "//imgcache.qq.com/qcloud/lowcode/static/ide/left-material-icon/TabsContainer.svg"
75
75
  }
76
76
  }
@@ -7,27 +7,62 @@
7
7
  "type": "string",
8
8
  "x-component": "textarea",
9
9
  "default": "文本内容",
10
+ "x-category": "基础属性",
11
+ "x-index": 1
12
+ },
13
+ "level": {
14
+ "enum": [
15
+ { "label": "正文", "value": "0" },
16
+ { "label": "标题 H1", "value": "1" },
17
+ { "label": "标题 H2", "value": "2" },
18
+ { "label": "标题 H3", "value": "3" },
19
+ { "label": "标题 H4", "value": "4" },
20
+ { "label": "标题 H5", "value": "5" },
21
+ { "label": "标题 H6", "value": "6" }
22
+ ],
23
+ "type": "string",
24
+ "title": "文本格式",
25
+ "default": "0",
26
+ "x-index": 2,
27
+ "description": "标题级别,H1 - H6"
28
+ },
29
+ "textAlign": {
30
+ "title": "对齐",
31
+ "type": "string",
32
+ "default": "left",
33
+ "x-component": "textAlign",
34
+ "x-index": 3,
10
35
  "x-category": "基础属性"
11
36
  },
37
+ "textColor": {
38
+ "title": "颜色",
39
+ "type": "string",
40
+ "x-component": "color",
41
+ "x-index": 4,
42
+ "x-category": "基础属性",
43
+ "default": "rgb(0, 0, 0)"
44
+ },
12
45
  "maxLines": {
13
- "title": "最大显示行数",
46
+ "title": "最大行数",
14
47
  "type": "number",
15
48
  "default": 2,
16
- "x-category": "基础属性"
49
+ "x-index": 5,
50
+ "x-category": "高级属性"
17
51
  },
52
+
18
53
  "space": {
19
54
  "title": "连续空格",
20
55
  "type": "boolean",
21
56
  "description": "是否显示连续空格",
22
57
  "default": false,
23
- "x-category": "基础属性"
58
+ "x-category": "高级属性"
24
59
  },
25
60
  "userSelect": {
26
61
  "title": "是否可选中",
27
62
  "type": "boolean",
28
63
  "description": "是否可选中文本",
29
64
  "default": true,
30
- "x-category": "基础属性"
65
+ "x-category": "高级属性"
31
66
  }
32
67
  }
33
68
  },
@@ -16,6 +16,7 @@ import Select from './components/form/select.json';
16
16
  import Auth from './components/auth.json';
17
17
  import Slot from './components/slot.json';
18
18
  import Uploader from './components/form/uploader.json';
19
+ import UploaderFile from './components/form/uploaderFile.json';
19
20
  import ScrollView from './components/scrollVeiw.json';
20
21
  import Swiper from './components/swiper.json';
21
22
  // import Label from './components/form/label.json';
@@ -24,10 +25,10 @@ import Modal from './components/modal.json';
24
25
  import Drawer from './components/drawer.json';
25
26
  import RichText from './components/form/richText.json';
26
27
  import RichTextView from './components/richtextview.json';
27
- import Tabs from './components/tabs';
28
+ import Tabs from './components/tabs.json';
28
29
 
29
- import showToast from './actions/showToast';
30
- import showModal from './actions/showModal';
30
+ import showToast from './actions/showToast.json';
31
+ import showModal from './actions/showModal.json';
31
32
 
32
33
  export const components = {
33
34
  Button,
@@ -48,6 +49,7 @@ export const components = {
48
49
  Auth,
49
50
  Slot,
50
51
  Uploader,
52
+ UploaderFile,
51
53
  ScrollView,
52
54
  Swiper,
53
55
  // Label,
@@ -0,0 +1,10 @@
1
+ /.yarn/*
2
+ !/.yarn/patches
3
+ !/.yarn/plugins
4
+ !/.yarn/releases
5
+ !/.yarn/sdks
6
+
7
+ # Swap the comments on the following lines if you don't wish to use zero-installs
8
+ # Documentation here: https://yarnpkg.com/features/zero-installs
9
+ !/.yarn/cache
10
+ #/.pnp.*
@@ -52,6 +52,7 @@ Component({
52
52
  'weda-button': true,
53
53
  'weui-btn': true,
54
54
  'weui-btn_mini': size === 'mini',
55
+ 'weui-btn_large': size === 'large',
55
56
  'weui-btn_primary': type === 'primary',
56
57
  'weui-btn_default': type === 'default',
57
58
  'weui-btn_warn': type === 'warn',
@@ -3,3 +3,11 @@
3
3
  .weui-btn.weui-btn_primary:not(.weui-btn_disabled):active {
4
4
  background-color: var(--weui-TAG-TEXT-BLUE);
5
5
  }
6
+ .weda-ui.weui-btn.weui-btn_large {
7
+ font-size: large;
8
+ display: block;
9
+ padding-left: 14rpx;
10
+ padding-right: 14rpx;
11
+ text-align: center;
12
+ width: 100%;
13
+ }
@@ -212,6 +212,24 @@ Component({
212
212
  displayCls: displayValue ? '' : 'weui-input__placeholder',
213
213
  });
214
214
  },
215
+ range: function (range) {
216
+ const { mode } = this.properties;
217
+ let selectRange = '';
218
+ switch (mode) {
219
+ case 'selector': {
220
+ selectRange = range.map((item) => item.label);
221
+ break;
222
+ }
223
+ default: {
224
+ break;
225
+ }
226
+ }
227
+ if (selectRange != '') {
228
+ this.setData({
229
+ selectRange,
230
+ });
231
+ }
232
+ },
215
233
  },
216
234
  methods: {
217
235
  onChange(e) {
@@ -1,5 +1,5 @@
1
1
  import { getCloudInstance } from '../../../utils/tcb';
2
- import deepEqual from '../../../utils/deepEqual';
2
+ // import deepEqual from '../../../utils/deepEqual';
3
3
 
4
4
  Component({
5
5
  options: {
@@ -9,9 +9,9 @@ Component({
9
9
  attached() {
10
10
  this.setData({
11
11
  urls: this.properties.defaultValue,
12
- files: this.properties.defaultValue.map(url => ({url}))
12
+ files: this.properties.defaultValue.map((url) => ({ url })),
13
13
  });
14
- }
14
+ },
15
15
  },
16
16
  properties: {
17
17
  maxUploadCount: {
@@ -28,20 +28,20 @@ Component({
28
28
  },
29
29
  layout: {
30
30
  type: String,
31
- value: 'horizontal'
31
+ value: 'horizontal',
32
32
  },
33
33
  defaultValue: {
34
34
  type: Array,
35
- value: []
35
+ value: [],
36
36
  },
37
37
  single: {
38
38
  type: Boolean,
39
- value: false
39
+ value: false,
40
40
  },
41
41
  maxSize: {
42
42
  type: Number,
43
- value: 10
44
- }
43
+ value: 10,
44
+ },
45
45
  },
46
46
  data: {
47
47
  maxCount: 0,
@@ -67,7 +67,7 @@ Component({
67
67
  // https://github.com/wechat-miniprogram/weui-miniprogram/blob/a3630575910302e3b94e69fcef266d2b509de650/src/components/uploader/uploader.ts#L149
68
68
  // 写死的从返回值的 .urls 获取展示用的url来用。一定要将tempFilePaths透传下去,否则会重新加载然后出现闪白
69
69
  return { urls: files.tempFilePaths, cloudUrls };
70
- }
70
+ },
71
71
  },
72
72
  methods: {
73
73
  uploadError: function (e) {
@@ -77,24 +77,20 @@ Component({
77
77
  uploadSuccess: async function (e) {
78
78
  const urls = e.detail.cloudUrls; // uploadFile 获取返回值
79
79
  // 小程序自带tempURL 不需要调用 tcb.getTempFileURL 获取
80
- this.triggerEvent(
81
- 'success',
82
- {
83
- value: urls[0]
84
- }
85
- );
80
+ this.triggerEvent('success', {
81
+ value: urls[0],
82
+ });
86
83
  this.setData({
87
- files: this.data.files.concat(e.detail.urls.map(url => ({url}))),
88
- urls: [...this.data.urls, ...urls]
84
+ files: this.data.files.concat(e.detail.urls.map((url) => ({ url }))),
85
+ urls: [...this.data.urls, ...urls],
89
86
  });
90
-
91
87
  },
92
- onDelete: function(e) {
88
+ onDelete: function (e) {
93
89
  this.setData({
94
90
  files: this.data.files.filter((v, index) => e.detail.index !== index),
95
- urls: this.data.urls.filter((v, index) => e.detail.index !== index)
91
+ urls: this.data.urls.filter((v, index) => e.detail.index !== index),
96
92
  });
97
- }
93
+ },
98
94
  },
99
95
  observers: {
100
96
  // 'defaultValue': function(value) {
@@ -108,18 +104,19 @@ Component({
108
104
  // });
109
105
  // }
110
106
  // },
111
- 'maxUploadCount, single': function(maxUploadCount, single) {
107
+
108
+ 'maxUploadCount, single': function (maxUploadCount, single) {
112
109
  const maxCount = single ? 1 : maxUploadCount;
113
110
  this.setData({
114
- maxCount
111
+ maxCount,
115
112
  });
116
113
  },
117
- 'urls': function (urls) {
114
+ urls: function (urls) {
118
115
  let value = urls;
119
- if(this.properties.single) {
116
+ if (this.properties.single) {
120
117
  value = urls[0] ?? '';
121
118
  }
122
- this.triggerEvent('change', {value});
123
- }
124
- }
125
- });
119
+ this.triggerEvent('change', { value });
120
+ },
121
+ },
122
+ });
@@ -0,0 +1,233 @@
1
+ import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
2
+ import deepEqual from '../../../utils/deepEqual';
3
+ import { transSize } from '../../../utils/platform';
4
+
5
+ Component({
6
+ options: {
7
+ virtualHost: true,
8
+ multipleSlots: true,
9
+ },
10
+ lifetimes: {
11
+ attached() {
12
+ this.setData({
13
+ urls: this.properties.defaultValue,
14
+ files: this.properties.defaultValue.map((url) => ({ url })),
15
+ });
16
+ },
17
+ },
18
+ properties: {
19
+ label: {
20
+ type: String,
21
+ value: '文件上传',
22
+ },
23
+ //是否显示标题
24
+ labelVisible: {
25
+ type: Boolean,
26
+ value: true,
27
+ },
28
+ //单文件上传模式
29
+ single: {
30
+ type: Boolean,
31
+ value: false,
32
+ },
33
+ defaultValue: {
34
+ type: Array,
35
+ value: [],
36
+ },
37
+ maxUploadCount: {
38
+ type: Number,
39
+ value: 9,
40
+ },
41
+ //单个文件最大使用限制
42
+ maxSize: {
43
+ type: Number,
44
+ value: 10,
45
+ },
46
+ layout: {
47
+ type: String,
48
+ value: 'horizontal',
49
+ },
50
+ extClass: {
51
+ type: String,
52
+ value: '',
53
+ },
54
+ tips: {
55
+ type: Boolean,
56
+ value: false,
57
+ },
58
+ status: {
59
+ type: String,
60
+ valve: 'success',
61
+ },
62
+ downloadVisible: {
63
+ type: Boolean,
64
+ value: true,
65
+ },
66
+ },
67
+ data: {
68
+ maxCount: 0,
69
+ files: [],
70
+ urls: [],
71
+ },
72
+ methods: {
73
+ // 批量上传文件前置事件
74
+ handleBefore: function (files = []) {
75
+ if (this.data.files.length + files.length > this.data.maxCount) {
76
+ wx.showToast({
77
+ title: `上传文件总数不能超过${this.data.maxCount}个`,
78
+ icon: 'none',
79
+ duration: 2000,
80
+ });
81
+ return false;
82
+ }
83
+ if (
84
+ this.properties.maxSize &&
85
+ files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)
86
+ ) {
87
+ wx.showToast({
88
+ title: `上传文件大小不能超过${this.properties.maxSize}M`,
89
+ icon: 'none',
90
+ duration: 2000,
91
+ });
92
+ return false;
93
+ }
94
+ if (files.some((f) => f.size > 1024 * 1024 * 1024)) {
95
+ wx.showToast({
96
+ title: `上传文件大小不能超过1024M`,
97
+ icon: 'none',
98
+ duration: 2000,
99
+ });
100
+ return false;
101
+ }
102
+ return true;
103
+ },
104
+ //上传文件过程
105
+ uploadFile: async function () {
106
+ //文件上传的函数,
107
+ wx.chooseMessageFile({
108
+ count: this.data.maxCount,
109
+ type: 'all',
110
+ success: async (files) => {
111
+ this.handleUpload(files);
112
+ },
113
+ fail(e) {
114
+ this.triggerEvent('error', e.detail);
115
+ },
116
+ });
117
+ },
118
+ handleUpload: async function (files) {
119
+ var _this = this;
120
+ if (!this.handleBefore(files?.tempFiles)) return;
121
+ const uploadPath = 'weda-uploader';
122
+ const uploadPromise = files.tempFiles.map(async (tempFile) => {
123
+ const fileType = tempFile.path.split('.')?.[1];
124
+ const cloudPath = `${uploadPath}/uploader-${Date.now()}.${fileType}`;
125
+ tempFile.percent = '0';
126
+ tempFile.cloudPath = null;
127
+ tempFile.filePath = tempFile?.path || null;
128
+ tempFile.size = transSize(tempFile?.size);
129
+ tempFile.status = 'uploading';
130
+ this.data.files.push(tempFile);
131
+ this.setData({
132
+ files: [...this.data.files],
133
+ });
134
+ //初始上传文件状态
135
+ let index = this.data.files.length - 1;
136
+ try {
137
+ const tcb = await getCloudInstance();
138
+ const uploadTask = await tcb.uploadFile({
139
+ cloudPath: cloudPath,
140
+ filePath: tempFile.path,
141
+ success(res) {
142
+ _this.data.files[index].cloudPath = res.fileID;
143
+ _this.data.files[index].percent = 100;
144
+ _this.data.files[index].status = 'success';
145
+ const arr = [];
146
+ arr.push(res.fileID);
147
+ _this.setData({
148
+ files: _this.data.files,
149
+ urls: [..._this.data.urls, ...arr],
150
+ });
151
+ if (_this.properties.single) {
152
+ _this.triggerEvent('success', {
153
+ value: _this.data.urls[0],
154
+ });
155
+ } else {
156
+ _this.triggerEvent('success', {
157
+ value: _this.data.urls,
158
+ });
159
+ }
160
+ },
161
+ fail() {
162
+ this.data.files[index].status = 'fail';
163
+ },
164
+ });
165
+ uploadTask.onProgressUpdate((res) => {
166
+ this.data.files[index].percent = String(res.progress);
167
+ res.progress == 100
168
+ ? (this.data.files[index].status = 'success')
169
+ : (this.data.files[index].status = 'uploading');
170
+ this.data.files[index].uploaded = transSize(res.totalBytesSent);
171
+ this.setData({
172
+ files: this.data.files,
173
+ });
174
+ });
175
+ return { fileID: uploadTask.fileID };
176
+ } catch (e) {
177
+ this.triggerEvent('error', e.detail);
178
+ this.data.files[index].status = 'fail';
179
+ }
180
+ });
181
+ this.setData({
182
+ files: this.data.files,
183
+ });
184
+ return { urls: files.tempFiles };
185
+ },
186
+
187
+ onDelete: function (e) {
188
+ const filelist = this.data.files.filter(
189
+ (item) => e.target.dataset.item?.path != item?.path
190
+ );
191
+ this.setData({
192
+ files: filelist,
193
+ urls: this.data.urls.filter(
194
+ (v, index) => e.target.dataset.item?.cloudPath != v
195
+ ),
196
+ });
197
+ },
198
+ reload: function (e) {
199
+ this.handleUpload(e.target.dataset.item);
200
+ },
201
+ downloadFile: async function (e) {
202
+ const fileSrc = await getTempFileURL(e.target.dataset.item?.cloudPath);
203
+ wx.downloadFile({
204
+ url: fileSrc,
205
+ success(res) {
206
+ // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
207
+ if (res.statusCode === 200) {
208
+ wx.showToast({
209
+ title: `下载成功`,
210
+ icon: 'none',
211
+ duration: 2000,
212
+ });
213
+ }
214
+ },
215
+ });
216
+ },
217
+ },
218
+ observers: {
219
+ 'maxUploadCount, single': function (maxUploadCount, single) {
220
+ const maxCount = single ? 1 : maxUploadCount;
221
+ this.setData({
222
+ maxCount,
223
+ });
224
+ },
225
+ urls: function (urls) {
226
+ let value = urls;
227
+ if (this.properties.single) {
228
+ value = urls[0] ?? '';
229
+ }
230
+ this.triggerEvent('change', { value });
231
+ },
232
+ },
233
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "component": true,
3
+ "styleIsolation": "shared",
4
+ "usingComponents": {
5
+ "mp-icon": "weui-miniprogram/icon/icon",
6
+ "mp-cells": "weui-miniprogram/cells/cells",
7
+ "mp-cell": "weui-miniprogram/cell/cell"
8
+ }
9
+ }