@cloudbase/weda-ui 1.0.24 → 2.0.8

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 (144) hide show
  1. package/package.json +2 -2
  2. package/src/configs/components/button.json +0 -2
  3. package/src/configs/components/calendar.json +5 -2
  4. package/src/configs/components/carousel.json +18 -9
  5. package/src/configs/components/chart/bar.json +12 -6
  6. package/src/configs/components/chart/line.json +8 -4
  7. package/src/configs/components/chart/pie.json +8 -4
  8. package/src/configs/components/dataView.json +10 -5
  9. package/src/configs/components/form/radio.json +27 -0
  10. package/src/configs/components/form/select.json +2 -2
  11. package/src/configs/components/graphicCard.json +6 -2
  12. package/src/configs/components/image.json +12 -6
  13. package/src/configs/components/link.json +6 -3
  14. package/src/configs/components/listView.json +20 -10
  15. package/src/configs/components/lottery.json +4 -2
  16. package/src/configs/components/navLayout.json +12 -6
  17. package/src/configs/components/richtextview.json +2 -1
  18. package/src/configs/components/scrollVeiw.json +24 -12
  19. package/src/configs/components/swiper.json +18 -9
  20. package/src/configs/components/tabs.json +4 -2
  21. package/src/configs/components/text.json +10 -5
  22. package/src/docs/common/format.tsx +112 -0
  23. package/src/docs/common/tableView.css +164 -0
  24. package/src/docs/common/tableView.tsx +273 -0
  25. package/src/docs/compsdocs/chart/Bar.mdx +159 -0
  26. package/src/docs/compsdocs/chart/Line.mdx +100 -0
  27. package/src/docs/compsdocs/chart/Pie.mdx +83 -0
  28. package/src/docs/compsdocs/chart/_category_.json +1 -0
  29. package/src/docs/compsdocs/chart/statisticsCard.mdx +51 -0
  30. package/src/docs/compsdocs/database/DataView.mdx +33 -0
  31. package/src/docs/compsdocs/database/ListView.mdx +33 -0
  32. package/src/docs/compsdocs/database/_category_.json +1 -0
  33. package/src/docs/compsdocs/form/Form.mdx +35 -0
  34. package/src/docs/compsdocs/form/FormCheckbox.mdx +35 -0
  35. package/src/docs/compsdocs/form/FormDate.mdx +30 -0
  36. package/src/docs/compsdocs/form/FormEmail.mdx +30 -0
  37. package/src/docs/compsdocs/form/FormImageUploader.mdx +31 -0
  38. package/src/docs/compsdocs/form/FormInput.mdx +30 -0
  39. package/src/docs/compsdocs/form/FormLocation.mdx +64 -0
  40. package/src/docs/compsdocs/form/FormPhone.mdx +30 -0
  41. package/src/docs/compsdocs/form/FormRadio.mdx +35 -0
  42. package/src/docs/compsdocs/form/FormRegion.mdx +30 -0
  43. package/src/docs/compsdocs/form/FormSelect.mdx +36 -0
  44. package/src/docs/compsdocs/form/FormSwitch.mdx +30 -0
  45. package/src/docs/compsdocs/form/FormTextarea.mdx +30 -0
  46. package/src/docs/compsdocs/form/FormTime.mdx +30 -0
  47. package/src/docs/compsdocs/form/FormUploadFile.mdx +30 -0
  48. package/src/docs/compsdocs/form/FormUrl.mdx +30 -0
  49. package/src/docs/compsdocs/form/_category_.json +1 -0
  50. package/src/docs/compsdocs/grid/Card.mdx +32 -0
  51. package/src/docs/compsdocs/grid/Container.mdx +42 -0
  52. package/src/docs/compsdocs/grid/Footer.mdx +31 -0
  53. package/src/docs/compsdocs/grid/GridLayout.mdx +32 -0
  54. package/src/docs/compsdocs/grid/Header.mdx +31 -0
  55. package/src/docs/compsdocs/grid/Layout.mdx +25 -0
  56. package/src/docs/compsdocs/grid/List.mdx +31 -0
  57. package/src/docs/compsdocs/grid/ScrollView.mdx +37 -0
  58. package/src/docs/compsdocs/grid/Swiper.mdx +58 -0
  59. package/src/docs/compsdocs/grid/_category_.json +1 -0
  60. package/src/docs/compsdocs/media/Icon.mdx +31 -0
  61. package/src/docs/compsdocs/media/Image.mdx +55 -0
  62. package/src/docs/compsdocs/media/_category_.json +1 -0
  63. package/src/docs/compsdocs/model/ModelCreate.mdx +20 -0
  64. package/src/docs/compsdocs/model/ModelDetail.mdx +20 -0
  65. package/src/docs/compsdocs/model/ModelTable.mdx +24 -0
  66. package/src/docs/compsdocs/model/ModelUpdate.mdx +21 -0
  67. package/src/docs/compsdocs/model/PageLayout.mdx +21 -0
  68. package/src/docs/compsdocs/model/_category_.json +1 -0
  69. package/src/docs/compsdocs/navmenu/Classification.mdx +38 -0
  70. package/src/docs/compsdocs/navmenu/NavBar.mdx +43 -0
  71. package/src/docs/compsdocs/navmenu/NavLayout.mdx +30 -0
  72. package/src/docs/compsdocs/navmenu/TabBar.mdx +43 -0
  73. package/src/docs/compsdocs/navmenu/TabBarItem.mdx +29 -0
  74. package/src/docs/compsdocs/navmenu/_category_.json +1 -0
  75. package/src/docs/compsdocs/senior/Lottery.mdx +48 -0
  76. package/src/docs/compsdocs/senior/Modal.mdx +58 -0
  77. package/src/docs/compsdocs/senior/SlotMachine.mdx +52 -0
  78. package/src/docs/compsdocs/senior/_category_.json +1 -0
  79. package/src/docs/compsdocs/show/Calendar.mdx +29 -0
  80. package/src/docs/compsdocs/show/Divider.mdx +31 -0
  81. package/src/docs/compsdocs/show/GraphicCard.mdx +30 -0
  82. package/src/docs/compsdocs/show/Item.mdx +32 -0
  83. package/src/docs/compsdocs/show/ItemList.mdx +47 -0
  84. package/src/docs/compsdocs/show/Media.mdx +25 -0
  85. package/src/docs/compsdocs/show/StatusTip.mdx +25 -0
  86. package/src/docs/compsdocs/show/Swiper.mdx +33 -0
  87. package/src/docs/compsdocs/show/Tabs.mdx +38 -0
  88. package/src/docs/compsdocs/show/_category_.json +1 -0
  89. package/src/docs/compsdocs/show/button.mdx +25 -0
  90. package/src/docs/compsdocs/text/Link.mdx +43 -0
  91. package/src/docs/compsdocs/text/RichTextView.mdx +36 -0
  92. package/src/docs/compsdocs/text/Text.mdx +31 -0
  93. package/src/docs/compsdocs/text/Title.mdx +32 -0
  94. package/src/docs/compsdocs/text/_category_.json +1 -0
  95. package/src/docs/compsdocs/wxOpen/Phone.mdx +60 -0
  96. package/src/docs/compsdocs/wxOpen/Share.mdx +46 -0
  97. package/src/docs/compsdocs/wxOpen/UserInfo.mdx +60 -0
  98. package/src/docs/compsdocs/wxOpen/_category_.json +4 -0
  99. package/src/mp/components/button/index.js +18 -2
  100. package/src/mp/components/button/index.wxml +6 -2
  101. package/src/mp/components/form/formcell/index.wxml +1 -1
  102. package/src/mp/components/form/formcell/index.wxss +17 -0
  103. package/src/mp/components/form/input/index.wxss +15 -0
  104. package/src/mp/components/form/location/index.wxss +4 -6
  105. package/src/mp/components/form/select/index.js +5 -3
  106. package/src/mp/components/form/select/index.wxss +4 -0
  107. package/src/mp/components/form/textarea/index.js +1 -1
  108. package/src/mp/components/form/textarea/index.wxss +4 -0
  109. package/src/mp/components/form/uploader/index.json +3 -2
  110. package/src/mp/components/form/uploader/index.wxml +11 -7
  111. package/src/mp/components/form/uploader/index.wxss +20 -2
  112. package/src/mp/components/form/uploader/weui-uploader.js +209 -0
  113. package/src/mp/components/form/uploader/weui-uploader.json +7 -0
  114. package/src/mp/components/form/uploader/weui-uploader.wxml +45 -0
  115. package/src/mp/components/form/uploader/weui-uploader.wxss +1 -0
  116. package/src/mp/components/form/uploaderFile/index.wxss +4 -4
  117. package/src/mp/components/image/index.wxss +3 -2
  118. package/src/mp/style/weda-ui.wxss +14 -0
  119. package/src/web/components/button/index.tsx +7 -7
  120. package/src/web/components/calendar/index.jsx +1 -1
  121. package/src/web/components/carousel/index.tsx +8 -8
  122. package/src/web/components/form/form/index.css +5 -1
  123. package/src/web/components/form/form/index.tsx +3 -1
  124. package/src/web/components/form/formcell/index.css +22 -1
  125. package/src/web/components/form/formcell/index.tsx +2 -2
  126. package/src/web/components/form/input/index.css +7 -12
  127. package/src/web/components/form/location/components/LocationH5/index.css +4 -7
  128. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +1 -1
  129. package/src/web/components/form/select/index.css +5 -0
  130. package/src/web/components/form/textarea/index.css +4 -0
  131. package/src/web/components/form/textarea/index.tsx +2 -2
  132. package/src/web/components/form/uploader/index.css +26 -2
  133. package/src/web/components/form/uploader/uploader.h5.tsx +81 -56
  134. package/src/web/components/form/uploaderFile/index.css +2 -4
  135. package/src/web/components/image/index.css +3 -3
  136. package/src/web/components/image/index.tsx +6 -7
  137. package/src/web/components/link/index.tsx +2 -2
  138. package/src/web/components/listView/index.tsx +2 -2
  139. package/src/web/components/navLayout/index.tsx +2 -2
  140. package/src/web/components/navigationBar/index.tsx +0 -1
  141. package/src/web/components/picker/timePicker.tsx +2 -2
  142. package/src/web/components/slot/index.tsx +1 -1
  143. package/src/web/components/text/index.tsx +6 -6
  144. package/src/web/weda-ui.css +5 -1
@@ -0,0 +1,60 @@
1
+ # 获取手机号
2
+
3
+ <TableLayoutView
4
+ componentKey="Phone"
5
+ type="description"
6
+ origin="sourceCode"
7
+ ></TableLayoutView>
8
+
9
+ ## 使用说明
10
+
11
+ 使用获取手机号组件能够在小程序运行态对用户的手机号进行获取,使用方式如下:
12
+
13
+ 1.创建应用,应用构建类型需要为小程序构建或三端构建。
14
+
15
+ ![](https://qcloudimg.tencent-cloud.cn/raw/b9e5a27263fe0f992618757086010017.png)
16
+
17
+ 2.在编辑器中添加**获取手机号**组件。
18
+
19
+ ![](https://qcloudimg.tencent-cloud.cn/raw/6eac32bcf54b345c5d23ee3ec49de19c.png)
20
+
21
+ 3.为应用创建一个字符串类型的普通变量,用于接收获取到的手机号信息。
22
+
23
+ ![](https://qcloudimg.tencent-cloud.cn/raw/5bd62e877d0a5805368ca55633627403.png)
24
+
25
+ 4.为获取手机号组件配置变量赋值事件,实现当用户授权成功后将返回的手机号信息赋值给步骤3中的普通变量。
26
+
27
+ ![](https://qcloudimg.tencent-cloud.cn/raw/98e456ef06ee76e138dcc13d03705f33.png)
28
+
29
+ 5.该组件仅在小程序真实运行状态下生效,因此我们在编辑器中添加一个文本组件并与普通变量进行绑定,当用户在小程序中点击获取手机号按钮并授权成功时,文本组件便会展示对应的手机号信息。
30
+
31
+ ![](https://qcloudimg.tencent-cloud.cn/raw/9373c76dd92a98cd222eab37e7cca495.png)
32
+
33
+ 6.将应用发布到小程序,可以看到当点击获取手机号按钮并授权时,文本组件便会对获取到的手机号码信息进行展示。
34
+
35
+ ![](https://qcloudimg.tencent-cloud.cn/raw/1b4c8a656ae0298534e9f5c2749c9b04.png)
36
+
37
+
38
+ ## 组件使用限制
39
+
40
+ 1.该组件仅支持在小程序端使用,并且小程序必须为**企业主体**。
41
+
42
+ 2.该组件必须在小程序真实环境使用才能够看到实际效果。
43
+
44
+ ## 属性
45
+
46
+ import TableLayoutView from '../../common/tableView';
47
+
48
+ <TableLayoutView
49
+ componentKey="Phone"
50
+ type="attribute"
51
+ origin="sourceCode"
52
+ ></TableLayoutView>
53
+
54
+ ## 事件
55
+
56
+ <TableLayoutView
57
+ componentKey="Phone"
58
+ type="event"
59
+ origin="sourceCode"
60
+ ></TableLayoutView>
@@ -0,0 +1,46 @@
1
+ # 小程序分享
2
+
3
+ <TableLayoutView
4
+ componentKey="Share"
5
+ type="description"
6
+ origin="sourceCode"
7
+ ></TableLayoutView>
8
+
9
+ ## 使用说明
10
+
11
+ 小程序分享组件支持快捷实现小程序分享功能,在小程序中点击该组件时,便会根据当前组件配置进行页面的分享,使用方法如下:
12
+
13
+ 1.创建应用,应用构建类型需要为小程序构建或三端构建。
14
+
15
+ ![](https://qcloudimg.tencent-cloud.cn/raw/b9e5a27263fe0f992618757086010017.png)
16
+
17
+ 2.为编辑区中添加**小程序分享**组件,并在右侧配置区进行分享参数的设置。
18
+
19
+ ![](https://qcloudimg.tencent-cloud.cn/raw/500bda4094df6b2c519eec8976ec4acd.png)
20
+
21
+ 3.将应用发布到小程序,可以看到当点击小程序分享按钮时,会自动调起分享弹窗,分享信息与配置区的配置相同。
22
+
23
+ ![](https://qcloudimg.tencent-cloud.cn/raw/5f9add0024c8cb8f65464a4700a12652.png)
24
+
25
+
26
+ ## 组件使用限制
27
+
28
+ 1.该组件必须在小程序真实环境使用才能够看到实际效果。
29
+
30
+ ## 属性
31
+
32
+ import TableLayoutView from '../../common/tableView';
33
+
34
+ <TableLayoutView
35
+ componentKey="Share"
36
+ type="attribute"
37
+ origin="sourceCode"
38
+ ></TableLayoutView>
39
+
40
+ ## 事件
41
+
42
+ <TableLayoutView
43
+ componentKey="Share"
44
+ type="event"
45
+ origin="sourceCode"
46
+ ></TableLayoutView>
@@ -0,0 +1,60 @@
1
+ # 获取用户信息
2
+
3
+ <TableLayoutView
4
+ componentKey="UserInfo"
5
+ type="description"
6
+ origin="sourceCode"
7
+ ></TableLayoutView>
8
+
9
+ ## 使用说明
10
+
11
+ 使用获取用户信息组件能够在小程序运行态对用户的微信头像、微信昵称等信息进行获取,使用方式如下:
12
+
13
+ 1.创建应用,应用构建类型需要为小程序构建或三端构建。
14
+
15
+ ![](https://qcloudimg.tencent-cloud.cn/raw/b9e5a27263fe0f992618757086010017.png)
16
+
17
+ 2.在编辑器中添加**获取用户信息**组件,并且在组件的右侧配置区填写**信息用途**。(若不填写**信息用途**,将导致功能不可用,请注意)
18
+
19
+ ![](https://qcloudimg.tencent-cloud.cn/raw/44d4f6bf1c9aaffa4bf7e3a1c0bcf83e.png)
20
+
21
+ 3.为应用创建一个字符串类型的普通变量,用于接收获取到的用户信息。
22
+
23
+ ![](https://qcloudimg.tencent-cloud.cn/raw/1dd6a703ff51f0fe45059fdb504d25ff.png)
24
+
25
+ 4.为获取用户信息组件配置变量赋值事件,实现当用户授权成功后将返回的用户信息赋值给步骤3中的普通变量。
26
+
27
+ ![](https://qcloudimg.tencent-cloud.cn/raw/ed12e3858ffba97f9ecbae7557ed03db.png)
28
+
29
+ 5.该组件仅在小程序真实运行状态下生效,因此我们在编辑器中添加一个文本组件并与普通变量进行绑定,当用户在小程序中点击获取用户信息按钮并授权成功时,文本组件便会展示对应的用户信息。
30
+
31
+ ![](https://qcloudimg.tencent-cloud.cn/raw/a55e1ab45de33489a1d61557a4f5f1b0.png)
32
+
33
+ 6.将应用发布到小程序,可以看到当点击获取用户信息按钮并授权时,文本组件便会对获取到的用户信息进行展示。
34
+
35
+ ![](https://qcloudimg.tencent-cloud.cn/raw/7aa344e9347a894975598ba1ab7b987e.png)
36
+
37
+
38
+ ## 组件使用限制
39
+
40
+ 1.该组件必须在小程序真实环境使用才能够看到实际效果。
41
+
42
+ 2.组件右侧配置区中**信息用途**必须进行填写,否则组件将无法正常使用。
43
+
44
+ ## 属性
45
+
46
+ import TableLayoutView from '../../common/tableView';
47
+
48
+ <TableLayoutView
49
+ componentKey="UserInfo"
50
+ type="attribute"
51
+ origin="sourceCode"
52
+ ></TableLayoutView>
53
+
54
+ ## 事件
55
+
56
+ <TableLayoutView
57
+ componentKey="UserInfo"
58
+ type="event"
59
+ origin="sourceCode"
60
+ ></TableLayoutView>
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "微信开放能力",
3
+ "position": 100
4
+ }
@@ -41,6 +41,24 @@ Component({
41
41
  openType: {
42
42
  type: String,
43
43
  },
44
+ sessionFrom: {
45
+ type: String,
46
+ },
47
+ sendMessageTitle: {
48
+ type: String,
49
+ },
50
+ sendMessagePath: {
51
+ type: String,
52
+ },
53
+ sendMessageImg: {
54
+ type: String,
55
+ },
56
+ showMessageCard: {
57
+ type: Boolean,
58
+ },
59
+ appParameter: {
60
+ type: String,
61
+ }
44
62
  },
45
63
  data: {
46
64
  cls: '',
@@ -48,9 +66,7 @@ Component({
48
66
  methods: {
49
67
  ...handleEvents([
50
68
  { title: '点击', name: 'tap' },
51
- { title: '获取手机号', name: 'getPhoneNumber' },
52
69
  { title: '打开客服会话', name: 'contact' },
53
- { title: '获取用户信息', name: 'getUserInfo' },
54
70
  { title: '打开App', name: 'launchApp' },
55
71
  { title: '打开授权设置', name: 'openSetting' },
56
72
  ]),
@@ -7,11 +7,15 @@
7
7
  open-type="{{openType}}"
8
8
  form-type="{{formType}}"
9
9
  bind:tap="tap"
10
- bindgetphonenumber="{{'getP' + 'honeN' + 'umber'}}"
11
10
  bindcontact="contact"
12
- bindgetuserinfo="getUserInfo"
13
11
  bindlaunchapp="launchApp"
14
12
  bindopensetting="openSetting"
13
+ session-from="{{sessionFrom}}"
14
+ send-message-title="{{sendMessageTitle}}"
15
+ send-message-path="{{sendMessagePath}}"
16
+ send-message-img="{{sendMessageImg}}"
17
+ show-message-card="{{showMessageCard}}"
18
+ app-parameter="{{appParameter}}"
15
19
  >
16
20
  <block>{{text ? text : ''}}</block>
17
21
  <slot name="contentSlot" wx:if="{{!text}}" />
@@ -1,8 +1,8 @@
1
1
  <view class="{{className}}" style="{{style}}">
2
2
  <view class="{{cls}}">
3
3
  <view wx:if="{{!!label}}" class="weda-formcells__label weui-cell">
4
- <label wx:if="{{requiredFlag}}" class="weda-formcells__flag">*</label>
5
4
  <label>{{label}}</label>
5
+ <label wx:if="{{requiredFlag}}" class="weda-formcells__flag">*</label>
6
6
  </view>
7
7
  <view class="weda-formcells__content {{isFlex ? 'weui-flex__item' : ''}}">
8
8
  <slot></slot>
@@ -6,4 +6,21 @@
6
6
  font-family: SimSun;
7
7
  font-size: 12px;
8
8
  color: #f60;
9
+ align-self: flex-start;
10
+ }
11
+
12
+ .weda-formcells.weui-flex .weda-formcells__label {
13
+ width: 130px;
14
+ }
15
+
16
+ .weui-cells__group_form .weui-cell {
17
+ padding: 16px 16px;
18
+ }
19
+
20
+ .weda-formcells__content.weui-flex__item .weui-cell_form {
21
+ padding: 0;
22
+ }
23
+
24
+ .weda-formcells__content.weui-flex__item .weui-cell_form {
25
+ padding-right: 16px;
9
26
  }
@@ -1 +1,16 @@
1
1
  @import '../../../style/weda-ui.wxss';
2
+
3
+ /*
4
+ 把weui-cell 的padding还回到input
5
+ */
6
+ .weda-ui .weui-input {
7
+ padding: 28rpx 0;
8
+ }
9
+
10
+ .weui-btn_input-clear {
11
+ align-self: center;
12
+ }
13
+
14
+ /**
15
+ * END
16
+ */
@@ -1,8 +1,5 @@
1
1
  /* components/location/location.wxss */
2
2
 
3
- .form-location {
4
- }
5
-
6
3
  .form-location-warp {
7
4
  display: flex;
8
5
  white-space: nowrap;
@@ -26,10 +23,11 @@
26
23
  bottom: 0;
27
24
  }
28
25
 
29
- .form-location-con {
26
+ .form-location_cell.form-location-con {
30
27
  flex: 1;
31
28
  display: flex;
32
29
  align-items: center;
30
+ padding-left: 0px;
33
31
  }
34
32
 
35
33
  .form-location-label_flag {
@@ -41,7 +39,7 @@
41
39
  }
42
40
 
43
41
  .form-location-label {
44
- max-width: 150px;
42
+ width: 130px;
45
43
  overflow: hidden;
46
44
  white-space: nowrap;
47
45
  text-overflow: ellipsis;
@@ -59,7 +57,7 @@
59
57
  }
60
58
 
61
59
  .form-location_cell {
62
- padding: 16px 32px;
60
+ padding: 16px;
63
61
  line-height: 1.41176471;
64
62
  font-size: 17px;
65
63
  overflow: hidden;
@@ -249,12 +249,14 @@ Component({
249
249
  },
250
250
  },
251
251
  observers: {
252
- 'defaultValue, defaultTime, defaultRegion,defaultMutiRegion': function (
252
+ 'defaultValue, defaultTime, defaultRegion,defaultMutiRegion,defaultDate': function (
253
253
  defaultValue,
254
254
  defaultTime,
255
- defaultRegion
255
+ defaultRegion,
256
+ defaultMutiRegion,
257
+ defaultDate
256
258
  ) {
257
- const { range, mode, separator, placeholder, dateMode, defaultDate, format, option, defaultMutiRegion } =
259
+ const { range, mode, separator, placeholder, dateMode, format, option } =
258
260
  this.properties;
259
261
  let value, displayValue;
260
262
  switch (mode) {
@@ -1 +1,5 @@
1
1
  @import '../../../style/weda-ui.wxss';
2
+ .weda-ui .weui-cell.weui-check__label {
3
+ padding: 16px;
4
+ padding-left: 0;
5
+ }
@@ -64,7 +64,7 @@ Component({
64
64
  this.setData({
65
65
  cls: classNames({
66
66
  'weda-ui': true,
67
- 'weda-radio': true,
67
+ 'weda-textarea': true,
68
68
  [className]: className,
69
69
  }),
70
70
  });
@@ -1 +1,5 @@
1
1
  @import '../../../style/weda-ui.wxss';
2
+
3
+ .weda-ui .weda-textarea .weui-cell_form {
4
+ padding: 16px;
5
+ }
@@ -2,8 +2,9 @@
2
2
  "component": true,
3
3
  "styleIsolation": "shared",
4
4
  "usingComponents": {
5
- "mp-uploader": "weui-miniprogram/uploader/uploader",
5
+ "mp-uploader": "./weui-uploader",
6
6
  "mp-cells": "weui-miniprogram/cells/cells",
7
- "mp-cell": "weui-miniprogram/cell/cell"
7
+ "mp-cell": "weui-miniprogram/cell/cell",
8
+ "formcell": "../formcell"
8
9
  }
9
10
  }
@@ -1,20 +1,24 @@
1
- <mp-cells>
2
- <mp-cell>
3
- <mp-uploader
1
+ <view
2
+ class="weda-ui weui-cells weui-cells_form {{className}}"
3
+ id="{{id}}"
4
+ style="{{style}}"
5
+ >
6
+ <mp-uploader
4
7
  max-size="{{maxSize * 1024 * 1024}}"
5
8
  files="{{files}}"
9
+ title="{{title}}"
6
10
  showDelete="{{true}}"
7
11
  ext-class="{{layout}}"
8
12
  bindfail="uploadError"
9
13
  bindsuccess="uploadSuccess"
14
+ layout="{{layout}}"
10
15
  select="{{selectFile}}"
11
16
  upload="{{uploadFile}}"
12
17
  maxCount="{{maxCount}}"
13
- title="{{title}}"
14
18
  binddelete="onDelete">
15
- </mp-uploader>
16
- </mp-cell>
17
- </mp-cells>
19
+ </mp-uploader>
20
+ </view>
21
+
18
22
  <!-- uploader delete 实际代码接受 showDelete
19
23
  https://developers.weixin.qq.com/community/develop/doc/000a4e7b9cc158c110aa3961056400
20
24
  -->
@@ -13,6 +13,24 @@
13
13
  justify-content: space-between;
14
14
  }
15
15
 
16
- .weui-uploader.horizontal .weui-uploader__bd {
17
- padding-left: 32px;
16
+ .weui-uploader.horizontal .weda-formcells__label {
17
+ width: 130px;
18
+ }
19
+
20
+ .weui-uploader__label {
21
+ display: flex;
22
+ flex: 1;
23
+ }
24
+
25
+ .weui-uploader__title {
26
+ flex: unset;
27
+ }
28
+ .weda-ui .weui-uploader.horizontal .weui-uploader__bd {
29
+ padding: 16px 0;
30
+ }
31
+ .weda-ui .weui-uploader.vertical .weui-uploader__bd {
32
+ padding: 16px;
33
+ }
34
+ .weui-uploader__hd.vertical {
35
+ padding-bottom: 0;
18
36
  }
@@ -0,0 +1,209 @@
1
+ Component({
2
+ options: {
3
+ addGlobalClass: true,
4
+ virtualHost: true
5
+ },
6
+ properties: {
7
+ title: {
8
+ type: String,
9
+ value: '图片上传'
10
+ },
11
+ sizeType: {
12
+ type: Array,
13
+ value: ['original', 'compressed']
14
+ },
15
+ sourceType: {
16
+ type: Array,
17
+ value: ['album', 'camera']
18
+ },
19
+ maxSize: {
20
+ type: Number,
21
+ value: 5 * 1024 * 1024
22
+ },
23
+ maxCount: {
24
+ // 最多上传多少个文件
25
+ type: Number,
26
+ value: 1
27
+ },
28
+ files: {
29
+ // 当前的图片列表, {url, error, loading}
30
+ type: Array,
31
+ value: [],
32
+ observer(newVal) {
33
+ this.setData({
34
+ currentFiles: newVal
35
+ });
36
+ }
37
+ },
38
+ select: {
39
+ // 过滤某个文件
40
+ type: null,
41
+ value: () => { }
42
+ },
43
+ upload: {
44
+ // 返回Promise的一个文件上传的函数
45
+ type: null,
46
+ value: null
47
+ },
48
+ tips: {
49
+ type: String,
50
+ value: ''
51
+ },
52
+ layout: {
53
+ type: String,
54
+ value: 'horizontal'
55
+ },
56
+ extClass: {
57
+ type: String,
58
+ value: ''
59
+ },
60
+ showDelete: {
61
+ // 是否显示delete按钮
62
+ type: Boolean,
63
+ value: true
64
+ }
65
+ },
66
+ data: {
67
+ currentFiles: [],
68
+ showPreview: false,
69
+ previewImageUrls: []
70
+ },
71
+ ready() { },
72
+ methods: {
73
+ previewImage(e) {
74
+ const { index } = e.currentTarget.dataset;
75
+ const previewImageUrls = [];
76
+ this.data.files.forEach((item) => {
77
+ previewImageUrls.push(item.url);
78
+ });
79
+ this.setData({
80
+ previewImageUrls,
81
+ previewCurrent: index,
82
+ showPreview: true
83
+ });
84
+ },
85
+ chooseImage() {
86
+ if (this.uploading)
87
+ return;
88
+ wx.chooseImage({
89
+ count: this.data.maxCount - this.data.files.length,
90
+ sizeType: this.data.sizeType,
91
+ sourceType: this.data.sourceType,
92
+ success: (res) => {
93
+ // console.log('chooseImage resp', res)
94
+ // 首先检查文件大小
95
+ let invalidIndex = -1;
96
+ // @ts-ignore
97
+ res.tempFiles.forEach((item, index) => {
98
+ if (item.size > this.data.maxSize) {
99
+ invalidIndex = index;
100
+ }
101
+ });
102
+ if (typeof this.data.select === 'function') {
103
+ const ret = this.data.select(res);
104
+ if (ret === false) {
105
+ return;
106
+ }
107
+ }
108
+ if (invalidIndex >= 0) {
109
+ this.triggerEvent('fail', {
110
+ type: 1,
111
+ errMsg: `chooseImage:fail size exceed ${this.data.maxSize}`,
112
+ total: res.tempFilePaths.length,
113
+ index: invalidIndex
114
+ }, {});
115
+ return;
116
+ }
117
+ // 获取文件内容
118
+ const mgr = wx.getFileSystemManager();
119
+ const contents = res.tempFilePaths.map((item) => {
120
+ // @ts-ignore
121
+ const fileContent = mgr.readFileSync(item);
122
+ return fileContent;
123
+ });
124
+ const obj = {
125
+ tempFilePaths: res.tempFilePaths,
126
+ tempFiles: res.tempFiles,
127
+ contents
128
+ };
129
+ // 触发选中的事件,开发者根据内容来上传文件,上传了把上传的结果反馈到files属性里面
130
+ this.triggerEvent('select', obj, {});
131
+ const files = res.tempFilePaths.map((item, i) => ({
132
+ loading: true,
133
+ url: res.tempFilePaths[i] ||
134
+ `data:image/jpg;base64,${wx.arrayBufferToBase64(contents[i])}`
135
+ }));
136
+ if (!files || !files.length)
137
+ return;
138
+ if (typeof this.data.upload === 'function') {
139
+ const len = this.data.files.length;
140
+ const newFiles = this.data.files.concat(files);
141
+ this.setData({
142
+ files: newFiles,
143
+ currentFiles: newFiles
144
+ });
145
+ this.loading = true;
146
+ this.data
147
+ .upload(obj)
148
+ .then((json) => {
149
+ this.loading = false;
150
+ if (json.urls) {
151
+ const oldFiles = this.data.files;
152
+ json.urls.forEach((url, index) => {
153
+ oldFiles[len + index].url = url;
154
+ oldFiles[len + index].loading = false;
155
+ });
156
+ this.setData({
157
+ files: oldFiles,
158
+ currentFiles: newFiles
159
+ });
160
+ this.triggerEvent('success', json, {});
161
+ }
162
+ else {
163
+ this.triggerEvent('fail', {
164
+ type: 3,
165
+ errMsg: 'upload file fail, urls not found'
166
+ }, {});
167
+ }
168
+ })
169
+ .catch((err) => {
170
+ this.loading = false;
171
+ const oldFiles = this.data.files;
172
+ res.tempFilePaths.forEach((item, index) => {
173
+ oldFiles[len + index].error = true;
174
+ oldFiles[len + index].loading = false;
175
+ });
176
+ this.setData({
177
+ files: oldFiles,
178
+ currentFiles: newFiles
179
+ });
180
+ this.triggerEvent('fail', {
181
+ type: 3,
182
+ errMsg: 'upload file fail',
183
+ error: err
184
+ }, {});
185
+ });
186
+ }
187
+ },
188
+ fail: (fail) => {
189
+ if (fail.errMsg.indexOf('chooseImage:fail cancel') >= 0) {
190
+ this.triggerEvent('cancel', {}, {});
191
+ return;
192
+ }
193
+ fail.type = 2;
194
+ this.triggerEvent('fail', fail, {});
195
+ }
196
+ });
197
+ },
198
+ deletePic(e) {
199
+ const index = e.detail.index;
200
+ const files = this.data.files;
201
+ const file = files.splice(index, 1);
202
+ this.setData({
203
+ files,
204
+ currentFiles: files
205
+ });
206
+ this.triggerEvent('delete', { index, item: file[0] });
207
+ }
208
+ }
209
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "component": true,
3
+ "usingComponents": {
4
+ "mp-gallery": "weui-miniprogram/gallery/gallery"
5
+ },
6
+ "styleIsolation": "shared"
7
+ }