|
@@ -109,7 +109,7 @@
|
|
|
<script lang="ts" setup>
|
|
|
import { defineComponent, ref, inject, watch } from 'vue'
|
|
|
import { ElButton, ElInput, ElTree, ElDialog, ElPagination } from 'element-plus'
|
|
|
-
|
|
|
+import algoliasearch from 'algoliasearch'
|
|
|
import { getCategoryTree, getSkuList } from '@/api/indent.js'
|
|
|
import skuApply from './skuApply.vue'
|
|
|
defineComponent({
|
|
@@ -193,16 +193,22 @@ const getCategory = () => {
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+let index = ref({} as any)
|
|
|
+const initAI = () => {
|
|
|
+ const client = algoliasearch('7BX4P6RSP2', 'aa9ec8e7e12a6633e7924fab6487e6af')
|
|
|
+ index.value = client.initIndex('indent_app')
|
|
|
+}
|
|
|
const getSku = () => {
|
|
|
- const params = Object.assign(
|
|
|
- { keywords: keywords.value, category: currentCategory.value },
|
|
|
- pageForm.value,
|
|
|
- )
|
|
|
loading.value = true
|
|
|
- getSkuList(params)
|
|
|
+ index.value
|
|
|
+ .search(keywords.value, {
|
|
|
+ hitsPerPage: pageForm.value.limit,
|
|
|
+ page: pageForm.value.page - 1,
|
|
|
+ })
|
|
|
.then((response: any) => {
|
|
|
- const res = response.result
|
|
|
- skuList.value = res.data.map((item: any) => {
|
|
|
+ const res = response.hits
|
|
|
+ skuList.value = res.map((item: any) => {
|
|
|
const t =
|
|
|
typeof item.images === 'string'
|
|
|
? `${item.images}`.split(',').filter((i: string) => i.length > 0)
|
|
@@ -216,7 +222,7 @@ const getSku = () => {
|
|
|
}),
|
|
|
}
|
|
|
})
|
|
|
- total.value = res.total
|
|
|
+ total.value = response.nbHits > 1000 ? 1000 : response.nbHits
|
|
|
})
|
|
|
.finally(() => {
|
|
|
loading.value = false
|
|
@@ -228,7 +234,10 @@ watch(
|
|
|
show.value = visible
|
|
|
resetData()
|
|
|
if (show.value) {
|
|
|
- getSku()
|
|
|
+ initAI()
|
|
|
+ setTimeout(() => {
|
|
|
+ getSku()
|
|
|
+ }, 500)
|
|
|
getCategory()
|
|
|
}
|
|
|
},
|