Commit 229f4b7a authored by shuaiqiang's avatar shuaiqiang 🇨🇳

refactor:api问题

parent a9fa7fc7
import service from '@utils/GraphApiService'
// export function CnConversionPCT(baseURL, data) {
// return service({
// baseURL: baseURL,
// url: 'Word/CN2PCT',
// method: 'post',
// data
// })
// }
export function fetchCnToCpc(baseURL, data) {
return service({
baseURL: baseURL,
url: 'Word/CN2CPC',
method: 'POST',
data
})
}
export function fetchCntToPct(baseURL, data) {
return service({
baseURL: baseURL,
url: 'Word/CN2PCT',
method: 'post',
data
})
}
export function fetchPctToCn(baseURL, data) {
return service({
......
......@@ -28,6 +28,5 @@ module.exports = {
},
dev_file_sz: {
VUE_APP_GRAPHAPI_URL: 'https://dev.essenptl.com/dev2/wade_ext/'
},
VUE_APP_USER_ID_MODE: 'variable'
}
}
\ No newline at end of file
......@@ -48,7 +48,6 @@
</template>
<script>
import GraphApiService from '@utils/GraphApiService'
import { fetchPctToCn } from '@api/convertApi'
export default {
name: 'Cn2CpcForm',
data: function() {
......@@ -74,35 +73,42 @@ export default {
this.fileList.forEach(e => {
formData.append('file', e.raw)
})
const response = await fetchPctToCn(this.baseUrl, formData)
if (response.status === 200) {
this.fileList = []
this.$refs.upload.clearFiles()
const excelFileName = response.data
GraphApiService
.get('RequestPayment/DownloadFile', {
params: {
fileName: excelFileName
},
responseType: 'blob'
})
.then(res => {
const blob = new Blob([res])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = excelFileName.split('/')[1]
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
})
} else {
this.$refs.upload.abort()
this.$message.error('下载档案失败!')
}
console.log(response.data)
GraphApiService
.post('Word/PCT2CN', formData)
.then(res => {
if (res.status === 200) {
this.fileList = []
this.$refs.upload.clearFiles()
const excelFileName = res.data
GraphApiService
.get('RequestPayment/DownloadFile', {
params: {
fileName: excelFileName
},
responseType: 'blob'
})
.then(response => {
const blob = new Blob([response])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = excelFileName.split('/')[1]
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
})
} else {
this.$refs.upload.abort()
this.$message.error('下载档案失败!')
}
console.log(res.data)
})
.catch(error => {
console.log('error', error)
this.$refs.upload.abort()
this.$message.error('下载档案失败!')
})
},
// 文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用
handelFileChange(file, fileList) {
......
......@@ -182,7 +182,6 @@ export default {
this.$refs.upload.clearFiles()
const zipFileName = response.data
this.downloadFile(zipFileName)
console.log(this.downloadFile)
} else {
this.$refs.upload.abort()
this.$message.error('下载档案失败!')
......
......@@ -25,7 +25,7 @@
<script>
import { mapGetters } from 'vuex'
import UploadExcelComponent from './components/UploadExcel.vue'
import graphRequest from '@utils/GraphApiService'
import uploadApiService from '@utils/uploadAPiService'
export default {
name:'uploadExcel',
components: { UploadExcelComponent },
......@@ -59,12 +59,10 @@ export default {
return false
},
handleSuccess({ results, header }) {
console.log(this.wadeUserID)
this.tableData = results
this.tableHeader = header
this.tableHeader.push('isUpload')
// this.tableData = this.tableData.map(obj => ({ ...obj, isUpload: false }))
console.log(this.tableData)
this.levelKeys.map(level => {
this.tableData.forEach((obj, index, array) => {
array[index][level.name] = this.getLevel(level.value)
......@@ -80,7 +78,7 @@ export default {
return item[level.value] === 'ν'
})
.map(item => {
graphRequest
uploadApiService
.get('/Wade/GetEhrEmployeeByName', {
params: { name: item['姓名'] }
})
......@@ -101,7 +99,7 @@ export default {
match_type: '1',
update_user_id: this.wadeUserID
}
graphRequest
uploadApiService
.post('/Wade/CreateCaseLevelList', params)
.then(res => {
if (res.status === 200) {
......
import axios from 'axios'
import { Message } from 'element-ui'
// create an axios instance
const uploadApiService = axios.create({
baseURL: "https://dev.essenptl.com/graphAPITest/api/v1.0/",
// withCredentials: true, // send cookies when cross-domain requests
timeout: 300000, // request timeout
headers: {
'Content-Type': 'application/json'
}
})
// 請求攔截
uploadApiService.interceptors.request.use(
confing => {
return confing
},
error => {
console.log(error) // for debug
return Promise.reject(error)
}
)
// 響應攔截
uploadApiService.interceptors.response.use(
response => {
const res = response.data
if (
res.type &&
(res.type ===
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ||
res.type === 'application/zip')
) {
return res
}
if (res.status !== 200) {
// if the custom code is not 200, it is judged as an error.
Message({
message: res.message || 'Error',
type: 'error',
duration: 5 * 1000
})
return Promise.reject(new Error(res.message || 'Error'))
} else {
return res
}
},
error => {
console.log('err' + error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)
export default uploadApiService
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment