1 Star 0 Fork 0

seepine / crco

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT


Crco

一个配置驱动视图,基于Vue3和ArcoDesign的组件库,企业快速开发,个人外包必备

https://crco.seepine.com

vue3+ arco2.30+ MIT github star

一、快速入门

1. npm 安装

1.1 安装 crco

安装后请锁定版本号

npm i crco -D

1.2 安装@arco-design/web-vue

crco基于arco封装,因此必须安装,且建议安装后锁定版本号

npm i @arco-design/web-vue -D

1.3 安装 axios

crco使用axios发起请求,因此必须安装,若项目中自定义请求拦截,请将自定义的axios传给crco或赋值给window.axios

npm i axios

引入 crco

import { createApp } from 'vue'
import App from './App.vue'

import Crco from 'crco'
import 'crco/dist/index.css'
import './utils/axios'

createApp(App)
  .use(Crco, {
    axios // 如果有自定义拦截的话,可传给crco
  })
  .mount('#app')

二、例子

2.1 表单

form.jpg
<template>
  <c-form :option="option" @submit="handleSubmit" />
</template>
<script setup lang="ts">
  import { Message } from '@arco-design/web-vue'

  const option = {
    columns: [
      {
        name: '姓名',
        prop: 'fullName'
      },
      {
        name: '性别',
        prop: 'gender',
        type: 'radio',
        dicData: ['', '']
      },
      {
        name: '年龄',
        prop: 'age',
        type: 'number',
        onChange: (val, form) => {
          return new Promise((RES) => {
            console.log('触发年龄onChange', val, form)
            setTimeout(() => {
              RES({
                ...form,
                fullName: `姓名随年龄变化:${val}`
              })
            }, 1000)
          })
        }
      },
      {
        name: '生日',
        prop: 'birthday',
        type: 'date'
      },
      {
        name: '是否婚配',
        prop: 'isMarry',
        type: 'switch'
      },
      {
        name: '爱好',
        prop: 'hobby',
        type: 'select',
        dicData: [
          { value: 0, label: '唱歌' },
          { value: 1, label: '跳舞' },
          { value: 2, label: '打篮球' }
        ],
        onChange: (item, form) => {
          console.log('触发爱好onChange', item, form)
          return {
            ...form,
            fullName: `姓名随着爱好变化:${item.label}`
          }
        }
      },
      {
        name: '特长',
        prop: 'specialty',
        value: ['唱歌'],
        type: 'tag'
      },
      {
        name: '介绍',
        span: 24,
        prop: 'description',
        type: 'textarea'
      },
      {
        name: 'markdown介绍',
        span: 24,
        prop: 'mdDescription',
        type: 'md',
        onUpload: (e) => {
          return new Promise((RES, REJ) => {
            console.log(e.files)
            console.log(e.ctx.getValue())
            console.log(e.ctx.setValue(`${e.ctx.getValue()},新增的`))
            REJ(Error('上传失败'))
          })
        }
      }
    ]
  }

  const handleSubmit = (data: any, done: Function) => {
    Message.success(JSON.stringify(data))
    // 可防重提交
    setTimeout(() => {
      done()
    }, 1000)
  }
</script>

2.2 表格

table.jpg
<template>
  <c-table
    :option="option"
    @load="handleLoad"
    @add="handleAdd"
    @edit="handleEdit"
    @del="handleDel"
  ></c-table>
</template>
<script setup lang="ts">
  import { nextTick, ref } from 'vue'

  const option = {
    columns: [
      {
        name: '姓名',
        prop: 'fullName'
      },
      {
        name: '性别',
        prop: 'gender',
        type: 'radio',
        dicData: ['', '']
      },
      {
        name: '年龄',
        prop: 'age',
        type: 'number'
      },
      {
        name: '生日',
        prop: 'birthday',
        type: 'date',
        width: 120 // 可手动调整宽度
      },
      {
        name: '是否婚配',
        prop: 'isMarry',
        type: 'switch'
      },
      {
        name: '爱好',
        prop: 'hobby',
        type: 'select',
        dicData: [
          { value: 0, label: '唱歌' },
          { value: 1, label: '跳舞' },
          { value: 2, label: '打篮球' }
        ],
        onChange: (val, item, record) => {
          console.log('触发onChange', val, item, record)
          // eslint-disable-next-line no-param-reassign
          record.fullName = `姓名随着爱好变化:${item.label}`
          return record
        }
      }
    ]
  }
  const data = ref<Array<any>>([])
  for (let i = 0; i < 11; i += 1) {
    data.value.push({
      id: i,
      fullName: '张三',
      gender: '',
      age: 20 + i,
      birthday: '2000-11-19'
    })
  }

  const loadPage = (params: any, list: Array<any>) => {
    const size = params.size || 10
    const theCurrent = params.current && params.current > 0 ? params.current : 1
    const start = (theCurrent - 1) * size
    const end = theCurrent * size
    const total = list.length
    return {
      records: end <= total ? list.slice(start, end) : list.slice(start, total),
      total,
      size,
      current: theCurrent
    }
  }

  const handleLoad = (params: any, done: Function) => {
    console.log('load params:', params)
    nextTick(() => {
      setTimeout(() => {
        done(loadPage(params, data.value))
      }, 1000)
    })
  }

  const handleAdd = (record: any, done: Function) => {
    data.value.push(record)
    done()
    // done(false) 若调用后端失败,可done(false),表示添加失败
  }

  const handleEdit = (record: any, done: Function) => {
    // record.rowIndex 可以获取当前行的索引
    data.value[record.rowIndex] = record
    done()
  }
  const handleDel = (record: any, done: Function) => {
    data.value.splice(record.rowIndex, 1)
    done()
  }
</script>

2.3 更多

更多使用方式请查看文档 https://crco.seepine.com/

三、贡献代码

  1. Fork仓库,并克隆到本地
  2. 执行npm run pre安装依赖
  3. 修改代码后执行npm run commit提交代码
  4. 发起合并请求

四、特别感谢 JetBrains 对开源项目支持

JetBrains
MIT License Copyright (c) 2021 Bytedance, Inc. and its affiliates. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个配置驱动视图,基于Vue3和ArcoDesign的组件库,企业快速开发,个人外包必备 展开 收起
TypeScript 等 5 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/seepine/crco.git
git@gitee.com:seepine/crco.git
seepine
crco
crco
main

搜索帮助