<|start_filename|>plop-templates/page/prompt.js<|end_filename|>
const path = require('path')
const fs = require('fs')

function getFolder(path) {
    let components = []
    const files = fs.readdirSync(path)
    files.forEach(function(item) {
        let stat = fs.lstatSync(path + '/' + item)
        if (stat.isDirectory() === true && item != 'components') {
            components.push(path + '/' + item)
            components.push.apply(components, getFolder(path + '/' + item))
        }
    })
    return components
}

module.exports = {
    description: '创建页面',
    prompts: [
        {
            type: 'list',
            name: 'path',
            message: '请选择页面创建目录',
            choices: getFolder('src/views')
        },
        {
            type: 'input',
            name: 'name',
            message: '请输入文件名',
            validate: v => {
                if (!v || v.trim === '') {
                    return '文件名不能为空'
                } else {
                    return true
                }
            }
        }
    ],
    actions: data => {
        let relativePath = path.relative('src/views', data.path)
        const actions = [
            {
                type: 'add',
                path: `${data.path}/{{dotCase name}}.vue`,
                templateFile: 'plop-templates/page/index.hbs',
                data: {
                    componentName: `${relativePath} ${data.name}`
                }
            }
        ]
        return actions
    }
}


<|start_filename|>src/util/global.properties.js<|end_filename|>
import api from '@/api'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import Cookies from 'js-cookie'
import mitt from 'mitt'

export default function globalProperties(app) {
    // 请求
    app.config.globalProperties.$api = api
    dayjs.locale('zh-cn')
    app.config.globalProperties.$dayjs = dayjs
    app.config.globalProperties.$cookies = Cookies
    app.config.globalProperties.$eventBus = mitt()
}


<|start_filename|>src/main.js<|end_filename|>
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)

import router from './router'
app.use(router)

import { piniaStore } from './store'
app.use(piniaStore)

import globalProperties from '@/util/global.properties'
globalProperties(app)

// 加载 svg 图标
import 'virtual:svg-icons-register'

// 全局样式
import '@/assets/styles/globals.scss'

app.mount('#app')


<|start_filename|>vite/plugins/components.js<|end_filename|>
import components from 'unplugin-vue-components/vite'

export default function createComponents() {
    return components({
        dirs: ['src/components']
    })
}


<|start_filename|>vite/plugins/banner.js<|end_filename|>
import banner from 'vite-plugin-banner'

export default function createBanner() {
    return banner(`
/**
 * 由 Fantastic-template 提供技术支持
 * https://hooray.gitee.io/fantastic-template/
 * Powered by Fantastic-template
 * https://hooray.github.io/fantastic-template/
 */
    `)
}


<|start_filename|>src/store/modules/settings.js<|end_filename|>
import { defineStore } from 'pinia'
import { piniaStore } from '@/store'

export const useSettingsStore = defineStore(
    // 唯一ID
    'settings',
    {
        state: () => ({
            title: ''
        }),
        actions: {
            // 设置网页标题
            setTitle(title) {
                this.title = title
            }
        }
    }
)

export function useSettingsOutsideStore() {
    return useSettingsStore(piniaStore)
}


<|start_filename|>src/store/modules/example.js<|end_filename|>
import { defineStore } from 'pinia'
import { piniaStore } from '@/store'
import api from '@/api'

export const useExampleStore = defineStore(
    // 唯一ID
    'example',
    {
        state: () => ({
            news: []
        }),
        getters: {
            newsCount: state => {
                return state.news.length
            }
        },
        actions: {
            getNews() {
                api.get('/news/list', {
                    baseURL: '/mock/'
                }).then(res => {
                    this.news = res.data.list
                })
            },
            removeLast() {
                this.news.splice(this.news.length - 1, 1)
            }
        }
    }
)

export function useExampleOutsideStore() {
    return useExampleStore(piniaStore)
}
