微信小程序上传附件
上传文件及图片 下载,预览、删除
自定义封装组件 哪儿用哪儿调用即可
wxml代码
<view class="fileImgAll">
<view class="imginfo"
style="border-bottom:{ { attachmentImgFile&&attachmentImgFile.length!==0?'1px dashed #999':''}};display: { { fileDetail?'none':'block'}};">
<view bindtap="uploadAction" class="fileLeft">
<i class="iconfont icon-weixin" style="color: rgb(13, 175, 75); font-size: larger;">i>
上传文件
view>
<view bindtap="uploadup" class="fileRight">
<i class="iconfont .icon-xiangce" style="color: rgb(148, 24, 206); font-size: larger;">i>
上传图片
view>
view>
<view class="allStyle">
<view wx:if="{
{orderShowUp.id&&orderAttachment==='order_attachment'}}" wx:for="{
{orderShowUp.attachment}}"
wx:key="index" class="fileImg">
<view class="fileAll" wx:if="{
{item.mime_type!=='image/'+item.extension}}">
<i bindtap="uploadDown" data-index="{
{index}}" class="iconfont .icon-wenjian1"
style="color: rgb(14 153 234); font-size: x-large;">i>
<i wx:if="{
{fileDetail===false}}" bindtap="setDelArr" class='fileTips' data-index="{
{index}}">Xi>
view>
<view class="fileAll" wx:if="{
{item.mime_type==='image/'+item.extension&&!item.thumb}}">
<i bindtap="listenerButtonPreviewImage" data-index="{
{index}}" class="iconfont .icon-wenjian1"
style="color: rgb(14 153 234); font-size: x-large;">i>
view>
<view class="imgStyle" wx:if="{
{item.mime_type==='image/'+item.extension}}">
<block>
<image mode='aspectFit' src="data:image/png;base64,{
{item.thumb}}"
bindtap="listenerButtonPreviewImage" style="width: 100%;height: 100%; border-radius: 10%;"
data-index="{
{index}}" />
<i wx:if="{
{fileDetail===false}}" bindtap="setDelArr" class='fileTips' data-index="{
{index}}">Xi>
block>
view>
view>
view>
view>
js 代码
const app = getApp()
Component({
properties: {
count: {
type: Number,
value: 9,
},
thumb: {
type: Boolean,
value: ''
},
orderShow: {
type: Object,
},
attachment: {
type: Array,
},
orderAttachment: {
type: String,
},
fileDetail: {
type: Boolean,
}
},
data: {
fileList: [],
isAct: false,
isSava: false,
files: [],
loading: false,
storeList: [],
imgModalBox: {
visible: false,
previewImage: '',
imgWidth: 0,
imgHeight: 0,
original: false,
},
tempFilePaths: [],
storeName: '',
deleteFilePathName: '',
tempUnImgList: [],
itemFilePathName: '',
itemFileUrlName: '',
fileNamePath: '',
fileData: [],
markFile: '',
allImgList: [],
imageShow: false,
filesShow: false,
orderShowUp: {
},
titleImg: '',
attachmentImgFile: [],
detailUrl: '',
},
attached() {
const {
orderShow,
orderAttachment,
fileDetail,
} = this.properties;
this.setData({
orderShowUp: orderShow,
})
if (orderAttachment === "order_attachment") {
this.setData({
attachmentImgFile: orderShow.attachment
})
} else if (orderAttachment === "order_patient_attachment") {
this.setData(