提交 2a77a7b1 作者: 宇宙超人

app选择文件插件

上级 005e1fbe
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { useGlobSetting } from '/@/hooks/setting' import { useGlobSetting } from '/@/hooks/setting'
import * as WodeAPI from '@/api/model/wode' import * as WodeAPI from '@/api/model/wode'
const lemonjkFileSelect = uni.requireNativePlugin('lemonjk-FileSelect')
// 定义Props // 定义Props
interface Props { interface Props {
show: boolean show: boolean
...@@ -179,11 +181,12 @@ ...@@ -179,11 +181,12 @@
const uplpoadFile = ref(null) const uplpoadFile = ref(null)
// 选择文件 // 选择文件
const chooseFile = () => { const chooseFile = () => {
// #ifdef H5
uni.chooseFile({ uni.chooseFile({
count: 1, count: 1,
extension: ['*'], extension: ['*'],
success: (res) => { success: (res) => {
uplpoadFile.value = res uplpoadFile.value = res.tempFilePaths[0]
const tempFilePaths = res.tempFilePaths const tempFilePaths = res.tempFilePaths
const tempFiles = res.tempFiles const tempFiles = res.tempFiles
console.log(tempFiles) console.log(tempFiles)
...@@ -212,6 +215,31 @@ ...@@ -212,6 +215,31 @@
uploading.value = false 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 @@ ...@@ -251,7 +279,6 @@
} }
const userStore = useUserStore() const userStore = useUserStore()
const globSetting = useGlobSetting() const globSetting = useGlobSetting()
const toastRef = ref()
// 提交表单 // 提交表单
const handleSubmit = async () => { const handleSubmit = async () => {
try { try {
...@@ -287,7 +314,7 @@ ...@@ -287,7 +314,7 @@
console.log('上传资源数据:', submitData) console.log('上传资源数据:', submitData)
uni.uploadFile({ uni.uploadFile({
url: globSetting.apiUrl + globSetting.urlPrefix + '/sys/common/upload', // 直接使用上传接口URL url: globSetting.apiUrl + globSetting.urlPrefix + '/sys/common/upload', // 直接使用上传接口URL
filePath: uplpoadFile.value.tempFilePaths[0], filePath: uplpoadFile.value,
name: 'file', name: 'file',
formData: { formData: {
biz: 'temp', biz: 'temp',
...@@ -302,9 +329,10 @@ ...@@ -302,9 +329,10 @@
submitData.fileSrc = data.message submitData.fileSrc = data.message
WodeAPI.addResource(submitData) WodeAPI.addResource(submitData)
.then((res) => { .then((res) => {
toastRef.value.show({ uni.showToast({
type: 'success', title: '上传成功',
text: `上传成功`, icon: 'success',
duration: 2000,
}) })
// emit('update:show', false) // emit('update:show', false)
emit('submitSuccess') emit('submitSuccess')
...@@ -323,9 +351,10 @@ ...@@ -323,9 +351,10 @@
} }
}, },
fail: () => { fail: () => {
toastRef.value.show({ uni.showToast({
type: 'error', title: '上传失败',
text: '上传失败', icon: 'none',
duration: 2000,
}) })
}, },
}) })
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论