0.1.15 • Published 10 days ago

app-template-render v0.1.15

Weekly downloads
-
License
ISC
Repository
github
Last release
10 days ago

APP-TEMPLATE-RENDER

ATR是一个基于VUE3ElementPlus的纯前端渲染组件,也仅仅是一个前端渲染组件,可以做到通过相应的JSON生成简单的表单和视图,提高前端开发效率

为什么要做ATR

面对B端页面的开发,前端更多的是CV一下之前差不多的页面,改UI改接口,然后就没有然后了,小团队立马开发出一套低代码工具来实现项目阻力也比较大,所以就搞了个ATR来提高一点前端的开发效率

快速开始

安装

# NPM
npm install app-template-render

# Yarn
yarn add app-template-render

引入

import appTemplateRender from 'app-template-render'
import 'app-template-render/dist/appTempRender.css'

const app = createApp(App)
app.use(appTemplateRender)

视图渲染

<template>
  <div class="demo-list">
    <view-render
      :viewData="listViewData"
      :layouts="listViewConfig.layouts"
      :components="listViewConfig.components"
      :searchForm="searchFormConfig"
      @search="handleSearch"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      @change="handleValueChange"
    />
  </div>
</template>

<script>
export default {
  name: 'ListDemo',
  data() {
    return {
      // 查询表单配置
      searchFormConfig: searchForm,
      // 视图配置
      listViewConfig: listView,
      // 视图
      listViewData: {
      	// 列表数据
        list: [],
        // 查询表单
        search: {
          name: '',
          address: ''
        },
        // 分页数据
        pagination: {
          currentPage: 1,
          pageSize: 10,
          total: 0
        }
      }
    }
  },
  methods: {
    /**
     * 查询
     */
    handleSearch() {
      ...
    },
  	/**
     * 修改每页条数
     * @param {Number} size 每页条数
     */
    handleSizeChange(size) {
      ...
    },
    /**
     * 翻页
     * @param {Number} current 页数
     */
    handleCurrentChange(current) {
      ...
    }
  }
}
</script>

表单渲染

<template>
  <el-form
    class="demo-form"
    label-position="right"
    label-width="120px"
    :model="formData"
  >
    <form-render
      :formData="formData"
      :layouts="formTemp.layouts"
      :components="formTemp.components"
      @change="handleValueChange"
    />
  </el-form>
</template>

<script>
import appTemplateRender from 'app-template-render'

const { setValue } = appTemplateRender.Utils

export default {
  name: 'DemoForm',
  data() {
    return {
      // 表单配置
      formTemp,
      // 表单数据
      formData: {
        name: '',
        address: ''
      }
    }
  },
  methods: {
    /**
     * 修改值
     * @param {*} val 控件值
     * @param {String} id 控件id
     */
    handleValueChange(val, id) {
      const component = this.formTemp.components.find((item) => item.id === id)
      if (component) {
        setValue(this.formData, component.fieldPath, val)
      }
    }
  }
}
</script>

配置渲染模板

https://ctank.github.io/app-template-render/play

数据保存在localStorage

组件列表

表单组件(form-render)

需要写在<el-form>中,不含操作按钮

属性说明类型默认值
formData表单数据objectnull
layouts控件布局array[]
components控件集合array[]
方法说明参数
change配合工具方法 setValue 修改表单数据值, 控件ID
getValue获取数据,目前用于 多选下拉 控件通过接口获取选项{id: 控件ID, field: 字段, relateValue: 关联字段值}, 回调

视图组件(view-render)

属性说明类型默认值
viewData表单数据objectnull
layouts控件布局array[]
components控件集合array[]
searchForm查询表单配置form-rendernull
方法说明参数
change配合工具方法 setValue 修改表单数据值, 控件ID
getValue获取数据,目前用于 多选下拉 控件通过接口获取选项{id: 控件ID, field: 字段, relateValue: 关联字段值}, 回调
current-changecurrent-page 改变时触发新当前页
size-changepage-size 改变时触发新每页条数

工具方法

方法说明参数
setValue根据字段路径修改字段值data, path, value
cascader.areaDataCodeToText区域选择使用element-china-area-dataareaDataCodeToText = CodeToText
cascader.areaDataTextToCode区域选择使用element-china-area-dataareaDataTextToCode = TextToCode

问题整理

更新日志

0.1.16-alpha.3

10 days ago

0.1.16-alpha.1

10 months ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago