diff --git a/bo/src/composable/useConteditable.ts b/bo/src/composable/useConteditable.ts index 2a7803f..00e8b59 100644 --- a/bo/src/composable/useConteditable.ts +++ b/bo/src/composable/useConteditable.ts @@ -1,37 +1,41 @@ import { ref, type Ref } from 'vue' import DOMPurify from 'dompurify' -import { useProductStore } from '@/stores/product' -export function useEditable() { - const isEditing = ref(false) - const productStore = useProductStore() +export function useEditable(elementRef: Ref) { - const removeAttribute = (editableRef: HTMLElement | null) => { - if (!editableRef) return - isEditing.value = true - Array.from(editableRef.children).forEach(item => { - item.setAttribute('contenteditable', 'true') - console.log('lllllll') - }) - } + const isEditing = ref(false) - const setAttribute = async (editableRef: HTMLElement | null): Promise => { - if (!editableRef) return - Array.from(editableRef.children).forEach(item => { - item.setAttribute('contenteditable', 'false') - }) - isEditing.value = false + const enableEdit = () => { + if (!elementRef.value) return - const html = editableRef.innerHTML - const cleanHtml = DOMPurify.sanitize(html) - await productStore.saveProductDescription(cleanHtml) + isEditing.value = true - return cleanHtml - } + Array.from(elementRef.value.children).forEach(item => { + item.setAttribute('contenteditable', 'true') + }) + } - return { - isEditing, - removeAttribute, - setAttribute - } + const disableEdit = () => { + if (!elementRef.value) return + + isEditing.value = false + + Array.from(elementRef.value.children).forEach(item => { + item.setAttribute('contenteditable', 'false') + }) + } + + const getCleanHtml = () => { + if (!elementRef.value) return '' + + const html = elementRef.value.innerHTML + return DOMPurify.sanitize(html) + } + + return { + isEditing, + enableEdit, + disableEdit, + getCleanHtml + } } \ No newline at end of file diff --git a/bo/src/views/customer/ProductDetailView.vue b/bo/src/views/customer/ProductDetailView.vue index 4b5254a..475c599 100644 --- a/bo/src/views/customer/ProductDetailView.vue +++ b/bo/src/views/customer/ProductDetailView.vue @@ -1,36 +1,116 @@ @@ -41,5 +121,4 @@ const { removeAttribute, setAttribute } = useEditable() gap: 70px; margin: 20px 0 20px 0; } - \ No newline at end of file diff --git a/tmp/main b/tmp/main index a844282..283f25d 100755 Binary files a/tmp/main and b/tmp/main differ