[UI] Added utilities to get and set args on the URL fragment.
This commit is contained in:
parent
a30c07fbb5
commit
6f01c35a0f
3 changed files with 40 additions and 1 deletions
|
@ -9,6 +9,7 @@ import Notification from "@/utils/Notification";
|
|||
import Screen from "@/utils/Screen";
|
||||
import Text from "@/utils/Text";
|
||||
import Types from "@/utils/Types";
|
||||
import Url from "@/utils/Url";
|
||||
|
||||
export default {
|
||||
name: "Utils",
|
||||
|
@ -23,6 +24,7 @@ export default {
|
|||
Screen,
|
||||
Text,
|
||||
Types,
|
||||
Url,
|
||||
],
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -4,7 +4,7 @@ $header-height: 3.5em;
|
|||
display: flex;
|
||||
align-items: center;
|
||||
padding: .75em .25em;
|
||||
box-shadow: 0 2.5px 2px -1px $default-shadow-color;
|
||||
border-bottom: 1px solid $default-shadow-color;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
|
|
37
platypush/backend/http/webapp/src/utils/Url.vue
Normal file
37
platypush/backend/http/webapp/src/utils/Url.vue
Normal file
|
@ -0,0 +1,37 @@
|
|||
<script>
|
||||
export default {
|
||||
name: "Url",
|
||||
methods: {
|
||||
parseUrlFragment() {
|
||||
return window.location.href.replace(/.*#(\w+)[?;]?.*/, '$1')
|
||||
},
|
||||
|
||||
getUrlArgs() {
|
||||
return window.location.href
|
||||
.replace(/.*#/, '')
|
||||
.replace(/.*\?/, '')
|
||||
.split(/[&;]/)
|
||||
.reduce((acc, obj) => {
|
||||
const tokens = obj.split('=')
|
||||
acc[tokens[0]] = tokens[1]
|
||||
return acc
|
||||
}, {})
|
||||
},
|
||||
|
||||
setUrlArgs(args) {
|
||||
window.location.href = (
|
||||
`/#${this.parseUrlFragment()}?${this.fragmentFromArgs(args)}`
|
||||
)
|
||||
},
|
||||
|
||||
fragmentFromArgs(args) {
|
||||
return Object.entries(args)
|
||||
.map(
|
||||
([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
|
||||
)
|
||||
.join('&')
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in a new issue