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[]
- }
- /**
- * CodeGen
- */
- export interface CodeGen {
- module: string
- controller: string
- model: string
- paginate: true
- schema: string
- }
- /**
- * generate
- */
- interface generate {
- schemaId: number
- structures: Structure[]
- codeGen: CodeGen
- }
- /**
- * useGenerateStore
- */
- export const useGenerateStore = defineStore('generateStore', {
- state(): generate {
- return {
- // schema id
- schemaId: 0,
- // structures
- structures: [] as Structure[],
- // codeGen
- 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
- },
- },
- // store actions
- actions: {
- // set schema
- setSchemaId(schemaId: any): void {
- this.schemaId = schemaId
- },
- // reset
- resetStructures(): void {
- this.structures = []
- },
- // filter structures
- filterStructures(field: string) {
- this.structures = this.structures.filter((s: Structure) => {
- return !(s.field === field)
- })
- },
- // init structure
- 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: [],
- }),
- )
- }
- })
- },
- },
- })
|