|
|
|
@ -1,63 +1,60 @@
|
|
|
|
|
import type { Ref } from 'vue' |
|
|
|
|
import { h } from 'vue' |
|
|
|
|
import type { Ref } from 'vue' |
|
|
|
|
import { Space, Tag } from 'ant-design-vue' |
|
|
|
|
import { createSharedComposable, useAsyncState } from '@vueuse/core' |
|
|
|
|
import type { BasicColumn, FormSchema } from '@/components/Table' |
|
|
|
|
import { useSystemEnumStore } from '@/store/modules/systemEnum' |
|
|
|
|
import { getAllProducts } from '@/api/product' |
|
|
|
|
import type { Product } from '@/api/product/types' |
|
|
|
|
|
|
|
|
|
const { getSystemEnums } = useSystemEnumStore() |
|
|
|
|
|
|
|
|
|
let productsCache: Pick<Product, 'id' | 'productName'>[] = [] |
|
|
|
|
async function getCachedProducts() { |
|
|
|
|
if (productsCache.length) |
|
|
|
|
return productsCache |
|
|
|
|
export const useSharedProducts = createSharedComposable(() => { |
|
|
|
|
const { state } = useAsyncState(getAllProducts, []) |
|
|
|
|
return { products: state } |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
return productsCache = await getAllProducts() |
|
|
|
|
} |
|
|
|
|
catch { |
|
|
|
|
return [] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
export function useColumns(): BasicColumn[] { |
|
|
|
|
const { getSystemEnums } = useSystemEnumStore() |
|
|
|
|
const { products } = useSharedProducts() |
|
|
|
|
|
|
|
|
|
export const columns: BasicColumn[] = [ |
|
|
|
|
{ |
|
|
|
|
title: '产品名称', |
|
|
|
|
dataIndex: 'productId', |
|
|
|
|
customRender({ value }) { |
|
|
|
|
return productsCache.find(item => item.id === value)?.productName |
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
title: '产品名称', |
|
|
|
|
dataIndex: 'productId', |
|
|
|
|
customRender({ value }) { |
|
|
|
|
return products.value.find(item => item.id === value)?.productName |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: '推送消息类型', |
|
|
|
|
dataIndex: 'messageType', |
|
|
|
|
customRender({ value }) { |
|
|
|
|
const values = value.split(',') |
|
|
|
|
const types = getSystemEnums('eSubscribeMessageType') |
|
|
|
|
return h( |
|
|
|
|
Space, |
|
|
|
|
() => types |
|
|
|
|
.map(item => values.includes(item.value.toString()) ? item.label : null) |
|
|
|
|
.filter(Boolean) |
|
|
|
|
.map(name => h(Tag, () => name)), |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
title: '推送消息类型', |
|
|
|
|
dataIndex: 'messageType', |
|
|
|
|
customRender({ value }) { |
|
|
|
|
const values = value.split(',') |
|
|
|
|
const types = getSystemEnums('eSubscribeMessageType') |
|
|
|
|
return h( |
|
|
|
|
Space, |
|
|
|
|
() => types |
|
|
|
|
.map(item => values.includes(item.value.toString()) ? item.label : null) |
|
|
|
|
.filter(Boolean) |
|
|
|
|
.map(name => h(Tag, () => name)), |
|
|
|
|
) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: '创建时间', |
|
|
|
|
dataIndex: 'createTime', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: '创建时间', |
|
|
|
|
dataIndex: 'createTime', |
|
|
|
|
}, |
|
|
|
|
] |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function useSearchFormSchema(productId?: string): FormSchema[] { |
|
|
|
|
const { products } = useSharedProducts() |
|
|
|
|
|
|
|
|
|
export function getSearchFormSchema(productId?: string): FormSchema[] { |
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
field: 'productId', |
|
|
|
|
label: '产品名称', |
|
|
|
|
component: 'ApiSelect', |
|
|
|
|
component: 'Select', |
|
|
|
|
componentProps: { |
|
|
|
|
api: getCachedProducts, |
|
|
|
|
options: products as any, |
|
|
|
|
showSearch: true, |
|
|
|
|
fieldNames: { |
|
|
|
|
label: 'productName', |
|
|
|
@ -72,7 +69,10 @@ export function getSearchFormSchema(productId?: string): FormSchema[] {
|
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getFormSchema(isUpload: Ref<boolean>): FormSchema[] { |
|
|
|
|
export function useFormSchema(isUpload: Ref<boolean>): FormSchema[] { |
|
|
|
|
const { products } = useSharedProducts() |
|
|
|
|
const { getSystemEnums } = useSystemEnumStore() |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
field: 'productId', |
|
|
|
@ -81,10 +81,12 @@ export function getFormSchema(isUpload: Ref<boolean>): FormSchema[] {
|
|
|
|
|
required: true, |
|
|
|
|
component: 'ApiSelect', |
|
|
|
|
componentProps: { |
|
|
|
|
api: getCachedProducts, |
|
|
|
|
valueField: 'id', |
|
|
|
|
labelField: 'productName', |
|
|
|
|
options: products as any, |
|
|
|
|
showSearch: true, |
|
|
|
|
fieldNames: { |
|
|
|
|
label: 'productName', |
|
|
|
|
value: 'id', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
dynamicDisabled: () => isUpload.value, |
|
|
|
|
}, |
|
|
|
|