migrate information / password input / passcode input sheet to composition API and typescript
This commit is contained in:
@@ -17,74 +17,71 @@
|
||||
</p>
|
||||
<textarea class="information-content full-line" readonly="readonly" :rows="rowCount" :value="information"></textarea>
|
||||
<div class="margin-top text-align-center">
|
||||
<f7-link @click="cancel" :text="$t('Close')"></f7-link>
|
||||
<f7-link @click="close" :text="$t('Close')"></f7-link>
|
||||
</div>
|
||||
</div>
|
||||
</f7-page-content>
|
||||
</f7-sheet>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup lang="ts">
|
||||
import { useTemplateRef, watch, onMounted, onUpdated } from 'vue';
|
||||
|
||||
import { ClipboardHolder } from '@/lib/clipboard.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
'title',
|
||||
'hint',
|
||||
'information',
|
||||
'rowCount',
|
||||
'enableCopy',
|
||||
'show'
|
||||
],
|
||||
emits: [
|
||||
'update:show',
|
||||
'info:copied'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
clipboardHolder: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.makeCopyToClipboardClickable();
|
||||
},
|
||||
updated() {
|
||||
this.makeCopyToClipboardClickable();
|
||||
},
|
||||
watch: {
|
||||
'information': function (newValue) {
|
||||
if (this.clipboardHolder) {
|
||||
this.clipboardHolder.setClipboardText(newValue);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSheetClosed() {
|
||||
this.close();
|
||||
},
|
||||
cancel() {
|
||||
this.close();
|
||||
},
|
||||
makeCopyToClipboardClickable() {
|
||||
const self = this;
|
||||
const props = defineProps<{
|
||||
title?: string
|
||||
hint?: string
|
||||
information: string
|
||||
rowCount: number
|
||||
enableCopy?: boolean
|
||||
show: boolean
|
||||
}>();
|
||||
|
||||
if (self.clipboardHolder) {
|
||||
return;
|
||||
}
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:show', value: boolean): void
|
||||
(e: 'info:copied'): void
|
||||
}>();
|
||||
|
||||
if (self.$refs.copyToClipboardIcon) {
|
||||
self.clipboardHolder = ClipboardHolder.create({
|
||||
el: '#copy-to-clipboard-icon',
|
||||
text: self.information,
|
||||
successCallback: function () {
|
||||
self.$emit('info:copied');
|
||||
}
|
||||
});
|
||||
const iconCopyToClipboard = useTemplateRef('copyToClipboardIcon');
|
||||
|
||||
let clipboardHolder: ClipboardHolder = null;
|
||||
|
||||
function makeCopyToClipboardClickable() {
|
||||
if (clipboardHolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (iconCopyToClipboard.value) {
|
||||
clipboardHolder = ClipboardHolder.create({
|
||||
el: '#copy-to-clipboard-icon',
|
||||
text: props.information,
|
||||
successCallback: function () {
|
||||
emit('info:copied');
|
||||
}
|
||||
},
|
||||
close() {
|
||||
this.$emit('update:show', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
emit('update:show', false);
|
||||
}
|
||||
|
||||
function onSheetClosed() {
|
||||
close();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
makeCopyToClipboardClickable();
|
||||
});
|
||||
|
||||
onUpdated(() => {
|
||||
makeCopyToClipboardClickable();
|
||||
});
|
||||
|
||||
watch(() => props.information, (newValue) => {
|
||||
if (clipboardHolder) {
|
||||
clipboardHolder.setClipboardText(newValue);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -36,47 +36,48 @@
|
||||
</f7-sheet>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: [
|
||||
'modelValue',
|
||||
'title',
|
||||
'hint',
|
||||
'confirmDisabled',
|
||||
'cancelDisabled',
|
||||
'show'
|
||||
],
|
||||
emits: [
|
||||
'update:modelValue',
|
||||
'update:show',
|
||||
'passcode:confirm'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
currentPasscode: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSheetOpen() {
|
||||
this.currentPasscode = '';
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.close();
|
||||
},
|
||||
confirm() {
|
||||
if (!this.currentPasscode || this.confirmDisabled) {
|
||||
return;
|
||||
}
|
||||
<script setup lang="ts">
|
||||
import { type Ref, ref } from 'vue';
|
||||
|
||||
this.$emit('update:modelValue', this.currentPasscode);
|
||||
this.$emit('passcode:confirm', this.currentPasscode);
|
||||
},
|
||||
cancel() {
|
||||
this.close();
|
||||
},
|
||||
close() {
|
||||
this.$emit('update:show', false);
|
||||
}
|
||||
const props = defineProps<{
|
||||
modelValue: string
|
||||
title?: string
|
||||
hint?: string
|
||||
confirmDisabled?: boolean
|
||||
cancelDisabled?: boolean
|
||||
show: boolean
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void
|
||||
(e: 'update:show', value: boolean): void
|
||||
(e: 'passcode:confirm', value: string): void
|
||||
}>();
|
||||
|
||||
const currentPasscode: Ref<string> = ref('');
|
||||
|
||||
function confirm() {
|
||||
if (!currentPasscode.value || props.confirmDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit('update:modelValue', currentPasscode.value);
|
||||
emit('passcode:confirm', currentPasscode.value);
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
close();
|
||||
}
|
||||
|
||||
function close() {
|
||||
emit('update:show', false);
|
||||
}
|
||||
|
||||
function onSheetOpen() {
|
||||
currentPasscode.value = '';
|
||||
}
|
||||
|
||||
function onSheetClosed() {
|
||||
close();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -37,48 +37,49 @@
|
||||
</f7-sheet>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: [
|
||||
'modelValue',
|
||||
'title',
|
||||
'hint',
|
||||
'color',
|
||||
'confirmDisabled',
|
||||
'cancelDisabled',
|
||||
'show'
|
||||
],
|
||||
emits: [
|
||||
'update:modelValue',
|
||||
'update:show',
|
||||
'password:confirm'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
currentPassword: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onSheetOpen() {
|
||||
this.currentPassword = '';
|
||||
},
|
||||
onSheetClosed() {
|
||||
this.close();
|
||||
},
|
||||
confirm() {
|
||||
if (!this.currentPassword || this.confirmDisabled) {
|
||||
return;
|
||||
}
|
||||
<script setup lang="ts">
|
||||
import { type Ref, ref } from 'vue';
|
||||
|
||||
this.$emit('update:modelValue', this.currentPassword);
|
||||
this.$emit('password:confirm', this.currentPassword);
|
||||
},
|
||||
cancel() {
|
||||
this.close();
|
||||
},
|
||||
close() {
|
||||
this.$emit('update:show', false);
|
||||
}
|
||||
const props = defineProps<{
|
||||
modelValue: string
|
||||
title?: string
|
||||
hint?: string
|
||||
color?: string
|
||||
confirmDisabled?: boolean
|
||||
cancelDisabled?: boolean
|
||||
show: boolean
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void
|
||||
(e: 'update:show', value: boolean): void
|
||||
(e: 'password:confirm', value: string): void
|
||||
}>();
|
||||
|
||||
const currentPassword: Ref<string> = ref('');
|
||||
|
||||
function confirm() {
|
||||
if (!currentPassword.value || props.confirmDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit('update:modelValue', currentPassword.value);
|
||||
emit('password:confirm', currentPassword.value);
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
close();
|
||||
}
|
||||
|
||||
function close() {
|
||||
emit('update:show', false);
|
||||
}
|
||||
|
||||
function onSheetOpen() {
|
||||
currentPassword.value = '';
|
||||
}
|
||||
|
||||
function onSheetClosed() {
|
||||
close();
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user