完成店铺创建
This commit is contained in:
@@ -160,10 +160,19 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { openRoute } from '@/layouts/admin/store/adminNavStore.uts'
|
||||
import supa, { ensureSupabaseReady } from '@/components/supadb/aksupainstance'
|
||||
import { SUPA_URL } from '@/ak/config.uts'
|
||||
|
||||
const activeStep = ref(0)
|
||||
const steps = ['基础信息', '规格库存', '商品详情', '物流设置', '会员价/佣金', '营销设置', '其他设置']
|
||||
|
||||
interface CategoryOption {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
const categoryOptions = ref<CategoryOption[]>([])
|
||||
const categories = ref<string[]>([])
|
||||
const categoryName = ref('')
|
||||
|
||||
const formData = ref({
|
||||
id: '',
|
||||
merchant_id: '',
|
||||
@@ -181,9 +190,6 @@ const formData = ref({
|
||||
published_at: null as string | null
|
||||
})
|
||||
|
||||
const categories = ref(['361度', '特步', '匹克', '生活家居'])
|
||||
const categoryName = ref('')
|
||||
|
||||
onMounted(async () => {
|
||||
await ensureSupabaseReady()
|
||||
const mId = supa.getSession().user?.id as string | null
|
||||
@@ -193,6 +199,9 @@ onMounted(async () => {
|
||||
}
|
||||
formData.value.merchant_id = mId
|
||||
|
||||
// 加载真实分类
|
||||
await loadCategoryOptions()
|
||||
|
||||
const editId = uni.getStorageSync('edit_product_id') as string | null
|
||||
if (editId) {
|
||||
uni.removeStorageSync('edit_product_id')
|
||||
@@ -200,6 +209,27 @@ onMounted(async () => {
|
||||
}
|
||||
})
|
||||
|
||||
async function loadCategoryOptions() {
|
||||
try {
|
||||
const res = await supa.from('ml_categories')
|
||||
.select('id, name')
|
||||
.eq('is_active', true)
|
||||
.order('sort_order', { ascending: true })
|
||||
.execute()
|
||||
|
||||
if (res.data != null) {
|
||||
const data = res.data as Array<UTSJSONObject>
|
||||
categoryOptions.value = data.map((item: UTSJSONObject): CategoryOption => ({
|
||||
id: item.get('id') as string,
|
||||
name: item.get('name') as string
|
||||
}))
|
||||
categories.value = categoryOptions.value.map((item: CategoryOption): string => item.name)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载分类失败', e)
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchProductDetail(id: string, mId: string) {
|
||||
try {
|
||||
const { data, error } = await supa
|
||||
@@ -228,8 +258,11 @@ async function fetchProductDetail(id: string, mId: string) {
|
||||
}
|
||||
|
||||
// Try to map category
|
||||
formData.value.category_id = data.category_id || ''
|
||||
categoryName.value = data.category_id ? '已绑定分类' : ''
|
||||
formData.value.category_id = data.category_id as string || ''
|
||||
if (formData.value.category_id) {
|
||||
const cat = categoryOptions.value.find((c: CategoryOption): boolean => c.id === formData.value.category_id)
|
||||
categoryName.value = cat ? cat.name : '未知分类'
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取详情失败', e)
|
||||
@@ -239,9 +272,9 @@ async function fetchProductDetail(id: string, mId: string) {
|
||||
|
||||
function onCategoryChange(e: any) {
|
||||
const v = e.detail.value as number
|
||||
categoryName.value = categories.value[v]
|
||||
// In a real project, this maps to an actual category ID, but for now we use a mock one
|
||||
formData.value.category_id = `cat_${v}`
|
||||
const selected = categoryOptions.value[v]
|
||||
categoryName.value = selected.name
|
||||
formData.value.category_id = selected.id
|
||||
}
|
||||
|
||||
function addTag() {
|
||||
@@ -305,16 +338,13 @@ async function uploadToSupabase(filePath: string): Promise<string> {
|
||||
|
||||
uni.showLoading({ title: '上传中...' })
|
||||
try {
|
||||
const { data, error } = await supa.storage.from('zhipao').upload(remotePath, filePath, {})
|
||||
if (error) {
|
||||
throw error
|
||||
const res = await supa.storage.from('zhipao').upload(remotePath, filePath, {})
|
||||
if (res.error != null) {
|
||||
throw res.error
|
||||
}
|
||||
const urlKey = typeof data === 'object' ? (data as any)['Key'] || (data as any)['path'] : ''
|
||||
// fallback logic, generally Supabase uses 'storage/v1/object/public/bucket/' + path
|
||||
if (urlKey) {
|
||||
return `https://ak3.oulog.com/storage/v1/object/public/${urlKey}`
|
||||
}
|
||||
return ''
|
||||
|
||||
return `${SUPA_URL}/storage/v1/object/public/zhipao/${remotePath}`
|
||||
|
||||
} catch (e: any) {
|
||||
console.error('上传文件失败:', e)
|
||||
throw new Error(e.message || '上传异常')
|
||||
|
||||
Reference in New Issue
Block a user