Browse Source

修改上传图片

master
邓宏 2 years ago
parent
commit
cb0991160f
  1. 6
      common/request.js
  2. 75
      components/form.vue
  3. 1
      pages/massif/index.vue
  4. 3
      pages/massif/info.vue

6
common/request.js

@ -3,7 +3,7 @@ import store from "@/store"
function host(host='default'){ function host(host='default'){
return( return(
process.env.NODE_ENV === 'development'?{ process.env.NODE_ENV === 'development'?{
default:"http://tishia.natappfree.cc/plant_manage" default:"http://qv6mj8.natappfree.cc/plant_manage"
}:{ }:{
default:"http://vtm3hk.natappfree.cc/plant_manage" default:"http://vtm3hk.natappfree.cc/plant_manage"
} }
@ -32,8 +32,8 @@ const request=async function(url,param={}){
if(param.file){ if(param.file){
var res=await uni.uploadFile({ var res=await uni.uploadFile({
url:`${param.host||host()}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`, url:`${param.host||host()}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
files:param.file, file:param.file,
// name:"file", name:"file",
formData:param.body||{}, formData:param.body||{},
timeout:param.timeout||60*1000, timeout:param.timeout||60*1000,
header, header,

75
components/form.vue

@ -48,18 +48,27 @@
color:rgb(48,49,51); color:rgb(48,49,51);
} }
} }
.upImg{ .u-upload{
width:100%;
background:#F7F7F7; background:#F7F7F7;
border-radius: 8rpx; border-radius: 8rpx;
padding:20rpx; padding:20rpx;
min-height:260rpx; min-height:260rpx;
margin-top:14rpx; margin-top:14rpx;
display:flex; align-content: flex-start;
flex-wrap: wrap; &/deep/ .u-upload__wrap__preview{
&>.album{ border-radius: 10rpx;
&>.u-upload__wrap__preview__image{
height:170rpx!important;
width:170rpx!important;
}
&>.u-upload__deletable{
width:30rpx;
height:30rpx;
}
}
.album{
background:#fff; background:#fff;
border-radius: 24rpx; border-radius: 20rpx;
width:170rpx; width:170rpx;
height:170rpx; height:170rpx;
text{ text{
@ -122,7 +131,7 @@
font-size:20rpx; font-size:20rpx;
color:#FBA83C; color:#FBA83C;
} }
&/deep/>.u-form-item__body__right__message{ &/deep/ .u-form-item__body__right__message{
margin-left:0!important; margin-left:0!important;
} }
} }
@ -138,11 +147,11 @@
<button v-if="btnText" @click="btnFun" class="cu-btn bg-green shadow">{{btnText}}</button> <button v-if="btnText" @click="btnFun" class="cu-btn bg-green shadow">{{btnText}}</button>
</view> </view>
<view v-if="type=='select'" class="plant-youbian" :class="{noData:!/^\d+$/.test(value)}" @click="show=true">{{/^\d+$/.test(value)&&columns[0][value][keyName]||placeholder||`请选择${label}`}}</view> <view v-if="type=='select'" class="plant-youbian" :class="{noData:!/^\d+$/.test(value)}" @click="show=true">{{/^\d+$/.test(value)&&columns[0][value][keyName]||placeholder||`请选择${label}`}}</view>
<view v-if="type=='upImg'" class="upImg"> <u-upload v-if="type=='upImg'" :fileList="imgList" previewFullImage multiple :maxCount="num" @delete="delImg" @afterRead="afterRead">
<view class="album" @click="selectImg"> <view class="album">
<text class="plant-paizhao">添加照片</text> <text class="plant-paizhao">添加照片</text>
</view> </view>
</view> </u-upload>
<textarea v-if="type=='textarea'" auto-height :value="value" :placeholder="placeholder||`请输入${label}`" @input="$emit('input',e)"/> <textarea v-if="type=='textarea'" auto-height :value="value" :placeholder="placeholder||`请输入${label}`" @input="$emit('input',e)"/>
<view v-if="type=='dateRange'" class="dateRange"> <view v-if="type=='dateRange'" class="dateRange">
<text style="margin-right:20rpx;" :class="{noData:!value[0]}" @click="dateType='start';show=true">{{value[0]||startPlaceholder||'开始时间'}}</text> <text style="margin-right:20rpx;" :class="{noData:!value[0]}" @click="dateType='start';show=true">{{value[0]||startPlaceholder||'开始时间'}}</text>
@ -173,6 +182,8 @@
:show="show" :show="show"
mode="date" mode="date"
:value="date" :value="date"
:maxDate="maxDate"
:minDate="minDate"
closeOnClickOverlay closeOnClickOverlay
@close="show=false" @close="show=false"
@cancel="show=false" @cancel="show=false"
@ -250,37 +261,49 @@ import request from '@/common/request'
downValue:[], downValue:[],
show:false, show:false,
dateType:"start", dateType:"start",
imgList:[],
} }
}, },
computed:{ computed:{
date(){ date(){
if(this.dateType=='start')return this.value[0]||new Date().format('yyyy-MM-dd'); if(this.dateType=='start')return this.value[0]||new Date().format('yyyy-MM-dd');
else return this.value[1]||new Date().format('yyyy-MM-dd'); else return this.value[1]||new Date().format('yyyy-MM-dd');
},
maxDate(){
if(this.type=='dateRange' && this.dateType=='start' && this.value[1])return new Date(this.value[1]).getTime();
},
minDate(){
if(this.type=='dateRange' && this.dateType=='end' && this.value[0])return new Date(this.value[0]).getTime();
} }
}, },
methods:{ methods:{
async selectImg(){ async afterRead(e){
var res=await uni.chooseImage({ this.imgList=this.imgList.concat(e.file.map(v=>Object.assign(v,{
count:this.num-this.value.length, status: 'uploading',
sizeType:['compressed'], message:"上传中",
})))
for(var i=0; i<e.file.length;i++){
var res=await request('/sys/common/upload',{
file:e.file[i]
}) })
if(/ok/.test(res[1].errMsg)){ if(res.statu){
console.log(res[1].tempFiles.map(v=>v.name),'---asfd-----') this.imgList.some((v,k)=>{
var upImg=await request("/sys/common/uploadBatch",{ if(v==e.file[i]){
file:res[1].tempFiles, v.status='success'
body:{ v.message=''
name:res[1].tempFiles.map(v=>v.name) this.$set(this.imgList,k,this.imgList[k])
return true
} }
return false
}) })
console.log(upImg,"-----333333------------")
}else{ }else{
uni.showModal({ this.imgList=this.imgList.filter(v=>!v==e.file[i])
title:"提示", }
content:res.msg||"选取图片失败!",
showCancel:false,
})
} }
}, },
delImg(e){
console.log(e,'------------delImg----------')
},
}, },
} }
</script> </script>

1
pages/massif/index.vue

@ -120,7 +120,6 @@ import request from '@/common/request'
}, },
onLoad(){ onLoad(){
this.search() this.search()
console.log(new FormData())
}, },
methods:{ methods:{
clean(){ clean(){

3
pages/massif/info.vue

@ -16,7 +16,7 @@
:field="k" :field="k"
:value="({dateRange:fields.date.value})[v.type||'text']||formData[k]" :value="({dateRange:fields.date.value})[v.type||'text']||formData[k]"
@input="formData[k]=$event" @input="formData[k]=$event"
@selectDate="selectDate"/> @selectRDate="selectDate"/>
</u-form> </u-form>
<button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button> <button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button>
</view> </view>
@ -68,7 +68,6 @@ import dForm from '@/components/form.vue'
}, },
methods:{ methods:{
selectDate(e){ selectDate(e){
console.log(e,'-----e---------')
switch(e.type){ switch(e.type){
case "start":this.fields.date.value[0]=e.value;break; case "start":this.fields.date.value[0]=e.value;break;
case 'end':this.fields.date.value[1]=e.value;break; case 'end':this.fields.date.value[1]=e.value;break;

Loading…
Cancel
Save