提交 2a77a7b1 作者: 宇宙超人

app选择文件插件

上级 005e1fbe
......@@ -58,6 +58,8 @@
import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting'
import * as WodeAPI from '@/api/model/wode'
const lemonjkFileSelect = uni.requireNativePlugin('lemonjk-FileSelect')
// 定义Props
interface Props {
show: boolean
......@@ -179,11 +181,12 @@
const uplpoadFile = ref(null)
// 选择文件
const chooseFile = () => {
// #ifdef H5
uni.chooseFile({
count: 1,
extension: ['*'],
success: (res) => {
uplpoadFile.value = res
uplpoadFile.value = res.tempFilePaths[0]
const tempFilePaths = res.tempFilePaths
const tempFiles = res.tempFiles
console.log(tempFiles)
......@@ -212,6 +215,31 @@
uploading.value = false
},
})
// #endif
// #ifndef H5
lemonjkFileSelect.showNativePicker(
{
//各属性配置见下方【showPicker可配置参数说明】
pathScope: '/Download',
mimeType: '*/*',
utisType: ['public.data'],
},
(result) => {
// 返回值说明见下方【showPicker返回值说明】
const tempFiles = result.files
console.log(tempFiles[0])
uplpoadFile.value = tempFiles[0].filePath
// 根据文件扩展名设置文件类型
const fileName = tempFiles[0].fileRealName || ''
const fileType = getFileTypeByExt(tempFiles[0].fileExtension)
formData.fileName = fileName
formData.file = { name: fileName }
formData.fileType = fileType.value
formData.fileTypeText = fileType.text
},
)
// #endif
}
// 移除文件
......@@ -251,7 +279,6 @@
}
const userStore = useUserStore()
const globSetting = useGlobSetting()
const toastRef = ref()
// 提交表单
const handleSubmit = async () => {
try {
......@@ -287,7 +314,7 @@
console.log('上传资源数据:', submitData)
uni.uploadFile({
url: globSetting.apiUrl + globSetting.urlPrefix + '/sys/common/upload', // 直接使用上传接口URL
filePath: uplpoadFile.value.tempFilePaths[0],
filePath: uplpoadFile.value,
name: 'file',
formData: {
biz: 'temp',
......@@ -302,9 +329,10 @@
submitData.fileSrc = data.message
WodeAPI.addResource(submitData)
.then((res) => {
toastRef.value.show({
type: 'success',
text: `上传成功`,
uni.showToast({
title: '上传成功',
icon: 'success',
duration: 2000,
})
// emit('update:show', false)
emit('submitSuccess')
......@@ -323,9 +351,10 @@
}
},
fail: () => {
toastRef.value.show({
type: 'error',
text: '上传失败',
uni.showToast({
title: '上传失败',
icon: 'none',
duration: 2000,
})
},
})
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论