123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- 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 {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<PageHelpV2Mitt>();
- 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<PageJsonObject>({
- 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
- }
- console.log(clone.paramsDefaultValue, clone.params)
- 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<any> | null = () => null
- function getColumns(data: Ref<TableData>, 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 = XEUtils.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}
|