123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import { defineStore } from 'pinia'
- export interface Structure {
- field: string
- label: string
- form_component: string
- list: boolean
- form: boolean
- search: boolean
- search_op: string
- validates: string[]
- }
- export interface CodeGen {
- module: string
- controller: string
- model: string
- paginate: true
- schema: string
- }
- /**
- * generate
- */
- interface generate {
- schemaId: number
- structures: Structure[]
- codeGen: CodeGen
- }
- export const useGenerateStore = defineStore('generateStore', {
- state(): generate {
- return {
-
- schemaId: 0,
-
- structures: [] as Structure[],
-
- codeGen: Object.assign({
- module: '',
- controller: '',
- model: '',
- paginate: true,
- schema: '',
- }),
- }
- },
- // store getters
- getters: {
- getSchemaId(): any {
- return this.schemaId
- },
- getStructures(): Structure[] {
- return this.structures
- },
- getCodeGen(): CodeGen {
- return this.codeGen
- },
- },
-
- actions: {
-
- setSchemaId(schemaId: any): void {
- this.schemaId = schemaId
- },
-
- resetStructures(): void {
- this.structures = []
- },
-
- filterStructures(field: string) {
- this.structures = this.structures.filter((s: Structure) => {
- return !(s.field === field)
- })
- },
-
- initStructures(fields: Array<any>): void {
- const unSupportFields = ['deleted_at', 'creator_id']
- fields.forEach(field => {
- if (!unSupportFields.includes(field.name)) {
- this.structures.push(
- Object.assign({
- field: field.name,
- label: '',
- form_component: 'input',
- list: true,
- form: true,
- search: false,
- search_op: '',
- validates: [],
- }),
- )
- }
- })
- },
- },
- })
|