feat: add drop image product mgmt
This commit is contained in:
parent
bd3a7bc9a4
commit
3eda26bbf7
3 changed files with 126 additions and 21 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { QSelect } from 'quasar';
|
import { QSelect } from 'quasar';
|
||||||
import useOptionStore from 'src/stores/options';
|
import useOptionStore from 'src/stores/options';
|
||||||
|
import { createEditorImageDrop } from 'src/utils/ui';
|
||||||
import { selectFilterOptionRefMod } from 'stores/utils';
|
import { selectFilterOptionRefMod } from 'stores/utils';
|
||||||
import { ref, onMounted, watch } from 'vue';
|
import { ref, onMounted, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
@ -66,6 +67,8 @@ watch(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const detailEditorImageDrop = createEditorImageDrop(detail);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -209,6 +212,7 @@ watch(
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
(v) => (typeof v === 'string' ? (detail = v) : '')
|
(v) => (typeof v === 'string' ? (detail = v) : '')
|
||||||
"
|
"
|
||||||
|
@drop="detailEditorImageDrop"
|
||||||
min-height="5rem"
|
min-height="5rem"
|
||||||
class="q-mt-sm q-mb-xs"
|
class="q-mt-sm q-mb-xs"
|
||||||
:flat="!readonly"
|
:flat="!readonly"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { createEditorImageDrop } from 'src/utils/ui';
|
||||||
import SelectBranch from '../shared/select/SelectBranch.vue';
|
import SelectBranch from '../shared/select/SelectBranch.vue';
|
||||||
|
|
||||||
const remark = defineModel<string>('remark');
|
const remark = defineModel<string>('remark');
|
||||||
|
|
@ -22,6 +23,8 @@ defineProps<{
|
||||||
disableCode?: boolean;
|
disableCode?: boolean;
|
||||||
service?: boolean;
|
service?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const detailEditorImageDrop = createEditorImageDrop(detail);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -88,18 +91,40 @@ defineProps<{
|
||||||
v-model="name"
|
v-model="name"
|
||||||
:rules="[(val: string) => !!val || $t('form.error.required')]"
|
:rules="[(val: string) => !!val || $t('form.error.required')]"
|
||||||
/>
|
/>
|
||||||
<q-input
|
<q-field
|
||||||
for="input-detail"
|
class="full-width"
|
||||||
:dense="dense"
|
|
||||||
outlined
|
outlined
|
||||||
|
for="input-detail"
|
||||||
|
id="input-detail"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
hide-bottom-space
|
:borderless="readonly"
|
||||||
type="textarea"
|
|
||||||
class="col-12"
|
|
||||||
:label="$t('general.detail')"
|
:label="$t('general.detail')"
|
||||||
:model-value="readonly ? detail || '-' : detail"
|
stack-label
|
||||||
@update:model-value="(v) => (typeof v === 'string' ? (detail = v) : '')"
|
dense
|
||||||
/>
|
>
|
||||||
|
<q-editor
|
||||||
|
dense
|
||||||
|
:model-value="readonly ? detail || '-' : detail || ''"
|
||||||
|
@update:model-value="
|
||||||
|
(v) => (typeof v === 'string' ? (detail = v) : '')
|
||||||
|
"
|
||||||
|
@drop="detailEditorImageDrop"
|
||||||
|
min-height="5rem"
|
||||||
|
class="q-mt-sm q-mb-xs"
|
||||||
|
:flat="!readonly"
|
||||||
|
:readonly="readonly"
|
||||||
|
:toolbar-color="
|
||||||
|
readonly ? 'disabled' : $q.dark.isActive ? 'white' : ''
|
||||||
|
"
|
||||||
|
:toolbar-toggle-color="readonly ? 'disabled' : 'primary'"
|
||||||
|
style="
|
||||||
|
cursor: auto;
|
||||||
|
color: var(--foreground);
|
||||||
|
border-color: var(--surface-3);
|
||||||
|
"
|
||||||
|
:style="`width: ${$q.screen.gt.xs ? '100%' : '63vw'}`"
|
||||||
|
/>
|
||||||
|
</q-field>
|
||||||
<q-input
|
<q-input
|
||||||
:dense="dense"
|
:dense="dense"
|
||||||
outlined
|
outlined
|
||||||
|
|
@ -142,21 +167,40 @@ defineProps<{
|
||||||
:rules="[(val: string) => !!val || $t('form.error.required')]"
|
:rules="[(val: string) => !!val || $t('form.error.required')]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<q-input
|
<q-field
|
||||||
id="input-service-description"
|
class="full-width"
|
||||||
for="input-service-description"
|
|
||||||
:dense="dense"
|
|
||||||
outlined
|
outlined
|
||||||
|
for="input-service-description"
|
||||||
|
id="input-service-description"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
hide-bottom-space
|
:borderless="readonly"
|
||||||
type="textarea"
|
|
||||||
class="col-12"
|
|
||||||
:label="$t('general.detail')"
|
:label="$t('general.detail')"
|
||||||
:model-value="readonly ? serviceDescription || '-' : serviceDescription"
|
stack-label
|
||||||
@update:model-value="
|
dense
|
||||||
(v) => (typeof v === 'string' ? (serviceDescription = v) : '')
|
>
|
||||||
"
|
<q-editor
|
||||||
/>
|
dense
|
||||||
|
:model-value="readonly ? detail || '-' : detail || ''"
|
||||||
|
@update:model-value="
|
||||||
|
(v) => (typeof v === 'string' ? (detail = v) : '')
|
||||||
|
"
|
||||||
|
@drop="detailEditorImageDrop"
|
||||||
|
min-height="5rem"
|
||||||
|
class="q-mt-sm q-mb-xs"
|
||||||
|
:flat="!readonly"
|
||||||
|
:readonly="readonly"
|
||||||
|
:toolbar-color="
|
||||||
|
readonly ? 'disabled' : $q.dark.isActive ? 'white' : ''
|
||||||
|
"
|
||||||
|
:toolbar-toggle-color="readonly ? 'disabled' : 'primary'"
|
||||||
|
style="
|
||||||
|
cursor: auto;
|
||||||
|
color: var(--foreground);
|
||||||
|
border-color: var(--surface-3);
|
||||||
|
"
|
||||||
|
:style="`width: ${$q.screen.gt.xs ? '100%' : '63vw'}`"
|
||||||
|
/>
|
||||||
|
</q-field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { ModelRef, Ref } from 'vue';
|
||||||
import { Dark } from 'quasar';
|
import { Dark } from 'quasar';
|
||||||
import { setLocale as setDateTimeLocale } from './datetime';
|
import { setLocale as setDateTimeLocale } from './datetime';
|
||||||
import { i18n } from 'src/boot/i18n';
|
import { i18n } from 'src/boot/i18n';
|
||||||
|
import { fileToBase64 } from './file';
|
||||||
|
|
||||||
export enum Theme {
|
export enum Theme {
|
||||||
Light = 'light',
|
Light = 'light',
|
||||||
|
|
@ -75,3 +77,58 @@ export function setLang(lang: Lang): Lang {
|
||||||
|
|
||||||
return lang;
|
return lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is for use with ContentEditable element and with q-editor
|
||||||
|
*/
|
||||||
|
export function createEditorImageDrop(ref: Ref<string> | ModelRef<string>) {
|
||||||
|
return async (e: DragEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
const target = e.target;
|
||||||
|
|
||||||
|
if (!target || !(target instanceof HTMLElement)) return;
|
||||||
|
|
||||||
|
const items = e.dataTransfer?.items;
|
||||||
|
const promises: Promise<string>[] = [];
|
||||||
|
|
||||||
|
if (!items) return;
|
||||||
|
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const file = items[i].getAsFile();
|
||||||
|
if (!file || file.type.indexOf('image') === -1) continue;
|
||||||
|
promises.push(fileToBase64(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCaret = () => {
|
||||||
|
if (target.isContentEditable || document.designMode === 'on') {
|
||||||
|
target.focus();
|
||||||
|
const range = document.getSelection()?.getRangeAt(0);
|
||||||
|
if (!range?.collapsed) return null;
|
||||||
|
const tmp = document.createTextNode('\0');
|
||||||
|
range.insertNode(tmp);
|
||||||
|
const pos = target.innerHTML.indexOf('\0');
|
||||||
|
tmp.parentNode?.removeChild(tmp);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const base64 of await Promise.all(promises)) {
|
||||||
|
const image = document.createElement('img') as HTMLImageElement;
|
||||||
|
const caret = getCaret();
|
||||||
|
|
||||||
|
image.src = base64;
|
||||||
|
|
||||||
|
if (caret) {
|
||||||
|
ref.value =
|
||||||
|
ref.value.substring(0, caret) +
|
||||||
|
image.outerHTML +
|
||||||
|
ref.value.substring(caret, ref.value.length);
|
||||||
|
} else {
|
||||||
|
ref.value += image.outerHTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue