import { ref } from 'vue' import { goDialog } from '@/utils' import { DialogEnum } from '@/enums/pluginEnum' import { ChartList } from '../../..' import { getConfigApi, deleteConfigApi } from '@/api/cloud/config.js' import router from '@/router' // 数据初始化 export const useDataListInit = () => { const list = ref([ // { // id: 1, // title: '物料1-假数据不可用', // release: true, // label: '官方案例' // }, // { // id: 2, // title: '物料2-假数据不可用', // release: false, // label: '官方案例' // }, // { // id: 3, // title: '物料3-假数据不可用', // release: false, // label: '官方案例' // }, // { // id: 4, // title: '物料4-假数据不可用', // release: false, // label: '官方案例' // }, // { // id: 5, // title: '物料5-假数据不可用', // release: false, // label: '官方案例' // } ]) const getDataList = async () => { const pathName = router.currentRoute.value.name const firstPath = window.location.pathname.split('/')[1] const getConfigList = async (datasource: string) => { const res = await getConfigApi({ application: 'config', datasource: 'config_service', name: 'all', param: { application: 'page_designer', datasource } }) return res.msg.map((item: any) => { return { id: item.name, ...JSON.parse(item.content), last_time: item.last_modify_time, c_id: item.id, type: datasource } }) } if (pathName === 'Project-My-Template') { // 租户模板 const templetes = await getConfigList('templete') list.value = templetes // 公共模板 linku if (firstPath === 'linku') { const publicTempletes = await getConfigList('public_templete') list.value = list.value.concat(publicTempletes) } } else { // 项目 list.value = await getConfigList(firstPath === 'linku' ? 'public_project' : 'project') } } // 删除 const deleteHandle = (cardData: any, index: number) => { goDialog({ type: DialogEnum.DELETE, promise: true, onPositiveCallback: () => new Promise(res => setTimeout(() => res(1), 1000)), promiseResCallback: async (e: any) => { await deleteConfigApi({ id: cardData.c_id, current_flag: 0 }) window.$message.success('删除成功') list.value.splice(index, 1) } }) } return { list, getDataList, deleteHandle } }