LouisLam
3 years ago
13 changed files with 292 additions and 30 deletions
@ -0,0 +1,7 @@ |
|||
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. |
|||
BEGIN TRANSACTION; |
|||
|
|||
ALTER TABLE monitor |
|||
ADD push_token VARCHAR(20) DEFAULT NULL; |
|||
|
|||
COMMIT; |
@ -0,0 +1,122 @@ |
|||
<template> |
|||
<div class="input-group mb-3"> |
|||
<input |
|||
:id="id" |
|||
ref="input" |
|||
v-model="model" |
|||
:type="type" |
|||
class="form-control" |
|||
:placeholder="placeholder" |
|||
:autocomplete="autocomplete" |
|||
:required="required" |
|||
:readonly="readonly" |
|||
:disabled="disabled" |
|||
> |
|||
|
|||
<a class="btn btn-outline-primary" @click="copyToClipboard(model)"> |
|||
<font-awesome-icon :icon="icon" /> |
|||
</a> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
|
|||
let timeout; |
|||
|
|||
export default { |
|||
props: { |
|||
id: { |
|||
type: String, |
|||
default: "" |
|||
}, |
|||
type: { |
|||
type: String, |
|||
default: "text" |
|||
}, |
|||
modelValue: { |
|||
type: String, |
|||
default: "" |
|||
}, |
|||
placeholder: { |
|||
type: String, |
|||
default: "" |
|||
}, |
|||
autocomplete: { |
|||
type: String, |
|||
default: undefined, |
|||
}, |
|||
required: { |
|||
type: Boolean |
|||
}, |
|||
readonly: { |
|||
type: String, |
|||
default: undefined, |
|||
}, |
|||
disabled: { |
|||
type: String, |
|||
default: undefined, |
|||
}, |
|||
}, |
|||
data() { |
|||
return { |
|||
visibility: "password", |
|||
icon: "copy", |
|||
}; |
|||
}, |
|||
computed: { |
|||
model: { |
|||
get() { |
|||
return this.modelValue; |
|||
}, |
|||
set(value) { |
|||
this.$emit("update:modelValue", value); |
|||
} |
|||
} |
|||
}, |
|||
created() { |
|||
|
|||
}, |
|||
methods: { |
|||
|
|||
showInput() { |
|||
this.visibility = "text"; |
|||
}, |
|||
|
|||
hideInput() { |
|||
this.visibility = "password"; |
|||
}, |
|||
|
|||
copyToClipboard(textToCopy) { |
|||
this.icon = "check"; |
|||
|
|||
clearTimeout(timeout); |
|||
timeout = setTimeout(() => { |
|||
this.icon = "copy"; |
|||
}, 3000); |
|||
|
|||
// navigator clipboard api needs a secure context (https) |
|||
if (navigator.clipboard && window.isSecureContext) { |
|||
// navigator clipboard api method' |
|||
return navigator.clipboard.writeText(textToCopy); |
|||
} else { |
|||
// text area method |
|||
let textArea = document.createElement("textarea"); |
|||
textArea.value = textToCopy; |
|||
// make the textarea out of viewport |
|||
textArea.style.position = "fixed"; |
|||
textArea.style.left = "-999999px"; |
|||
textArea.style.top = "-999999px"; |
|||
document.body.appendChild(textArea); |
|||
textArea.focus(); |
|||
textArea.select(); |
|||
return new Promise((res, rej) => { |
|||
// here the magic happens |
|||
document.execCommand("copy") ? res() : rej(); |
|||
textArea.remove(); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
} |
|||
}; |
|||
</script> |
Loading…
Reference in new issue