Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
539c605a
提交
539c605a
authored
11月 07, 2025
作者:
宇宙超人
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
合并
上级
e07d0d6f
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
324 行增加
和
108 行删除
+324
-108
keybindings.json
.vscode/keybindings.json
+23
-0
wode.ts
src/api/model/wode.ts
+24
-2
fui-swiper-dot.vue
src/components/FirstUI/fui-swiper-dot/fui-swiper-dot.vue
+9
-0
nongchang.vue
src/pages/nongchang/nongchang.vue
+0
-0
save-dialog.vue
src/pages/resource/components/save-dialog.vue
+0
-0
resource.vue
src/pages/resource/resource.vue
+0
-0
shouye.vue
src/pages/shouye/shouye.vue
+0
-0
wode.vue
src/pages/wode/wode.vue
+9
-106
local-address.png
src/static/images/local-address.png
+0
-0
download.ts
src/utils/download.ts
+257
-0
index.ts
src/utils/index.ts
+2
-0
没有找到文件。
.vscode/keybindings.json
0 → 100644
浏览文件 @
539c605a
[
{
"key"
:
"ctrl+/"
,
"command"
:
"editor.action.commentLine"
,
"when"
:
"editorTextFocus && !editorReadonly"
},
{
"key"
:
"shift+alt+a"
,
"command"
:
"editor.action.blockComment"
,
"when"
:
"editorTextFocus && !editorReadonly"
},
{
"key"
:
"ctrl+k ctrl+c"
,
"command"
:
"editor.action.addCommentLine"
,
"when"
:
"editorTextFocus && !editorReadonly"
},
{
"key"
:
"ctrl+k ctrl+u"
,
"command"
:
"editor.action.removeCommentLine"
,
"when"
:
"editorTextFocus && !editorReadonly"
}
]
\ No newline at end of file
src/api/model/wode.ts
浏览文件 @
539c605a
...
...
@@ -15,9 +15,20 @@ export function bizCommonFileList(params = {}) {
})
}
/**
* 资源列表
* @param params
* @returns
*/
export
function
getResourceList
(
params
=
{})
{
return
otherHttp
.
get
({
url
:
'/resource/list'
,
params
,
})
}
/**
* 添加资源
* @param params
* @returns
* @param params
* @returns
*/
export
function
addResource
(
params
=
{})
{
return
otherHttp
.
post
({
...
...
@@ -25,3 +36,14 @@ export function addResource(params = {}) {
params
,
})
}
/**
* 下载资源
* @param params
* @returns
*/
export
function
downloadResource
(
params
=
{})
{
return
otherHttp
.
get
({
url
:
'/resource/download'
,
params
,
})
}
src/components/FirstUI/fui-swiper-dot/fui-swiper-dot.vue
浏览文件 @
539c605a
...
...
@@ -135,6 +135,10 @@
flex-direction
:
column
;
position
:
relative
;
overflow
:
hidden
;
/* #ifdef APP-PLUS */
position
:
relative
;
z-index
:
1
;
/* #endif */
}
.fui-swiper__dot
{
...
...
@@ -146,7 +150,12 @@
flex-direction
:
row
;
align-items
:
center
;
justify-content
:
center
;
/* #ifdef APP-PLUS */
z-index
:
998
;
/* #endif */
/* #ifndef APP-PLUS */
z-index
:
2
;
/* #endif */
overflow
:
hidden
;
}
...
...
src/pages/nongchang/nongchang.vue
浏览文件 @
539c605a
差异被折叠。
点击展开。
src/pages/resource/components/save-dialog.vue
浏览文件 @
539c605a
差异被折叠。
点击展开。
src/pages/resource/resource.vue
浏览文件 @
539c605a
差异被折叠。
点击展开。
src/pages/shouye/shouye.vue
浏览文件 @
539c605a
差异被折叠。
点击展开。
src/pages/wode/wode.vue
浏览文件 @
539c605a
...
...
@@ -248,118 +248,21 @@ function onResourceClick(resource: any) {
}
// 资源下载点击事件
function
onDownloadClick
(
e
,
resource
:
any
)
{
async
function
onDownloadClick
(
e
,
resource
:
any
)
{
// 阻止事件冒泡
e
?.
stopPropagation
()
// 显示加载提示
uni
.
showLoading
({
title
:
'下载中...'
,
mask
:
true
,
})
// 判断是否为H5平台
/* #ifdef H5 */
downloadFileForWeb
(
resource
)
/* #endif */
/* #ifndef H5 */
downloadFileForNative
(
resource
)
/* #endif */
const
{
downloadResource
}
=
await
import
(
'@/utils'
)
// 使用封装的下载方法
const
result
=
await
downloadResource
(
resource
)
if
(
!
result
.
success
)
{
console
.
error
(
'下载失败:'
,
result
.
error
)
}
}
// H5平台下载文件函数
function
downloadFileForWeb
(
resource
:
any
)
{
const
url
=
resource
.
fileSrc
// 创建一个临时的a标签用于下载
const
link
=
document
.
createElement
(
'a'
)
link
.
href
=
url
link
.
download
=
resource
.
fileName
||
'download'
// 设置下载文件名
link
.
style
.
display
=
'none'
// 添加到文档并触发点击
document
.
body
.
appendChild
(
link
)
link
.
click
()
// 清理
document
.
body
.
removeChild
(
link
)
uni
.
hideLoading
()
uni
.
showToast
({
title
:
'开始下载'
,
icon
:
'success'
,
duration
:
1500
})
}
// 原生平台下载文件函数
function
downloadFileForNative
(
resource
:
any
)
{
uni
.
downloadFile
({
url
:
resource
.
fileSrc
,
success
:
(
res
)
=>
{
if
(
res
.
statusCode
===
200
)
{
uni
.
saveFile
({
tempFilePath
:
res
.
tempFilePath
,
success
:
(
saveRes
)
=>
{
uni
.
hideLoading
()
uni
.
showToast
({
title
:
'下载成功'
,
icon
:
'success'
,
duration
:
1500
})
// 提示用户文件已保存
uni
.
showModal
({
title
:
'下载完成'
,
content
:
`文件已保存至:
${
saveRes
.
savedFilePath
}
\n是否立即打开?`
,
success
:
(
modalRes
)
=>
{
if
(
modalRes
.
confirm
)
{
uni
.
openDocument
({
filePath
:
saveRes
.
savedFilePath
,
fileType
:
resource
.
fileType
?.
toString
()
||
''
,
showMenu
:
true
,
fail
:
()
=>
{
uni
.
showToast
({
title
:
'无法打开文件'
,
icon
:
'error'
,
duration
:
1500
})
},
})
}
},
})
},
fail
:
(
err
)
=>
{
uni
.
hideLoading
()
console
.
error
(
'保存文件失败:'
,
err
)
uni
.
showToast
({
title
:
'保存文件失败'
,
icon
:
'error'
,
duration
:
1500
})
},
})
}
else
{
uni
.
hideLoading
()
uni
.
showToast
({
title
:
`下载失败,状态码:
${
res
.
statusCode
}
`
,
icon
:
'error'
,
duration
:
1500
})
}
},
fail
:
(
err
)
=>
{
uni
.
hideLoading
()
console
.
error
(
'下载失败:'
,
err
)
uni
.
showToast
({
title
:
'网络错误,下载失败'
,
icon
:
'error'
,
duration
:
1500
})
},
})
}
// 查看所有资源
function
onViewAllResources
()
{
...
...
src/static/images/local-address.png
0 → 100644
浏览文件 @
539c605a
543 Bytes
src/utils/download.ts
0 → 100644
浏览文件 @
539c605a
/**
* 下载工具类
* 提供跨平台的文件下载功能,支持H5和原生平台
*/
/**
* 文件下载选项接口
*/
export
interface
DownloadOptions
{
/** 文件下载URL */
url
:
string
/** 文件名 */
fileName
?:
string
/** 文件类型 */
fileType
?:
string
/** 文件大小 */
fileSize
?:
string
/** 是否显示下载进度 */
showProgress
?:
boolean
}
/**
* 下载结果接口
*/
export
interface
DownloadResult
{
/** 是否成功 */
success
:
boolean
/** 错误信息 */
error
?:
string
/** 文件保存路径(仅原生平台) */
savedFilePath
?:
string
}
/**
* H5平台下载文件
* @param options 下载选项
* @returns Promise<DownloadResult>
*/
export
function
downloadFileForWeb
(
options
:
DownloadOptions
):
Promise
<
DownloadResult
>
{
return
new
Promise
((
resolve
)
=>
{
const
{
url
,
fileName
=
'download'
}
=
options
try
{
// 检查是否在浏览器环境
if
(
typeof
document
===
'undefined'
)
{
resolve
({
success
:
false
,
error
:
'H5下载功能仅支持浏览器环境'
,
})
return
}
// 创建一个临时的a标签用于下载
const
link
=
document
.
createElement
(
'a'
)
link
.
href
=
url
link
.
download
=
fileName
link
.
style
.
display
=
'none'
// 添加到文档并触发点击
document
.
body
.
appendChild
(
link
)
link
.
click
()
// 清理
document
.
body
.
removeChild
(
link
)
// 显示下载成功提示
uni
.
showToast
({
title
:
'开始下载'
,
icon
:
'success'
,
duration
:
1500
,
})
resolve
({
success
:
true
,
})
}
catch
(
error
)
{
console
.
error
(
'H5下载失败:'
,
error
)
resolve
({
success
:
false
,
error
:
'H5下载失败'
,
})
}
})
}
/**
* 原生平台下载文件
* @param options 下载选项
* @returns Promise<DownloadResult>
*/
export
function
downloadFileForNative
(
options
:
DownloadOptions
):
Promise
<
DownloadResult
>
{
return
new
Promise
((
resolve
)
=>
{
const
{
url
,
fileName
=
'download'
,
fileType
=
''
,
showProgress
=
true
}
=
options
if
(
showProgress
)
{
// 显示加载提示
uni
.
showLoading
({
title
:
'下载中...'
,
mask
:
true
,
})
}
uni
.
downloadFile
({
url
,
success
:
(
res
)
=>
{
if
(
res
.
statusCode
===
200
)
{
uni
.
saveFile
({
tempFilePath
:
res
.
tempFilePath
,
success
:
(
saveRes
)
=>
{
if
(
showProgress
)
{
uni
.
hideLoading
()
uni
.
showToast
({
title
:
'下载成功'
,
icon
:
'success'
,
duration
:
1500
,
})
}
// 提示用户文件已保存
uni
.
showModal
({
title
:
'下载完成'
,
content
:
`文件已保存至:
${
saveRes
.
savedFilePath
}
\n是否立即打开?`
,
success
:
(
modalRes
)
=>
{
if
(
modalRes
.
confirm
)
{
uni
.
openDocument
({
filePath
:
saveRes
.
savedFilePath
,
fileType
:
fileType
?.
toString
()
||
''
,
showMenu
:
true
,
fail
:
()
=>
{
uni
.
showToast
({
title
:
'无法打开文件'
,
icon
:
'none'
,
duration
:
1500
,
})
},
})
}
},
})
resolve
({
success
:
true
,
savedFilePath
:
saveRes
.
savedFilePath
,
})
},
fail
:
(
err
)
=>
{
if
(
showProgress
)
{
uni
.
hideLoading
()
console
.
error
(
'保存文件失败:'
,
err
)
uni
.
showToast
({
title
:
'保存文件失败'
,
icon
:
'none'
,
duration
:
1500
,
})
}
resolve
({
success
:
false
,
error
:
'保存文件失败'
,
})
},
})
}
else
{
if
(
showProgress
)
{
uni
.
hideLoading
()
uni
.
showToast
({
title
:
`下载失败,状态码:
${
res
.
statusCode
}
`
,
icon
:
'none'
,
duration
:
1500
,
})
}
resolve
({
success
:
false
,
error
:
`下载失败,状态码:
${
res
.
statusCode
}
`
,
})
}
},
fail
:
(
err
)
=>
{
if
(
showProgress
)
{
uni
.
hideLoading
()
console
.
error
(
'下载失败:'
,
err
)
uni
.
showToast
({
title
:
'网络错误,下载失败'
,
icon
:
'none'
,
duration
:
1500
,
})
}
resolve
({
success
:
false
,
error
:
'网络错误,下载失败'
,
})
},
})
})
}
/**
* 通用下载文件方法
* 自动判断平台并调用相应的下载方法
* @param options 下载选项
* @returns Promise<DownloadResult>
*/
export
function
downloadFile
(
options
:
DownloadOptions
):
Promise
<
DownloadResult
>
{
// 判断是否为H5平台
/* #ifdef H5 */
return
downloadFileForWeb
(
options
)
/* #endif */
// 其他平台使用原生下载
/* #ifndef H5*/
return
downloadFileForNative
(
options
)
/* #endif */
}
/**
* 便捷下载方法,支持资源对象
* @param resource 资源对象,包含 fileSrc、fileName、fileType 等属性
* @returns Promise<DownloadResult>
*/
export
function
downloadResource
(
resource
:
any
):
Promise
<
DownloadResult
>
{
const
options
:
DownloadOptions
=
{
url
:
resource
.
fileSrc
,
fileName
:
resource
.
fileName
||
'download'
,
fileType
:
resource
.
fileType
||
''
,
fileSize
:
resource
.
fileSize
||
''
,
showProgress
:
true
,
}
return
downloadFile
(
options
)
}
/**
* 检查下载链接是否有效
* @param url 下载链接
* @returns Promise<boolean>
*/
export
function
checkDownloadUrl
(
url
:
string
):
Promise
<
boolean
>
{
return
new
Promise
((
resolve
)
=>
{
// 在原生平台检查链接有效性
/* #ifndef H5 */
uni
.
request
({
url
,
method
:
'HEAD'
,
success
:
(
res
)
=>
{
resolve
(
res
.
statusCode
===
200
)
},
fail
:
()
=>
{
resolve
(
false
)
},
})
/* #endif */
// 在H5平台,直接返回true(浏览器会处理链接有效性)
/* #ifdef H5 */
resolve
(
true
)
/* #endif */
})
}
src/utils/index.ts
浏览文件 @
539c605a
...
...
@@ -3,6 +3,8 @@ import type { App, Plugin } from 'vue'
import
{
unref
}
from
'vue'
import
{
isObject
}
from
'/@/utils/is'
export
*
from
'./download'
export
function
noop
()
{}
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论