123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <template>
- <!-- 上传附件 -->
- <lsj-upload
- ref="lsjUpload"
- childId="upload1"
- :width="width"
- :height="height"
- :option="option"
- :size="size"
- :formats="formats"
- :debug="debug"
- :instantly="instantly"
- @progress=""
- @uploadEnd="onuploadEnd" >
- <view class="btn" :style="{width: width,height: height}">选择附件</view>
- </lsj-upload>
- </template>
- <script>
- import config from '@/config'
- const baseUrl = config.baseUrl
- import { getToken } from '@/utils/auth'
- export default{
- data(){
- return{
- //附件
- option: {
- // 上传服务器地址,需要替换为你的接口地址
- url: baseUrl+'/common/upload', // 该地址非真实路径,需替换为你项目自己的接口地址
- // 上传附件的key
- name: 'file',
- // 根据你接口需求自定义请求头,默认不要写content-type,让浏览器自适配
- header: {
- // 示例参数可删除
- 'Authorization': 'Bearer ' + getToken(),
- },
- // 根据你接口需求自定义body参数
- formData: {
- }
- },
- // 选择文件后是否立即自动上传,true=选择后立即上传
- instantly: true,
- // 必传宽高且宽高应与slot宽高保持一致
- width: '',
- height: '48rpx',
- // 限制允许上传的格式,空串=不限制,默认为空
- formats: 'doc,docx,xls,ppt,txt,pdf,zip,rar,word',
- // 文件上传大小限制
- size: 100,
- // 文件数量限制 默认10
- count: 5,
- // 文件回显列表
- files: new Map(),
- // 微信小程序Map对象for循环不显示,所以转成普通数组,不要问为什么,我也不知道
- wxFiles: [],
- // 是否打印日志
- debug: false,
-
- // 演示用
- tabIndex: 0,
- // filelist:[{originalFilename:'ceisi.docx',fileName:'/profile/upload/2023/03/05/ceisi_20230305125835A007.docx'}],
- filelist:[{fjName:'ceisi.docx',path:'/profile/upload/2023/03/05/ceisi_20230305125835A007.docx'}],
- }
- },
- methods:{
- onuploadEnd(item) {
- var newobj={}
- var responseText=JSON.parse(item.responseText)
- newobj.fjName=responseText.originalFilename;
- newobj.path=responseText.fileName;
- this.filelist.push(newobj)
- },
- getDelFj(idx){
- this.filelist.splice(idx,1)
- },
- getDown(e){
- uni.showLoading({
- title: '加载中'
- });
- var url=baseUrl+e;
- uni.downloadFile({
- url: url,//文件的下载路径
- success(result) {
- uni.hideLoading()
- var filePath = result.tempFilePath;
- uni.openDocument({
- filePath: filePath,
- showMenu: true,
- success: function (res) {
- console.log('打开文档成功');
- }
- });
- },
- fail(res) {uni.hideLoading()}
- })
- },
- }
- }
- </script>
- <style>
- </style>
|