@cloudbase/weda-ui 0.2.17 → 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.
- package/README.md +3 -0
- package/package.json +10 -5
- package/src/configs/components/button.json +0 -2
- package/src/configs/components/calendar.json +9 -3
- package/src/configs/components/carousel.json +18 -9
- package/src/configs/components/chart/bar.json +31 -12
- package/src/configs/components/chart/line.json +27 -10
- package/src/configs/components/chart/pie.json +22 -8
- package/src/configs/components/chart/statisticsCard.json +61 -13
- package/src/configs/components/container.json +7 -2
- package/src/configs/components/dataView.json +31 -11
- package/src/configs/components/form/checkbox.json +97 -5
- package/src/configs/components/form/radio.json +123 -4
- package/src/configs/components/form/select.json +247 -13
- package/src/configs/components/graphicCard.json +90 -75
- package/src/configs/components/image.json +19 -8
- package/src/configs/components/link.json +25 -6
- package/src/configs/components/listView.json +83 -27
- package/src/configs/components/lottery.json +153 -0
- package/src/configs/components/modal.json +37 -5
- package/src/configs/components/navLayout.json +97 -79
- package/src/configs/components/navigationBar.json +59 -0
- package/src/configs/components/richtextview.json +6 -2
- package/src/configs/components/scrollVeiw.json +98 -34
- package/src/configs/components/swiper.json +22 -10
- package/src/configs/components/tabs.json +54 -9
- package/src/configs/components/text.json +43 -30
- package/src/configs/components/wxOpenApi/phone.json +141 -0
- package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
- package/src/configs/components/wxOpenApi/share.json +167 -0
- package/src/configs/components/wxOpenApi/userInfo.json +174 -0
- package/src/configs/index.js +13 -0
- package/src/docs/common/format.tsx +112 -0
- package/src/docs/common/tableView.css +164 -0
- package/src/docs/common/tableView.tsx +273 -0
- package/src/docs/compsdocs/chart/Bar.mdx +159 -0
- package/src/docs/compsdocs/chart/Line.mdx +100 -0
- package/src/docs/compsdocs/chart/Pie.mdx +83 -0
- package/src/docs/compsdocs/chart/_category_.json +1 -0
- package/src/docs/compsdocs/chart/statisticsCard.mdx +51 -0
- package/src/docs/compsdocs/database/DataView.mdx +33 -0
- package/src/docs/compsdocs/database/ListView.mdx +33 -0
- package/src/docs/compsdocs/database/_category_.json +1 -0
- package/src/docs/compsdocs/form/Form.mdx +35 -0
- package/src/docs/compsdocs/form/FormCheckbox.mdx +35 -0
- package/src/docs/compsdocs/form/FormDate.mdx +30 -0
- package/src/docs/compsdocs/form/FormEmail.mdx +30 -0
- package/src/docs/compsdocs/form/FormImageUploader.mdx +31 -0
- package/src/docs/compsdocs/form/FormInput.mdx +30 -0
- package/src/docs/compsdocs/form/FormLocation.mdx +64 -0
- package/src/docs/compsdocs/form/FormPhone.mdx +30 -0
- package/src/docs/compsdocs/form/FormRadio.mdx +35 -0
- package/src/docs/compsdocs/form/FormRegion.mdx +30 -0
- package/src/docs/compsdocs/form/FormSelect.mdx +36 -0
- package/src/docs/compsdocs/form/FormSwitch.mdx +30 -0
- package/src/docs/compsdocs/form/FormTextarea.mdx +30 -0
- package/src/docs/compsdocs/form/FormTime.mdx +30 -0
- package/src/docs/compsdocs/form/FormUploadFile.mdx +30 -0
- package/src/docs/compsdocs/form/FormUrl.mdx +30 -0
- package/src/docs/compsdocs/form/_category_.json +1 -0
- package/src/docs/compsdocs/grid/Card.mdx +32 -0
- package/src/docs/compsdocs/grid/Container.mdx +42 -0
- package/src/docs/compsdocs/grid/Footer.mdx +31 -0
- package/src/docs/compsdocs/grid/GridLayout.mdx +32 -0
- package/src/docs/compsdocs/grid/Header.mdx +31 -0
- package/src/docs/compsdocs/grid/Layout.mdx +25 -0
- package/src/docs/compsdocs/grid/List.mdx +31 -0
- package/src/docs/compsdocs/grid/ScrollView.mdx +37 -0
- package/src/docs/compsdocs/grid/Swiper.mdx +58 -0
- package/src/docs/compsdocs/grid/_category_.json +1 -0
- package/src/docs/compsdocs/media/Icon.mdx +31 -0
- package/src/docs/compsdocs/media/Image.mdx +55 -0
- package/src/docs/compsdocs/media/_category_.json +1 -0
- package/src/docs/compsdocs/model/ModelCreate.mdx +20 -0
- package/src/docs/compsdocs/model/ModelDetail.mdx +20 -0
- package/src/docs/compsdocs/model/ModelTable.mdx +24 -0
- package/src/docs/compsdocs/model/ModelUpdate.mdx +21 -0
- package/src/docs/compsdocs/model/PageLayout.mdx +21 -0
- package/src/docs/compsdocs/model/_category_.json +1 -0
- package/src/docs/compsdocs/navmenu/Classification.mdx +38 -0
- package/src/docs/compsdocs/navmenu/NavBar.mdx +43 -0
- package/src/docs/compsdocs/navmenu/NavLayout.mdx +30 -0
- package/src/docs/compsdocs/navmenu/TabBar.mdx +43 -0
- package/src/docs/compsdocs/navmenu/TabBarItem.mdx +29 -0
- package/src/docs/compsdocs/navmenu/_category_.json +1 -0
- package/src/docs/compsdocs/senior/Lottery.mdx +48 -0
- package/src/docs/compsdocs/senior/Modal.mdx +58 -0
- package/src/docs/compsdocs/senior/SlotMachine.mdx +52 -0
- package/src/docs/compsdocs/senior/_category_.json +1 -0
- package/src/docs/compsdocs/show/Calendar.mdx +29 -0
- package/src/docs/compsdocs/show/Divider.mdx +31 -0
- package/src/docs/compsdocs/show/GraphicCard.mdx +30 -0
- package/src/docs/compsdocs/show/Item.mdx +32 -0
- package/src/docs/compsdocs/show/ItemList.mdx +47 -0
- package/src/docs/compsdocs/show/Media.mdx +25 -0
- package/src/docs/compsdocs/show/StatusTip.mdx +25 -0
- package/src/docs/compsdocs/show/Swiper.mdx +33 -0
- package/src/docs/compsdocs/show/Tabs.mdx +38 -0
- package/src/docs/compsdocs/show/_category_.json +1 -0
- package/src/docs/compsdocs/show/button.mdx +25 -0
- package/src/docs/compsdocs/text/Link.mdx +43 -0
- package/src/docs/compsdocs/text/RichTextView.mdx +36 -0
- package/src/docs/compsdocs/text/Text.mdx +31 -0
- package/src/docs/compsdocs/text/Title.mdx +32 -0
- package/src/docs/compsdocs/text/_category_.json +1 -0
- package/src/docs/compsdocs/wxOpen/Phone.mdx +60 -0
- package/src/docs/compsdocs/wxOpen/Share.mdx +46 -0
- package/src/docs/compsdocs/wxOpen/UserInfo.mdx +60 -0
- package/src/docs/compsdocs/wxOpen/_category_.json +4 -0
- package/src/index.js +2 -0
- package/src/mp/components/button/index.js +18 -2
- package/src/mp/components/button/index.wxml +7 -4
- package/src/mp/components/chart/bar/index.js +6 -2
- package/src/mp/components/chart/common/core/eChartBar.js +9 -8
- package/src/mp/components/chart/common/core/eChartBase.js +20 -16
- package/src/mp/components/chart/common/core/eChartLine.js +6 -5
- package/src/mp/components/chart/line/index.js +10 -6
- package/src/mp/components/chart/pie/index.js +6 -2
- package/src/mp/components/chart/statisticsCard/index.js +33 -6
- package/src/mp/components/dataView/index.json +1 -1
- package/src/mp/components/form/checkbox/index.js +41 -2
- package/src/mp/components/form/checkbox/index.wxml +1 -1
- package/src/mp/components/form/form/index.wxml +1 -2
- package/src/mp/components/form/formcell/index.wxml +1 -1
- package/src/mp/components/form/formcell/index.wxss +17 -0
- package/src/mp/components/form/input/index.js +1 -1
- package/src/mp/components/form/input/index.wxss +15 -0
- package/src/mp/components/form/location/index.js +43 -2
- package/src/mp/components/form/location/index.wxss +4 -6
- package/src/mp/components/form/radio/index.js +34 -1
- package/src/mp/components/form/select/index.js +351 -41
- package/src/mp/components/form/select/index.wxml +17 -2
- package/src/mp/components/form/select/index.wxss +4 -0
- package/src/mp/components/form/select/region/index.js +101 -0
- package/src/mp/components/form/textarea/index.js +1 -1
- package/src/mp/components/form/textarea/index.wxss +4 -0
- package/src/mp/components/form/uploader/index.js +39 -27
- package/src/mp/components/form/uploader/index.json +3 -2
- package/src/mp/components/form/uploader/index.wxml +11 -7
- package/src/mp/components/form/uploader/index.wxss +20 -2
- package/src/mp/components/form/uploader/weui-uploader.js +209 -0
- package/src/mp/components/form/uploader/weui-uploader.json +7 -0
- package/src/mp/components/form/uploader/weui-uploader.wxml +45 -0
- package/src/mp/components/form/uploader/weui-uploader.wxss +1 -0
- package/src/mp/components/form/uploaderFile/index.js +10 -6
- package/src/mp/components/form/uploaderFile/index.wxss +4 -4
- package/src/mp/components/image/index.wxss +3 -2
- package/src/mp/components/listView/index.js +38 -43
- package/src/mp/components/listView/index.wxml +1 -1
- package/src/mp/components/listView/index.wxss +5 -0
- package/src/mp/components/lottery/index.js +270 -0
- package/src/mp/components/{internals/listView → lottery}/index.json +0 -0
- package/src/mp/components/lottery/index.wxml +43 -0
- package/src/mp/components/lottery/index.wxss +317 -0
- package/src/mp/components/navigationBar/index.js +193 -0
- package/src/mp/components/navigationBar/index.json +6 -0
- package/src/mp/components/navigationBar/index.wxml +88 -0
- package/src/mp/components/navigationBar/index.wxss +1257 -0
- package/src/mp/components/tabs/index.js +7 -2
- package/src/mp/components/tabs/index.wxml +2 -1
- package/src/mp/components/text/index.js +0 -25
- package/src/mp/components/text/index.wxml +3 -3
- package/src/mp/components/wxOpenApi/phone/index.js +117 -0
- package/src/mp/components/wxOpenApi/phone/index.json +4 -0
- package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/share/index.js +117 -0
- package/src/mp/components/wxOpenApi/share/index.json +4 -0
- package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
- package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
- package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
- package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
- package/src/mp/index.json +7 -1
- package/src/mp/style/weda-ui.wxss +16 -0
- package/src/mp/utils/constant.js +15 -0
- package/src/mp/utils/destr.js +48 -0
- package/src/mp/utils/lodash.js +2 -0
- package/src/mp/utils/platform.js +10 -0
- package/src/mp/utils/tcb.js +44 -0
- package/src/web/components/button/index.css +8 -1
- package/src/web/components/button/index.tsx +10 -9
- package/src/web/components/calendar/index.jsx +1 -1
- package/src/web/components/carousel/index.tsx +8 -8
- package/src/web/components/chart/bar/index.tsx +40 -39
- package/src/web/components/chart/common/config/line.js +1 -1
- package/src/web/components/chart/common/core/eChartBar.js +7 -6
- package/src/web/components/chart/common/core/eChartBase.ts +20 -16
- package/src/web/components/chart/common/core/eChartLine.js +8 -6
- package/src/web/components/chart/line/index.tsx +40 -39
- package/src/web/components/chart/statisticsCard/index.tsx +29 -8
- package/src/web/components/form/checkbox/index.tsx +61 -23
- package/src/web/components/form/form/index.css +5 -1
- package/src/web/components/form/form/index.tsx +3 -1
- package/src/web/components/form/formcell/index.css +22 -1
- package/src/web/components/form/formcell/index.tsx +11 -6
- package/src/web/components/form/input/index.css +7 -12
- package/src/web/components/form/location/components/LocationH5/index.css +4 -7
- package/src/web/components/form/location/components/LocationH5/location.h5.jsx +1 -1
- package/src/web/components/form/radio/index.tsx +90 -53
- package/src/web/components/form/select/h5.tsx +370 -73
- package/src/web/components/form/select/index.css +15 -0
- package/src/web/components/form/select/index.tsx +392 -145
- package/src/web/components/form/select/region/index.ts +122 -31
- package/src/web/components/form/select/time.jsx +89 -0
- package/src/web/components/form/select/year.tsx +170 -0
- package/src/web/components/form/textarea/index.css +4 -0
- package/src/web/components/form/textarea/index.tsx +2 -2
- package/src/web/components/form/tips/index.css +4 -0
- package/src/web/components/form/tips/index.tsx +4 -3
- package/src/web/components/form/uploader/index.css +26 -2
- package/src/web/components/form/uploader/uploader.h5.tsx +89 -57
- package/src/web/components/form/uploader/uploader.pc.tsx +4 -4
- package/src/web/components/form/uploaderFile/index.css +2 -4
- package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +13 -7
- package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +13 -5
- package/src/web/components/image/image.tsx +1 -1
- package/src/web/components/image/index.css +3 -3
- package/src/web/components/image/index.tsx +6 -7
- package/src/web/components/index.js +8 -0
- package/src/web/components/link/index.tsx +7 -4
- package/src/web/components/listView/index.css +4 -0
- package/src/web/components/listView/index.tsx +12 -20
- package/src/web/components/lottery/index.css +327 -0
- package/src/web/components/lottery/index.tsx +567 -0
- package/src/web/components/lottery/lotteryUtil.ts +130 -0
- package/src/web/components/modal/index.tsx +3 -1
- package/src/web/components/navLayout/index.tsx +2 -2
- package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
- package/src/web/components/navigationBar/common.tsx +198 -0
- package/src/web/components/navigationBar/h5Menu.tsx +179 -0
- package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
- package/src/web/components/navigationBar/index.css +762 -0
- package/src/web/components/navigationBar/index.tsx +230 -0
- package/src/web/components/navigationBar/type.d.ts +111 -0
- package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
- package/src/web/components/phone/index.css +0 -0
- package/src/web/components/phone/index.tsx +22 -0
- package/src/web/components/phoneCode/index.css +0 -0
- package/src/web/components/phoneCode/index.tsx +22 -0
- package/src/web/components/picker/timePicker.tsx +2 -2
- package/src/web/components/richTextView/index.tsx +3 -5
- package/src/web/components/share/index.css +0 -0
- package/src/web/components/share/index.tsx +38 -0
- package/src/web/components/slot/index.tsx +1 -1
- package/src/web/components/tabs/index.tsx +2 -0
- package/src/web/components/tabs/tabs.h5.tsx +43 -33
- package/src/web/components/tabs/tabs.pc.tsx +23 -10
- package/src/web/components/text/index.tsx +12 -20
- package/src/web/components/userInfo/index.css +0 -0
- package/src/web/components/userInfo/index.tsx +30 -0
- package/src/web/utils/{constant.js → constant.ts} +17 -2
- package/src/web/utils/lodash.ts +2 -0
- package/src/web/utils/platform.js +9 -0
- package/src/web/utils/tcb.js +26 -0
- package/src/web/weda-ui.css +7 -1
- package/src/mp/components/internals/listView/arrow-right-line.svg +0 -3
- package/src/mp/components/internals/listView/index.js +0 -286
- package/src/mp/components/internals/listView/index.wxml +0 -40
- package/src/mp/components/internals/listView/index.wxss +0 -150
- package/src/mp/components/internals/listView/more-line.svg +0 -3
- package/src/web/components/form/select/region/cities.ts +0 -2410
- package/src/web/components/form/select/region/provinces.ts +0 -240
- package/src/web/components/form/select/region/regions.ts +0 -20645
|
@@ -6,20 +6,35 @@
|
|
|
6
6
|
multiCell="{{false}}"
|
|
7
7
|
requiredFlag="{{requiredFlag}}"
|
|
8
8
|
>
|
|
9
|
-
|
|
9
|
+
<view class="{{subCls}}">
|
|
10
10
|
<view class="weui-cell__bd">
|
|
11
11
|
<picker
|
|
12
|
+
wx:if="{{mode!='mutiRegion'}}"
|
|
12
13
|
class="weui-picker__group weui-input"
|
|
13
14
|
bindchange="onChange"
|
|
14
15
|
bindcancel="onCancel"
|
|
15
16
|
mode="{{mode}}"
|
|
16
17
|
range="{{selectRange}}"
|
|
18
|
+
disabled="{{disabled}}"
|
|
17
19
|
start="{{start}}"
|
|
18
20
|
end="{{end}}"
|
|
21
|
+
disabled="{{disabled}}"
|
|
19
22
|
value="{{value}}"
|
|
23
|
+
fields="{{dateMode}}"
|
|
20
24
|
>
|
|
25
|
+
<label class="{{displayCls}}">{{displayValue}}</label>
|
|
26
|
+
</picker>
|
|
27
|
+
<picker wx:if="{{mode=='mutiRegion'}}"
|
|
28
|
+
mode="multiSelector"
|
|
29
|
+
disabled="{{disabled}}"
|
|
30
|
+
range="{{multiArray}}"
|
|
31
|
+
range-key='value'
|
|
32
|
+
bindcolumnchange="columnchange"
|
|
33
|
+
value="{{multiIndex}}"
|
|
34
|
+
bindchange='onChange'
|
|
35
|
+
class="weui-picker__group weui-input">
|
|
21
36
|
<label class="{{displayCls}}">{{displayValue}}</label>
|
|
22
37
|
</picker>
|
|
23
38
|
</view>
|
|
24
|
-
|
|
39
|
+
</view>
|
|
25
40
|
</formcell>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { callWedaApi } from '../../../../utils/tcb';
|
|
2
|
+
|
|
3
|
+
export let provinces = [];
|
|
4
|
+
export let cities = [];
|
|
5
|
+
export let regions = [];
|
|
6
|
+
export let regionData = [];
|
|
7
|
+
/**
|
|
8
|
+
* 获取运行态地区数据
|
|
9
|
+
* 查询所有的省市区数据https://iwiki.woa.com/pages/viewpage.action?pageId=1582408865
|
|
10
|
+
*/
|
|
11
|
+
export async function getAreaCode() {
|
|
12
|
+
try {
|
|
13
|
+
const res = await callWedaApi({
|
|
14
|
+
action: 'QueryRuntimeAreaCode',
|
|
15
|
+
data: { Mask: "11100" },
|
|
16
|
+
});
|
|
17
|
+
return res?.AreaCodeList;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('错误', error);
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const getRegionTree = async function (defaultValue) {
|
|
24
|
+
regionData = await getAreaCode();
|
|
25
|
+
splitAreaData(regionData, regionData);
|
|
26
|
+
return changeResult(defaultValue, regionData);
|
|
27
|
+
};
|
|
28
|
+
export const splitAreaData = (areaData) => {
|
|
29
|
+
provinces = [];
|
|
30
|
+
cities = [];
|
|
31
|
+
regions = [];
|
|
32
|
+
areaData.forEach(item => {
|
|
33
|
+
if (!item.Deprecated) {
|
|
34
|
+
if (item?.Type == 1) {
|
|
35
|
+
provinces.push(item);
|
|
36
|
+
} if (item?.Type == 2 || (item?.Type == 1 && item.CentralCity)) {
|
|
37
|
+
cities.push(item);
|
|
38
|
+
} else if (item?.Type == 3) {
|
|
39
|
+
regions.push(item);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
/***
|
|
45
|
+
* 用于构建change事件result返回值
|
|
46
|
+
*/
|
|
47
|
+
export const changeResult = (regionValue, areaData) => {
|
|
48
|
+
const defaultValue = regionValue ? regionValue.split(',') : null;
|
|
49
|
+
const changeValue = [];
|
|
50
|
+
const defaultIndex = [];
|
|
51
|
+
if (defaultValue && defaultValue.length > 0) {
|
|
52
|
+
defaultValue.forEach((element, index) => {
|
|
53
|
+
areaData.map((item, id) => {
|
|
54
|
+
//区级判重
|
|
55
|
+
if ((item?.Value == element && index != 2) || (item?.Value == element && item.Code.substr(0, 2) == changeValue[0].code.substr(0, 2) && index == 2)) {
|
|
56
|
+
changeValue.push({
|
|
57
|
+
value: item?.Value,
|
|
58
|
+
code: item?.Code
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
defaultIndex.push(id);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return { value: regionValue, result: changeValue };
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 拼接地区选择默认值显示规则
|
|
70
|
+
*/
|
|
71
|
+
export const buildDisplayValue = (data, indexList, type) => {
|
|
72
|
+
let provinceItem = [];
|
|
73
|
+
let cityItem;
|
|
74
|
+
let regionItem;
|
|
75
|
+
switch (type) {
|
|
76
|
+
case 'levelOne': {
|
|
77
|
+
provinceItem = data[0][indexList[0]];
|
|
78
|
+
return {
|
|
79
|
+
value: provinceItem.value,
|
|
80
|
+
result: [provinceItem]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
case 'levelTwo': {
|
|
84
|
+
provinceItem = data[0][indexList[0]];
|
|
85
|
+
cityItem = data[1][indexList[1]];
|
|
86
|
+
return {
|
|
87
|
+
value: provinceItem.value + "," + cityItem.value,
|
|
88
|
+
result: [provinceItem, cityItem]
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
case 'levelThree': {
|
|
92
|
+
provinceItem = data[0][indexList[0]];
|
|
93
|
+
cityItem = data[1][indexList[1]];
|
|
94
|
+
regionItem = data[2][indexList[2]];
|
|
95
|
+
return {
|
|
96
|
+
value: provinceItem.value + "," + cityItem.value + "," + regionItem.value,
|
|
97
|
+
result: [provinceItem, cityItem, regionItem]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -40,30 +40,39 @@ Component({
|
|
|
40
40
|
cloudFile: [],
|
|
41
41
|
files: [],
|
|
42
42
|
urls: [],
|
|
43
|
+
singleFlag: false,
|
|
43
44
|
uploadFile: async function (files) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
try {
|
|
46
|
+
// 文件上传的函数,返回一个promise
|
|
47
|
+
const uploadPath = 'weda-uploader';
|
|
48
|
+
const tcb = await getCloudInstance();
|
|
49
|
+
const uploadPromise = files.tempFilePaths.map(
|
|
50
|
+
async (tempFilePath, index) => {
|
|
51
|
+
var spark = new SparkMD5.ArrayBuffer();
|
|
52
|
+
spark.append(files.contents[index]);
|
|
53
|
+
var md5Path = spark.end(false);
|
|
54
|
+
const fileType = tempFilePath.split('.')[1];
|
|
55
|
+
const cloudPath = `${uploadPath}/${md5Path}-${Date.now()}.${fileType}`;
|
|
56
|
+
const uploadRes = await tcb.uploadFile({
|
|
57
|
+
cloudPath,
|
|
58
|
+
filePath: tempFilePath,
|
|
59
|
+
});
|
|
60
|
+
return { fileID: uploadRes.fileID };
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
const uploadFileList = await Promise.all(uploadPromise);
|
|
64
|
+
const cloudUrls = uploadFileList.map((file) => file.fileID);
|
|
65
|
+
// 这里返回的东西会在uploadSuccess回调函数中获取到
|
|
66
|
+
// https://github.com/wechat-miniprogram/weui-miniprogram/blob/a3630575910302e3b94e69fcef266d2b509de650/src/components/uploader/uploader.ts#L149
|
|
67
|
+
// 写死的从返回值的 .urls 获取展示用的url来用。一定要将tempFilePaths透传下去,否则会重新加载然后出现闪白
|
|
68
|
+
return { urls: files.tempFilePaths, cloudUrls };
|
|
69
|
+
} catch (e) {
|
|
70
|
+
wx.showToast({
|
|
71
|
+
title: `${e}` || '上传失败',
|
|
72
|
+
icon: 'none',
|
|
73
|
+
duration: 2000,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
67
76
|
},
|
|
68
77
|
},
|
|
69
78
|
methods: {
|
|
@@ -103,10 +112,13 @@ Component({
|
|
|
103
112
|
},
|
|
104
113
|
observers: {
|
|
105
114
|
defaultValue: async function (value) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
//当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
|
|
116
|
+
if (Array.isArray(value) && !this.data.singleFlag) {
|
|
117
|
+
this.setData({
|
|
118
|
+
urls: value
|
|
119
|
+
});
|
|
120
|
+
this.data.singleFlag = true;
|
|
121
|
+
}
|
|
110
122
|
if (value) {
|
|
111
123
|
let httpFiles = [];
|
|
112
124
|
for (let f of value) {
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"component": true,
|
|
3
3
|
"styleIsolation": "shared",
|
|
4
4
|
"usingComponents": {
|
|
5
|
-
"mp-uploader": "weui-
|
|
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
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 .
|
|
17
|
-
|
|
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,45 @@
|
|
|
1
|
+
<view class="weui-uploader {{extClass}}">
|
|
2
|
+
<view class="weui-uploader__hd {{layout}}">
|
|
3
|
+
<view class="weda-formcells__label weui-cell">
|
|
4
|
+
<block wx:if="{{layout === 'horizontal'}}">
|
|
5
|
+
<view class="">
|
|
6
|
+
<view class="weui-uploader__title">{{title}}</view>
|
|
7
|
+
<view class="weui-uploader__info" wx:if="{{maxCount > 1}}">{{currentFiles.length}}/{{maxCount}}</view>
|
|
8
|
+
</view>
|
|
9
|
+
<label wx:if="{{true}}" class="weda-formcells__flag">*</label>
|
|
10
|
+
</block>
|
|
11
|
+
<block wx:if="{{layout === 'vertical'}}">
|
|
12
|
+
<view class="weui-uploader__label">
|
|
13
|
+
<view class="weui-uploader__title">{{title}}</view>
|
|
14
|
+
<label wx:if="{{true}}" class="weda-formcells__flag">*</label>
|
|
15
|
+
</view>
|
|
16
|
+
<view class="weui-uploader__info" wx:if="{{maxCount > 1}}">{{currentFiles.length}}/{{maxCount}}</view>
|
|
17
|
+
</block>
|
|
18
|
+
</view>
|
|
19
|
+
</view>
|
|
20
|
+
<view class="weui-uploader__bd">
|
|
21
|
+
<view class="weui-uploader__files">
|
|
22
|
+
<block wx:for="{{currentFiles}}" wx:key="*this">
|
|
23
|
+
<view wx:if="{{item.error}}" data-index="{{index}}" bindtap="previewImage" class="weui-uploader__file weui-uploader__file_status">
|
|
24
|
+
<image class="weui-uploader__img" src="{{item.url}}" mode="aspectFill" />
|
|
25
|
+
<view class="weui-uploader__file-content">
|
|
26
|
+
<icon type="warn" size="23" color="#F43530"></icon>
|
|
27
|
+
</view>
|
|
28
|
+
</view>
|
|
29
|
+
<view wx:elif="{{item.loading}}" data-index="{{index}}" bindtap="previewImage" class="weui-uploader__file weui-uploader__file_status">
|
|
30
|
+
<image class="weui-uploader__img" src="{{item.url}}" mode="aspectFill" />
|
|
31
|
+
<view class="weui-uploader__file-content">
|
|
32
|
+
<view class="weui-loading"></view>
|
|
33
|
+
</view>
|
|
34
|
+
</view>
|
|
35
|
+
<view wx:else class="weui-uploader__file" data-index="{{index}}" bindtap="previewImage">
|
|
36
|
+
<image class="weui-uploader__img" src="{{item.url}}" mode="aspectFill" />
|
|
37
|
+
</view>
|
|
38
|
+
</block>
|
|
39
|
+
</view>
|
|
40
|
+
<view wx:if="{{currentFiles.length < maxCount}}" class="weui-uploader__input-box" hover-class="weui-active">
|
|
41
|
+
<view class="weui-uploader__input" bindtap="chooseImage"></view>
|
|
42
|
+
</view>
|
|
43
|
+
</view>
|
|
44
|
+
<mp-gallery class="gallery" hide-on-click="{{true}}" show-delete="{{showDelete}}" show="{{showPreview}}" binddelete="deletePic" img-urls="{{previewImageUrls}}" current="{{previewCurrent}}"></mp-gallery>
|
|
45
|
+
</view>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* materials/gsd-h5-react/components/form/uploader/weui-uploader.wxss */
|
|
@@ -60,6 +60,7 @@ Component({
|
|
|
60
60
|
urls: [],
|
|
61
61
|
cloudFile: [],
|
|
62
62
|
strogeUrls: [],
|
|
63
|
+
singleFlag: false
|
|
63
64
|
},
|
|
64
65
|
methods: {
|
|
65
66
|
// 批量上传文件前置事件
|
|
@@ -133,9 +134,8 @@ Component({
|
|
|
133
134
|
if (!this.handleBefore(files?.tempFiles)) return;
|
|
134
135
|
const uploadPath = 'weda-uploader';
|
|
135
136
|
const uploadPromise = files.tempFiles.map(async (tempFile) => {
|
|
136
|
-
const cloudPath = `${uploadPath}/${uuid().replaceAll('-', '')}-${
|
|
137
|
-
|
|
138
|
-
}`;
|
|
137
|
+
const cloudPath = `${uploadPath}/${uuid().replaceAll('-', '')}-${tempFile.name
|
|
138
|
+
}`;
|
|
139
139
|
tempFile.percent = '0';
|
|
140
140
|
tempFile.cloudPath = null;
|
|
141
141
|
tempFile.filePath = tempFile?.path || null;
|
|
@@ -257,9 +257,13 @@ Component({
|
|
|
257
257
|
},
|
|
258
258
|
observers: {
|
|
259
259
|
defaultValue: async function (value) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
260
|
+
//当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
|
|
261
|
+
if (Array.isArray(value) && !this.data.singleFlag) {
|
|
262
|
+
this.setData({
|
|
263
|
+
urls: value
|
|
264
|
+
});
|
|
265
|
+
this.data.singleFlag = true;
|
|
266
|
+
}
|
|
263
267
|
let httpFiles = [];
|
|
264
268
|
if (value && JSON.stringify(value) != '[]') {
|
|
265
269
|
for (let f of value) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
}
|
|
6
6
|
.weda-uploader-files__hd {
|
|
7
7
|
width: 100%;
|
|
8
|
-
padding:
|
|
8
|
+
padding: 16px;
|
|
9
|
+
padding-left: 0;
|
|
9
10
|
display: flex;
|
|
10
11
|
background-color: #ffffff;
|
|
11
12
|
}
|
|
@@ -20,9 +21,8 @@
|
|
|
20
21
|
.weda-uploader-files__title {
|
|
21
22
|
font-size: 14px;
|
|
22
23
|
line-height: 20px;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
padding-top: 6px;
|
|
24
|
+
padding: 16px;
|
|
25
|
+
width: 130px;
|
|
26
26
|
}
|
|
27
27
|
.weda-uploader-files__btn {
|
|
28
28
|
margin: 0;
|