import Mitt from "../../../utils/mitt"; import {PageHeader, PageJsonObject, ReportForms} from "@/api/reports/report-query-center"; import {Ref, ref} from 'vue' import XEUtils from "xe-utils"; import {reportQueryCenterApi, saveTheFile} from "@/api/base-data/report-center"; import * as ElementPlus from "element-plus"; // @ts-ignore import XcComboGridV2 from "../../../components/xiao-chan/combo-grid/XcComboGridV2.vue"; // @ts-ignore import CyComboGrid from "@/components/cy/combo-grid/src/CyComboGrid.vue"; import {eachAndReturnList} from "@/utils/cyRefList"; import {copyStrFunc} from "@/utils/public"; // @ts-ignore import SystemDeptSelect from "@/components/system/dept-select/SystemDeptSelect.vue"; // @ts-ignore import SystemStaffSelect from '@/components/system/staff-select/SystemStaffSelect.vue' import {xcMessage} from "@/utils/xiaochan-element-plus"; import {CyJsonEditorDialog} from "@/components/cy/cy-monaco-editor/CyMonacoEditor"; interface TableData { data: any[], columns: any[] } export const ElAndXc = { ...ElementPlus, XcComboGridV2: XcComboGridV2, CyComboGrid: CyComboGrid, SystemDeptSelect: SystemDeptSelect, SystemStaffSelect: SystemStaffSelect } export const createFile = () => { const data: PageJsonObject = { header: [], submitUrl: '', params: {}, fromConfig: { labelWidth: '80px', inline: true }, paramsDefaultValue: {} } return JSON.stringify(data) } export interface PageHelpV2Mitt { changePageJson: (data: ReportForms) => void; componentReady: (data: any) => void doTest: (id: string, queryParam: any) => void; openMagic: () => void doTestResult: (data: any, id: string, url: string) => void; getCurrentPageData: () => any queryTree: () => void [key: string]: (...args: any[]) => any; } export interface ComponentBind { renderName: 'select' | 'boolean' | 'input' | 'number', label: string, selectData?: string[], defaultValue: string | number | boolean, on?: { [key: string]: string }, jsonType?: string } export const pageHelpV2Mitt = new Mitt(); export function capitalizeFirstLetter(str: string, prefix: string = '') { return prefix + str.charAt(0).toUpperCase() + str.slice(1); } export const REPORT_FOLDER = "8283a0956dd9455cbf77c6246306ec98" export function usePageStore(props: any) { const currentClickIndex = ref(-1) const pageData = ref({ header: [], params: {}, submitUrl: '', fromConfig: { inline: true, labelWidth: '120px' }, paramsDefaultValue: {} }) const tableBind = ref({ data: [], columns: [] }) function clearOnAndFunc() { XEUtils.arrayEach(pageData.value.header, (item: PageHeader) => { if (item.on) { for (let onKey in item.on) { const key = capitalizeFirstLetter(onKey, 'on') delete item.bind[key] } } if (item.func) { for (let funcKey in item.func) { delete item.bind[funcKey] } } }) } function handleSavaData() { const clone: PageJsonObject = XEUtils.clone(pageData.value, true) if (XEUtils.isEmpty(clone.paramsDefaultValue)) { defaultValue() xcMessage.error('没有设置默认值。') return } if (Object.keys(clone.paramsDefaultValue).length !== Object.keys(clone.params).length) { defaultValue() xcMessage.error('有新增的组件没有创建默认值。') return } clone.params = {} clone.header.forEach(item => { if (item.name === 'ElSelectV2') { item.bind.options = [] } if (item.name === 'CyComboGrid') { item.bind.data = [] } }) const data = pageHelpV2Mitt.emit('getCurrentPageData') data.pageJson = JSON.stringify(clone) saveTheFile(data).then(r => { pageHelpV2Mitt.emit('queryTree') }) } const bindData = ref() let changeCurrentBind: (item: any) => Promise | null = () => null function getColumns(data: Ref, tableName: 'dialogTableRef' | 'mainTableRef' = 'mainTableRef', copy = true) { if (data.value.columns.length === 0 && data.value.data.length > 0) { for (let key in data.value.data[0]) { if (key === '_X_ROW_KEY') { continue; } data.value.columns.push({ title: key, field: key, width: 120, }) } } else if (data.value.columns.length > 0) { const table = { mainTableRef: mainTableRef, dialogTableRef: dialogTableRef } const temp = eachAndReturnList(data.value.columns, (item) => { return { ...item, width: table[tableName].value.getColumnWidth(item.field) } }) copy && copyStrFunc(temp) } } const mainTableRef = ref() const dialogTableRef = ref() const compData = ref([]) async function addComponentRefresh() { compData.value = await reportQueryCenterApi('/reportCenterOption/components/addComponents') } const mutation = { setPageData: (data: PageJsonObject, currentIndex = -1) => { } } function defaultValue() { let temp: {}; const headerParams = {} pageData.value.header.forEach(item => { // @ts-ignore headerParams[item.key] = "" }) if (XEUtils.isEmpty(pageData.value.paramsDefaultValue)) { temp = headerParams } else { temp = {...headerParams, ...pageData.value.paramsDefaultValue}; } // @ts-ignore CyJsonEditorDialog(temp, {bodyWidth: '60%'}).then(res => { pageData.value.paramsDefaultValue = res.json }) } return { currentClickIndex, pageData, clearOnAndFunc, handleSavaData, tableBind, bindData, changeCurrentBind, mainTableRef, props, getColumns, dialogTableRef, compData, addComponentRefresh, defaultValue, mutation } } class HelperStore { Return = usePageStore({}) } type PageStore = HelperStore['Return'] export type {PageStore}