Skip to content

Commit e07dbdd

Browse files
feat: ✨ Upload上传组件新增支持上传视频和文件 (#412)
closes #186 and #336
1 parent d09bd03 commit e07dbdd

14 files changed

Lines changed: 846 additions & 162 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
"i18n-ally.localesPaths": [
4141
"src/uni_modules/wot-design-uni/locale",
4242
"src/uni_modules/wot-design-uni/locale/lang"
43-
]
43+
],
44+
"common-intellisense.ui": []
4445
}

docs/component/cell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
通过设置 `clickable` 开启点击反馈,之后可以监听`click`事件。
8080

8181
```html
82-
<wd-toast id="wd-toast" />
82+
<wd-toast />
8383
<wd-cell title="标题文字" value="内容" clickable @click="toast" />
8484
```
8585

docs/component/upload.md

Lines changed: 162 additions & 36 deletions
Large diffs are not rendered by default.

src/pages/upload/Index.vue

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
<wd-privacy-popup></wd-privacy-popup>
55
<!-- #endif -->
66
<wd-message-box></wd-message-box>
7-
<wd-toast id="wd-toast"></wd-toast>
7+
<wd-toast></wd-toast>
88
<demo-block title="基本用法">
9-
<wd-upload :file-list="fileList1" image-mode="aspectFill" :action="action" @change="handleChange1"></wd-upload>
10-
</demo-block>
11-
<demo-block title="多选上传">
12-
<wd-upload :file-list="fileList2" multiple :action="action" @change="handleChange2"></wd-upload>
9+
<wd-upload accept="image" :file-list="fileList" image-mode="aspectFill" :action="action" @change="handleChange"></wd-upload>
1310
</demo-block>
1411
<demo-block title="最大上传数限制">
1512
<wd-upload :file-list="fileList3" :limit="3" :action="action" @change="handleChange3"></wd-upload>
@@ -48,32 +45,58 @@
4845
<!-- <demo-block title="上传至oss">
4946
<wd-upload :file-list="fileList11" action="https://xxx.aliyuncs.com" :build-form-data="buildFormData" @change="handleChange11"></wd-upload>
5047
</demo-block> -->
48+
49+
<demo-block title="上传视频">
50+
<wd-upload accept="video" multiple :file-list="fileList1" :action="action" @change="handleChange1"></wd-upload>
51+
</demo-block>
52+
53+
<!-- #ifdef MP-WEIXIN -->
54+
<demo-block title="上传视频和图片">
55+
<wd-upload accept="media" multiple :file-list="fileList11" :action="action" @change="handleChange11"></wd-upload>
56+
</demo-block>
57+
<demo-block title="仅上传文件">
58+
<wd-upload accept="file" multiple :file-list="fileList12" :action="action" @change="handleChange12"></wd-upload>
59+
</demo-block>
60+
<!-- #endif -->
61+
62+
<!-- #ifdef MP-WEIXIN || H5 -->
63+
<demo-block title="上传视频图片和文件">
64+
<wd-upload accept="all" multiple :file-list="fileList13" :action="action" @change="handleChange13"></wd-upload>
65+
</demo-block>
66+
<!-- #endif -->
5167
</page-wraper>
5268
</template>
5369
<script lang="ts" setup>
5470
import { useToast, useMessage } from '@/uni_modules/wot-design-uni'
71+
import type { UploadFile } from '@/uni_modules/wot-design-uni/components/wd-upload/types'
5572
import { ref } from 'vue'
5673
57-
const action: string = 'https://ftf.jd.com/api/uploadImg'
58-
const fileList1 = ref<any[]>([
74+
const action: string = 'https://mockapi.eolink.com/zhTuw2P8c29bc981a741931bdd86eb04dc1e8fd64865cb5/upload'
75+
const fileList = ref<UploadFile[]>([
5976
{
6077
url: 'https://img.yzcdn.cn/vant/cat.jpeg'
6178
}
6279
])
63-
const fileList2 = ref<any[]>([
80+
81+
const fileList1 = ref<UploadFile[]>([])
82+
const fileList2 = ref<UploadFile[]>([
6483
{
6584
url: 'https://img12.360buyimg.com//n0/jfs/t1/29118/6/4823/55969/5c35c16bE7c262192/c9fdecec4b419355.jpg'
6685
}
6786
])
68-
const fileList3 = ref([])
69-
const fileList4 = ref([])
70-
const fileList5 = ref([])
71-
const fileList6 = ref([])
72-
const fileList7 = ref([])
73-
const fileList8 = ref([])
74-
const fileList9 = ref([])
75-
const fileList10 = ref([])
76-
const fileList11 = ref([])
87+
const fileList3 = ref<UploadFile[]>([])
88+
const fileList4 = ref<UploadFile[]>([])
89+
const fileList5 = ref<UploadFile[]>([])
90+
const fileList6 = ref<UploadFile[]>([])
91+
const fileList7 = ref<UploadFile[]>([])
92+
const fileList8 = ref<UploadFile[]>([])
93+
const fileList9 = ref<UploadFile[]>([])
94+
const fileList10 = ref<UploadFile[]>([])
95+
const fileList11 = ref<UploadFile[]>([])
96+
const fileList12 = ref<UploadFile[]>([])
97+
const fileList13 = ref<UploadFile[]>([])
98+
const fileList14 = ref<UploadFile[]>([])
99+
const fileList15 = ref<UploadFile[]>([])
77100
78101
const messageBox = useMessage()
79102
const toast = useToast()
@@ -176,7 +199,17 @@ function handleFail(event: any) {
176199
function handleProgess(event: any) {
177200
console.log('加载中', event)
178201
}
179-
function handleChange1({ fileList }: any) {
202+
203+
function handleChange({ fileList }: any) {
204+
fileList.value = fileList
205+
}
206+
207+
function handleChange1({ fileList }: { fileList: UploadFile[] }) {
208+
// fileList.forEach((item) => {
209+
// if (!item.thumb) {
210+
// item.thumb = 'https://unpkg.com/wot-design-uni-assets/redpanda.jpg'
211+
// }
212+
// })
180213
fileList1.value = fileList
181214
}
182215
function handleChange2({ fileList }: any) {
@@ -209,5 +242,14 @@ function handleChange10({ fileList }: any) {
209242
function handleChange11({ fileList }: any) {
210243
fileList11.value = fileList
211244
}
245+
function handleChange12({ fileList }: any) {
246+
fileList12.value = fileList
247+
}
248+
function handleChange13({ fileList }: any) {
249+
fileList13.value = fileList
250+
}
251+
function handleChange14({ fileList }: any) {
252+
fileList14.value = fileList
253+
}
212254
</script>
213255
<style lang="scss" scoped></style>

src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ $-upload-evoke-disabled-color: var(--wot-upload-evoke-disabled-color, rgba(0, 0,
700700
$-upload-close-icon-size: var(--wot-upload-close-icon-size, 16px) !default; // 移除按钮尺寸
701701
$-upload-close-icon-color: var(--wot-upload-close-icon-color, rgba(0, 0, 0, 0.65)) !default; // 移除按钮颜色
702702
$-upload-progress-fs: var(--wot-upload-progress-fs, 14px) !default; // 进度文字字号
703+
$-upload-file-fs: var(--wot-upload-file-fs, 12px) !default; // 文件名字号
704+
$-upload-file-color: var(--wot-upload-file-color, $-color-secondary) !default; // 文件名字颜色
705+
706+
703707
$-upload-preview-name-fs: var(--wot-upload-preview-name-fs, 12px) !default; // 预览图片名字号
704708
$-upload-preview-icon-size: var(--wot-upload-preview-icon-size, 24px) !default; // 预览内部图标尺寸
705709
$-upload-preview-name-bg: var(--wot-upload-preview-name-bg, rgba(0, 0, 0, 0.6)) !default; // 预览文件名背景色

src/uni_modules/wot-design-uni/components/common/util.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,28 @@ export const getPropByPath = (obj: any, path: string): any => {
656656
*/
657657
export const isDate = (val: unknown): val is Date => Object.prototype.toString.call(val) === '[object Date]' && !Number.isNaN((val as Date).getTime())
658658

659+
/**
660+
* 检查提供的URL是否为视频链接。
661+
* @param url 需要检查的URL字符串。
662+
* @returns 返回一个布尔值,如果URL是视频链接则为true,否则为false。
663+
*/
664+
export function isVideoUrl(url: string): boolean {
665+
// 使用正则表达式匹配视频文件类型的URL
666+
const videoRegex = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|video)/i
667+
return videoRegex.test(url)
668+
}
669+
670+
/**
671+
* 检查提供的URL是否为图片URL。
672+
* @param url 待检查的URL字符串。
673+
* @returns 返回一个布尔值,如果URL是图片格式,则为true;否则为false。
674+
*/
675+
export function isImageUrl(url: string): boolean {
676+
// 使用正则表达式匹配图片URL
677+
const imageRegex = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg|image)/i
678+
return imageRegex.test(url)
679+
}
680+
659681
/**
660682
* 判断环境是否是H5
661683
*/

src/uni_modules/wot-design-uni/components/wd-upload/index.scss

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
color: $-dark-color-gray;
1212
}
1313
}
14+
15+
@include e(file) {
16+
background-color: $-dark-background4;
17+
}
18+
19+
@include e(file-name) {
20+
color: $-dark-color3;
21+
}
1422
}
1523

1624
}
@@ -70,12 +78,46 @@
7078
display: flex;
7179
}
7280

73-
@include e(picture) {
81+
@include e(picture, file, video) {
82+
position: relative;
7483
display: block;
7584
width: 100%;
7685
height: 100%;
7786
}
7887

88+
@include e(file, video) {
89+
display: flex;
90+
flex-direction: column;
91+
align-items: center;
92+
justify-content: center;
93+
background-color: $-upload-evoke-bg;
94+
}
95+
96+
@include e(file-name, video-name) {
97+
width: 100%;
98+
font-size: $-upload-file-fs;
99+
color: $-upload-file-color;
100+
box-sizing: border-box;
101+
padding: 0 4px;
102+
text-align: center;
103+
margin-top: 8px;
104+
@include lineEllipsis()
105+
}
106+
107+
@include edeep(video-paly) {
108+
position: absolute;
109+
top: 50%;
110+
left: 50%;
111+
transform: translate(-50%, -50%);
112+
font-size: 24px;
113+
color: $-color-white;
114+
115+
&::before {
116+
background-color: rgba(0, 0, 0, 0.5);
117+
border-radius: 50%;
118+
}
119+
}
120+
79121
@include edeep(close) {
80122
position: absolute;
81123
right: calc($-upload-close-icon-size / 2 * -1);

0 commit comments

Comments
 (0)