Files
im-uniapp/components/oa/oa-file-upload/index.vue

53 lines
1.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<button type="primary" @click="chooseFile">选择文件</button>
<view v-if="fileName" class="file-name">已选择{{ fileName }}</view>
</view>
</template>
<script>
export default {
name: 'OaFileUpload',
props: {
// 选择文件后回调,参数为文件临时路径和文件信息
onChoose: {
type: Function,
default: null
}
},
data() {
return {
fileName: ''
}
},
methods: {
chooseFile() {
uni.chooseFile({
count: 1,
success: (res) => {
if (res.tempFiles && res.tempFiles.length > 0) {
const file = res.tempFiles[0];
this.fileName = file.name;
this.$emit('choose', file);
if (this.onChoose) {
this.onChoose(file);
}
}
},
fail: (err) => {
uni.showToast({ title: '文件选择失败', icon: 'none' });
}
});
}
}
}
</script>
<style scoped>
.file-name {
margin-top: 16rpx;
color: #666;
font-size: 28rpx;
}
</style>