53 lines
1.0 KiB
Vue
53 lines
1.0 KiB
Vue
|
|
<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>
|