Browse Source

修改请求方法

master
邓宏 2 years ago
parent
commit
94c18bcc09
  1. 6
      common/request.js
  2. 21
      components/form.vue
  3. 3
      pages/massif/info.vue

6
common/request.js

@ -1,11 +1,11 @@
import store from "@/store" import store from "@/store"
function host(host='default'){ export function host(host='default',suffix='/plant_manage'){
return( return(
process.env.NODE_ENV === 'development'?{ process.env.NODE_ENV === 'development'?{
default:"http://qv6mj8.natappfree.cc/plant_manage" default:`http://qv6mj8.natappfree.cc${suffix}`
}:{ }:{
default:"http://vtm3hk.natappfree.cc/plant_manage" default:`http://qv6mj8.natappfree.cc${suffix}`
} }
)[host] )[host]
} }

21
components/form.vue

@ -147,7 +147,7 @@
<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>
<u-upload v-if="type=='upImg'" :fileList="imgList" previewFullImage multiple :maxCount="num" @delete="delImg" @afterRead="afterRead"> <u-upload v-if="type=='upImg'" :fileList="imgs" previewFullImage multiple :maxCount="num" @delete="delImg" @afterRead="afterRead">
<view class="album"> <view class="album">
<text class="plant-paizhao">添加照片</text> <text class="plant-paizhao">添加照片</text>
</view> </view>
@ -198,7 +198,7 @@
</template> </template>
<script> <script>
import request from '@/common/request' import request,{host} from '@/common/request'
export default{ export default{
props:{ props:{
label:{ label:{
@ -274,6 +274,10 @@ import request from '@/common/request'
}, },
minDate(){ minDate(){
if(this.type=='dateRange' && this.dateType=='end' && this.value[0])return new Date(this.value[0]).getTime(); if(this.type=='dateRange' && this.dateType=='end' && this.value[0])return new Date(this.value[0]).getTime();
},
imgs(){
if(this.type=='upImg')return this.value.map((v,index)=>({url:`${host(null,"/sys/common/static")}/${v}`,status:"success",index,type:'saved'})).concat(this.imgList.map((v,index)=>Object.assign(v,{index,type:'unsaved'})))
return []
} }
}, },
methods:{ methods:{
@ -286,11 +290,12 @@ import request from '@/common/request'
var res=await request('/sys/common/upload',{ var res=await request('/sys/common/upload',{
file:e.file[i] file:e.file[i]
}) })
if(res.statu){ if(res.statu ||true){
this.imgList.some((v,k)=>{ this.imgList.some((v,k)=>{
if(v==e.file[i]){ if(v==e.file[i]){
v.status='success' v.status='success'
v.message='' v.message=''
v.tempUrl=res.data.data
this.$set(this.imgList,k,this.imgList[k]) this.$set(this.imgList,k,this.imgList[k])
return true return true
} }
@ -300,9 +305,15 @@ import request from '@/common/request'
this.imgList=this.imgList.filter(v=>!v==e.file[i]) this.imgList=this.imgList.filter(v=>!v==e.file[i])
} }
} }
this.$emit('imgs',this.imgs.map(v=>({saved:v.url,unsaved:v.tempUrl})[v.type]))
}, },
delImg(e){ delImg({file}){
console.log(e,'------------delImg----------') if(file.type=='unsaved'){
this.imgList.splice(file.index,1)
}else{
this.$emit("input",this.value.filter(v=>v.index!=file.index).map(v=>v.url))
}
this.$emit('imgs',this.imgs.map(v=>({saved:v.url,unsaved:v.tempUrl})[v.type]))
}, },
}, },
} }

3
pages/massif/info.vue

@ -16,7 +16,8 @@
: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"
@selectRDate="selectDate"/> @selectRDate="selectDate"
@imgs="fields[k].value=$event"/>
</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>

Loading…
Cancel
Save