Refactor some code
This commit is contained in:
parent
db628eec24
commit
e1c53b99da
|
|
@ -3,82 +3,25 @@
|
|||
class="document-form"
|
||||
ref="documentform"
|
||||
>
|
||||
<div
|
||||
v-if="!value.url"
|
||||
ref="uploadcare-panel"
|
||||
<document-input
|
||||
:url="value.url"
|
||||
@update="updateUrl"
|
||||
/>
|
||||
<div
|
||||
class="document-form__spinner"
|
||||
v-if="loading"
|
||||
>
|
||||
<loading-icon class="document-form__loading-icon" />
|
||||
</div>
|
||||
<div
|
||||
class="document-form__uploaded"
|
||||
v-if="value.url"
|
||||
>
|
||||
<document-icon class="document-form__icon" />
|
||||
<a
|
||||
:href="previewUrl"
|
||||
class="document-form__link"
|
||||
target="_blank"
|
||||
>{{ previewLink }}</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { uploadcare } from '@/helpers/uploadcare';
|
||||
import LoadingIcon from '@/components/icons/LoadingIcon.vue';
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
|
||||
const DocumentIcon = defineAsyncComponent(() =>
|
||||
import('@/components/icons/DocumentIcon.vue')
|
||||
);
|
||||
|
||||
export default {
|
||||
props: ['value', 'index'],
|
||||
|
||||
components: {
|
||||
LoadingIcon,
|
||||
DocumentIcon,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
previewUrl() {
|
||||
if (this.value && this.value.url) {
|
||||
return this.value.url;
|
||||
<script setup lang="ts">
|
||||
import DocumentInput from '@/components/content-forms/DocumentInput.vue';
|
||||
export interface Props {
|
||||
value: any;
|
||||
index: number;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
previewLink() {
|
||||
if (this.value && this.value.url) {
|
||||
const parts = this.value.url.split('/');
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
return '';
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
uploadcare(
|
||||
this,
|
||||
(url) => {
|
||||
this.$emit('change-url', url, this.index);
|
||||
this.loading = false;
|
||||
},
|
||||
() => {
|
||||
this.loading = true;
|
||||
}
|
||||
);
|
||||
},
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits(['change-url']);
|
||||
|
||||
const updateUrl = (url: string) => {
|
||||
emit('change-url', url, props.index);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export default {
|
|||
.link-form {
|
||||
display: grid;
|
||||
grid-auto-rows: auto;
|
||||
grid-row-gap: 11px;
|
||||
grid-row-gap: $small-spacing;
|
||||
|
||||
&__text,
|
||||
&__url {
|
||||
|
|
|
|||
Loading…
Reference in New Issue