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'){
return(
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"
}
@ -32,8 +32,8 @@ const request=async function(url,param={}){
if(param.file){
var res=await uni.uploadFile({
url:`${param.host||host()}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
files:param.file,
// name:"file",
file:param.file,
name:"file",
formData:param.body||{},
timeout:param.timeout||60*1000,
header,

75
components/form.vue

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

1
pages/massif/index.vue

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

3
pages/massif/info.vue

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

Loading…
Cancel
Save