朱鑫波 4 年之前
父节点
当前提交
d0631118a0
共有 1 个文件被更改,包括 97 次插入12 次删除
  1. 97 12
      src/views/modules/autoLaunch/application/components/creatApplication.vue

+ 97 - 12
src/views/modules/autoLaunch/application/components/creatApplication.vue

@@ -50,8 +50,24 @@
             :labelCol="{ xs: { span: 24 }, sm: { span: 5 } }"
             :wrapperCol="{ xs: { span: 24 }, sm: { span: 16 } }"
           >
-            <a-upload name="file" :file-list="fileList" :before-upload="beforeUpload" @change="handleChange">
+            <!-- <a-upload name="file" :file-list="fileList" :before-upload="beforeUpload" @change="handleChange">
               <a-button><a-icon type="upload" />文件上传</a-button>
+            </a-upload> -->
+            <a-upload
+              name="file"
+              :multiple="false"
+              :action="uploadAction"
+              :headers="tokenHeader"
+              :file-list="fileList"
+              :showUploadList="false"
+              :beforeUpload="beforeUpload"
+              @change="handleChange"
+              style="margin-right: 20px"
+            >
+              <a-button :disabled="(!projectId && !fileUrl) || loadDisabled">
+                <a-icon type="upload" />
+                {{ loadDisabled ? '上传中,请稍后' : '文件上传' }}
+              </a-button>
             </a-upload>
             <a @click="downLoadFile">文件格式下载</a>
           </a-form-item>
@@ -186,11 +202,14 @@
 </template>
 
 <script>
+import Vue from 'vue'
+import { ACCESS_TOKEN } from '@/store/mutation-types'
 import { deleteAction, postAction, getAction, downFilePost, downFile } from '@/api/manage'
 import uploadFile from '@/components/uploadFile.vue'
 import { mapActions, mapGetters } from 'vuex'
 import BMF from 'browser-md5-file'
 import selectTable from '@/views/modules/Statistics/components/selectPagination.vue'
+const fileSuffix = ['xlsx', 'xls', 'zip']
 export default {
   name: 'BaseForm',
   components: {
@@ -199,6 +218,7 @@ export default {
   },
   data() {
     return {
+      loadDisabled: false,
       projectId: '',
       accountId: '',
       fileList: [],
@@ -232,23 +252,24 @@ export default {
       application: false,
       confirmLoading: false,
       imageToken: '',
+      uploadAction: '/kuaishouAppPackage/importAppExcel',
+      tokenHeader: { 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) },
     }
   },
   methods: {
-    checkAppVersion(rule, value, callback){
-      if(value!=''){
+    checkAppVersion(rule, value, callback) {
+      if (value != '') {
         let params = {}
         params.projectId = this.projectId
         params.appVersion = value
-        getAction('/kuaishouAppPackage/checkAppVersion',params).then(res=>{
-          if(res.success){
+        getAction('/kuaishouAppPackage/checkAppVersion', params).then((res) => {
+          if (res.success) {
             callback()
-          }else{
+          } else {
             callback(res.message)
           }
         })
       }
-     
     },
     overUpload(file) {
       console.log(file)
@@ -269,10 +290,76 @@ export default {
       })
     },
     handleChange(info) {
-      this.fileList = info.fileList
+      console.log(info)
+      let fileList = [...info.fileList]
+
+      // 1. Limit the number of uploaded files
+      //    Only to show two recent uploaded files, and old ones will be replaced by the new
+      fileList = fileList.slice(-2)
+
+      // 2. read from response and show file link
+      fileList = fileList.map((file) => {
+        if (file.response) {
+          // Component will show file.url as link
+          file.url = file.response.url
+        }
+        return file
+      })
+      if (fileList.length > 0) {
+        this.fileList = [
+          {
+            ...fileList[fileList.length - 1],
+          },
+        ]
+      } else {
+        this.fileList = []
+      }
+      // this.loadDisabled = false
+      // this.$message.success('文件导入成功,异步创建中,请稍后查看...')
+      if (info.file.status !== 'uploading') {
+        console.log(info.file, info.fileList)
+      }
+      if (info.file.status === 'done') {
+        this.loadDisabled = false
+        if (info.file.response.code == 0) {
+          this.$message.success(info.file.response.message)
+        } else {
+          this.$message.error(info.file.response.message)
+        }
+      } else if (info.file.status === 'error') {
+        this.$message.error(`${info.file.name}上传失败`)
+        this.loadDisabled = false
+      }
+
+      // console.log(this.form)
     },
     beforeUpload(file) {
-      this.cosUpload(file)
+      // this.cosUpload(file)
+      if (process.env.NODE_ENV == 'development') {
+        this.uploadAction = `/jeecg-boot/kuaishouAppPackage/importAppExcel?projectId=${this.projectId}&platform=${
+          this.appType == 'ios' ? +this.platform + 2 : +this.platform
+        }&imageUrl=${this.fileUrl}`
+      } else if (process.env.NODE_ENV == 'debug') {
+      } else if (process.env.NODE_ENV == 'production') {
+        this.uploadAction = `${this.axios.defaults.baseURL}/kuaishouAppPackage/importAppExcel?projectId=${
+          this.projectId
+        }&platform=${this.appType == 'ios' ? +this.platform + 2 : +this.platform}&imageUrl=${this.fileUrl}`
+      }
+      this.loadDisabled = true
+      const size = (Number(file.size) / (1024 * 1024)).toFixed(2)
+      const fileName = file.name
+      const fileStrArr = fileName.split('.')
+      const suffix = fileStrArr[fileStrArr.length - 1]
+
+      let result = fileSuffix.some((item) => {
+        return item === suffix
+      })
+
+      if (!result) {
+        this.$message.error('不支持该文件类型')
+        this.loadDisabled = false
+        return false
+      }
     },
     cosUpload(file) {
       let that = this
@@ -437,13 +524,11 @@ export default {
             this.url.insertTemplateUrl = '/kuaishouAppPackage/importAppExcel'
             params.platform = this.appType == 'ios' ? +this.platform + 2 : +this.platform
             params.imageUrl = this.fileUrl
-            params.imageToken = this.imageToken
           } else {
             this.url.insertTemplateUrl = '/kuaishouAppPackage/fillInLink'
-            params = {...values}
+            params = { ...values }
             params.projectId = this.projectId
             params.appIconUrl = this.fileUrl
-            params.imageToken = this.imageToken
             params.platform = this.appType == 'ios' ? +this.platform + 2 : +this.platform
           }
           // if (this.appType == 'android') {