fix: 修复导入时url中有参数导致的拼接错误

perf: 优化一下获取url
This commit is contained in:
ibuler
2021-07-13 10:29:15 +08:00
committed by 老广
parent e4657f3bf6
commit 34a72467d2
3 changed files with 16 additions and 4 deletions

View File

@@ -33,7 +33,7 @@
<script>
import DataTable from '@/components/DataTable'
import { sleep } from '@/utils/common'
import { sleep, getUpdateObjURL } from '@/utils/common'
import { EditableInputFormatter, StatusFormatter } from '@/components/TableFormatters'
export default {
name: 'ImportTable',
@@ -350,7 +350,7 @@ export default {
}
},
async performUpdateObject(item) {
const updateUrl = `${this.url}${item.id}/`
const updateUrl = getUpdateObjURL(this.url, item.id)
return this.$axios.put(
updateUrl,
item,

View File

@@ -15,6 +15,7 @@
</template>
<script>
import AutoDataForm from '@/components/AutoDataForm'
import { getUpdateObjURL } from '@/utils/common'
export default {
name: 'GenericCreateUpdateForm',
components: {
@@ -129,7 +130,7 @@ export default {
const params = this.$route.params
let url = this.url
if (params.id) {
url = `${url}${params.id}/`
url = getUpdateObjURL(url, params.id)
}
return url
}

View File

@@ -214,11 +214,22 @@ export function newURL(url) {
if (url.indexOf('//') > -1) {
obj = new URL(url)
} else {
obj = new URL(url, 'http://localhost')
obj = new URL(url, location.origin)
}
return obj
}
export function getUpdateObjURL(url, objId) {
const urlObj = new URL(url, location.origin)
let pathname = urlObj.pathname
if (!pathname.endsWith('/')) {
pathname += '/'
}
pathname += `${objId}/`
urlObj.pathname = pathname
return urlObj.href
}
export const assignIfNot = _.partialRight(_.assignInWith, customizer)
const scheme = document.location.protocol