sunjh 6 年 前
コミット
fe8a6d9f69
2 ファイル変更96 行追加101 行削除
  1. 1 1
      src/components/project/Project.vue
  2. 95 100
      src/js/http.js

+ 1 - 1
src/components/project/Project.vue

@@ -489,7 +489,7 @@ export default {
       this.$refs[formName].validate(valid => {
         if (valid) {
           this.isModifyMode = false;
-          Http.post(Apis.PROJECT.UPDATE_PROJECT_SUBMIT,this.project).then((res)=>{
+          Http.put(Apis.PROJECT.UPDATE_PROJECT_SUBMIT,this.project).then((res)=>{
             console.log(res)
             console.log(this.project)
           })

+ 95 - 100
src/js/http.js

@@ -47,12 +47,6 @@ function handleParams (data) {
 }
 
 export default {
-  /*
-   * @param url
-   * @param data
-   * @param response 请求成功时的回调函数
-   * @param exception 异常的回调函数
-   */
   post (url, data) {
     return new Promise((resolve, reject) => {
       axios({
@@ -74,12 +68,6 @@ export default {
       )
     })
   },
-  /*
-   * get 请求
-   * @param url
-   * @param response 请求成功时的回调函数
-   * @param exception 异常的回调函数
-   */
   get (url, params) {
     return new Promise((resolve, reject) => {
       axios.get(handleUrl(url), {params: params})
@@ -92,97 +80,104 @@ export default {
     })
 
   },
-  /*
-   * 导入文件
-   * @param url
-   * @param data
-   * @param response 请求成功时的回调函数
-   * @param exception 异常的回调函数
-   */
-  uploadFile (url, data, response, exception) {
-    axios({
-      method: 'post',
-      url: handleUrl(url),
-      data: handleParams(data),
-      dataType: 'json',
-      processData: false,
-      contentType: false
-    }).then(
-      (result) => {
-        response(handleResults(result, data))
-      }
-    ).catch(
-      (error) => {
-        if (exception) {
-          exception(error)
-        } else {
-          console.log(error)
+  put (url, data) {
+    return new Promise((resolve, reject) => {
+      axios({
+        method: 'put',
+        url: handleUrl(url),
+        data: handleParams(data),
+        timeout: TIME_OUT_MS,
+        headers: {
+          'Content-Type': 'application/json; charset=UTF-8'
         }
-      }
-    )
-  },
-  /*
-   * 下载文件用,导出 Excel 表格可以用这个方法
-   * @param url
-   * @param param
-   * @param fileName 如果是导出 Excel 表格文件名后缀最好用.xls 而不是.xlsx,否则文件可能会因为格式错误导致无法打开
-   * @param exception 异常的回调函数
-   */
-  downloadFile (url, data, fileName, exception) {
-    axios({
-      method: 'post',
-      url: handleUrl(url),
-      data: handleParams(data),
-      responseType: 'blob'
-    }).then(
-      (result) => {
-        const excelBlob = result.data
-        if ('msSaveOrOpenBlob' in navigator) {
-          // Microsoft Edge and Microsoft Internet Explorer 10-11
-          window.navigator.msSaveOrOpenBlob(excelBlob, fileName)
-        } else {
-          const elink = document.createElement('a')
-          elink.download = fileName
-          elink.style.display = 'none'
-          const blob = new Blob([excelBlob])
-          elink.href = URL.createObjectURL(blob)
-          document.body.appendChild(elink)
-          elink.click()
-          document.body.removeChild(elink)
+      }).then(
+        (result) => {
+          resolve(result)
         }
-      }
-    ).catch(
-      (error) => {
-        if (exception) {
-          exception(error)
-        } else {
-          console.log(error)
+      ).catch(
+        (error) => {
+          reject(error)
         }
-      }
-    )
+      )
+    })
   },
-  uploadFileFormData (url, data, response, exception) {
-    axios({
-      method: 'post',
-      url: handleUrl(url),
-      data: data,
-      timeout: TIME_OUT_MS,
-      headers: {
-        'Content-Type': 'multipart/form-data'
-      }
-    }).then(
-      (result) => {
-        response(handleResults(result))
-      }
-    ).catch(
-      (error) => {
-        if (exception) {
-          exception(error)
-        } else {
-          console.log(error)
-        }
-      }
-    )
-  }
+  // uploadFile (url, data, response, exception) {
+  //   axios({
+  //     method: 'post',
+  //     url: handleUrl(url),
+  //     data: handleParams(data),
+  //     dataType: 'json',
+  //     processData: false,
+  //     contentType: false
+  //   }).then(
+  //     (result) => {
+  //       response(handleResults(result, data))
+  //     }
+  //   ).catch(
+  //     (error) => {
+  //       if (exception) {
+  //         exception(error)
+  //       } else {
+  //         console.log(error)
+  //       }
+  //     }
+  //   )
+  // },
+  // downloadFile (url, data, fileName, exception) {
+  //   axios({
+  //     method: 'post',
+  //     url: handleUrl(url),
+  //     data: handleParams(data),
+  //     responseType: 'blob'
+  //   }).then(
+  //     (result) => {
+  //       const excelBlob = result.data
+  //       if ('msSaveOrOpenBlob' in navigator) {
+  //         // Microsoft Edge and Microsoft Internet Explorer 10-11
+  //         window.navigator.msSaveOrOpenBlob(excelBlob, fileName)
+  //       } else {
+  //         const elink = document.createElement('a')
+  //         elink.download = fileName
+  //         elink.style.display = 'none'
+  //         const blob = new Blob([excelBlob])
+  //         elink.href = URL.createObjectURL(blob)
+  //         document.body.appendChild(elink)
+  //         elink.click()
+  //         document.body.removeChild(elink)
+  //       }
+  //     }
+  //   ).catch(
+  //     (error) => {
+  //       if (exception) {
+  //         exception(error)
+  //       } else {
+  //         console.log(error)
+  //       }
+  //     }
+  //   )
+  // },
+  // uploadFileFormData (url, data, response, exception) {
+  //   axios({
+  //     method: 'post',
+  //     url: handleUrl(url),
+  //     data: data,
+  //     timeout: TIME_OUT_MS,
+  //     headers: {
+  //       'Content-Type': 'multipart/form-data'
+  //     }
+  //   }).then(
+  //     (result) => {
+  //       response(handleResults(result))
+  //     }
+  //   ).catch(
+  //     (error) => {
+  //       if (exception) {
+  //         exception(error)
+  //       } else {
+  //         console.log(error)
+  //       }
+  //     }
+  //   )
+  // }
 }