guoshilong
2022-09-30 3ba473d1c7d430a54a1a67b079138aecc7fb388b
pages/taskinfo/eventsReported.vue
@@ -40,7 +40,8 @@
         </u-action-sheet> -->
         
         <u-form-item label-position="top" label-width="25%" label="图片上传:">
            <u-upload ref="uUpload" :header="header" :action="uploadApi" max-count="5" ></u-upload>
            <!-- <u-upload ref="uUpload" :header="header" :action="uploadApi" max-count="5" ></u-upload> -->
            <evan-upload ref="evanUpload" :imgLimit="4" :options="uploadOption" @on-upload="onUpload"></evan-upload>
         </u-form-item>
         
         <u-form-item label-position="top" label="备注:">
@@ -51,6 +52,7 @@
      <view class="submitBtn">
         <u-button @click="submit">提交</u-button>
      </view>
   </view>
</template>
@@ -59,7 +61,9 @@
import {clientId,clientSecret} from '@/common/setting'
import {add} from "@/api/eventgm/eventgm.js"
import {getDicList} from "@/api/dict/dict.js"
import evanUpload from "@/components/evan-upload/evan-upload.vue";
export default {
   components: {'evan-upload' :evanUpload },
   data() {
      return {
         form: {
@@ -91,6 +95,11 @@
         //换用其他写法
         uploadApi:"http://localhost/blade-resource/oss/endpoint/put-file-attach",
         header:{},
         uploadOption:{
            url:"http://localhost/blade-resource/oss/endpoint/put-file-attach",
            header:{},
         },
         uploadList:[],
         showType:false,
         typeList:[],
         showState:false,
@@ -119,11 +128,14 @@
   methods:{
      getHeader(){
         let accessToken = uni.getStorageSync('accessToken');
         var myHeader = {}
         if (accessToken) {
            this.header['Blade-Auth'] = 'bearer ' + accessToken;
            myHeader['Blade-Auth'] = 'bearer ' + accessToken;
         }
         // 客户端认证参数
         this.header['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
         myHeader['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
         this.header = myHeader
         this.uploadOption.header = myHeader
      },
      getAddress(){
         uni.getLocation({
@@ -131,7 +143,6 @@
            isHighAccuracy:true,
            geocode:true,
            success: res=> {
               console.log(res)
               console.log('当前位置的经度:' + res.longitude);
               console.log('当前位置的纬度:' + res.latitude);
               this.form.longitude = res.longitude
@@ -180,12 +191,23 @@
      submit(){
         this.$refs.uForm.validate(valid => {
            if (valid) {
               let lists = this.$refs.uUpload.lists
               if(lists.length>0){
                  lists.forEach(e=>{
               // let lists = this.$refs.uUpload.lists
               // if(lists.length>0){
               //    lists.forEach(e=>{
               //       this.form.picUrls.push({
               //          label:e.response.data.name,
               //          value:e.response.data.link
               //       })
               //    })
               // }else{
               //    this.form.picUrls = null
               // }
               if(this.uploadList.length>0){
                  this.uploadList.forEach(e=>{
                     var res = JSON.parse(e.url)
                     this.form.picUrls.push({
                        label:e.response.data.name,
                        value:e.response.data.link
                        label:res.data.name,
                        value:res.data.link
                     })
                  })
               }else{
@@ -200,6 +222,23 @@
               })
            } 
         });
      },
      onUpload(res){
         this.uploadList = res.data
         if(this.$refs.evanUpload.imgArr.length>0){
            this.$refs.evanUpload.imgArr.forEach(e=>{
               var res = JSON.parse(e.url)
               e.thumbnail = res.data.link
            })
         }
         if(this.$refs.evanUpload.videoArr.length>0){
            this.$refs.evanUpload.videoArr.forEach(e=>{
               var res = JSON.parse(e.url)
               e.thumbnail = res.data.link
            })
         }
      }
   }
};