Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes-pad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ximai
mes-pad
Commits
a93b3703
Commit
a93b3703
authored
Mar 12, 2024
by
张海景
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:提交预览pdf测试文件
parent
525190e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
210 additions
and
0 deletions
+210
-0
test.vue
pages/test/test.vue
+210
-0
No files found.
pages/test/test.vue
0 → 100644
View file @
a93b3703
<
template
>
<view>
<u-button
@
click=
"exportPDF"
>
预览pdf
</u-button>
</view>
</
template
>
<
script
>
import
{
io
}
from
'socket.io-client'
;
import
uButton
from
'../../uview-ui/components/u-button/u-button.vue'
;
export
default
{
components
:
{
uButton
},
data
()
{
return
{
socket
:
{},
url
:
'http://192.168.3.91:8082/static/123.pdf'
};
},
created
()
{
// this.socket = io('http://192.168.23.19:17521', {
// transports: ['websocket'],
// auth: {
// token: 'Bearer ' + this.vuex_token // 在此处填入你 client 设置的 token,缺省可留空
// }
// });
// this.socket.on('connect', () => {
// globalThis.connect = true;
// console.log('连接成功444');
// // TODO: Do something for your project
// });
// this.socket.on('clients', (clients) => {
// globalThis.clients = clients;
// console.log(clients, 'clients');
// });
// this.socket.on('printerList', (printerList) => {
// globalThis.printerList = printerList;
// console.log(printerList, 'printerList');
// });
},
methods
:
{
handlePrint
()
{
console
.
log
(
this
.
socket
,
'this.$socket'
);
this
.
$socket
.
emit
(
'news'
,
{
client
:
null
,
printer
:
null
,
type
:
'url_pdf'
,
pdf_path
:
'http://192.168.23.19:8081/static/123.pdf'
});
},
previewPdf
()
{
// 预览pdf文件
// uni.openDocument({
// filePath: 'http://192.168.3.91:8082/static/123.pdf',
// showMenu: true,
// success: function(file) {
// console.log("file-success", file)
// }
// })
let
fileType
=
[
'doc'
,
'xls'
,
'ppt'
,
'pdf'
,
'docx'
,
'xlsx'
,
'pptx'
];
//下载文件资源到本地
const
url
=
'/api/static/123.pdf'
;
uni
.
downloadFile
({
url
,
success
:
function
(
res
)
{
console
.
log
(
res
);
var
filePath
=
res
.
tempFilePath
;
uni
.
openDocument
({
filePath
:
filePath
,
showMenu
:
true
,
success
:
function
(
res
)
{}
});
},
fail
:
function
(
err
)
{
console
.
log
(
'下载失败:'
,
err
);
}
});
},
saveFile
(
tempFilePath
)
{
//保存到本地
//文件保存到本地
const
url
=
'/api/static/123.pdf'
;
uni
.
saveFile
({
tempFilePath
:
url
,
//临时路径
success
:
function
(
res
)
{
uni
.
showToast
({
icon
:
'none'
,
mask
:
true
,
title
:
'文件已保存:'
+
res
.
savedFilePath
,
//保存路径
duration
:
3000
});
setTimeout
(()
=>
{
//打开文档查看
uni
.
openDocument
({
filePath
:
res
.
savedFilePath
,
success
:
function
(
res
)
{
// console.log('打开文档成功');
}
});
},
3000
);
}
});
},
exportPDF
()
{
let
url
=
this
.
url
;
// #ifdef APP-PLUS
uni
.
downloadFile
({
url
,
success
:
(
res
)
=>
{
console
.
log
(
res
);
if
(
res
.
statusCode
===
200
)
{
// 保存pdf文件至手机,一般安卓端存储路径为:手机存储/dcim/camera文件夹下
// uni.showToast({
// title: '文件已保存至/DCIM/CAMERA文件夹下',
// icon: 'none'
// });
// 预览pdf文件
uni
.
openDocument
({
filePath
:
res
.
tempFilePath
,
showMenu
:
true
,
success
:
function
(
file
)
{
console
.
log
(
'file-success'
,
file
);
}
});
}
}
});
// #endif
},
downLoadFile
(
fileName
,
fileType
)
{
console
.
log
(
'开始下载'
);
//这里填写接口地址
let
url
=
'/api/static/123.pdf'
;
uni
.
downloadFile
({
//调用官方提供的uni.downloadFile
url
:
url
,
//将刚刚提前准备好的url传过来
header
:
{
//如果需要填写请求头信息则在此处填写
},
success
:
function
(
res
)
{
console
.
log
(
res
);
if
(
res
.
statusCode
===
200
)
{
console
.
log
(
'下载成功:'
,
res
.
tempFilePath
);
//下载成功,并把下载好的文件保存在临时区域中
uni
.
saveFile
({
//使用该功能,以将临时文件保存在手机中可长久存储的区域
tempFilePath
:
res
.
tempFilePath
,
success
:
(
saveResult
)
=>
{
// 在保存文件成功后,使用 uni.openDocument 方法打开文件
console
.
log
(
'文件保存成功:'
,
saveResult
);
uni
.
openDocument
({
filePath
:
saveResult
.
savedFilePath
,
fileType
:
fileType
,
//这里把预先限定好的文件类型传来
success
:
function
()
{
console
.
log
(
'文件打开成功!'
);
//至此,手机会从app中跳转到文件预览界面
//之后可从预览界面返回app中
},
fail
:
function
(
err
)
{
console
.
log
(
'打开失败'
,
err
);
}
});
},
fail
:
function
(
err
)
{
console
.
log
(
'保存文件失败'
,
err
);
}
});
}
},
fail
:
function
(
err
)
{
console
.
log
(
'下载失败:'
,
err
);
}
});
},
//文件预览
prefile
(
e
)
{
let
that
=
this
;
let
url
=
'/api/static/123.pdf'
;
uni
.
downloadFile
({
url
:
url
,
success
:
function
(
res
)
{
let
filepathss
=
plus
.
io
.
convertLocalFileSystemURL
(
res
.
tempFilePath
);
setTimeout
(
()
=>
uni
.
openDocument
({
filePath
:
filepathss
,
showMenu
:
false
,
success
:
function
()
{
console
.
log
(
'打开文档成功'
);
},
fail
:
function
()
{
uni
.
showToast
({
title
:
'暂不支持此类型'
,
duration
:
2000
,
icon
:
'none'
});
}
}),
1000
);
},
fail
:
function
(
res
)
{
console
.
log
(
res
);
//失败
}
});
}
}
};
</
script
>
<
style
lang=
"scss"
></
style
>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment