更新记录

0.0.2(2024-10-11) 下载此版本

  • chore: 兼容 vue2

0.0.1(2024-10-11) 下载此版本

  • init

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 4.26 app-vue app-uvue × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × ×

lime-upload

  • 文件上传组件,可以选择图片视频等任意文件,支持指定服务或当前uniCloud,兼容uniapp/uniappx
  • 插件依赖lime-stylelime-sharedlime-iconlime-svg:这插件为收费(5元),但若不使用svg可删除SVG插件,不影响使用。不喜勿下
  • 插件为初版,可能存在BUG

安装

插件市场导入即可,首次导入需要重新编译

代码演示

基础使用

选择文件会触发 add 事件,获取到对应的 file 对象。

<l-upload @add="handleAdd"/>
import {UploadFile} from '@/uni_modules/lime-upload';

const handleAdd = (files: UploadFile[])=>{
    console.log(files)
}

单选

通过设置max1,multiplefalse关闭多选,只允许单选

<l-upload :max="1" :multiple="false" v-model="files">
import {UploadFile} from '@/uni_modules/lime-upload';
const files = ref<UploadFile[]>([])

文件预览

通过设置default-filesv-model可以绑定已经上传的文件列表,并展示文件列表的预览图

<l-upload :column="4" :default-files="files">
import {UploadFile} from '@/uni_modules/lime-upload';
const files = ref<UploadFile[]>([{
    url: 'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/lime-barcode_0.png',
    name: 'uploaded4.png',
    type: 'image',
}])

上传状态

通过设置status属性可以标识上传状态,loading表示上传中,reload表示重新上传,failed表示上传失败,done表示上传完成。percent属性表示上传进度

<l-upload :column="4" :default-files="files">
import {UploadFile} from '@/uni_modules/lime-upload';
const files = ref<UploadFile[]>([{
    url: 'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/lime-tag_0.png',
    name: 'uploaded1.png',
    type: 'image',
    status: 'loading'
},
{
    url: 'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/lime-button_0.png',
    name: 'uploaded2.png',
    type: 'image',
    status: 'loading',
    percent: 68,
},
{
    url: 'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/lime-color_0.png',
    name: 'uploaded3.png',
    type: 'image',
    status: 'reload',
},
{
    url: 'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/lime-barcode_0.png',
    name: 'uploaded4.png',
    type: 'image',
    status: 'failed',
},
{
    url: 'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/aff13f50-b9d4-11ee-9303-15d888ed69e8_0.png',
    name: 'uploaded5.png',
    type: 'image',
}])

禁用

通过设置disabled可禁用组件

<l-upload :disabled="true">

限制上传数量

通过设置max可设置上传的数量

<l-upload :column="4" :max="10"></l-upload>

自定义样式

通过插槽可以自定义选择区域的样式。

<l-upload :multiple="false" :column="1" grid-height="200px" add-bg-color="#fff">
    <view style="height: 100%; width: 100%; display: flex; justify-content: center; align-items: center;">
        <image style="width: 100%; height: 100%; position: absolute; opacity: 0.5;" src="https://tdesign.gtimg.com/mobile/demos/upload1.png"></image>
        <view style="width: 72px; height: 72px; background: #e0eefe; border-radius: 99px; display: flex; justify-content: center; align-items: center; position: relative; z-index: 10;">
            <image style="width: 32px; height: 32px;" src="https://tdesign.gtimg.com/mobile/demos/upload3.png" />
        </view>
    </view>
</l-upload>

上传方式

通过设置action指定服务器地址,如果为uniCloud则上传到当前绑定的uniCloud,设置autoUploadtrue选文件后就立即上传。

<!-- 上传到uniCloud -->
<l-upload action="uniCloud" :autoUpload="true">
<!-- 指定服务器 -->
<l-upload action="//service-bv448zsw-1257786608.gz.apigw.tencentcs.com/api/upload-demo" :autoUpload="true">
<!-- 手动上传 -->
<l-upload v-model="files" @add="handleAdd">
import {UploadFile} from '@/uni_modules/lime-upload';

const files = ref<UploadFile[]>([]);

const handleAdd = (files: UploadFile[])=> {
    files.forEach(file =>{
        const task = uni.uploadFile({
            url: 'https://example.xxx.com/upload', // 仅为示例,非真实的接口地址
            filePath: file.url,
            name: 'file',
            formData: { user: 'test' },
            success: (res) => {
                file.status = 'done'
                file.url = res.data.url
                console.log('上传完成')
            }
        });
        task.onProgressUpdate((res) => {
            file.status = 'loading'
            file.percent = res.progress
           console.log('上传进度:', res)
        });
    })
}

查看示例

  • 导入后直接使用这个标签查看演示效果
<!-- // 代码位于 uni_modules/lime-upload/compoents/lime-upload -->
<lime-upload />

插件标签

  • 默认 l-upload 为 component
  • 默认 lime-upload 为 demo

API

Props

参数 说明 类型 默认值
v-model 双向绑定值 number -
disabled 是否禁用文件上传 boolean false
multiple 支持多文件上传 boolean true
disabled 禁用全部操作 boolean false
disablePreview 是否禁用预览 boolean false
autoUpload 是否自动上传 boolean false
defaultFiles 默认列表 UploadFile[] -
imageFit 预览图裁剪模式,可选值参考小程序image组件的mode属性 string -
gutter 格子间隔 string 8px
column 列数 string 8px
mediatype 支持上传的文件类型,图片或视频 'image'\|'video' string 8px
maxDuration 拍摄视频最长拍摄时间,单位秒 number 10
sizeType original 原图,compressed 压缩图 string[] ['original','compressed']
sourceType album 从相册选图,camera 使用相机,默认二者都有 string[] ['album', 'camera']
max 用于控制文件上传数量,值为 0 则不限制 number 100
sizeLimit 图片文件大小限制,默认单位 KB。 number -
uploadIcon 上传图标name number 1
uploadIconSize 上传图标尺寸 string -
gridWidth 格子宽度 string 80px
gridHeight 格子高度 string 80px
gridBgColor 格子背景色 string -
gridBorderRadius 格子圆角 string -
addBgColor 上传格子背景色 string -
loadingText 上传文本 string -
reloadText 重新上传文本 string -
failedText 错误文本 string -
action 上传地址 如需使用uniCloud服务,设置为uniCloud即可 string -
headers 请求中其他额外的 form data object -

UploadFile

名称 类型 默认值 说明
name String - 文件名称 N
percent Number - 上传进度 N
size Number - 文件大小 N
status String - 文件上传状态:上传成功,上传失败,上传中,等待上传。TS 类型:'loading' \| 'reload' \| 'failed' \| 'done' N
type String - 文件类型 N
url String - 文件上传成功后的下载/访问地址 N
path String - 临时地址 N

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式。uvue app无效

名称 默认值 描述
--l-upload-radius $border-radius -
--l-upload-width 80px -
--l-upload-height 80px -
--l-upload-background $upload-add-bg-color -
--l-upload-delete-icon-color white -
--l-upload-add-icon-font-size 28px -
--l-upload-add-bg-color $gray-1 -
--l-upload-add-color $text-color-4 -

打赏

如果你觉得本插件,解决了你的问题,赠人玫瑰,手留余香。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问